| 1 | /* Machine dependent pthreads code. Hurd/x86_64 version. |
| 2 | Copyright (C) 2000-2024 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 | |
| 28 | int |
| 29 | __thread_set_pcsptp (thread_t thread, |
| 30 | int set_ip, void *ip, |
| 31 | int set_sp, void *sp, |
| 32 | int set_tp, void *tp) |
| 33 | { |
| 34 | error_t err; |
| 35 | struct i386_thread_state state; |
| 36 | struct i386_fsgs_base_state fsgs_state; |
| 37 | mach_msg_type_number_t state_count; |
| 38 | |
| 39 | state_count = i386_THREAD_STATE_COUNT; |
| 40 | |
| 41 | err = __thread_get_state (thread, i386_REGS_SEGS_STATE, |
| 42 | (thread_state_t) &state, &state_count); |
| 43 | if (err) |
| 44 | return err; |
| 45 | assert (state_count == i386_THREAD_STATE_COUNT); |
| 46 | |
| 47 | if (set_sp) |
| 48 | state.ursp = (uintptr_t) sp; |
| 49 | if (set_ip) |
| 50 | state.rip = (uintptr_t) ip; |
| 51 | |
| 52 | err = __thread_set_state (thread, i386_REGS_SEGS_STATE, |
| 53 | (thread_state_t) &state, i386_THREAD_STATE_COUNT); |
| 54 | if (err) |
| 55 | return err; |
| 56 | |
| 57 | if (set_tp) |
| 58 | { |
| 59 | state_count = i386_FSGS_BASE_STATE_COUNT; |
| 60 | err = __thread_get_state (thread, i386_FSGS_BASE_STATE, |
| 61 | (thread_state_t) &fsgs_state, &state_count); |
| 62 | if (err) |
| 63 | return err; |
| 64 | assert (state_count == i386_FSGS_BASE_STATE_COUNT); |
| 65 | fsgs_state.fs_base = (uintptr_t) tp; |
| 66 | err = __thread_set_state (thread, i386_FSGS_BASE_STATE, |
| 67 | (thread_state_t) &fsgs_state, state_count); |
| 68 | if (err) |
| 69 | return err; |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |