| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <errno.h> |
| 20 |
|
| 21 |
#include <mach.h> |
| 22 |
#include <mach/machine/thread_status.h> |
| 23 |
#include <mach/i386/mach_i386.h> |
| 24 |
#include <mach/mig_errors.h> |
| 25 |
#include <mach/thread_status.h> |
| 26 |
#include <pt-sysdep.h> |
| 27 |
|
| 28 |
#define HURD_TLS_DESC_DECL(desc, tcb) \ |
| 29 |
struct descriptor desc = \ |
| 30 |
{ \ |
| 31 |
0xffff \ |
| 32 |
| (((unsigned int) (tcb)) << 16) \ |
| 33 |
, \ |
| 34 |
((((unsigned int) (tcb)) >> 16) & 0xff) \ |
| 35 |
| ((0x12 | 0x60 | 0x80) << 8) \ |
| 36 |
| (0xf << 16) \ |
| 37 |
| ((4 | 8) << 20) \ |
| 38 |
| (((unsigned int) (tcb)) & 0xff000000) \ |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
__thread_set_pcsptp (thread_t thread, |
| 43 |
int set_ip, void *ip, |
| 44 |
int set_sp, void *sp, |
| 45 |
int set_tp, void *tp) |
| 46 |
{ |
| 47 |
error_t err; |
| 48 |
struct i386_thread_state state; |
| 49 |
mach_msg_type_number_t state_count; |
| 50 |
|
| 51 |
state_count = i386_THREAD_STATE_COUNT; |
| 52 |
|
| 53 |
err = __thread_get_state (thread, i386_REGS_SEGS_STATE, |
| 54 |
(thread_state_t) &state, &state_count); |
| 55 |
if (err) |
| 56 |
return err; |
| 57 |
|
| 58 |
if (set_sp) |
| 59 |
state.uesp = (unsigned int) sp; |
| 60 |
if (set_ip) |
| 61 |
state.eip = (unsigned int) ip; |
| 62 |
if (set_tp) |
| 63 |
{ |
| 64 |
HURD_TLS_DESC_DECL (desc, tp); |
| 65 |
int sel; |
| 66 |
|
| 67 |
asm ("mov %%gs, %w0": "=q" (sel):"0" (0)); |
| 68 |
if (__builtin_expect (sel, 0x48) & 4) |
| 69 |
err = __i386_set_ldt (thread, sel, &desc, 1); |
| 70 |
else |
| 71 |
err = __i386_set_gdt (thread, &sel, desc); |
| 72 |
if (err) |
| 73 |
return err; |
| 74 |
state.gs = sel; |
| 75 |
} |
| 76 |
|
| 77 |
err = __thread_set_state (thread, i386_REGS_SEGS_STATE, |
| 78 |
(thread_state_t) &state, i386_THREAD_STATE_COUNT); |
| 79 |
if (err) |
| 80 |
return err; |
| 81 |
|
| 82 |
return 0; |
| 83 |
} |
| 84 |
libc_hidden_def (__thread_set_pcsptp) |