PERFORCE change 152065 for review
Peter Wemm
peter at FreeBSD.org
Mon Oct 27 22:59:49 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=152065
Change 152065 by peter at peter_overcee on 2008/10/27 22:59:25
Initial update to get this to compile/link in amd64 on 8.x
Affected files ...
.. //depot/projects/valgrind/Makefile.am#6 edit
.. //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-freebsd.c#6 edit
.. //depot/projects/valgrind/coregrind/m_debuginfo/debuginfo.c#5 edit
.. //depot/projects/valgrind/coregrind/m_machine.c#5 edit
.. //depot/projects/valgrind/coregrind/m_sigframe/sigframe-amd64-freebsd.c#2 edit
.. //depot/projects/valgrind/coregrind/m_syswrap/syscall-amd64-freebsd.S#2 edit
.. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-amd64-freebsd.c#3 edit
.. //depot/projects/valgrind/include/vki/vki-amd64-freebsd.h#2 edit
Differences ...
==== //depot/projects/valgrind/Makefile.am#6 (text+ko) ====
@@ -221,9 +221,9 @@
valt_load_address_amd64_freebsd.lds: Makefile
$(CC) -m64 -Wl,--verbose -nostdlib 2>&1 | sed \
- -e '1,/^=====+$$/d' \
- -e '/^=====+$$/d' \
- -e '/\. = 0x[0-9A-Fa-f]+ \+ SIZEOF_HEADERS/s/0x[0-9A-Fa-f]+/valt_load_address/g' > $@ \
+ -e '1,/^=====\+$$/d' \
+ -e '/^=====\+$$/d' \
+ -e '/\. = 0x[0-9A-Fa-f]\+ + SIZEOF_HEADERS/s/0x[0-9A-Fa-f]\+/valt_load_address/g' > $@ \
|| rm -f $@
valt_load_address_x86_linux.lds: Makefile
==== //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-freebsd.c#6 (text+ko) ====
@@ -358,7 +358,7 @@
Int i;
/* Callback function for parsing map */
- static void get_name_for_addr_callback(Addr addr, SizeT len, UInt prot,
+ void get_name_for_addr_callback(Addr addr, SizeT len, UInt prot,
ULong dev, ULong ino, ULong offset,
const UChar* filename )
{
==== //depot/projects/valgrind/coregrind/m_debuginfo/debuginfo.c#5 (text+ko) ====
@@ -647,7 +647,7 @@
# if defined(VGP_x86_linux) || defined(VGP_x86_freebsd)
is_rx_map = seg->hasR && seg->hasX;
is_rw_map = seg->hasR && seg->hasW;
-# elif defined(VGP_amd64_linux) \
+# elif defined(VGP_amd64_linux) || defined(VGP_amd64_freebsd) \
|| defined(VGP_ppc32_linux) || defined(VGP_ppc64_linux)
is_rx_map = seg->hasR && seg->hasX && !seg->hasW;
is_rw_map = seg->hasR && seg->hasW && !seg->hasX;
==== //depot/projects/valgrind/coregrind/m_machine.c#5 (text+ko) ====
@@ -104,6 +104,10 @@
VG_(threads)[tid].arch.vex_shadow1.guest_EAX = s1res;
VG_(threads)[tid].arch.vex_shadow2.guest_EAX = s2res;
/* QQQ: this is very incomplete. EDX and EFL are affected */
+# elif defined(VGP_amd64_freebsd)
+ VG_(threads)[tid].arch.vex_shadow1.guest_RAX = s1res;
+ VG_(threads)[tid].arch.vex_shadow2.guest_RAX = s2res;
+ /* QQQ: this is very incomplete. EDX and EFL are affected */
# else
# error "Unknown plat"
# endif
==== //depot/projects/valgrind/coregrind/m_sigframe/sigframe-amd64-freebsd.c#2 (text+ko) ====
@@ -30,6 +30,7 @@
*/
#include "pub_core_basics.h"
+#include "pub_core_vki.h"
#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
@@ -37,10 +38,10 @@
#include "pub_core_libcprint.h"
#include "pub_core_machine.h"
#include "pub_core_options.h"
-#include "pub_core_sigframe.h"
#include "pub_core_signals.h"
#include "pub_core_tooliface.h"
#include "pub_core_trampoline.h"
+#include "pub_core_sigframe.h" /* self */
/* This module creates and removes signal frames for signal deliveries
@@ -93,7 +94,8 @@
/* XXX This is wrong. Surely we should store the shadow values
into the shadow memory behind the actual values? */
- VexGuestAMD64State vex_shadow;
+ VexGuestAMD64State vex_shadow1;
+ VexGuestAMD64State vex_shadow2;
/* HACK ALERT */
VexGuestAMD64State vex;
@@ -382,7 +384,7 @@
static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
{
ThreadId tid = tst->tid;
- NSegment *stackseg = NULL;
+ const NSegment *stackseg = NULL;
if (VG_(extend_stack)(addr, tst->client_stack_szB)) {
stackseg = VG_(am_find_nsegment)(addr);
@@ -413,7 +415,7 @@
/* For tracking memory events, indicate the entire frame has been
allocated. */
VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
- size + VG_STACK_REDZONE_SZB );
+ size + VG_STACK_REDZONE_SZB, tid );
return True;
}
@@ -429,7 +431,8 @@
{
frame->sigNo_private = sigNo;
frame->magicPI = 0x31415927;
- frame->vex_shadow = tst->arch.vex_shadow;
+ frame->vex_shadow1 = tst->arch.vex_shadow1;
+ frame->vex_shadow2 = tst->arch.vex_shadow2;
/* HACK ALERT */
frame->vex = tst->arch.vex;
/* end HACK ALERT */
@@ -492,6 +495,7 @@
void VG_(sigframe_create)( ThreadId tid,
Addr rsp_top_of_frame,
const vki_siginfo_t *siginfo,
+ const struct vki_ucontext *uc,
void *handler,
UInt flags,
const vki_sigset_t *mask,
@@ -547,7 +551,8 @@
}
tst->sig_mask = frame->mask;
tst->tmp_sig_mask = frame->mask;
- tst->arch.vex_shadow = frame->vex_shadow;
+ tst->arch.vex_shadow1 = frame->vex_shadow1;
+ tst->arch.vex_shadow2 = frame->vex_shadow2;
/* HACK ALERT */
tst->arch.vex = frame->vex;
/* end HACK ALERT */
==== //depot/projects/valgrind/coregrind/m_syswrap/syscall-amd64-freebsd.S#2 (text+ko) ====
@@ -29,7 +29,7 @@
*/
#include "pub_core_basics_asm.h"
-#include "vki_unistd.h"
+#include "pub_core_vkiscnums.h"
#include "libvex_guest_offsets.h"
==== //depot/projects/valgrind/coregrind/m_syswrap/syswrap-amd64-freebsd.c#3 (text+ko) ====
@@ -34,6 +34,8 @@
*/
#include "pub_core_basics.h"
+#include "pub_core_vki.h"
+#include "pub_core_vkiscnums.h"
#include "pub_core_threadstate.h"
#include "pub_core_debuginfo.h" // VG_(di_notify_mmap)
#include "pub_core_aspacemgr.h"
@@ -43,6 +45,7 @@
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_libcsignal.h"
+#include "pub_core_machine.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_scheduler.h"
@@ -51,14 +54,13 @@
#include "pub_core_syscall.h"
#include "pub_core_syswrap.h"
#include "pub_core_tooliface.h"
+#include "pub_core_stacks.h" // VG_(register_stack)
#include "priv_types_n_macros.h"
#include "priv_syswrap-generic.h" /* for decls of generic wrappers */
#include "priv_syswrap-freebsd.h" /* for decls of freebsd-ish wrappers */
#include "priv_syswrap-main.h"
-#include "vki_unistd.h" /* for the __NR_* constants */
-
/* Simulate C-style return values for pipe(2). This does not belong
here at all, it should be in m_libcfile.c.
*/
@@ -217,7 +219,7 @@
{
SysRes r;
- PRINT("sys_mmap ( %p, %lu, %d, %d, %d, pad%d, 0x%lx)",
+ PRINT("sys_mmap ( %#lx, %lu, %ld, %ld, %ld, pad%ld, 0x%lx)",
ARG1, (UWord)ARG2, ARG3, ARG4, ARG5, ARG6, ARG7 );
PRE_REG_READ7(long, "mmap",
char *, addr, unsigned long, len, int, prot, int, flags,
@@ -232,7 +234,7 @@
{
SysRes r;
- PRINT("sys_mmap ( %p, %lu, %d, %d, %d, 0x%lx)",
+ PRINT("sys_mmap ( %#lx, %lu, %ld, %ld, %ld, 0x%lx)",
ARG1, (UWord)ARG2, ARG3, ARG4, ARG5, ARG6 );
PRE_REG_READ6(long, "mmap",
char *, addr, unsigned long, len, int, prot, int, flags,
@@ -244,7 +246,7 @@
PRE(sys_lseek)
{
- PRINT("sys_lseek ( %d, 0x%x, %p, %d )", ARG1,ARG3,ARG4);
+ PRINT("sys_lseek ( %ld, 0x%lx, %#lx, %ld )", ARG1,ARG2,ARG3,ARG4);
PRE_REG_READ4(long, "lseek",
unsigned int, fd, int, pad, unsigned long, offset,
unsigned int, whence);
@@ -252,7 +254,7 @@
PRE(sys_lseek7)
{
- PRINT("sys_lseek ( %d, 0x%lx, %d )", ARG1,ARG2,ARG3);
+ PRINT("sys_lseek ( %ld, 0x%lx, %ld )", ARG1,ARG2,ARG3);
PRE_REG_READ3(long, "lseek",
unsigned int, fd, unsigned long, offset,
unsigned int, whence);
@@ -261,7 +263,7 @@
PRE(sys_pread)
{
*flags |= SfMayBlock;
- PRINT("sys_read ( %d, %p, %lu, %lu, %lu )", ARG1, ARG2, ARG3, ARG5);
+ PRINT("sys_read ( %ld, %#lx, %lu, %lu, %lu )", ARG1, ARG2, ARG3, ARG4, ARG5);
PRE_REG_READ5(ssize_t, "read",
unsigned int, fd, char *, buf, vki_size_t, count,
int, pad, unsigned long, off);
@@ -281,7 +283,7 @@
PRE(sys_pread7)
{
*flags |= SfMayBlock;
- PRINT("sys_read ( %d, %p, %lu, %lu, %lu )", ARG1, ARG2, ARG3, ARG4);
+ PRINT("sys_read ( %ld, %#lx, %lu, %lu )", ARG1, ARG2, ARG3, ARG4);
PRE_REG_READ4(ssize_t, "read",
unsigned int, fd, char *, buf, vki_size_t, count,
unsigned long, off);
@@ -302,7 +304,7 @@
{
Bool ok;
*flags |= SfMayBlock;
- PRINT("sys_write ( %d, %p, %lu, %lu, %lu )", ARG1, ARG2, ARG3, ARG5);
+ PRINT("sys_write ( %ld, %#lx, %lu, %lu, %lu )", ARG1, ARG2, ARG3, ARG4, ARG5);
PRE_REG_READ5(ssize_t, "write",
unsigned int, fd, const char *, buf, vki_size_t, count,
int, pad, unsigned long, off);
@@ -322,7 +324,7 @@
{
Bool ok;
*flags |= SfMayBlock;
- PRINT("sys_write ( %d, %p, %lu, %lu )", ARG1, ARG2, ARG3, ARG4);
+ PRINT("sys_write ( %ld, %#lx, %lu, %lu )", ARG1, ARG2, ARG3, ARG4);
PRE_REG_READ4(ssize_t, "write",
unsigned int, fd, const char *, buf, vki_size_t, count,
unsigned long, off);
@@ -341,7 +343,7 @@
PRE(sys_ftruncate)
{
*flags |= SfMayBlock;
- PRINT("sys_ftruncate ( %d, %lu )", ARG1,ARG3);
+ PRINT("sys_ftruncate ( %ld, %lu )", ARG1,ARG3);
PRE_REG_READ3(long, "ftruncate", unsigned int, fd, int, pad,
unsigned int, length);
}
@@ -349,7 +351,7 @@
PRE(sys_ftruncate7)
{
*flags |= SfMayBlock;
- PRINT("sys_ftruncate ( %d, %lu )", ARG1,ARG2);
+ PRINT("sys_ftruncate ( %ld, %lu )", ARG1,ARG2);
PRE_REG_READ2(long, "ftruncate", unsigned int, fd,
unsigned long, length);
}
@@ -357,7 +359,7 @@
PRE(sys_truncate)
{
*flags |= SfMayBlock;
- PRINT("sys_truncate ( %p(%s), %lu )", ARG1,ARG1,ARG3);
+ PRINT("sys_truncate ( %#lx(%s), %lu )", ARG1,(char *)ARG1,ARG3);
PRE_REG_READ3(long, "truncate",
const char *, path, int, pad, unsigned int, length);
PRE_MEM_RASCIIZ( "truncate(path)", ARG1 );
@@ -366,12 +368,49 @@
PRE(sys_truncate7)
{
*flags |= SfMayBlock;
- PRINT("sys_truncate ( %p(%s), %lu )", ARG1,ARG1,ARG2);
+ PRINT("sys_truncate ( %#lx(%s), %lu )", ARG1,(char *)ARG1,ARG2);
PRE_REG_READ2(long, "truncate",
const char *, path, unsigned long, length);
PRE_MEM_RASCIIZ( "truncate(path)", ARG1 );
}
+PRE(sys_sysarch)
+{
+ ThreadState *tst;
+ void **p;
+
+ PRINT("sys_sysarch ( %ld, %#lx )", ARG1, ARG2);
+ PRE_REG_READ2(int, "sysarch",
+ int, number, void *, args);
+ switch (ARG1) {
+ case VKI_AMD64_SET_FSBASE:
+ PRINT("sys_amd64_set_fsbase ( %#lx )", ARG2);
+ PRE_REG_READ1(long, "amd64_set_fsbase", void *, base)
+
+ /* On FreeBSD, the syscall loads the %gs selector for us, so do it now. */
+ tst = VG_(get_ThreadState)(tid);
+ p = (void**)ARG2;
+ tst->arch.vex.guest_FS_ZERO = *p;
+ /* "do" the syscall ourselves; the kernel never sees it */
+ SET_STATUS_Success2(*p, tst->arch.vex.guest_RDX );
+
+ break;
+ case VKI_AMD64_GET_FSBASE:
+ PRINT("sys_amd64_get_fsbase ( %#lx )", ARG2);
+ PRE_REG_READ1(int, "amd64_get_fsbase", void *, basep)
+ PRE_MEM_WRITE( "amd64_get_fsbase(basep)", ARG2, sizeof(void *) );
+
+ /* "do" the syscall ourselves; the kernel never sees it */
+ SET_STATUS_Success2( tst->arch.vex.guest_FS_ZERO, tst->arch.vex.guest_RDX );
+ POST_MEM_WRITE( ARG2, sizeof(void *) );
+ break;
+ default:
+ VG_(message) (Vg_UserMsg, "unhandled sysarch cmd %ld", ARG1);
+ VG_(unimplemented) ("unhandled sysarch cmd");
+ break;
+ }
+}
+
#undef PRE
#undef POST
==== //depot/projects/valgrind/include/vki/vki-amd64-freebsd.h#2 (text+ko) ====
@@ -42,6 +42,8 @@
/* PAGE_SHIFT determines the page size */
#define VKI_PAGE_SHIFT 12
#define VKI_PAGE_SIZE (1UL << VKI_PAGE_SHIFT)
+#define VKI_MAX_PAGE_SHIFT VKI_PAGE_SHIFT
+#define VKI_MAX_PAGE_SIZE VKI_PAGE_SIZE
//----------------------------------------------------------------------
// From sys/signal.h
@@ -135,43 +137,18 @@
// From linux-2.6.8.1/include/asm-i386/sigcontext.h
//----------------------------------------------------------------------
-/* QQQ not right */
-struct _vki_fpreg {
- unsigned short significand[4];
- unsigned short exponent;
-};
-
-/* QQQ not right */
-struct _vki_fpxreg {
- unsigned short significand[4];
- unsigned short exponent;
- unsigned short padding[3];
-};
-
-struct _vki_xmmreg {
- unsigned long element[4];
-};
-
struct _vki_fpstate {
- /* Regular FPU environment */
- unsigned long cw;
- unsigned long sw;
- unsigned long tag;
- unsigned long ipoff;
- unsigned long cssel;
- unsigned long dataoff;
- unsigned long datasel;
- struct _vki_fpreg _st[8];
- unsigned short status;
- unsigned short magic; /* 0xffff = regular FPU data only */
-
- /* FXSR FPU environment */
- unsigned long _fxsr_env[6]; /* FXSR FPU env is ignored */
- unsigned long mxcsr;
- unsigned long reserved;
- struct _vki_fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */
- struct _vki_xmmreg _xmm[8];
- unsigned long padding[56];
+ unsigned short cwd;
+ unsigned short swd;
+ unsigned short twd;
+ unsigned short fop;
+ unsigned long rip;
+ unsigned long rdp;
+ unsigned int mxcsr;
+ unsigned int mxcsr_mask;
+ unsigned int st_space[32]; /* 8*16 bytes for each FP-reg */
+ unsigned int xmm_space[64]; /* 16*16 bytes for each XMM-reg */
+ unsigned int reserved2[24];
};
struct vki_sigcontext {
@@ -208,38 +185,23 @@
long spare2[8];
};
-#if 0
//----------------------------------------------------------------------
// From linux-2.6.8.1/include/asm-i386/user.h
//----------------------------------------------------------------------
struct vki_user_i387_struct {
- long cwd;
- long swd;
- long twd;
- long fip;
- long fcs;
- long foo;
- long fos;
- long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
-};
-
-struct vki_user_fxsr_struct {
unsigned short cwd;
unsigned short swd;
unsigned short twd;
unsigned short fop;
- long fip;
- long fcs;
- long foo;
- long fos;
- long mxcsr;
- long reserved;
- long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
- long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
- long padding[56];
+ unsigned long fip;
+ unsigned long fdp;
+ unsigned int mxcsr;
+ unsigned int mxcsr_mask;
+ unsigned int st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
+ unsigned int xmm_space[64]; /* 16*16 bytes for each XMM-reg = 128 bytes */
+ unsigned int padding[24];
};
-#endif
/* AAA check that this linux layout is appropriate */
@@ -252,7 +214,6 @@
unsigned long ds,es,fs,gs;
};
-#if 0
//----------------------------------------------------------------------
// From linux-2.6.8.1/include/asm-i386/elf.h
//----------------------------------------------------------------------
@@ -263,10 +224,8 @@
typedef vki_elf_greg_t vki_elf_gregset_t[VKI_ELF_NGREG];
typedef struct vki_user_i387_struct vki_elf_fpregset_t;
-typedef struct vki_user_fxsr_struct vki_elf_fpxregset_t;
#define VKI_AT_SYSINFO 32
-#endif
//----------------------------------------------------------------------
// From linux-2.6.8.1/include/asm-i386/ucontext.h
@@ -323,39 +282,6 @@
int __spare__[4];
};
-#if 0
-
-//----------------------------------------------------------------------
-// From linux-2.6.8.1/include/asm-i386/ldt.h
-//----------------------------------------------------------------------
-
-/* [[Nb: This is the structure passed to the modify_ldt syscall. Just so as
- to confuse and annoy everyone, this is _not_ the same as an
- VgLdtEntry and has to be translated into such. The logic for doing
- so, in vg_ldt.c, is copied from the kernel sources.]] */
-struct vki_user_desc {
- unsigned int entry_number;
- unsigned long base_addr;
- unsigned int limit;
- unsigned int seg_32bit:1;
- unsigned int contents:2;
- unsigned int read_exec_only:1;
- unsigned int limit_in_pages:1;
- unsigned int seg_not_present:1;
- unsigned int useable:1;
- // [[Nb: this field is not in the kernel sources, but it has always
- // been in the Valgrind sources so I will keep it there in case it's
- // important... this is an x86-defined data structure so who
- // knows; maybe it's important to set this field to zero at some
- // point. --njn]]
- unsigned int reserved:25;
-};
-
-// [[Nb: for our convenience within Valgrind, use a more specific name]]
-typedef struct vki_user_desc vki_modify_ldt_t;
-
-#endif
-
//----------------------------------------------------------------------
// And that's it!
//----------------------------------------------------------------------
More information about the p4-projects
mailing list