Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

peb

windows.peb
pub fn peb() *PEB

File

lib/std/os/windows.zig:3647

Code

pub fn peb() *PEB {
    if (builtin.zig_backend == .stage2_c) switch (native_arch) {
        .x86, .x86_64 => return @ptrCast(@alignCast(struct {
            /// This is a workaround for the C backend until zig has the ability to put
            /// C code in inline assembly.
            extern fn zig_windows_peb() callconv(.c) *anyopaque;
        }.zig_windows_peb())),
        else => {},
    } else switch (native_arch) {
        .aarch64 => {
            comptime assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);
            return asm (
                \\ ldr %[ptr], [x18, #0x60]
                : [ptr] "=r" (-> *PEB),
            );
        },
        .x86 => {
            comptime assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30);
            return asm (
                \\ movl %%fs:0x30, %[ptr]
                : [ptr] "=r" (-> *PEB),
            );
        },
        .x86_64 => {
            comptime assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);
            return asm (
                \\ movq %%gs:0x60, %[ptr]
                : [ptr] "=r" (-> *PEB),
            );
        },
        else => {},
    }
    return teb().ProcessEnvironmentBlock;
}