Deleted Added
full compact
ia32_syscall.c (160801) ia32_syscall.c (165303)
1/*-
2 * Copyright (C) 1994, David Greenman
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * the University of Utah, and William Jolitz.
8 *

--- 22 unchanged lines hidden (view full) ---

31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#include <sys/cdefs.h>
1/*-
2 * Copyright (C) 1994, David Greenman
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * the University of Utah, and William Jolitz.
8 *

--- 22 unchanged lines hidden (view full) ---

31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/sys/amd64/ia32/ia32_syscall.c 160801 2006-07-28 20:22:58Z jhb $");
39__FBSDID("$FreeBSD: head/sys/amd64/ia32/ia32_syscall.c 165303 2006-12-17 06:48:40Z kmacy $");
40
41/*
42 * 386 Trap and System call handling
43 */
44
45#include "opt_clock.h"
46#include "opt_cpu.h"
47#include "opt_isa.h"

--- 33 unchanged lines hidden (view full) ---

81#include <machine/intr_machdep.h>
82#include <machine/md_var.h>
83
84#define IDTVEC(name) __CONCAT(X,name)
85
86extern inthand_t IDTVEC(int0x80_syscall), IDTVEC(rsvd);
87extern const char *freebsd32_syscallnames[];
88
40
41/*
42 * 386 Trap and System call handling
43 */
44
45#include "opt_clock.h"
46#include "opt_cpu.h"
47#include "opt_isa.h"

--- 33 unchanged lines hidden (view full) ---

81#include <machine/intr_machdep.h>
82#include <machine/md_var.h>
83
84#define IDTVEC(name) __CONCAT(X,name)
85
86extern inthand_t IDTVEC(int0x80_syscall), IDTVEC(rsvd);
87extern const char *freebsd32_syscallnames[];
88
89void ia32_syscall(struct trapframe frame); /* Called from asm code */
89void ia32_syscall(struct trapframe *frame); /* Called from asm code */
90
91void
90
91void
92ia32_syscall(struct trapframe frame)
92ia32_syscall(struct trapframe *frame)
93{
94 caddr_t params;
95 int i;
96 struct sysent *callp;
97 struct thread *td = curthread;
98 struct proc *p = td->td_proc;
99 register_t orig_tf_rflags;
100 int error;

--- 5 unchanged lines hidden (view full) ---

106
107 /*
108 * note: PCPU_LAZY_INC() can only be used if we can afford
109 * occassional inaccuracy in the count.
110 */
111 PCPU_LAZY_INC(cnt.v_syscall);
112
113 td->td_pticks = 0;
93{
94 caddr_t params;
95 int i;
96 struct sysent *callp;
97 struct thread *td = curthread;
98 struct proc *p = td->td_proc;
99 register_t orig_tf_rflags;
100 int error;

--- 5 unchanged lines hidden (view full) ---

106
107 /*
108 * note: PCPU_LAZY_INC() can only be used if we can afford
109 * occassional inaccuracy in the count.
110 */
111 PCPU_LAZY_INC(cnt.v_syscall);
112
113 td->td_pticks = 0;
114 td->td_frame = &frame;
114 td->td_frame = frame;
115 if (td->td_ucred != p->p_ucred)
116 cred_update_thread(td);
115 if (td->td_ucred != p->p_ucred)
116 cred_update_thread(td);
117 params = (caddr_t)frame.tf_rsp + sizeof(u_int32_t);
118 code = frame.tf_rax;
119 orig_tf_rflags = frame.tf_rflags;
117 params = (caddr_t)frame->tf_rsp + sizeof(u_int32_t);
118 code = frame->tf_rax;
119 orig_tf_rflags = frame->tf_rflags;
120
121 if (p->p_sysent->sv_prepsyscall) {
122 /*
123 * The prep code is MP aware.
124 */
120
121 if (p->p_sysent->sv_prepsyscall) {
122 /*
123 * The prep code is MP aware.
124 */
125 (*p->p_sysent->sv_prepsyscall)(&frame, args, &code, &params);
125 (*p->p_sysent->sv_prepsyscall)(frame, args, &code, ¶ms);
126 } else {
127 /*
128 * Need to check if this is a 32 bit or 64 bit syscall.
129 * fuword is MP aware.
130 */
131 if (code == SYS_syscall) {
132 /*
133 * Code is first argument, followed by actual args.

--- 38 unchanged lines hidden (view full) ---

172 if (KTRPOINT(td, KTR_SYSCALL))
173 ktrsyscall(code, narg, args64);
174#endif
175 CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td,
176 td->td_proc->p_pid, td->td_proc->p_comm, code);
177
178 if (error == 0) {
179 td->td_retval[0] = 0;
126 } else {
127 /*
128 * Need to check if this is a 32 bit or 64 bit syscall.
129 * fuword is MP aware.
130 */
131 if (code == SYS_syscall) {
132 /*
133 * Code is first argument, followed by actual args.

--- 38 unchanged lines hidden (view full) ---

172 if (KTRPOINT(td, KTR_SYSCALL))
173 ktrsyscall(code, narg, args64);
174#endif
175 CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td,
176 td->td_proc->p_pid, td->td_proc->p_comm, code);
177
178 if (error == 0) {
179 td->td_retval[0] = 0;
180 td->td_retval[1] = frame.tf_rdx;
180 td->td_retval[1] = frame->tf_rdx;
181
182 STOPEVENT(p, S_SCE, narg);
183
184 PTRACESTOP_SC(p, td, S_PT_SCE);
185
186 AUDIT_SYSCALL_ENTER(code, td);
187 error = (*callp->sy_call)(td, args64);
188 AUDIT_SYSCALL_EXIT(error, td);
189 }
190
191 switch (error) {
192 case 0:
181
182 STOPEVENT(p, S_SCE, narg);
183
184 PTRACESTOP_SC(p, td, S_PT_SCE);
185
186 AUDIT_SYSCALL_ENTER(code, td);
187 error = (*callp->sy_call)(td, args64);
188 AUDIT_SYSCALL_EXIT(error, td);
189 }
190
191 switch (error) {
192 case 0:
193 frame.tf_rax = td->td_retval[0];
194 frame.tf_rdx = td->td_retval[1];
195 frame.tf_rflags &= ~PSL_C;
193 frame->tf_rax = td->td_retval[0];
194 frame->tf_rdx = td->td_retval[1];
195 frame->tf_rflags &= ~PSL_C;
196 break;
197
198 case ERESTART:
199 /*
200 * Reconstruct pc, assuming lcall $X,y is 7 bytes,
201 * int 0x80 is 2 bytes. We saved this in tf_err.
202 */
196 break;
197
198 case ERESTART:
199 /*
200 * Reconstruct pc, assuming lcall $X,y is 7 bytes,
201 * int 0x80 is 2 bytes. We saved this in tf_err.
202 */
203 frame.tf_rip -= frame.tf_err;
203 frame->tf_rip -= frame->tf_err;
204 break;
205
206 case EJUSTRETURN:
207 break;
208
209 default:
210 if (p->p_sysent->sv_errsize) {
211 if (error >= p->p_sysent->sv_errsize)
212 error = -1; /* XXX */
213 else
214 error = p->p_sysent->sv_errtbl[error];
215 }
204 break;
205
206 case EJUSTRETURN:
207 break;
208
209 default:
210 if (p->p_sysent->sv_errsize) {
211 if (error >= p->p_sysent->sv_errsize)
212 error = -1; /* XXX */
213 else
214 error = p->p_sysent->sv_errtbl[error];
215 }
216 frame.tf_rax = error;
217 frame.tf_rflags |= PSL_C;
216 frame->tf_rax = error;
217 frame->tf_rflags |= PSL_C;
218 break;
219 }
220
221 /*
222 * Traced syscall.
223 */
224 if (orig_tf_rflags & PSL_T) {
218 break;
219 }
220
221 /*
222 * Traced syscall.
223 */
224 if (orig_tf_rflags & PSL_T) {
225 frame.tf_rflags &= ~PSL_T;
225 frame->tf_rflags &= ~PSL_T;
226 ksiginfo_init_trap(&ksi);
227 ksi.ksi_signo = SIGTRAP;
228 ksi.ksi_code = TRAP_TRACE;
226 ksiginfo_init_trap(&ksi);
227 ksi.ksi_signo = SIGTRAP;
228 ksi.ksi_code = TRAP_TRACE;
229 ksi.ksi_addr = (void *)frame.tf_rip;
229 ksi.ksi_addr = (void *)frame->tf_rip;
230 trapsignal(td, &ksi);
231 }
232
233 /*
234 * Check for misbehavior.
235 */
236 WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning",
237 (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???");
238 KASSERT(td->td_critnest == 0,
239 ("System call %s returning in a critical section",
240 (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???"));
241 KASSERT(td->td_locks == 0,
242 ("System call %s returning with %d locks held",
243 (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???",
244 td->td_locks));
245
246 /*
247 * Handle reschedule and other end-of-syscall issues
248 */
230 trapsignal(td, &ksi);
231 }
232
233 /*
234 * Check for misbehavior.
235 */
236 WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning",
237 (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???");
238 KASSERT(td->td_critnest == 0,
239 ("System call %s returning in a critical section",
240 (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???"));
241 KASSERT(td->td_locks == 0,
242 ("System call %s returning with %d locks held",
243 (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???",
244 td->td_locks));
245
246 /*
247 * Handle reschedule and other end-of-syscall issues
248 */
249 userret(td, &frame);
249 userret(td, frame);
250
251 CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td,
252 td->td_proc->p_pid, td->td_proc->p_comm, code);
253#ifdef KTRACE
254 if (KTRPOINT(td, KTR_SYSRET))
255 ktrsysret(code, error, td->td_retval[0]);
256#endif
257

--- 27 unchanged lines hidden ---
250
251 CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td,
252 td->td_proc->p_pid, td->td_proc->p_comm, code);
253#ifdef KTRACE
254 if (KTRPOINT(td, KTR_SYSRET))
255 ktrsysret(code, error, td->td_retval[0]);
256#endif
257

--- 27 unchanged lines hidden ---