R32(esi, si);
        R32(ebp, bp);
        R32(eax, ax);
-       R32(orig_eax, orig_ax);
        R32(eip, ip);
        R32(esp, sp);
 
+       case offsetof(struct user32, regs.orig_eax):
+               /*
+                * Sign-extend the value so that orig_eax = -1
+                * causes (long)orig_ax < 0 tests to fire correctly.
+                */
+               regs->orig_ax = (long) (s32) value;
+               break;
+
        case offsetof(struct user32, regs.eflags):
                return set_flags(child, value);
 
 
        return -EFAULT;
 }
 
+/*
+ * Return -1L or the syscall number that @regs is executing.
+ */
+static long current_syscall(struct pt_regs *regs)
+{
+       /*
+        * We always sign-extend a -1 value being set here,
+        * so this is always either -1L or a syscall number.
+        */
+       return regs->orig_ax;
+}
+
+/*
+ * Return a value that is -EFOO if the system call in @regs->orig_ax
+ * returned an error.  This only works for @regs from @current.
+ */
+static long current_syscall_ret(struct pt_regs *regs)
+{
+#ifdef CONFIG_IA32_EMULATION
+       if (test_thread_flag(TIF_IA32))
+               /*
+                * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
+                * and will match correctly in comparisons.
+                */
+               return (int) regs->ax;
+#endif
+       return regs->ax;
+}
+
 /*
  * OK, we're invoking a handler
  */    
 #endif
 
        /* Are we from a system call? */
-       if ((long)regs->orig_ax >= 0) {
+       if (current_syscall(regs) >= 0) {
                /* If so, check system call restarting.. */
-               switch (regs->ax) {
+               switch (current_syscall_ret(regs)) {
                        case -ERESTART_RESTARTBLOCK:
                        case -ERESTARTNOHAND:
                                regs->ax = -EINTR;
        }
 
        /* Did we come from a system call? */
-       if ((long)regs->orig_ax >= 0) {
+       if (current_syscall(regs) >= 0) {
                /* Restart the system call - no handlers present */
-               long res = regs->ax;
-               switch (res) {
+               switch (current_syscall_ret(regs)) {
                case -ERESTARTNOHAND:
                case -ERESTARTSYS:
                case -ERESTARTNOINTR: