aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start_windows_tls.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-12-12 18:56:39 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-12-12 18:56:39 -0500
commit7699b5b997c7a024a6d9558df0ec72d71ef402fe (patch)
treeea996d6252efe24158a802fb50c1a28c3b3d6717 /lib/std/start_windows_tls.zig
parent81f1f72197113a45e827d5c984e219a28aa28083 (diff)
parentfff3c1fff4c3ebfcb2bd4f08a43ae7815b5c446b (diff)
downloadzig-7699b5b997c7a024a6d9558df0ec72d71ef402fe.tar.gz
zig-7699b5b997c7a024a6d9558df0ec72d71ef402fe.zip
Merge branch 'Xe-expose-callMain'
closes #3891
Diffstat (limited to 'lib/std/start_windows_tls.zig')
-rw-r--r--lib/std/start_windows_tls.zig48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/std/start_windows_tls.zig b/lib/std/start_windows_tls.zig
new file mode 100644
index 0000000000..f6dd2bc132
--- /dev/null
+++ b/lib/std/start_windows_tls.zig
@@ -0,0 +1,48 @@
+const std = @import("std");
+const builtin = std.builtin;
+
+export var _tls_index: u32 = std.os.windows.TLS_OUT_OF_INDEXES;
+export var _tls_start: u8 linksection(".tls") = 0;
+export var _tls_end: u8 linksection(".tls$ZZZ") = 0;
+export var __xl_a: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLA") = null;
+export var __xl_z: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLZ") = null;
+
+comptime {
+ if (builtin.arch == .i386) {
+ // The __tls_array is the offset of the ThreadLocalStoragePointer field
+ // in the TEB block whose base address held in the %fs segment.
+ asm (
+ \\ .global __tls_array
+ \\ __tls_array = 0x2C
+ );
+ }
+}
+
+// TODO this is how I would like it to be expressed
+// TODO also note, ReactOS has a +1 on StartAddressOfRawData and AddressOfCallBacks. Investigate
+// why they do that.
+//export const _tls_used linksection(".rdata$T") = std.os.windows.IMAGE_TLS_DIRECTORY {
+// .StartAddressOfRawData = @ptrToInt(&_tls_start),
+// .EndAddressOfRawData = @ptrToInt(&_tls_end),
+// .AddressOfIndex = @ptrToInt(&_tls_index),
+// .AddressOfCallBacks = @ptrToInt(__xl_a),
+// .SizeOfZeroFill = 0,
+// .Characteristics = 0,
+//};
+// This is the workaround because we can't do @ptrToInt at comptime like that.
+pub const IMAGE_TLS_DIRECTORY = extern struct {
+ StartAddressOfRawData: *c_void,
+ EndAddressOfRawData: *c_void,
+ AddressOfIndex: *c_void,
+ AddressOfCallBacks: *c_void,
+ SizeOfZeroFill: u32,
+ Characteristics: u32,
+};
+export const _tls_used linksection(".rdata$T") = IMAGE_TLS_DIRECTORY{
+ .StartAddressOfRawData = &_tls_start,
+ .EndAddressOfRawData = &_tls_end,
+ .AddressOfIndex = &_tls_index,
+ .AddressOfCallBacks = &__xl_a,
+ .SizeOfZeroFill = 0,
+ .Characteristics = 0,
+};