Date: Thu, 11 Mar 2010 16:24:48 -0500 From: Jung-uk Kim <jkim@FreeBSD.org> To: freebsd-hackers@freebsd.org Subject: [RFC] Saving the latest errno from syscalls. Message-ID: <201003111624.51018.jkim@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
--Boundary-00=_i+VmLqoe2tbAbnx
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
While I was debugging syscalls, I found a very useful field in struct
thread, td_errno. It seems it was added for dtrace but it is only
populated on amd64 and i386. Is the attached patch acceptable for
maintainers of other platforms?
Thanks,
Jung-uk Kim
--Boundary-00=_i+VmLqoe2tbAbnx
Content-Type: text/plain;
charset="iso-8859-1";
name="syscall.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="syscall.diff"
Index: sys/arm/arm/trap.c
===================================================================
--- sys/arm/arm/trap.c (revision 205027)
+++ sys/arm/arm/trap.c (working copy)
@@ -928,6 +928,10 @@ syscall(struct thread *td, trapframe_t *frame, u_i
AUDIT_SYSCALL_ENTER(code, td);
error = (*callp->sy_call)(td, args);
AUDIT_SYSCALL_EXIT(error, td);
+
+ /* Save the latest error return value. */
+ td->td_errno = error;
+
KASSERT(td->td_ar == NULL,
("returning from syscall with td_ar set!"));
}
Index: sys/powerpc/booke/trap.c
===================================================================
--- sys/powerpc/booke/trap.c (revision 205027)
+++ sys/powerpc/booke/trap.c (working copy)
@@ -413,6 +413,9 @@ syscall(struct trapframe *frame)
error = (*callp->sy_call)(td, params);
AUDIT_SYSCALL_EXIT(error, td);
+ /* Save the latest error return value. */
+ td->td_errno = error;
+
CTR3(KTR_SYSC, "syscall: p=%s %s ret=%x", p->p_comm,
syscallnames[code], td->td_retval[0]);
}
Index: sys/powerpc/aim/trap.c
===================================================================
--- sys/powerpc/aim/trap.c (revision 205027)
+++ sys/powerpc/aim/trap.c (working copy)
@@ -409,6 +409,9 @@ syscall(struct trapframe *frame)
error = (*callp->sy_call)(td, params);
AUDIT_SYSCALL_EXIT(error, td);
+ /* Save the latest error return value. */
+ td->td_errno = error;
+
CTR3(KTR_SYSC, "syscall: p=%s %s ret=%x", td->td_name,
syscallnames[code], td->td_retval[0]);
}
Index: sys/sparc64/sparc64/trap.c
===================================================================
--- sys/sparc64/sparc64/trap.c (revision 205027)
+++ sys/sparc64/sparc64/trap.c (working copy)
@@ -652,6 +652,9 @@ syscall(struct trapframe *tf)
error = (*sa.callp->sy_call)(td, sa.argp);
AUDIT_SYSCALL_EXIT(error, td);
+ /* Save the latest error return value. */
+ td->td_errno = error;
+
CTR5(KTR_SYSC, "syscall: p=%p error=%d %s return %#lx %#lx",
p, error, syscallnames[sa.code], td->td_retval[0],
td->td_retval[1]);
Index: sys/ia64/ia64/trap.c
===================================================================
--- sys/ia64/ia64/trap.c (revision 205027)
+++ sys/ia64/ia64/trap.c (working copy)
@@ -974,6 +974,9 @@ syscall(struct trapframe *tf)
error = (*callp->sy_call)(td, args);
AUDIT_SYSCALL_EXIT(error, td);
+ /* Save the latest error return value. */
+ td->td_errno = error;
+
cpu_set_syscall_retval(td, error);
td->td_syscalls++;
Index: sys/ia64/ia32/ia32_trap.c
===================================================================
--- sys/ia64/ia32/ia32_trap.c (revision 205027)
+++ sys/ia64/ia32/ia32_trap.c (working copy)
@@ -127,6 +127,9 @@ ia32_syscall(struct trapframe *tf)
AUDIT_SYSCALL_ENTER(code, td);
error = (*callp->sy_call)(td, args64);
AUDIT_SYSCALL_EXIT(error, td);
+
+ /* Save the latest error return value. */
+ td->td_errno = error;
}
switch (error) {
Index: sys/sun4v/sun4v/trap.c
===================================================================
--- sys/sun4v/sun4v/trap.c (revision 205027)
+++ sys/sun4v/sun4v/trap.c (working copy)
@@ -666,6 +666,9 @@ syscall(struct trapframe *tf)
error = (*callp->sy_call)(td, argp);
AUDIT_SYSCALL_EXIT(error, td);
+ /* Save the latest error return value. */
+ td->td_errno = error;
+
CTR5(KTR_SYSC, "syscall: p=%p error=%d %s return %#lx %#lx ", p,
error, syscallnames[code], td->td_retval[0],
td->td_retval[1]);
--Boundary-00=_i+VmLqoe2tbAbnx--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003111624.51018.jkim>
