| author | |
| committer | |
| log | 2e04b61275062f4a3672cdea2456effbc0cb22a5 |
| tree | 50010fba00281c8c27b91fc91f460312b311780a |
| parent | b9a1d67637cfae6206fffce78fc2e40780ef4fb5 |
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 | } |
| 1085 | 1085 | ||
| 1086 | pub 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 | |||
| 1086 | pub fn peb() *PEB { | 1104 | pub fn peb() *PEB { |
| 1087 | return ntdll.NtCurrentTeb().ProcessEnvironmentBlock; | 1105 | return teb().ProcessEnvironmentBlock; |
| 1088 | } | 1106 | } |
| 1089 | 1107 | ||
| 1090 | /// A file time is a 64-bit value that represents the number of 100-nanosecond | 1108 | /// 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; |
| 19 | pub extern "NtDll" fn NtCurrentTeb() callconv(.Stdcall) *TEB; | ||
| 20 | 19 | ||
| 21 | pub extern "NtDll" fn NtQueryAttributesFile( | 20 | pub extern "NtDll" fn NtQueryAttributesFile( |
| 22 | ObjectAttributes: *OBJECT_ATTRIBUTES, | 21 | ObjectAttributes: *OBJECT_ATTRIBUTES, |