authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-06 09:17:14+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-06 09:17:14+01:00
log2e04b61275062f4a3672cdea2456effbc0cb22a5
tree50010fba00281c8c27b91fc91f460312b311780a
parentb9a1d67637cfae6206fffce78fc2e40780ef4fb5

std: Work around unexported NtCurrentTeb

Apparently NtCurrentTeb is only exported for i386 and some other platforms but not for x86_64 nor AArch64. Let's go with the flow and provide our own NtCurrentTeb like the Windows headers do. Thank you Microsoft.

2 files changed, 19 insertions(+), 2 deletions(-)

lib/std/os/windows.zig+19-1
...@@ -1083,8 +1083,26 @@ pub fn SetFileTime(...@@ -1083,8 +1083,26 @@ pub fn SetFileTime(
1083 }1083 }
1084}1084}
10851085
1086pub fn teb() *TEB {
1087 return switch (builtin.arch) {
1088 .i386 => asm volatile (
1089 \\ movl %%fs:0x18, %[ptr]
1090 : [ptr] "=r" (-> *TEB)
1091 ),
1092 .x86_64 => asm volatile (
1093 \\ movq %%gs:0x30, %[ptr]
1094 : [ptr] "=r" (-> *TEB)
1095 ),
1096 .aarch64 => asm volatile (
1097 \\ mov %[ptr], x18
1098 : [ptr] "=r" (-> *TEB)
1099 ),
1100 else => @compileError("unsupported arch"),
1101 };
1102}
1103
1086pub fn peb() *PEB {1104pub fn peb() *PEB {
1087 return ntdll.NtCurrentTeb().ProcessEnvironmentBlock;1105 return teb().ProcessEnvironmentBlock;
1088}1106}
10891107
1090/// A file time is a 64-bit value that represents the number of 100-nanosecond1108/// A file time is a 64-bit value that represents the number of 100-nanosecond
lib/std/os/windows/ntdll.zig-1
...@@ -16,7 +16,6 @@ pub extern "NtDll" fn NtQueryInformationFile(...@@ -16,7 +16,6 @@ pub extern "NtDll" fn NtQueryInformationFile(
16 Length: ULONG,16 Length: ULONG,
17 FileInformationClass: FILE_INFORMATION_CLASS,17 FileInformationClass: FILE_INFORMATION_CLASS,
18) callconv(.Stdcall) NTSTATUS;18) callconv(.Stdcall) NTSTATUS;
19pub extern "NtDll" fn NtCurrentTeb() callconv(.Stdcall) *TEB;
2019
21pub extern "NtDll" fn NtQueryAttributesFile(20pub extern "NtDll" fn NtQueryAttributesFile(
22 ObjectAttributes: *OBJECT_ATTRIBUTES,21 ObjectAttributes: *OBJECT_ATTRIBUTES,