45 |
#ifdef i386_THREAD_STATE |
#ifdef i386_THREAD_STATE |
46 |
# define ELF_MACHINE EM_386 |
# define ELF_MACHINE EM_386 |
47 |
|
|
48 |
/* There is a natural layout for this on x86, so it happens |
/* The gregset_t format (compatible with Linux/x86) almost fits |
49 |
that the canonical gregset_t from <sys/ucontext.h> |
the Mach i386_thread_state. */ |
|
matches Mach's i386_thread_state exactly. */ |
|
50 |
static inline void |
static inline void |
51 |
fetch_thread_regset (thread_t thread, prgregset_t *gregs) |
fetch_thread_regset (thread_t thread, prgregset_t *gregs) |
52 |
{ |
{ |
53 |
|
union |
54 |
|
{ |
55 |
|
struct i386_thread_state state; |
56 |
|
prgregset_t gregs; |
57 |
|
} *u = (void *) gregs; |
58 |
mach_msg_type_number_t count = i386_THREAD_STATE_COUNT; |
mach_msg_type_number_t count = i386_THREAD_STATE_COUNT; |
59 |
assert (sizeof (struct i386_thread_state) == sizeof (prgregset_t)); |
assert (sizeof (struct i386_thread_state) < sizeof (prgregset_t)); |
60 |
assert (offsetof (struct i386_thread_state, gs) == REG_GS); |
assert (offsetof (struct i386_thread_state, gs) == REG_GS * 4); |
61 |
assert (offsetof (struct i386_thread_state, eip) == REG_EIP * 4); |
assert (offsetof (struct i386_thread_state, eax) == REG_EAX * 4); |
62 |
assert (offsetof (struct i386_thread_state, ss) == REG_SS * 4); |
|
63 |
(void) thread_get_state (thread, i386_THREAD_STATE, |
(void) thread_get_state (thread, i386_THREAD_STATE, |
64 |
(thread_state_t) gregs, &count); |
(thread_state_t) &u->state, &count); |
65 |
|
|
66 |
|
u->gregs[REG_EIP] = u->state.eip; |
67 |
|
u->gregs[REG_CS] = u->state.cs; |
68 |
|
u->gregs[REG_EFL] = u->state.efl; |
69 |
|
u->gregs[REG_UESP] = u->state.uesp; |
70 |
|
u->gregs[REG_SS] = u->state.ss; |
71 |
|
|
72 |
|
/* These are the extra words that don't exist in prgregset_t. */ |
73 |
|
u->gregs[REG_ERR] = u->gregs[REG_TRAPNO] = 0; |
74 |
} |
} |
75 |
|
|
76 |
static inline void |
static inline void |