From owner-p4-projects@FreeBSD.ORG Thu Aug 20 12:19:37 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7191D1065691; Thu, 20 Aug 2009 12:19:37 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1C73C106568C for ; Thu, 20 Aug 2009 12:19:37 +0000 (UTC) (envelope-from stas@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 0B2348FC65 for ; Thu, 20 Aug 2009 12:19:37 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n7KCJa9O026019 for ; Thu, 20 Aug 2009 12:19:36 GMT (envelope-from stas@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n7KCJa2M026017 for perforce@freebsd.org; Thu, 20 Aug 2009 12:19:36 GMT (envelope-from stas@freebsd.org) Date: Thu, 20 Aug 2009 12:19:36 GMT Message-Id: <200908201219.n7KCJa2M026017@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to stas@freebsd.org using -f From: Stanislav Sedov To: Perforce Change Reviews Cc: Subject: PERFORCE change 167531 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Aug 2009 12:19:37 -0000 http://perforce.freebsd.org/chv.cgi?CH=167531 Change 167531 by stas@stas_yandex on 2009/08/20 12:19:11 - Fix syscalls on amd64. Affected files ... .. //depot/projects/valgrind/coregrind/m_libcfile.c#9 edit .. //depot/projects/valgrind/coregrind/m_syscall.c#11 edit .. //depot/projects/valgrind/coregrind/m_syswrap/syscall-amd64-freebsd.S#7 edit .. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#34 edit .. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-main.c#16 edit .. //depot/projects/valgrind/include/pub_tool_basics.h#5 edit .. //depot/projects/valgrind/include/vki/vki-scnums-freebsd.h#4 edit Differences ... ==== //depot/projects/valgrind/coregrind/m_libcfile.c#9 (text+ko) ==== @@ -234,14 +234,13 @@ OffT VG_(lseek) ( Int fd, OffT offset, Int whence ) { -# if defined(VGO_linux) || defined(VGO_aix5) || defined(VGP_amd64_darwin) +# if defined(VGO_linux) || defined(VGO_aix5) || defined(VGP_amd64_darwin) || \ + defined(VGP_amd64_freebsd) SysRes res = VG_(do_syscall3)(__NR_lseek, fd, offset, whence); vg_assert(sizeof(OffT) == sizeof(Word)); -# elif defined(VGP_x86_darwin) +# elif defined(VGP_x86_darwin) || defined (VGP_x86_freebsd) SysRes res = VG_(do_syscall4)(__NR_lseek, fd, offset & 0xffffffff, offset >> 32, whence); -# elif defined(VGO_freebsd) - SysRes res = VG_(do_syscall4)(__NR_lseek, fd, 0, offset, whence); # else # error "Unknown plat" # endif ==== //depot/projects/valgrind/coregrind/m_syscall.c#11 (text+ko) ==== @@ -462,10 +462,6 @@ ); #elif defined(VGP_amd64_freebsd) -/* This is similar to amd64-linux, except that we have to deal with - 7 args potentially. (mmap takes 7) - */ -// AAA: fix 7th arg! extern UWord do_syscall_WRK ( UWord syscall_no, /* %rdi */ UWord a1, /* %rsi */ @@ -484,28 +480,32 @@ "do_syscall_WRK:\n" /* Convert function calling convention --> syscall calling convention */ +" pushq %rbp\n" +" movq %rsp, %rbp\n" " movq %rdi, %rax\n" /* syscall_no */ " movq %rsi, %rdi\n" /* a1 */ " movq %rdx, %rsi\n" /* a2 */ " movq %rcx, %rdx\n" /* a3 */ " movq %r8, %r10\n" /* a4 */ " movq %r9, %r8\n" /* a5 */ -" movq 8(%rsp), %r9\n" /* a6 last arg from stack */ -" movq 16(%rsp), %r11\n" /* a7 from stack */ -" movq 24(%rsp), %rcx\n" /* a8 from stack */ -" pushq %rcx\n" +" movq 16(%rbp), %r9\n" /* a6 last arg from stack, account for %rbp */ +" movq 24(%rbp), %r11\n" /* a7 from stack */ +" pushq %r11\n" +" movq 32(%rbp), %r11\n" /* a8 from stack */ " pushq %r11\n" " subq $8,%rsp\n" /* fake return addr */ " syscall\n" " jb 1f\n" -" addq $24,%rsp\n" -" movq 40(%rsp),%rsi\n" +" movq 48(%rbp),%rsi\n" " movq %rdx, (%rsi)\n" +" movq %rbp, %rsp\n" +" popq %rbp\n" " ret\n" "1:\n" -" addq $24,%rsp\n" -" movq 32(%rsp), %rsi\n" +" movq 40(%rbp), %rsi\n" " movl $1,(%rsi)\n" +" movq %rbp, %rsp\n" +" popq %rbp\n" " ret\n" ".previous\n" ); @@ -815,7 +815,7 @@ # elif defined(VGP_x86_freebsd) ULong val; - UInt err; + UInt err = 0; val = do_syscall_WRK(sysno, a1, a2, a3, a4, a5, a6, a7, a8, &err); return VG_(mk_SysRes_x86_freebsd)( (UInt)val, (UInt)(val>>32), err); @@ -823,10 +823,10 @@ # elif defined(VGP_amd64_freebsd) UWord val; UWord val2 = 0; - UInt err; + UInt err = 0; val = do_syscall_WRK(sysno, a1, a2, a3, a4, a5, a6, a7, a8, &err, &val2); - return VG_(mk_SysRes_amd64_freebsd)( val, val2, err); + return VG_(mk_SysRes_amd64_freebsd)( val, val2, err ? True : False); # elif defined(VGP_ppc32_linux) ULong ret = do_syscall_WRK(sysno,a1,a2,a3,a4,a5,a6); ==== //depot/projects/valgrind/coregrind/m_syswrap/syscall-amd64-freebsd.S#7 (text+ko) ==== @@ -108,7 +108,7 @@ movq OFFSET_amd64_RDI(%r11), %rdi movq OFFSET_amd64_RSI(%r11), %rsi movq OFFSET_amd64_RDX(%r11), %rdx - movq OFFSET_amd64_RCX(%r11), %r10 /* rcx is passed in r10 instead */ + movq OFFSET_amd64_R10(%r11), %r10 movq OFFSET_amd64_R8(%r11), %r8 movq OFFSET_amd64_R9(%r11), %r9 /* 2 stack parameters plus return address (ignored by syscall) */ @@ -138,7 +138,7 @@ movq %rdx, OFFSET_amd64_RDX(%r11) /* save back to RDX */ /* save carry flag to VEX */ - xor %rax, %rax + xorq %rax, %rax movb 0(%rsp), %al movq %rax, %rdi /* arg1 = new flag */ movq %r11, %rsi /* arg2 = vex state */ ==== //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#34 (text+ko) ==== @@ -3300,7 +3300,7 @@ BSDXY(__NR_getdirentries, sys_getdirentries), // 196 BSDX_(__NR_mmap, sys_mmap), // 197 // __syscall (handled specially) // 198 - BSDX_(__NR_lseek, sys_lseek), // 199 + BSDX_(__NR_lseek6, sys_lseek), // 199 BSDX_(__NR_truncate, sys_truncate), // 200 BSDX_(__NR_ftruncate, sys_ftruncate), // 201 @@ -3649,7 +3649,7 @@ BSDX_(__NR_pwrite7, sys_pwrite7), // 476 BSDX_(__NR_mmap7, sys_mmap7), // 477 - BSDX_(__NR_lseek7, sys_lseek7), // 478 + BSDX_(__NR_lseek, sys_lseek), // 478 BSDX_(__NR_truncate7, sys_truncate7), // 479 BSDX_(__NR_ftruncate7, sys_ftruncate7), // 480 ==== //depot/projects/valgrind/coregrind/m_syswrap/syswrap-main.c#16 (text+ko) ==== @@ -77,7 +77,7 @@ DARWIN: x86 eax +4 +8 +12 +16 +20 +24 +28 +32 edx:eax, eflags.c - amd64 rax rdi rsi rdx rcx r8 r9 +8 +16 rdx:rax, rflags.c + amd64 rax rdi rsi rdx r10 r8 r9 +8 +16 rdx:rax, rflags.c For x86-darwin and x86-freebsd, "+N" denotes "in memory at N(%esp)"; ditto amd64-darwin/amd64-freebsd. Apparently 0(%esp) is some kind of return address @@ -529,7 +529,7 @@ canonical->arg1 = gst->guest_RDI; canonical->arg2 = gst->guest_RSI; canonical->arg3 = gst->guest_RDX; - canonical->arg4 = gst->guest_RCX; + canonical->arg4 = gst->guest_R10; canonical->arg5 = gst->guest_R8; canonical->arg6 = gst->guest_R9; canonical->arg7 = stack[1]; @@ -538,7 +538,7 @@ // stack[0] is return address canonical->arg1 = gst->guest_RSI; canonical->arg2 = gst->guest_RDX; - canonical->arg3 = gst->guest_RCX; + canonical->arg3 = gst->guest_R10; canonical->arg4 = gst->guest_R8; canonical->arg5 = gst->guest_R9; canonical->arg6 = stack[1]; @@ -778,7 +778,7 @@ gst->guest_RDI = VG_FREEBSD_SYSNO_INDEX(canonical->sysno); gst->guest_RSI = canonical->arg1; gst->guest_RDX = canonical->arg2; - gst->guest_RCX = canonical->arg3; + gst->guest_R10 = canonical->arg3; gst->guest_R8 = canonical->arg4; gst->guest_R9 = canonical->arg5; stack[1] = canonical->arg6; @@ -790,7 +790,7 @@ gst->guest_RDI = VG_FREEBSD_SYSNO_INDEX(canonical->sysno); gst->guest_RSI = canonical->arg1; gst->guest_RDX = canonical->arg2; - gst->guest_RCX = canonical->arg3; + gst->guest_R10 = canonical->arg3; gst->guest_R8 = canonical->arg4; gst->guest_R9 = canonical->arg5; stack[1] = canonical->arg6; @@ -802,7 +802,7 @@ gst->guest_RDI = canonical->arg1; gst->guest_RSI = canonical->arg2; gst->guest_RDX = canonical->arg3; - gst->guest_RCX = canonical->arg4; + gst->guest_R10 = canonical->arg4; gst->guest_R8 = canonical->arg5; gst->guest_R9 = canonical->arg6; stack[1] = canonical->arg7; @@ -1268,7 +1268,7 @@ layout->o_arg1 = OFFSET_amd64_RDI; layout->o_arg2 = OFFSET_amd64_RSI; layout->o_arg3 = OFFSET_amd64_RDX; - layout->o_arg4 = OFFSET_amd64_RCX; + layout->o_arg4 = OFFSET_amd64_R10; layout->o_arg5 = OFFSET_amd64_R8; layout->o_arg6 = OFFSET_amd64_R9; layout->s_arg7 = sizeof(UWord) * 1; ==== //depot/projects/valgrind/include/pub_tool_basics.h#5 (text+ko) ==== @@ -117,7 +117,7 @@ #if defined(VGO_linux) || defined(VGO_aix5) typedef Word OffT; // 32 64 #elif defined(VGO_freebsd) -typedef Word OffT; // 32 64 +typedef Long OffT; // 64 64 #elif defined(VGO_darwin) typedef Long OffT; // 64 64 #else ==== //depot/projects/valgrind/include/vki/vki-scnums-freebsd.h#4 (text+ko) ==== @@ -176,7 +176,7 @@ #define __NR_getdirentries 196 #define __NR_mmap 197 #define __NR___syscall 198 -#define __NR_lseek 199 +#define __NR_lseek6 199 #define __NR_truncate 200 #define __NR_ftruncate 201 #define __NR___sysctl 202 @@ -388,7 +388,7 @@ #define __NR_pread7 475 #define __NR_pwrite7 476 #define __NR_mmap7 477 -#define __NR_lseek7 478 +#define __NR_lseek 478 #define __NR_truncate7 479 #define __NR_ftruncate7 480 #define __NR_thr_kill2 481