]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 511329 - Darwin and FreeBSD: Move setting of carry flag out of ML_(do_syscall_for...
authorPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 29 Oct 2025 20:30:35 +0000 (21:30 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 29 Oct 2025 20:32:33 +0000 (21:32 +0100)
This changeset includes the changes to ML_(do_syscall_for_client_WRK)
for the 2 supported Darwin platforms.

To come: remove SETC from guest state and OFFSET.

coregrind/m_syswrap/syscall-amd64-darwin.S
coregrind/m_syswrap/syscall-x86-darwin.S
coregrind/m_syswrap/syswrap-main.c

index 9abfd998f5367b4b4010f3e2fc0ec854da6db51c..456b4c84ceffd083ddb3cdbccb9683c9208a8515 100644 (file)
@@ -67,7 +67,8 @@
                                  void* guest_state,            // rsi
                                  const vki_sigset_t *sysmask,  // rdx
                                  const vki_sigset_t *postmask, // rcx
-                                 Int sigsetSzB)                // r8
+                                 Int sigsetSzB,                // r8
+                                 UChar *cflag)                 // r9
 
         Note that sigsetSzB is totally ignored (and irrelevant).
 */
@@ -90,6 +91,7 @@
        pushq   %rdx  // -24(%rbp)  sysmask
        pushq   %rcx  // -32(%rbp)  postmask
        pushq   %r8   // -40(%rbp)  sigsetSzB
+       pushq   %r9   // -48(%rbp)  cflag
        // stack is now aligned
        
 L_$0_1:        /* Even though we can't take a signal until the sigprocmask completes,
@@ -140,25 +142,16 @@ L_$0_3:   /* In the range [3, 4), the syscall result is in %rax,
           but hasn't been committed to RAX. */
 
        /* stack contents: 3 words for syscall above, plus our prologue */
-       setc    0(%rsp)         /* stash returned carry flag */
 
        movq    -16(%rbp), %r11 /* r11 = VexGuestAMD64State * */
        movq    %rax, OFFSET_amd64_RAX(%r11)    /* save back to RAX */
        movq    %rdx, OFFSET_amd64_RDX(%r11)    /* save back to RDX */
 
 .if $0 == UNIX
-       /* save carry flag to VEX */
-       xor     %rax, %rax
-       movb    0(%rsp), %al
-       movq    %rax, %rdi      /* arg1 = new flag */
-       movq    %r11, %rsi      /* arg2 = vex state */
-       addq    $$24, %rsp      /* remove syscall parameters */
-        movl    $$1, OFFSET_amd64_SETC(%r11)
-       call    _LibVEX_GuestAMD64_put_rflag_c
-        movq   -16(%rbp), %r11
-        movl    $$0, OFFSET_amd64_SETC(%r11)
+       movq    -48(%rbp), %rcx
+       setc    0(%rcx)                         /* save returned carry flag */
 .else
-       addq    $$24, %rsp      /* remove syscall parameters*/
+       addq    $$24, %rsp                      /* remove syscall parameters*/
 .endif
 
 L_$0_4:        /* Re-block signals.  If eip is in [4,5), then the syscall 
index 393cc8eb721fe6e393042fd7b42fc69da3dd6c6c..4ac1ef23a2ce6883059d0ed17cf0f50ccdfc6839 100644 (file)
@@ -67,7 +67,8 @@
                                  void* guest_state,            // ebp+12
                                  const vki_sigset_t *sysmask,  // ebp+16
                                  const vki_sigset_t *postmask, // ebp+20
-                                 Int sigsetSzB)                // ebp+24
+                                 Int sigsetSzB,                // ebp+24
+                                 UChar *cflag)                 // ebp+28
 
         Note that sigsetSzB is totally ignored (and irrelevant).
 */
@@ -145,22 +146,12 @@ L_$0_2:
 
 L_$0_3:        /* In the range [3, 4), the syscall result is in %eax and %edx and C,
            but hasn't been committed to the thread state. */
-       setc    0(%esp)                         /* stash returned carry flag */
        movl    12(%ebp), %ecx
        movl    %eax, OFFSET_x86_EAX(%ecx)      /* save EAX to vex */
        movl    %edx, OFFSET_x86_EDX(%ecx)      /* save EDX to vex */
 .if $0 == UNIX
-       /* UNIX: save carry flag to vex */
-       subl    $$12, %esp
-       movl    %ecx, 4(%esp)
-       movl    $$0, 0(%esp)
-       movb    12(%esp), %al
-       movb    %al, 0(%esp)
-        movl    $$1, OFFSET_x86_SETC(%ecx)
-       call    _LibVEX_GuestX86_put_eflag_c
-        movl   12(%ebp), %ecx
-        movl    $$0, OFFSET_x86_SETC(%ecx)
-       addl    $$12, %esp
+       movl     28(%ebp), %ecx
+       setc     0(%ecx)                        /* save returned carry flag */
 .endif
 
 L_$0_4:        /* Re-block signals.  If eip is in [4,5), then the syscall is
index 936124f4604d181ab42b5d678b8d95b3ba1fc308..64fa3c325b8b2c7e8e04af2bb420bb31420fecd2 100644 (file)
@@ -315,7 +315,8 @@ UWord ML_(do_syscall_for_client_unix_WRK)( Word syscallno,
                                            void* guest_state,
                                            const vki_sigset_t *syscall_mask,
                                            const vki_sigset_t *restore_mask,
-                                           Word sigsetSzB ); /* unused */
+                                           Word sigsetSzB, /* unused */
+                                           UChar* cflag );
 extern
 UWord ML_(do_syscall_for_client_mach_WRK)( Word syscallno, 
                                            void* guest_state,
@@ -375,7 +376,6 @@ void do_syscall_for_client ( Int syscallno,
    /* Save the carry flag. */
 #  if defined(VGP_amd64_freebsd)
    LibVEX_GuestAMD64_put_rflag_c(cflag, &tst->arch.vex);
-
 #  elif defined(VGP_arm64_freebsd)
    LibVEX_GuestARM64_put_nzcv_c(cflag, &tst->arch.vex);
 #  elif defined(VGP_x86_freebsd)
@@ -384,12 +384,23 @@ void do_syscall_for_client ( Int syscallno,
 #    error "Unknown platform"
 #  endif
 #  elif defined(VGO_darwin)
+   UChar cflag;
    switch (VG_DARWIN_SYSNO_CLASS(syscallno)) {
       case VG_DARWIN_SYSCALL_CLASS_UNIX:
          err = ML_(do_syscall_for_client_unix_WRK)(
                   VG_DARWIN_SYSNO_FOR_KERNEL(syscallno), &tst->arch.vex, 
-                  syscall_mask, &saved, 0/*unused:sigsetSzB*/
+                  syscall_mask, &saved, 0/*unused:sigsetSzB*/, &cflag
                );
+         /* Save the carry flag. */
+#  if defined(VGP_amd64_darwin)
+         LibVEX_GuestAMD64_put_rflag_c(cflag, &tst->arch.vex);
+#  elif defined(VGP_arm64_darwin)
+         LibVEX_GuestARM64_put_nzcv_c(cflag, &tst->arch.vex);
+#  elif defined(VGP_x86_darwin)
+         LibVEX_GuestX86_put_eflag_c(cflag, &tst->arch.vex);
+#  else
+#    error "Unknown platform"
+#  endif
          break;
       case VG_DARWIN_SYSCALL_CLASS_MACH:
          err = ML_(do_syscall_for_client_mach_WRK)(