Debian Codegraph @

sysdeps/mach/hurd/i386/htl/pt-machdep.c

raw symbols SCIP
1 /* Machine dependent pthreads code. Hurd/i386 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
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 { /* low word: */ \
31 0xffff /* limit 0..15 */ \
32 | (((unsigned int) (tcb)) << 16) /* base 0..15 */ \
33 , /* high word: */ \
34 ((((unsigned int) (tcb)) >> 16) & 0xff) /* base 16..23 */ \
35 | ((0x12 | 0x60 | 0x80) << 8) /* access = ACC_DATA_W|ACC_PL_U|ACC_P */ \
36 | (0xf << 16) /* limit 16..19 */ \
37 | ((4 | 8) << 20) /* granularity = SZ_32|SZ_G */ \
38 | (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */ \
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) /* LDT selector */
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)