authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-06 17:33:05-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-03-06 17:33:05-05:00
log7df9169081ef570b2560646e2d341e81df1a3976
tree6a27d3720e146c8076b1c8f50b14bfd053851bf8
parent3163a16617a2628284d0766b4aa132a1a86aafae
parent2e04b61275062f4a3672cdea2456effbc0cb22a5
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4651 from LemonBoy/fix-4645

std: Nicer way to access the PEB

2 files changed, 32 insertions(+), 16 deletions(-)

lib/std/os/windows.zig+19-16
...@@ -1083,23 +1083,26 @@ pub fn SetFileTime(...@@ -1083,23 +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 switch (builtin.arch) {1105 return teb().ProcessEnvironmentBlock;
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 }
1103}1106}
11041107
1105/// 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/bits.zig+13
...@@ -1154,6 +1154,19 @@ const RTL_BITMAP = @OpaqueType();...@@ -1154,6 +1154,19 @@ const RTL_BITMAP = @OpaqueType();
1154pub const PRTL_BITMAP = *RTL_BITMAP;1154pub const PRTL_BITMAP = *RTL_BITMAP;
1155const KAFFINITY = usize;1155const KAFFINITY = usize;
11561156
1157pub 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/// Process Environment Block1170/// Process Environment Block
1158/// Microsoft documentation of this is incomplete, the fields here are taken from various resources including:1171/// Microsoft documentation of this is incomplete, the fields here are taken from various resources including:
1159/// - https://github.com/wine-mirror/wine/blob/1aff1e6a370ee8c0213a0fd4b220d121da8527aa/include/winternl.h#L2691172/// - https://github.com/wine-mirror/wine/blob/1aff1e6a370ee8c0213a0fd4b220d121da8527aa/include/winternl.h#L269