| 1 |
/* Machine dependent pthreads code. Hurd/x86_64 version. |
| 2 |
Copyright (C) 2000-2026 Free Software Foundation, Inc. |
| 3 |
This file is part of the GNU C Library. |
| 4 |
|
| 5 |
The GNU C Library is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU Lesser General Public |
| 7 |
License as published by the Free Software Foundation; either |
| 8 |
version 2.1 of the License, or (at your option) any later version. |
| 9 |
|
| 10 |
The GNU C Library is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
Lesser General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public |
| 16 |
License along with the GNU C Library; if not, see |
| 17 |
<https://www.gnu.org/licenses/>. */ |
| 18 |
|
| 19 |
#include <errno.h> |
| 20 |
#include <assert.h> |
| 21 |
|
| 22 |
#include <mach.h> |
| 23 |
#include <mach/machine/thread_status.h> |
| 24 |
#include <mach/x86_64/mach_i386.h> |
| 25 |
#include <mach/mig_errors.h> |
| 26 |
#include <mach/thread_status.h> |
| 27 |
#include <thread_state.h> |
| 28 |
#include <pt-sysdep.h> |
| 29 |
|
| 30 |
int |
| 31 |
__thread_set_pcsptp (thread_t thread, |
| 32 |
int set_ip, void *ip, |
| 33 |
int set_sp, void *sp, |
| 34 |
int set_tp, void *tp) |
| 35 |
{ |
| 36 |
error_t err; |
| 37 |
struct i386_thread_state state; |
| 38 |
struct i386_fsgs_base_state fsgs_state; |
| 39 |
mach_msg_type_number_t state_count; |
| 40 |
|
| 41 |
state_count = i386_THREAD_STATE_COUNT; |
| 42 |
|
| 43 |
err = __thread_get_state (thread, i386_REGS_SEGS_STATE, |
| 44 |
(thread_state_t) &state, &state_count); |
| 45 |
if (err) |
| 46 |
return err; |
| 47 |
assert (state_count == i386_THREAD_STATE_COUNT); |
| 48 |
|
| 49 |
if (set_sp) |
| 50 |
state.ursp = (uintptr_t) sp; |
| 51 |
if (set_ip) |
| 52 |
{ |
| 53 |
/* Making it call something else, we have to re-align the stack for SSE. */ |
| 54 |
state.ursp = PTR_ALIGN_DOWN_8_16 (state.ursp); |
| 55 |
state.rip = (uintptr_t) ip; |
| 56 |
} |
| 57 |
|
| 58 |
err = __thread_set_state (thread, i386_REGS_SEGS_STATE, |
| 59 |
(thread_state_t) &state, i386_THREAD_STATE_COUNT); |
| 60 |
if (err) |
| 61 |
return err; |
| 62 |
|
| 63 |
if (set_tp) |
| 64 |
{ |
| 65 |
state_count = i386_FSGS_BASE_STATE_COUNT; |
| 66 |
err = __thread_get_state (thread, i386_FSGS_BASE_STATE, |
| 67 |
(thread_state_t) &fsgs_state, &state_count); |
| 68 |
if (err) |
| 69 |
return err; |
| 70 |
assert (state_count == i386_FSGS_BASE_STATE_COUNT); |
| 71 |
fsgs_state.fs_base = (uintptr_t) tp; |
| 72 |
err = __thread_set_state (thread, i386_FSGS_BASE_STATE, |
| 73 |
(thread_state_t) &fsgs_state, state_count); |
| 74 |
if (err) |
| 75 |
return err; |
| 76 |
} |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |
| 80 |
libc_hidden_def (__thread_set_pcsptp) |