diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2022-01-27 12:39:57 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2022-05-12 22:00:24 +0200 |
commit | c2f599fb69012550086d25bde3f37f3e75d46367 (patch) | |
tree | 29a40e8b22651902dc95250b5675972c66c363a3 /winsup | |
parent | 7887f9e85c4591c78ad9b7de8025621035cb9f12 (diff) | |
download | newlib-c2f599fb69012550086d25bde3f37f3e75d46367.zip newlib-c2f599fb69012550086d25bde3f37f3e75d46367.tar.gz newlib-c2f599fb69012550086d25bde3f37f3e75d46367.tar.bz2 |
Cygwin: config.h: stop including auto-generated tlsoffsets.h file
This was a hack to begin with. Clean this mess up:
- Move definition of CYGTLS_PADSIZE to cygwin/config.h and drop
local cygtls_padsize.h
- Rename CYGTLS_PADSIZE to __CYGTLS_PADSIZE__ to keep namespace
clean. Redefine as macro, rather than as const.
- Move struct _reent first in struct _cygtls to allow using
__CYGTLS_PADSIZE__ as offset in __getreent().
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/cygtls.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/cygtls.h | 9 | ||||
-rw-r--r-- | winsup/cygwin/cygtls_padsize.h | 12 | ||||
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/external.cc | 2 | ||||
-rwxr-xr-x | winsup/cygwin/gentls_offsets | 4 | ||||
-rw-r--r-- | winsup/cygwin/how-cygtls-works.txt | 10 | ||||
-rw-r--r-- | winsup/cygwin/include/cygwin/config.h | 23 | ||||
-rw-r--r-- | winsup/cygwin/init.cc | 4 | ||||
-rw-r--r-- | winsup/cygwin/miscfuncs.cc | 10 | ||||
-rw-r--r-- | winsup/cygwin/tlsoffsets-x86_64.h (renamed from winsup/cygwin/tlsoffsets64.h) | 24 | ||||
-rw-r--r-- | winsup/utils/mingw/strace.cc | 4 |
12 files changed, 42 insertions, 64 deletions
diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index c8352ad..a183d18 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -20,7 +20,7 @@ details. */ void _cygtls::call (DWORD (*func) (void *, void *), void *arg) { - char buf[CYGTLS_PADSIZE]; + char buf[__CYGTLS_PADSIZE__]; /* Initialize this thread's ability to respond to things like SIGSEGV or SIGFPE. */ exception protect; diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index c2c4141..7ee6165 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -170,13 +170,13 @@ typedef uintptr_t __tlsstack_t; class _cygtls { public: - /* Please keep these two declarations first */ - struct _local_storage locals; + /* Keep these two declarations first, keep local_clib first. */ union { struct _reent local_clib; char __dontuse[8 * ((sizeof(struct _reent) + 4) / 8)]; }; + struct _local_storage locals; /**/ void (*func) /*gentls_offsets*/(int, siginfo_t *, void *)/*gentls_offsets*/; int saved_errno; @@ -280,14 +280,13 @@ private: }; #pragma pack(pop) -#include "cygtls_padsize.h" - /*gentls_offsets*/ #include "cygerrno.h" #include "ntdll.h" -#define _my_tls (*((_cygtls *) ((PBYTE) NtCurrentTeb()->Tib.StackBase - CYGTLS_PADSIZE))) +#define _my_tls (*((_cygtls *) ((PBYTE) NtCurrentTeb()->Tib.StackBase \ + - __CYGTLS_PADSIZE__))) extern _cygtls *_main_tls; extern _cygtls *_sig_tls; diff --git a/winsup/cygwin/cygtls_padsize.h b/winsup/cygwin/cygtls_padsize.h deleted file mode 100644 index d3f024a..0000000 --- a/winsup/cygwin/cygtls_padsize.h +++ /dev/null @@ -1,12 +0,0 @@ -/* cygtls_padsize.h: Extra file to be included from utils. - -This software is a copyrighted work licensed under the terms of the -Cygwin license. Please consult the file "CYGWIN_LICENSE" for -details. */ - -/* FIXME: Find some way to autogenerate this value */ -#ifdef __x86_64__ -const int CYGTLS_PADSIZE = 12800; /* Must be 16-byte aligned */ -#else -const int CYGTLS_PADSIZE = 12700; -#endif diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 5f460d8..4a3609d 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -1107,7 +1107,7 @@ dll_crt0 (per_process *uptr) } /* This must be called by anyone who uses LoadLibrary to load cygwin1.dll. - You must have CYGTLS_PADSIZE bytes reserved at the bottom of the stack + You must have __CYGTLS_PADSIZE__ bytes reserved at the bottom of the stack calling this function, and that storage must not be overwritten until you unload cygwin1.dll, as it is used for _my_tls. It is best to load cygwin1.dll before spawning any additional threads in your process. diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index 74413a8..f65ac26 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -449,7 +449,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) res = 0; break; case CW_CYGTLS_PADSIZE: - res = CYGTLS_PADSIZE; + res = __CYGTLS_PADSIZE__; break; case CW_SET_DOS_FILE_WARNING: res = 0; diff --git a/winsup/cygwin/gentls_offsets b/winsup/cygwin/gentls_offsets index ef78d44..8e9ce71 100755 --- a/winsup/cygwin/gentls_offsets +++ b/winsup/cygwin/gentls_offsets @@ -66,11 +66,11 @@ main(int argc, char **argv) { $struct *foo; # define foo_beg ((char *) foo) -# define offset(f) ((unsigned)((int) (((char *) &(foo->f)) - foo_beg) - CYGTLS_PADSIZE)) +# define offset(f) ((unsigned)((int) (((char *) &(foo->f)) - foo_beg) - __CYGTLS_PADSIZE__)) # define poffset(f) ((unsigned)(((char *) &(foo->f)) - ((char *) foo))) EOF print TMP 'puts ("//;# autogenerated: Do not edit.\n");', "\n\n"; - print TMP "printf (\"//; \$tls::start_offset = -%d;\\n\", CYGTLS_PADSIZE);\n"; + print TMP "printf (\"//; \$tls::start_offset = -%d;\\n\", __CYGTLS_PADSIZE__);\n"; for my $f (@fields) { print TMP ' printf ("//; $tls::', $f, ' = %d;\n", ', "offset($f));\n"; print TMP ' printf ("//; $tls::p', $f, ' = %d;\n", ', "poffset($f));\n"; diff --git a/winsup/cygwin/how-cygtls-works.txt b/winsup/cygwin/how-cygtls-works.txt index 8bba0a7..e4f6941 100644 --- a/winsup/cygwin/how-cygtls-works.txt +++ b/winsup/cygwin/how-cygtls-works.txt @@ -1,7 +1,7 @@ Contributed by Max Kaehn All cygwin threads have separate context in an object of class _cygtls. The -storage for this object is kept on the stack in the bottom CYGTLS_PADSIZE +storage for this object is kept on the stack in the bottom __CYGTLS_PADSIZE__ bytes. Each thread references the storage via the Thread Environment Block (aka Thread Information Block), which Windows maintains for each user thread in the system, with the address in the FS segment register. The memory @@ -34,13 +34,13 @@ And accesses cygtls like this: Initialization always goes through _cygtls::init_thread(). It works in the following ways: -* In the main thread, _dll_crt0() provides CYGTLS_PADSIZE bytes on the stack +* In the main thread, _dll_crt0() provides __CYGTLS_PADSIZE__ bytes on the stack and passes them to initialize_main_tls(), which calls _cygtls::init_thread(). It then calls dll_crt0_1(), which terminates with cygwin_exit() rather than by returning, so the storage never goes out of scope. If you load cygwin1.dll dynamically from a non-cygwin application, it is - vital that the bottom CYGTLS_PADSIZE bytes of the stack are not in use + vital that the bottom __CYGTLS_PADSIZE__ bytes of the stack are not in use before you call cygwin_dll_init(). See winsup/testsuite/cygload for more information. @@ -49,7 +49,7 @@ in the following ways: - dll_entry() calls munge_threadfunc(), which grabs the function pointer for the thread from the stack frame and substitutes threadfunc_fe(), - which then passes the original function pointer to _cygtls::call(), - - which then allocates CYGTLS_PADSIZE bytes on the stack and hands them + - which then allocates __CYGTLS_PADSIZE__ bytes on the stack and hands them to call2(), - which allocates an exception_list object on the stack and hands it to init_exceptions() (in exceptions.cc), which attaches it to the end of @@ -60,7 +60,7 @@ in the following ways: Note that the padding isn't necessarily going to be just where the _cygtls structure lives; it just makes sure there's enough room on the stack when the -CYGTLS_PADSIZE bytes down from there are overwritten. +__CYGTLS_PADSIZE__ bytes down from there are overwritten. Debugging diff --git a/winsup/cygwin/include/cygwin/config.h b/winsup/cygwin/include/cygwin/config.h index 71a216f..ad9a095 100644 --- a/winsup/cygwin/include/cygwin/config.h +++ b/winsup/cygwin/include/cygwin/config.h @@ -24,23 +24,14 @@ extern "C" { version of a function that takes _REENT. This saves the overhead of a function call for what amounts to a simple computation. - The definition below is essentially equivalent to the one in cygtls.h - (&_my_tls.local_clib) however it uses a fixed precomputed - offset rather than dereferencing a field of a structure. - - Including tlsoffets.h here in order to get this constant offset - tls_local_clib is a bit of a hack, but the alternative would require - dragging the entire definition of struct _cygtls (a large and complex - Cygwin internal data structure) into newlib. The machinery to - compute these offsets already exists for the sake of gendef so - we might as well just use it here. */ + This is the allocation size of the TLS area on the stack. Parts of + the stack are in use by the OS, so we need to go a bit higher than + what's actually required by the cygtls struct. The _reent struct is + right at the beginning of struct cygtls and always has to be. */ +#define __CYGTLS_PADSIZE__ 12800 /* Must be 16-byte aligned */ #if defined (_LIBC) || defined (__INSIDE_CYGWIN__) -#ifdef __x86_64__ -#include "../tlsoffsets64.h" -#else -#include "../tlsoffsets.h" -#endif + __attribute__((__gnu_inline__)) extern inline struct _reent *__getreent (void) { @@ -50,7 +41,7 @@ extern inline struct _reent *__getreent (void) #else __asm __volatile__ ("movl %%fs:4,%0" : "=r" (ret)); #endif - return (struct _reent *) (ret + tls_local_clib); + return (struct _reent *) (ret - __CYGTLS_PADSIZE__); } #endif /* _LIBC || __INSIDE_CYGWIN__ */ diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc index 7787b16..ab20ce5 100644 --- a/winsup/cygwin/init.cc +++ b/winsup/cygwin/init.cc @@ -92,8 +92,8 @@ dll_entry (HANDLE h, DWORD reason, void *static_load) initialized to NULL, so subsequent calls to locale-specific functions will always fall back to __global_locale, rather then crash due to _REENT->_locale having an arbitrary value. */ - alloca_dummy = alloca (CYGTLS_PADSIZE); - ZeroMemory (alloca_dummy, CYGTLS_PADSIZE); + alloca_dummy = alloca (__CYGTLS_PADSIZE__); + ZeroMemory (alloca_dummy, __CYGTLS_PADSIZE__); memcpy (_REENT, _GLOBAL_REENT, sizeof (struct _reent)); dll_crt0_0 (); diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index 4a5db6f..739d9de 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -415,7 +415,7 @@ pthread_wrapper (PVOID arg) SetThreadStackGuarantee (&wrapper_arg.guardsize); } /* Initialize new _cygtls. */ - _my_tls.init_thread (wrapper_arg.stackbase - CYGTLS_PADSIZE, + _my_tls.init_thread (wrapper_arg.stackbase - __CYGTLS_PADSIZE__, (DWORD (*)(void*, void*)) wrapper_arg.func); #ifdef __i386__ /* Copy exception list over to new stack. I'm not quite sure how the @@ -458,7 +458,7 @@ pthread_wrapper (PVOID arg) movq 8(%%rbx), %%r13 # Load thread arg into r13 \n\ movq 16(%%rbx), %%rcx # Load stackaddr into rcx \n\ movq 24(%%rbx), %%rsp # Load stackbase into rsp \n\ - subq %[CYGTLS], %%rsp # Subtract CYGTLS_PADSIZE \n\ + subq %[CYGTLS], %%rsp # Subtract __CYGTLS_PADSIZE__ \n\ # (here we are 16 bytes aligned)\n\ subq $32, %%rsp # Subtract another 32 bytes \n\ # (shadow space for arg regs) \n\ @@ -474,7 +474,7 @@ pthread_wrapper (PVOID arg) movq %%r13, %%rcx # Move thread arg to 1st arg reg\n\ call *%%r12 # Call thread func \n" : : [WRAPPER_ARG] "o" (wrapper_arg), - [CYGTLS] "i" (CYGTLS_PADSIZE)); + [CYGTLS] "i" (__CYGTLS_PADSIZE__)); #else __asm__ ("\n\ leal %[WRAPPER_ARG], %%ebx # Load &wrapper_arg into ebx \n\ @@ -482,7 +482,7 @@ pthread_wrapper (PVOID arg) movl 4(%%ebx), %%ecx # Load thread arg into ecx \n\ movl 8(%%ebx), %%edx # Load stackaddr into edx \n\ movl 12(%%ebx), %%ebx # Load stackbase into ebx \n\ - subl %[CYGTLS], %%ebx # Subtract CYGTLS_PADSIZE \n\ + subl %[CYGTLS], %%ebx # Subtract __CYGTLS_PADSIZE__ \n\ subl $4, %%ebx # Subtract another 4 bytes \n\ movl %%ebx, %%esp # Set esp \n\ xorl %%ebp, %%ebp # Set ebp to 0 \n\ @@ -505,7 +505,7 @@ pthread_wrapper (PVOID arg) popl %%eax # Pop thread_func address \n\ call *%%eax # Call thread func \n" : : [WRAPPER_ARG] "o" (wrapper_arg), - [CYGTLS] "i" (CYGTLS_PADSIZE)); + [CYGTLS] "i" (__CYGTLS_PADSIZE__)); #endif /* pthread::thread_init_wrapper calls pthread::exit, which in turn calls ExitThread, so we should never arrive here. */ diff --git a/winsup/cygwin/tlsoffsets64.h b/winsup/cygwin/tlsoffsets-x86_64.h index d137408..9388cad 100644 --- a/winsup/cygwin/tlsoffsets64.h +++ b/winsup/cygwin/tlsoffsets-x86_64.h @@ -1,12 +1,12 @@ //;# autogenerated: Do not edit. //; $tls::start_offset = -12800; -//; $tls::locals = -12800; -//; $tls::plocals = 0; -//; $tls::local_clib = -10624; -//; $tls::plocal_clib = 2176; -//; $tls::__dontuse = -10624; -//; $tls::p__dontuse = 2176; +//; $tls::local_clib = -12800; +//; $tls::plocal_clib = 0; +//; $tls::__dontuse = -12800; +//; $tls::p__dontuse = 0; +//; $tls::locals = -10912; +//; $tls::plocals = 1888; //; $tls::func = -8736; //; $tls::pfunc = 4064; //; $tls::saved_errno = -8728; @@ -63,12 +63,12 @@ //; $tls::pinitialized = 7768; //; __DATA__ -#define tls_locals (-12800) -#define tls_plocals (0) -#define tls_local_clib (-10624) -#define tls_plocal_clib (2176) -#define tls___dontuse (-10624) -#define tls_p__dontuse (2176) +#define tls_local_clib (-12800) +#define tls_plocal_clib (0) +#define tls___dontuse (-12800) +#define tls_p__dontuse (0) +#define tls_locals (-10912) +#define tls_plocals (1888) #define tls_func (-8736) #define tls_pfunc (4064) #define tls_saved_errno (-8728) diff --git a/winsup/utils/mingw/strace.cc b/winsup/utils/mingw/strace.cc index d8a095f..2731fd3 100644 --- a/winsup/utils/mingw/strace.cc +++ b/winsup/utils/mingw/strace.cc @@ -24,7 +24,7 @@ details. */ #include "sys/strace.h" #include "sys/cygwin.h" #include "cygwin/version.h" -#include "cygtls_padsize.h" +#include "cygwin/config.h" #include "gcc_seh.h" #include "path.h" #undef cygwin_internal @@ -1218,7 +1218,7 @@ main (int argc, char **argv) This is required to make sure cygwin_internal calls into Cygwin work reliably. This problem has been noticed under AllocationPreference registry setting to 0x100000 (TOP_DOWN). */ - char buf[CYGTLS_PADSIZE]; + char buf[__CYGTLS_PADSIZE__]; RtlSecureZeroMemory (buf, sizeof (buf)); exit (main2 (argc, argv)); |