From: Jacek Caban <jacek@codeweavers.com> --- dlls/winecrt0/Makefile.in | 1 + dlls/winecrt0/tls.c | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 dlls/winecrt0/tls.c diff --git a/dlls/winecrt0/Makefile.in b/dlls/winecrt0/Makefile.in index 5b0d5705174..5893c98bf62 100644 --- a/dlls/winecrt0/Makefile.in +++ b/dlls/winecrt0/Makefile.in @@ -22,4 +22,5 @@ SOURCES = \ register.c \ setjmp.c \ stub.c \ + tls.c \ unix_lib.c diff --git a/dlls/winecrt0/tls.c b/dlls/winecrt0/tls.c new file mode 100644 index 00000000000..67f52e0e5da --- /dev/null +++ b/dlls/winecrt0/tls.c @@ -0,0 +1,55 @@ +/* + * Copyright 2026 Jacek Caban for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifdef __WINE_PE_BUILD + +#include <stdarg.h> +#include "windef.h" +#include "winbase.h" +#include "wine/asm.h" + +#ifdef __i386__ +/* Offset of ThreadLocalStoragePointer in the TEB, the compiler uses %fs:_tls_array to access it. */ +asm( ".globl " __ASM_NAME("_tls_array") "\n\t" + __ASM_NAME("_tls_array") "=44" ); +#endif + +int _tls_index = 0; + +__attribute__((section(".tls"))) char _tls_start = 0; +__attribute__((section(".tls$ZZZ"))) char _tls_end = 0; + +__attribute__((section(".CRT$XLA"))) void *__xl_a = 0; +__attribute__((section(".CRT$XLZ"))) void *__xl_z = 0; + +const struct +{ + void *StartAddressOfRawData; + void *EndAddressOfRawData; + void *AddressOfIndex; + void *AddressOfCallBacks; + ULONG SizeOfZeroFill; + ULONG Characteristics; +} _tls_used = { + &_tls_start, + &_tls_end, + &_tls_index, + &__xl_a + 1, +}; + +#endif -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10160