]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/i386/sigtramp.S
OpenSSL: update to 3.0.11
[FreeBSD/FreeBSD.git] / sys / i386 / i386 / sigtramp.S
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * William Jolitz.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *      from: @(#)locore.s      7.3 (Berkeley) 5/13/91
33  *
34  *              originally from: locore.s, by William F. Jolitz
35  *
36  *              Substantially rewritten by David Greenman, Rod Grimes,
37  *                      Bruce Evans, Wolfgang Solfrank, Poul-Henning Kamp
38  *                      and many others.
39  */
40
41 #include <sys/syscall.h>
42 #include <machine/asmacros.h>
43 #include <machine/psl.h>
44
45 #include "assym.inc"
46
47 /*
48  * Signal trampoline, copied to top of user stack
49  */
50 ENTRY(sigcode)
51         calll   *SIGF_HANDLER(%esp)
52         leal    SIGF_UC(%esp),%eax      /* get ucontext */
53         pushl   %eax
54         testl   $PSL_VM,UC_EFLAGS(%eax)
55         jne     1f
56         mov     UC_GS(%eax),%gs         /* restore %gs */
57 1:
58         movl    $SYS_sigreturn,%eax
59         pushl   %eax                    /* junk to fake return addr. */
60         int     $0x80                   /* enter kernel with args */
61                                         /* on stack */
62 1:
63         jmp     1b
64
65 #ifdef COMPAT_FREEBSD4
66         ALIGN_TEXT
67 freebsd4_sigcode:
68         calll   *SIGF_HANDLER(%esp)
69         leal    SIGF_UC4(%esp),%eax     /* get ucontext */
70         pushl   %eax
71         testl   $PSL_VM,UC4_EFLAGS(%eax)
72         jne     1f
73         mov     UC4_GS(%eax),%gs        /* restore %gs */
74 1:
75         movl    $344,%eax               /* 4.x SYS_sigreturn */
76         pushl   %eax                    /* junk to fake return addr. */
77         int     $0x80                   /* enter kernel with args */
78                                         /* on stack */
79 1:
80         jmp     1b
81 #endif
82
83 #ifdef COMPAT_43
84         ALIGN_TEXT
85 osigcode:
86         call    *SIGF_HANDLER(%esp)     /* call signal handler */
87         lea     SIGF_SC(%esp),%eax      /* get sigcontext */
88         pushl   %eax
89         testl   $PSL_VM,SC_PS(%eax)
90         jne     9f
91         mov     SC_GS(%eax),%gs         /* restore %gs */
92 9:
93         movl    $103,%eax               /* 3.x SYS_sigreturn */
94         pushl   %eax                    /* junk to fake return addr. */
95         int     $0x80                   /* enter kernel with args */
96 0:      jmp     0b
97
98 /*
99  * Our lcall $7,$0 handler remains in user mode (ring 3), since lcalls
100  * don't change the interrupt mask, so if this one went directly to the
101  * kernel then there would be a window with interrupts enabled in kernel
102  * mode, and all interrupt handlers would have to be almost as complicated
103  * as the NMI handler to support this.
104  *
105  * Instead, convert the lcall to an int0x80 call.  The kernel does most
106  * of the conversion by popping the lcall return values off the user
107  * stack and returning to them instead of to here, except when the
108  * conversion itself fails.  Adjusting the stack here is impossible for
109  * vfork() and harder for other syscalls.
110  */
111         ALIGN_TEXT
112 lcall_tramp:
113         int     $0x80
114 1:      jmp     1b
115
116 #endif /* COMPAT_43 */
117
118         ALIGN_TEXT
119 esigcode:
120
121         .data
122         .globl  szsigcode
123 szsigcode:
124         .long   esigcode-sigcode
125 #ifdef COMPAT_FREEBSD4
126         .globl  szfreebsd4_sigcode
127 szfreebsd4_sigcode:
128         .long   esigcode-freebsd4_sigcode
129 #endif
130 #ifdef COMPAT_43
131         .globl  szosigcode
132 szosigcode:
133         .long   esigcode-osigcode
134         .globl  sz_lcall_tramp
135 sz_lcall_tramp:
136         .long   esigcode-lcall_tramp
137 #endif