diff options
| author | Takeshi Yoneda <takeshi@tetrate.io> | 2021-08-09 14:39:26 +0900 |
|---|---|---|
| committer | Takeshi Yoneda <takeshi@tetrate.io> | 2021-08-09 14:39:26 +0900 |
| commit | 97560cd915008f04addc2c30af087aa89c162b02 (patch) | |
| tree | 8aed12c207ff84cc256a0c78955c23b61129ba22 /lib/std/os | |
| parent | 7814a2bd4a3ec22cd9548c622f7dc837dba968f7 (diff) | |
| parent | 799fedf612aa8742c446b015c12d21707a1dbec0 (diff) | |
| download | zig-97560cd915008f04addc2c30af087aa89c162b02.tar.gz zig-97560cd915008f04addc2c30af087aa89c162b02.zip | |
Merge remote-tracking branch 'origin' into libc-wasi-test
Diffstat (limited to 'lib/std/os')
| -rw-r--r-- | lib/std/os/bits.zig | 29 | ||||
| -rw-r--r-- | lib/std/os/bits/darwin.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/bits/dragonfly.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/bits/freebsd.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/bits/haiku.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/bits/linux.zig | 5 | ||||
| -rw-r--r-- | lib/std/os/bits/netbsd.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/bits/openbsd.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/bits/posix.zig | 34 | ||||
| -rw-r--r-- | lib/std/os/bits/wasi.zig | 3 | ||||
| -rw-r--r-- | lib/std/os/bits/windows.zig | 5 | ||||
| -rw-r--r-- | lib/std/os/linux.zig | 12 | ||||
| -rw-r--r-- | lib/std/os/linux/arm-eabi.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/arm64.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/i386.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/mips.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/powerpc.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/powerpc64.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/riscv64.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/sparc64.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/thumb.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/x86_64.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/windows.zig | 19 | ||||
| -rw-r--r-- | lib/std/os/windows/kernel32.zig | 5 |
24 files changed, 104 insertions, 40 deletions
diff --git a/lib/std/os/bits.zig b/lib/std/os/bits.zig index 5d1de28bad..5c39609182 100644 --- a/lib/std/os/bits.zig +++ b/lib/std/os/bits.zig @@ -25,32 +25,3 @@ pub usingnamespace switch (std.Target.current.os.tag) { }; pub usingnamespace if (@hasDecl(root, "os") and @hasDecl(root.os, "bits")) root.os.bits else struct {}; - -pub const iovec = extern struct { - iov_base: [*]u8, - iov_len: usize, -}; - -pub const iovec_const = extern struct { - iov_base: [*]const u8, - iov_len: usize, -}; - -// syslog - -/// system is unusable -pub const LOG_EMERG = 0; -/// action must be taken immediately -pub const LOG_ALERT = 1; -/// critical conditions -pub const LOG_CRIT = 2; -/// error conditions -pub const LOG_ERR = 3; -/// warning conditions -pub const LOG_WARNING = 4; -/// normal but significant condition -pub const LOG_NOTICE = 5; -/// informational -pub const LOG_INFO = 6; -/// debug-level messages -pub const LOG_DEBUG = 7; diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig index be77722c05..91705c0d2e 100644 --- a/lib/std/os/bits/darwin.zig +++ b/lib/std/os/bits/darwin.zig @@ -7,6 +7,8 @@ const std = @import("../../std.zig"); const assert = std.debug.assert; const maxInt = std.math.maxInt; +pub usingnamespace @import("posix.zig"); + // See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html // TODO: audit mode_t/pid_t, should likely be u16/i32 pub const fd_t = c_int; diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index 9f6d3088ba..573721749c 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -6,6 +6,8 @@ const std = @import("../../std.zig"); const maxInt = std.math.maxInt; +pub usingnamespace @import("posix.zig"); + pub fn S_ISCHR(m: u32) bool { return m & S_IFMT == S_IFCHR; } diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index 6d227a168a..1805941993 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -7,6 +7,8 @@ const std = @import("../../std.zig"); const builtin = @import("builtin"); const maxInt = std.math.maxInt; +pub usingnamespace @import("posix.zig"); + pub const blksize_t = i32; pub const blkcnt_t = i64; pub const clockid_t = i32; diff --git a/lib/std/os/bits/haiku.zig b/lib/std/os/bits/haiku.zig index cb31166608..b3ea4aa0e2 100644 --- a/lib/std/os/bits/haiku.zig +++ b/lib/std/os/bits/haiku.zig @@ -6,6 +6,8 @@ const std = @import("../../std.zig"); const maxInt = std.math.maxInt; +pub usingnamespace @import("posix.zig"); + pub const fd_t = c_int; pub const pid_t = c_int; pub const uid_t = u32; diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 81bdfa6608..fdf240e954 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -6,7 +6,7 @@ const std = @import("../../std.zig"); const maxInt = std.math.maxInt; const arch = @import("builtin").target.cpu.arch; -usingnamespace @import("../bits.zig"); +pub usingnamespace @import("posix.zig"); pub usingnamespace switch (arch) { .mips, .mipsel => @import("linux/errno-mips.zig"), @@ -119,6 +119,9 @@ pub const FUTEX_LOCK_PI = 6; pub const FUTEX_UNLOCK_PI = 7; pub const FUTEX_TRYLOCK_PI = 8; pub const FUTEX_WAIT_BITSET = 9; +pub const FUTEX_WAKE_BITSET = 10; +pub const FUTEX_WAIT_REQUEUE_PI = 11; +pub const FUTEX_CMP_REQUEUE_PI = 12; pub const FUTEX_PRIVATE_FLAG = 128; diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index d0240709e3..f3ece93493 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -7,6 +7,8 @@ const std = @import("../../std.zig"); const builtin = std.builtin; const maxInt = std.math.maxInt; +pub usingnamespace @import("posix.zig"); + pub const blkcnt_t = i64; pub const blksize_t = i32; pub const clock_t = u32; diff --git a/lib/std/os/bits/openbsd.zig b/lib/std/os/bits/openbsd.zig index 3b9f8ccd4a..233ebcbd68 100644 --- a/lib/std/os/bits/openbsd.zig +++ b/lib/std/os/bits/openbsd.zig @@ -7,6 +7,8 @@ const std = @import("../../std.zig"); const builtin = std.builtin; const maxInt = std.math.maxInt; +pub usingnamespace @import("posix.zig"); + pub const blkcnt_t = i64; pub const blksize_t = i32; pub const clock_t = i64; diff --git a/lib/std/os/bits/posix.zig b/lib/std/os/bits/posix.zig new file mode 100644 index 0000000000..0f015cd573 --- /dev/null +++ b/lib/std/os/bits/posix.zig @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +pub const iovec = extern struct { + iov_base: [*]u8, + iov_len: usize, +}; + +pub const iovec_const = extern struct { + iov_base: [*]const u8, + iov_len: usize, +}; + +// syslog + +/// system is unusable +pub const LOG_EMERG = 0; +/// action must be taken immediately +pub const LOG_ALERT = 1; +/// critical conditions +pub const LOG_CRIT = 2; +/// error conditions +pub const LOG_ERR = 3; +/// warning conditions +pub const LOG_WARNING = 4; +/// normal but significant condition +pub const LOG_NOTICE = 5; +/// informational +pub const LOG_INFO = 6; +/// debug-level messages +pub const LOG_DEBUG = 7; diff --git a/lib/std/os/bits/wasi.zig b/lib/std/os/bits/wasi.zig index 3f5b25c679..5102d9b439 100644 --- a/lib/std/os/bits/wasi.zig +++ b/lib/std/os/bits/wasi.zig @@ -5,6 +5,9 @@ // and substantial portions of the software. // Convenience types and consts used by std.os module const builtin = @import("builtin"); +const posix = @import("posix.zig"); +pub const iovec = posix.iovec; +pub const iovec_const = posix.iovec_const; pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; diff --git a/lib/std/os/bits/windows.zig b/lib/std/os/bits/windows.zig index c5b101296b..05c50ffe47 100644 --- a/lib/std/os/bits/windows.zig +++ b/lib/std/os/bits/windows.zig @@ -8,6 +8,11 @@ usingnamespace @import("../windows/bits.zig"); const ws2_32 = @import("../windows/ws2_32.zig"); +// TODO: Stop using os.iovec in std.fs et al on Windows in the future +const posix = @import("posix.zig"); +pub const iovec = posix.iovec; +pub const iovec_const = posix.iovec_const; + pub const fd_t = HANDLE; pub const ino_t = LARGE_INTEGER; pub const pid_t = HANDLE; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index ef7c0ff077..ca8f0907e1 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -253,6 +253,18 @@ pub fn mkdirat(dirfd: i32, path: [*:0]const u8, mode: u32) usize { return syscall3(.mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode); } +pub fn mknod(path: [*:0]const u8, mode: u32, dev: u32) usize { + if (@hasField(SYS, "mknod")) { + return syscall3(.mknod, @ptrToInt(path), mode, dev); + } else { + return mknodat(AT_FDCWD, path, mode, dev); + } +} + +pub fn mknodat(dirfd: i32, path: [*:0]const u8, mode: u32, dev: u32) usize { + return syscall4(.mknodat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, dev); +} + pub fn mount(special: [*:0]const u8, dir: [*:0]const u8, fstype: [*:0]const u8, flags: u32, data: usize) usize { return syscall5(.mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data); } diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig index bac7048615..469b7299d1 100644 --- a/lib/std/os/linux/arm-eabi.zig +++ b/lib/std/os/linux/arm-eabi.zig @@ -3,7 +3,7 @@ // This file is part of [zig](https://ziglang.org/), which is MIT licensed. // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall0(number: SYS) usize { return asm volatile ("svc #0" diff --git a/lib/std/os/linux/arm64.zig b/lib/std/os/linux/arm64.zig index dd5c3ef3af..4c8306c048 100644 --- a/lib/std/os/linux/arm64.zig +++ b/lib/std/os/linux/arm64.zig @@ -3,7 +3,7 @@ // This file is part of [zig](https://ziglang.org/), which is MIT licensed. // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall0(number: SYS) usize { return asm volatile ("svc #0" diff --git a/lib/std/os/linux/i386.zig b/lib/std/os/linux/i386.zig index c1ac6938fb..2ec34bac40 100644 --- a/lib/std/os/linux/i386.zig +++ b/lib/std/os/linux/i386.zig @@ -3,7 +3,7 @@ // This file is part of [zig](https://ziglang.org/), which is MIT licensed. // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall0(number: SYS) usize { return asm volatile ("int $0x80" diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index a04a592f3b..85157f04f8 100644 --- a/lib/std/os/linux/mips.zig +++ b/lib/std/os/linux/mips.zig @@ -3,7 +3,7 @@ // This file is part of [zig](https://ziglang.org/), which is MIT licensed. // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall0(number: SYS) usize { return asm volatile ( diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig index 567ad2bc1f..611eee1c5f 100644 --- a/lib/std/os/linux/powerpc.zig +++ b/lib/std/os/linux/powerpc.zig @@ -4,7 +4,7 @@ // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall0(number: SYS) usize { return asm volatile ( diff --git a/lib/std/os/linux/powerpc64.zig b/lib/std/os/linux/powerpc64.zig index 567ad2bc1f..611eee1c5f 100644 --- a/lib/std/os/linux/powerpc64.zig +++ b/lib/std/os/linux/powerpc64.zig @@ -4,7 +4,7 @@ // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall0(number: SYS) usize { return asm volatile ( diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index d58e080407..3e2b15b599 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/lib/std/os/linux/riscv64.zig @@ -3,7 +3,7 @@ // This file is part of [zig](https://ziglang.org/), which is MIT licensed. // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall0(number: SYS) usize { return asm volatile ("ecall" diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index 902940071e..f347a0e88e 100644 --- a/lib/std/os/linux/sparc64.zig +++ b/lib/std/os/linux/sparc64.zig @@ -1,4 +1,4 @@ -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall_pipe(fd: *[2]i32) usize { return asm volatile ( diff --git a/lib/std/os/linux/thumb.zig b/lib/std/os/linux/thumb.zig index 5db9d2cbf4..85f8bfc52b 100644 --- a/lib/std/os/linux/thumb.zig +++ b/lib/std/os/linux/thumb.zig @@ -3,7 +3,7 @@ // This file is part of [zig](https://ziglang.org/), which is MIT licensed. // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); // The syscall interface is identical to the ARM one but we're facing an extra // challenge: r7, the register where the syscall number is stored, may be diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig index b9b3ff47eb..5aa32c56c3 100644 --- a/lib/std/os/linux/x86_64.zig +++ b/lib/std/os/linux/x86_64.zig @@ -3,7 +3,7 @@ // This file is part of [zig](https://ziglang.org/), which is MIT licensed. // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -usingnamespace @import("../bits.zig"); +usingnamespace @import("../bits/linux.zig"); pub fn syscall0(number: SYS) usize { return asm volatile ("syscall" diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index cbd4ce065b..04ce433758 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -1631,6 +1631,10 @@ pub fn HeapDestroy(hHeap: HANDLE) void { assert(kernel32.HeapDestroy(hHeap) != 0); } +pub fn LocalFree(hMem: HLOCAL) void { + assert(kernel32.LocalFree(hMem) == null); +} + pub const GetFileInformationByHandleError = error{Unexpected}; pub fn GetFileInformationByHandle( @@ -2011,6 +2015,21 @@ pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { return error.Unexpected; } +pub fn SetThreadDescription(hThread: HANDLE, lpThreadDescription: LPCWSTR) !void { + if (kernel32.SetThreadDescription(hThread, lpThreadDescription) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} +pub fn GetThreadDescription(hThread: HANDLE, ppszThreadDescription: *LPWSTR) !void { + if (kernel32.GetThreadDescription(hThread, ppszThreadDescription) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + test "" { if (builtin.os.tag == .windows) { _ = @import("windows/test.zig"); diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig index 971273ef3a..a04314324d 100644 --- a/lib/std/os/windows/kernel32.zig +++ b/lib/std/os/windows/kernel32.zig @@ -192,6 +192,8 @@ pub extern "kernel32" fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: ?*co pub extern "kernel32" fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD) callconv(WINAPI) ?LPVOID; pub extern "kernel32" fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) callconv(WINAPI) BOOL; +pub extern "kernel32" fn LocalFree(hMem: HLOCAL) callconv(WINAPI) ?HLOCAL; + pub extern "kernel32" fn MoveFileExW( lpExistingFileName: [*:0]const u16, lpNewFileName: [*:0]const u16, @@ -342,3 +344,6 @@ pub extern "kernel32" fn SleepConditionVariableSRW( pub extern "kernel32" fn TryAcquireSRWLockExclusive(s: *SRWLOCK) callconv(WINAPI) BOOLEAN; pub extern "kernel32" fn AcquireSRWLockExclusive(s: *SRWLOCK) callconv(WINAPI) void; pub extern "kernel32" fn ReleaseSRWLockExclusive(s: *SRWLOCK) callconv(WINAPI) void; + +pub extern "kernel32" fn SetThreadDescription(hThread: HANDLE, lpThreadDescription: LPCWSTR) callconv(WINAPI) HRESULT; +pub extern "kernel32" fn GetThreadDescription(hThread: HANDLE, ppszThreadDescription: *LPWSTR) callconv(WINAPI) HRESULT; |
