| author | |
| committer | |
| log | b9a1d67637cfae6206fffce78fc2e40780ef4fb5 |
| tree | 9b36f734cb9814ab03114ddecb0b4b0965858a6a |
| parent | eaccfffe56655ab11a382685886492e5b9b0865c |
Use the NtCurrentTeb API instead of using some inline asm, this is much
nicer and also more portable.
Closes #46453 files changed, 15 insertions(+), 16 deletions(-)
lib/std/os/windows.zig+1-16| ... | ... | @@ -1084,22 +1084,7 @@ pub fn SetFileTime( |
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | pub fn peb() *PEB { |
| 1087 | switch (builtin.arch) { | |
| 1088 | .i386 => { | |
| 1089 | return asm ( | |
| 1090 | \\ mov %%fs:0x18, %[ptr] | |
| 1091 | \\ mov %%ds:0x30(%[ptr]), %[ptr] | |
| 1092 | : [ptr] "=r" (-> *PEB) | |
| 1093 | ); | |
| 1094 | }, | |
| 1095 | .x86_64 => { | |
| 1096 | return asm ( | |
| 1097 | \\ mov %%gs:0x60, %[ptr] | |
| 1098 | : [ptr] "=r" (-> *PEB) | |
| 1099 | ); | |
| 1100 | }, | |
| 1101 | else => @compileError("unsupported architecture"), | |
| 1102 | } | |
| 1087 | return ntdll.NtCurrentTeb().ProcessEnvironmentBlock; | |
| 1103 | 1088 | } |
| 1104 | 1089 | |
| 1105 | 1090 | /// A file time is a 64-bit value that represents the number of 100-nanosecond |
lib/std/os/windows/bits.zig+13| ... | ... | @@ -1154,6 +1154,19 @@ const RTL_BITMAP = @OpaqueType(); |
| 1154 | 1154 | pub const PRTL_BITMAP = *RTL_BITMAP; |
| 1155 | 1155 | const KAFFINITY = usize; |
| 1156 | 1156 | |
| 1157 | pub const TEB = extern struct { | |
| 1158 | Reserved1: [12]PVOID, | |
| 1159 | ProcessEnvironmentBlock: *PEB, | |
| 1160 | Reserved2: [399]PVOID, | |
| 1161 | Reserved3: [1952]u8, | |
| 1162 | TlsSlots: [64]PVOID, | |
| 1163 | Reserved4: [8]u8, | |
| 1164 | Reserved5: [26]PVOID, | |
| 1165 | ReservedForOle: PVOID, | |
| 1166 | Reserved6: [4]PVOID, | |
| 1167 | TlsExpansionSlots: PVOID, | |
| 1168 | }; | |
| 1169 | ||
| 1157 | 1170 | /// Process Environment Block |
| 1158 | 1171 | /// Microsoft documentation of this is incomplete, the fields here are taken from various resources including: |
| 1159 | 1172 | /// - https://github.com/wine-mirror/wine/blob/1aff1e6a370ee8c0213a0fd4b220d121da8527aa/include/winternl.h#L269 |
lib/std/os/windows/ntdll.zig+1| ... | ... | @@ -16,6 +16,7 @@ pub extern "NtDll" fn NtQueryInformationFile( |
| 16 | 16 | Length: ULONG, |
| 17 | 17 | FileInformationClass: FILE_INFORMATION_CLASS, |
| 18 | 18 | ) callconv(.Stdcall) NTSTATUS; |
| 19 | pub extern "NtDll" fn NtCurrentTeb() callconv(.Stdcall) *TEB; | |
| 19 | 20 | |
| 20 | 21 | pub extern "NtDll" fn NtQueryAttributesFile( |
| 21 | 22 | ObjectAttributes: *OBJECT_ATTRIBUTES, |