initial commit
[glibc.git] / sysdeps / unix / bsd / bsd4.4 / kfreebsd / x86_64 / fbtl / tls.h
1 /* Definitions for thread-local data handling. fbtl/x86-64 version.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Modification for FreeBSD by Petr Salinger, 2006.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #ifndef _FREEBSD_TLS_H
22 #define _FREEBSD_TLS_H
23
24 #include <fbtl/sysdeps/x86_64/tls.h>
25
26 #ifndef __ASSEMBLER__
27
28 #include <sysarch.h>
29 #include <sys/syscall.h>
30
31 #if 0
32 /* in Linux one; */
33 /* Magic for libthread_db to know how to do THREAD_SELF. */
34 # define DB_THREAD_SELF_INCLUDE <sys/reg.h> /* For the FS constant. */
35 # define DB_THREAD_SELF CONST_THREAD_AREA (64, FS)
36 #else
37 /* # warning proper FS constant needed */
38 # undef DB_THREAD_SELF_INCLUDE
39 # undef DB_THREAD_SELF
40 # define DB_THREAD_SELF CONST_THREAD_AREA (64, 25)
41 #endif
42
43 /* Code to initially initialize the thread pointer. This might need
44 special attention since 'errno' is not yet available and if the
45 operation can cause a failure 'errno' must not be touched. */
46
47 # undef TLS_INIT_TP
48 # define TLS_INIT_TP(descr) \
49 ({ \
50 void *_descr = (descr); \
51 tcbhead_t *head = _descr; \
52 long int _result; \
53 \
54 head->tcb = _descr; \
55 /* For now the thread descriptor is at the same address. */ \
56 head->self = _descr; \
57 \
58 asm volatile ("syscall" \
59 : "=a" (_result) \
60 : "0" ((unsigned long int) SYS_sysarch), \
61 "D" ((unsigned long int) AMD64_SET_FSBASE), \
62 "S" (&_descr) \
63 : "memory", "cc", "cx", "dx", "r8", "r9", "r10", "r11"); \
64 \
65 _result ? "cannot set %fs base address for thread-local storage" : 0; \
66 })
67
68 /* in fact this is OS-specific, but we do not have better header for it */
69 #define NEED_STACK_SIZE_FOR_PTH_CREATE 1
70
71 #endif /* __ASSEMBLER__ */
72
73 #endif /* tls.h */