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
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]);
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to