Bug 501850 - FreeBSD syscall arguments 7 and 8 incorrect.
Summary: FreeBSD syscall arguments 7 and 8 incorrect.
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: 3.25 GIT
Platform: Other FreeBSD
: NOR normal
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-21 21:50 UTC by Paul Floyd
Modified: 2025-03-22 07:17 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Floyd 2025-03-21 21:50:58 UTC
This is a bit tricky as there are very few syscalls that use 7 or 8 arguments.

sendfile on x86 is definitely wrong.
In scalar there is

   SY(SYS_sendfile, x0-1, x0+2, x0+3, x0+4, x0+1, x0+1, x0+3); FAIL;

but ktrace shows that as

  9330 memcheck-x86-freebs CALL  sendfile(0xffffffff,0x2,0x3,0x4,0x1,0x1,0x3<SF_NODISKIO|SF_MNOWAIT>,0x1) 

(last 2 args reversed)

On amd64 ML_(do_syscall_for_client_WRK) and  VG(do_syscall)  are not consistent

ML_(do_syscall_for_client_WRK)

   movq  16(%r11), %rax
   pushq %rax
   movq  8(%r11), %rax
   pushq %rax

reading in decreasing order from r11


VG(do_syscall):

"      movq    24(%rbp), %r11\n" /* a7 from stack */
"      pushq  %r11\n"
"      movq    32(%rbp), %r11\n" /* a8 from stack */
"      pushq  %r11\n" 

reading in increasing order from rbp this time
Comment 1 Paul Floyd 2025-03-22 07:12:42 UTC
I wrote a little test based on scalar

#include "scalar.h"

int main(void)
{
   SY(SYS_sendfile, 1000, 2, 3, 4, 5, 6, 7, 8);

   return(0);
}

I can comment out the sfMayBlock - the syscall will fail so no question of blocking. That allows me to test both VG_(do_syscall) and 
ML_(do_syscall_for_client_WRK).

On arm64 I get the right arguments in ktrace in both cases.

On both x86 and amd64 ML_(do_syscall_for_client_WRK) (with sfMayBlock) both look OK.

On x86 VG_(do_syscall) (without sfMayBlock) looks OK

On amd64 VG_(do_syscall) (without sfMayBlock) looks bad

 74122 memcheck-amd64-free CALL  sendfile(0x3e8,0x2,0x3,0x4,0x5,0x6,0x8<><invalid>8)

That last argument should be 7.

If I reverse the stack offsets used for a7 and a8 in do_syscall_WRK then I get good results.
Comment 2 Paul Floyd 2025-03-22 07:17:32 UTC
No testcase. Not sure how to get Vallgrind to run under something like truss or ktrace.

commit 5334917c8e0e44e6a98657050a66bc28fa638165 (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Sat Mar 22 08:15:35 2025 +0100

    Bug 501850 - FreeBSD syscall arguments 7 and 8 incorrect.