| author | |
| committer | |
| log | 7df9169081ef570b2560646e2d341e81df1a3976 |
| tree | 6a27d3720e146c8076b1c8f50b14bfd053851bf8 |
| parent | 3163a16617a2628284d0766b4aa132a1a86aafae |
| parent | 2e04b61275062f4a3672cdea2456effbc0cb22a5 |
| signature |
std: Nicer way to access the PEB2 files changed, 32 insertions(+), 16 deletions(-)
lib/std/os/windows.zig+19-16| ... | ... | @@ -1083,23 +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 | 1104 | 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 | } | |
| 1105 | return teb().ProcessEnvironmentBlock; | |
| 1103 | 1106 | } |
| 1104 | 1107 | |
| 1105 | 1108 | /// 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 |