mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-10 13:40:25 +00:00
It compiles, but aborts immediately if you try to run it.
I didn't include ldt.c; I'm not sure how the LDT is used on AMD64. It can be
added later if necessary.
While doing this, did some 64-bit cleanness fixes:
- Added necessary intermediate casts to ULong to avoid warnings when converting
ThreadId to void* and vice versa, in vg_scheduler.c.
- Fixed VALGRIND_NON_SIMD_CALL[0123] to use 'long' as the return type.
- Fixed VALGRIND_PRINTF{,BACKTRACE} to use unsigned longs instead of unsigned
ints, as needed.
- Converted some offsets in vg_symtab2.h from "Int" to "OffT".
- Made strlen, strncat, etc, use SizeT instead of 'unsigned int' for the length
parameter.
- Couple of other minor things.
I had to insert some "#ifdef __amd64__" and "#ifndef __amd64__" guards in
places. In particular, in vg_mylibc.c, some of our syscall wrappers aren't
appropriate for AMD64 because the syscall numbering is a bit different in
places. This difference will have to be abstracted out somehow.
Also rewrote the sys_fcntl and sys_fcntl64 wrappers, as required for AMD64.
Also moved the ipc wrapper into x86, since it's not applicable for
AMD64. However, it is applicable (I think) for ARM, so it would be nice
to work out a way to share syscall wrappers between some, but not all,
archs. Hmm. Also now using the real IPC constants rather than magic
numbers in the wrapper.
Other non-AMD64-related fixes:
- ARM: fixed syscall table by accounting for the fact that syscall
numbers don't start at 0, but rather at 0x900000.
- Converted a few places to use ThreadId instead of 'int' or 'Int' for
thread IDs.
- Added both AMD64 and ARM (which I'd forgotten) entries to valgrind.spec.in.
- Tweaked comments in various places.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3136
178 lines
5.8 KiB
C
178 lines
5.8 KiB
C
|
|
/*--------------------------------------------------------------------*/
|
|
/*--- Arch-specific stuff for the core. x86/core_arch.h ---*/
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
/*
|
|
This file is part of Valgrind, an extensible x86 protected-mode
|
|
emulator for monitoring program execution on x86-Unixes.
|
|
|
|
Copyright (C) 2000-2004 Nicholas Nethercote
|
|
njn25@cam.ac.uk
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307, USA.
|
|
|
|
The GNU General Public License is contained in the file COPYING.
|
|
*/
|
|
|
|
#ifndef __X86_CORE_ARCH_H
|
|
#define __X86_CORE_ARCH_H
|
|
|
|
#include "core_arch_asm.h" // arch-specific asm stuff
|
|
#include "tool_arch.h" // arch-specific tool stuff
|
|
|
|
#include "libvex_guest_x86.h"
|
|
|
|
|
|
/* ---------------------------------------------------------------------
|
|
Interesting registers
|
|
------------------------------------------------------------------ */
|
|
|
|
// Vex field names
|
|
#define ARCH_INSTR_PTR guest_EIP
|
|
#define ARCH_STACK_PTR guest_ESP
|
|
#define ARCH_FRAME_PTR guest_EBP
|
|
|
|
#define ARCH_CLREQ_ARGS guest_EAX
|
|
#define ARCH_CLREQ_RET guest_EDX
|
|
#define ARCH_PTHREQ_RET guest_EDX
|
|
|
|
// Register numbers, for vg_symtab2.c
|
|
#define R_STACK_PTR 4
|
|
#define R_FRAME_PTR 5
|
|
|
|
// Stack frame layout and linkage
|
|
#define FIRST_STACK_FRAME(ebp) (ebp)
|
|
#define STACK_FRAME_RET(ebp) (((UInt*)ebp)[1])
|
|
#define STACK_FRAME_NEXT(ebp) (((UInt*)ebp)[0])
|
|
|
|
// Get stack pointer and frame pointer
|
|
#define ARCH_GET_REAL_STACK_PTR(esp) do { \
|
|
asm("movl %%esp, %0" : "=r" (esp)); \
|
|
} while (0)
|
|
|
|
#define ARCH_GET_REAL_FRAME_PTR(ebp) do { \
|
|
asm("movl %%ebp, %0" : "=r" (ebp)); \
|
|
} while (0)
|
|
|
|
/* ---------------------------------------------------------------------
|
|
Elf stuff
|
|
------------------------------------------------------------------ */
|
|
|
|
#define VG_ELF_ENDIANNESS ELFDATA2LSB
|
|
#define VG_ELF_MACHINE EM_386
|
|
#define VG_ELF_CLASS ELFCLASS32
|
|
|
|
|
|
/* ---------------------------------------------------------------------
|
|
LDT type
|
|
------------------------------------------------------------------ */
|
|
|
|
// XXX: eventually this will be x86-private, not seen by the core(?)
|
|
|
|
/* This is the hardware-format for a segment descriptor, ie what the
|
|
x86 actually deals with. It is 8 bytes long. It's ugly. */
|
|
|
|
typedef struct _LDT_ENTRY {
|
|
union {
|
|
struct {
|
|
UShort LimitLow;
|
|
UShort BaseLow;
|
|
unsigned BaseMid : 8;
|
|
unsigned Type : 5;
|
|
unsigned Dpl : 2;
|
|
unsigned Pres : 1;
|
|
unsigned LimitHi : 4;
|
|
unsigned Sys : 1;
|
|
unsigned Reserved_0 : 1;
|
|
unsigned Default_Big : 1;
|
|
unsigned Granularity : 1;
|
|
unsigned BaseHi : 8;
|
|
} Bits;
|
|
struct {
|
|
UInt word1;
|
|
UInt word2;
|
|
} Words;
|
|
}
|
|
LdtEnt;
|
|
} VgLdtEntry;
|
|
|
|
|
|
/* ---------------------------------------------------------------------
|
|
Architecture-specific part of a ThreadState
|
|
------------------------------------------------------------------ */
|
|
|
|
// Architecture-specific part of a ThreadState
|
|
// XXX: eventually this should be made abstract, ie. the fields not visible
|
|
// to the core... then VgLdtEntry can be made non-visible to the core
|
|
// also.
|
|
typedef
|
|
struct {
|
|
/* Pointer to this thread's Local (Segment) Descriptor Table.
|
|
Starts out as NULL, indicating there is no table, and we hope
|
|
to keep it that way. If the thread does __NR_modify_ldt to
|
|
create entries, we allocate a 8192-entry table at that point.
|
|
This is a straight copy of the Linux kernel's scheme. Don't
|
|
forget to deallocate this at thread exit. */
|
|
VgLdtEntry* ldt;
|
|
|
|
/* TLS table. This consists of a small number (currently 3) of
|
|
entries from the Global Descriptor Table. */
|
|
VgLdtEntry tls[VKI_GDT_ENTRY_TLS_ENTRIES];
|
|
|
|
/* --- BEGIN vex-mandated guest state --- */
|
|
|
|
/* Saved machine context. */
|
|
VexGuestX86State vex;
|
|
|
|
/* Saved shadow context. */
|
|
VexGuestX86State vex_shadow;
|
|
|
|
/* Spill area. */
|
|
UChar vex_spill[LibVEX_N_SPILL_BYTES];
|
|
|
|
/* --- END vex-mandated guest state --- */
|
|
}
|
|
ThreadArchState;
|
|
|
|
typedef VexGuestX86State VexGuestArchState;
|
|
|
|
/* ---------------------------------------------------------------------
|
|
libpthread stuff
|
|
------------------------------------------------------------------ */
|
|
|
|
struct _ThreadArchAux {
|
|
void* tls_data;
|
|
int tls_segment;
|
|
unsigned long sysinfo;
|
|
};
|
|
|
|
/* ---------------------------------------------------------------------
|
|
Miscellaneous constants
|
|
------------------------------------------------------------------ */
|
|
|
|
// Valgrind's signal stack size, in words.
|
|
#define VG_SIGSTACK_SIZE_W 10000
|
|
|
|
// Base address of client address space.
|
|
#define CLIENT_BASE 0x00000000ul
|
|
|
|
#endif // __X86_CORE_ARCH_H
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
/*--- end ---*/
|
|
/*--------------------------------------------------------------------*/
|