Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/CMakeLists.txt b/CMakeLists.txt
- index bda57634..9839218a 100644
- --- a/CMakeLists.txt
- +++ b/CMakeLists.txt
- @@ -426,6 +426,7 @@ set(ZIG_STD_FILES
- "c/darwin.zig"
- "c/index.zig"
- "c/linux.zig"
- + "c/openbsd.zig"
- "c/windows.zig"
- "crypto/blake2.zig"
- "crypto/hmac.zig"
- @@ -537,6 +538,9 @@ set(ZIG_STD_FILES
- "os/linux/index.zig"
- "os/linux/vdso.zig"
- "os/linux/x86_64.zig"
- + "os/openbsd/errno.zig"
- + "os/openbsd/index.zig"
- + "os/openbsd/x86_64.zig"
- "os/path.zig"
- "os/time.zig"
- "os/windows/error.zig"
- diff --git a/src/analyze.cpp b/src/analyze.cpp
- index d6137a42..2c1c1b19 100644
- --- a/src/analyze.cpp
- +++ b/src/analyze.cpp
- @@ -4468,6 +4468,8 @@ void find_libc_lib_path(CodeGen *g) {
- } else if (g->zig_target.os == OsLinux) {
- g->libc_lib_dir = get_linux_libc_lib_path("crt1.o");
- + } else if (g->zig_target.os == OsOpenBSD) {
- + g->libc_lib_dir = get_linux_libc_lib_path("crt0.o");
- } else {
- zig_panic("Unable to determine libc lib path.");
- }
- @@ -4478,7 +4480,7 @@ void find_libc_lib_path(CodeGen *g) {
- if (g->libc_static_lib_dir == nullptr) {
- if ((g->zig_target.os == OsWindows) && (g->msvc_lib_dir != NULL)) {
- return;
- - } else if (g->zig_target.os == OsLinux) {
- + } else if (g->zig_target.os == OsLinux || g->zig_target.os == OsOpenBSD) {
- g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o");
- } else {
- zig_panic("Unable to determine libc static lib path.");
- diff --git a/src/link.cpp b/src/link.cpp
- index d454d77a..279fcc8b 100644
- --- a/src/link.cpp
- +++ b/src/link.cpp
- @@ -18,13 +18,13 @@ struct LinkJob {
- bool link_in_crt;
- HashMap<Buf *, bool, buf_hash, buf_eql_buf> rpath_table;
- };
- -
- +/*
- static const char *get_libc_file(CodeGen *g, const char *file) {
- Buf *out_buf = buf_alloc();
- os_path_join(g->libc_lib_dir, buf_create_from_str(file), out_buf);
- return buf_ptr(out_buf);
- }
- -
- +*/
- static const char *get_libc_static_file(CodeGen *g, const char *file) {
- Buf *out_buf = buf_alloc();
- os_path_join(g->libc_static_lib_dir, buf_create_from_str(file), out_buf);
- @@ -256,11 +256,11 @@ static void construct_linker_job_elf(LinkJob *lj) {
- crt1o = "crt1.o";
- crtbegino = "crtbeginT.o";
- } else {
- - crt1o = "Scrt1.o";
- +// crt1o = "Scrt1.o";
- crtbegino = "crtbegin.o";
- }
- - lj->args.append(get_libc_file(g, crt1o));
- - lj->args.append(get_libc_file(g, "crti.o"));
- +// lj->args.append(get_libc_file(g, crt1o));
- +// ((lj->args.append(get_libc_file(g, "crti.o"))));
- lj->args.append(get_libc_static_file(g, crtbegino));
- }
- @@ -354,21 +354,23 @@ static void construct_linker_job_elf(LinkJob *lj) {
- if (g->libc_link_lib != nullptr) {
- if (g->is_static) {
- lj->args.append("--start-group");
- + lj->args.append("-L /usr/local/lib");
- lj->args.append("-lgcc");
- lj->args.append("-lgcc_eh");
- lj->args.append("-lc");
- lj->args.append("-lm");
- lj->args.append("--end-group");
- } else {
- - lj->args.append("-lgcc");
- + lj->args.append("-L /usr/local/lib");
- +// lj->args.append("-lgcc");
- lj->args.append("--as-needed");
- - lj->args.append("-lgcc_s");
- +// lj->args.append("-lgcc_s");
- lj->args.append("--no-as-needed");
- lj->args.append("-lc");
- lj->args.append("-lm");
- - lj->args.append("-lgcc");
- + // lj->args.append("-lgcc");
- lj->args.append("--as-needed");
- - lj->args.append("-lgcc_s");
- + // lj->args.append("-lgcc_s");
- lj->args.append("--no-as-needed");
- }
- }
- @@ -376,7 +378,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
- // crt end
- if (lj->link_in_crt) {
- lj->args.append(get_libc_static_file(g, "crtend.o"));
- - lj->args.append(get_libc_file(g, "crtn.o"));
- +// lj->args.append(get_libc_file(g, "crtn.O"));
- }
- if (!g->is_native_target) {
- diff --git a/src/os.cpp b/src/os.cpp
- index 97462bd6..113439f0 100644
- --- a/src/os.cpp
- +++ b/src/os.cpp
- @@ -1010,6 +1010,12 @@ int os_self_exe_path(Buf *out_path) {
- buf_resize(out_path, amt);
- return 0;
- }
- +#elif defined(ZIG_OS_OPENBSD)
- + buf_resize(out_path, 256);
- + if (realpath(getprogname(), buf_ptr(out_path)) == NULL) {
- + return ErrorUnexpected;
- + }
- + return 0;
- #endif
- return ErrorFileNotFound;
- }
- diff --git a/src/os.hpp b/src/os.hpp
- index b94e98ec..91a72d89 100644
- --- a/src/os.hpp
- +++ b/src/os.hpp
- @@ -98,6 +98,8 @@ int os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchTy
- #define ZIG_OS_WINDOWS
- #elif defined(__linux__)
- #define ZIG_OS_LINUX
- +#elif defined(__OpenBSD__)
- +#define ZIG_OS_OPENBSD
- #else
- #define ZIG_OS_UNKNOWN
- #endif
- diff --git a/std/c/index.zig b/std/c/index.zig
- index 34269d2a..3390a5c8 100644
- --- a/std/c/index.zig
- +++ b/std/c/index.zig
- @@ -5,6 +5,7 @@ pub use switch(builtin.os) {
- Os.linux => @import("linux.zig"),
- Os.windows => @import("windows.zig"),
- Os.macosx, Os.ios => @import("darwin.zig"),
- + Os.openbsd => @import("openbsd.zig"),
- else => empty_import,
- };
- const empty_import = @import("../empty.zig");
- @@ -42,6 +43,7 @@ pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: u
- pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
- pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;
- pub extern "c" fn gettimeofday(tv: ?&timeval, tz: ?&timezone) c_int;
- +pub extern "c" fn getprogname() &const u8;
- pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
- pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?×pec) c_int;
- pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
- diff --git a/std/c/openbsd.zig b/std/c/openbsd.zig
- new file mode 100644
- index 00000000..da2a3b9b
- --- /dev/null
- +++ b/std/c/openbsd.zig
- @@ -0,0 +1,24 @@
- +pub use @import("../os/openbsd/errno.zig");
- +
- +pub extern "c" fn getentropy(buf_ptr: &u8, buf_len: usize) c_int;
- +extern "c" fn __errno() &c_int;
- +pub const _errno = __errno;
- +
- +/// Renamed to Stat to not conflict with the stat function.
- +pub const Stat = extern struct {
- + dev: i32,
- + ino: u64,
- + mode: u16,
- + nlink: u16,
- + uid: u32,
- + gid: u32,
- + rdev: i32,
- + atime: usize,
- + mtime: usize,
- + ctime: usize,
- + size: i64,
- + blocks: i64,
- + blksize: i32,
- + flags: u32,
- + gen: u32
- +};
- diff --git a/std/heap.zig b/std/heap.zig
- index 7b753524..40978ed6 100644
- --- a/std/heap.zig
- +++ b/std/heap.zig
- @@ -70,7 +70,8 @@ pub const DirectAllocator = struct {
- switch (builtin.os) {
- Os.linux,
- Os.macosx,
- - Os.ios => {
- + Os.ios,
- + Os.openbsd => {
- const p = os.posix;
- const alloc_size = if (alignment <= os.page_size) n else n + alignment;
- const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
- @@ -123,7 +124,8 @@ pub const DirectAllocator = struct {
- switch (builtin.os) {
- Os.linux,
- Os.macosx,
- - Os.ios => {
- + Os.ios,
- + Os.openbsd => {
- if (new_size <= old_mem.len) {
- const base_addr = @ptrToInt(old_mem.ptr);
- const old_addr_end = base_addr + old_mem.len;
- @@ -170,7 +172,8 @@ pub const DirectAllocator = struct {
- switch (builtin.os) {
- Os.linux,
- Os.macosx,
- - Os.ios => {
- + Os.ios,
- + Os.openbsd => {
- _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
- },
- Os.windows => {
- diff --git a/std/os/file.zig b/std/os/file.zig
- index 61fc2b14..3a8536ae 100644
- --- a/std/os/file.zig
- +++ b/std/os/file.zig
- @@ -141,7 +141,10 @@ pub const File = struct {
- pub fn seekForward(self: &File, amount: isize) !void {
- switch (builtin.os) {
- - Os.linux, Os.macosx, Os.ios => {
- + Os.linux,
- + Os.macosx,
- + Os.ios,
- + Os.openbsd => {
- const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);
- const err = posix.getErrno(result);
- if (err > 0) {
- @@ -170,7 +173,10 @@ pub const File = struct {
- pub fn seekTo(self: &File, pos: usize) !void {
- switch (builtin.os) {
- - Os.linux, Os.macosx, Os.ios => {
- + Os.linux,
- + Os.macosx,
- + Os.ios,
- + Os.openbsd => {
- const ipos = try math.cast(isize, pos);
- const result = posix.lseek(self.handle, ipos, posix.SEEK_SET);
- const err = posix.getErrno(result);
- @@ -201,7 +207,10 @@ pub const File = struct {
- pub fn getPos(self: &File) !usize {
- switch (builtin.os) {
- - Os.linux, Os.macosx, Os.ios => {
- + Os.linux,
- + Os.macosx,
- + Os.ios,
- + Os.openbsd => {
- const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);
- const err = posix.getErrno(result);
- if (err > 0) {
- diff --git a/std/os/get_user_id.zig b/std/os/get_user_id.zig
- index 11410ffa..1eafde9d 100644
- --- a/std/os/get_user_id.zig
- +++ b/std/os/get_user_id.zig
- @@ -11,7 +11,7 @@ pub const UserInfo = struct {
- /// POSIX function which gets a uid from username.
- pub fn getUserInfo(name: []const u8) !UserInfo {
- return switch (builtin.os) {
- - Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name),
- + Os.linux, Os.macosx, Os.ios, Os.openbsd => posixGetUserInfo(name),
- else => @compileError("Unsupported OS"),
- };
- }
- diff --git a/std/os/index.zig b/std/os/index.zig
- index 7d19cd82..d9672bdf 100644
- --- a/std/os/index.zig
- +++ b/std/os/index.zig
- @@ -4,7 +4,8 @@ const Os = builtin.Os;
- const is_windows = builtin.os == Os.windows;
- const is_posix = switch (builtin.os) {
- builtin.Os.linux,
- - builtin.Os.macosx => true,
- + builtin.Os.macosx,
- + builtin.Os.openbsd => true,
- else => false,
- };
- const os = this;
- @@ -15,6 +16,7 @@ test "std.os" {
- _ = @import("darwin_errno.zig");
- _ = @import("get_user_id.zig");
- _ = @import("linux/index.zig");
- + _ = @import("openbsd/index.zig");
- _ = @import("path.zig");
- _ = @import("test.zig");
- _ = @import("time.zig");
- @@ -25,11 +27,13 @@ pub const windows = @import("windows/index.zig");
- pub const darwin = @import("darwin.zig");
- pub const linux = @import("linux/index.zig");
- pub const zen = @import("zen.zig");
- +pub const openbsd = @import("openbsd/index.zig");
- pub const posix = switch (builtin.os) {
- Os.linux => linux,
- Os.macosx,
- Os.ios => darwin,
- Os.zen => zen,
- + Os.openbsd => openbsd,
- else => @compileError("Unsupported OS"),
- };
- pub const net = @import("net.zig");
- @@ -157,6 +161,17 @@ pub fn getRandomBytes(buf: []u8) !void {
- buf[i] = randomness[i];
- }
- },
- + Os.openbsd => {
- + const err = posix.getErrno(posix.getentropy(buf.ptr, buf.len));
- + if (err > 0) {
- + return switch (err) {
- + posix.EFAULT => unreachable,
- + posix.EIO => unreachable,
- + else => unexpectedErrorPosix(err),
- + };
- + }
- + return;
- + },
- else => @compileError("Unsupported OS"),
- }
- }
- @@ -177,7 +192,8 @@ pub fn abort() noreturn {
- switch (builtin.os) {
- Os.linux,
- Os.macosx,
- - Os.ios => {
- + Os.ios,
- + Os.openbsd => {
- _ = posix.raise(posix.SIGABRT);
- _ = posix.raise(posix.SIGKILL);
- while (true) {}
- @@ -201,7 +217,8 @@ pub fn exit(status: u8) noreturn {
- switch (builtin.os) {
- Os.linux,
- Os.macosx,
- - Os.ios => {
- + Os.ios,
- + Os.openbsd => {
- posix.exit(status);
- },
- Os.windows => {
- @@ -1847,6 +1864,12 @@ pub fn openSelfExe() !os.File {
- const self_exe_path = try selfExePath(&fixed_allocator.allocator);
- return os.File.openRead(&fixed_allocator.allocator, self_exe_path);
- },
- + Os.openbsd => {
- + var fixed_buffer_mem: [openbsd.PATH_MAX * 2]u8 = undefined;
- + var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
- + const self_exe_path = try selfExePath(&fixed_allocator.allocator);
- + return os.File.openRead(&fixed_allocator.allocator, self_exe_path);
- + },
- else => @compileError("Unsupported OS"),
- }
- }
- @@ -1855,7 +1878,8 @@ test "openSelfExe" {
- switch (builtin.os) {
- Os.linux,
- Os.macosx,
- - Os.ios => (try openSelfExe()).close(),
- + Os.ios,
- + Os.openbsd => (try openSelfExe()).close(),
- else => return, // Unsupported OS.
- }
- }
- @@ -1904,6 +1928,14 @@ pub fn selfExePath(allocator: &mem.Allocator) ![]u8 {
- assert(ret2 == 0);
- return bytes;
- },
- + Os.openbsd => {
- + const ret1 = c.getprogname();
- + const bytes = try allocator.alloc(u8, 256);
- + errdefer allocator.free(bytes);
- + const ret2 = c.realpath(ret1, bytes.ptr);
- + assert(ret2 != null);
- + return bytes;
- + },
- else => @compileError("Unsupported OS"),
- }
- }
- diff --git a/std/os/openbsd/errno.zig b/std/os/openbsd/errno.zig
- new file mode 100644
- index 00000000..f56b413b
- --- /dev/null
- +++ b/std/os/openbsd/errno.zig
- @@ -0,0 +1,112 @@
- +pub const EPERM = 1; /// Operation not permitted
- +pub const ENOENT = 2; /// No such file or directory
- +pub const ESRCH = 3; /// No such process
- +pub const EINTR = 4; /// Interrupted system call
- +pub const EIO = 5; /// Input/output error
- +pub const ENXIO = 6; /// Device not configured
- +pub const E2BIG = 7; /// Arg list too long
- +pub const ENOEXEC = 8; /// Exec format error
- +pub const EBADF = 9; /// Bad file descriptor
- +pub const ECHILD = 10; /// No child processes
- +pub const EDEADLK = 11; /// Ressource deadlock avoided
- +pub const ENOMEM = 12; /// Cannot allocate memory
- +pub const EACCES = 13; /// Permission denied
- +pub const EFAULT = 14; /// Bad address
- +pub const ENOTBLK = 15; /// Block device required
- +pub const EBUSY = 16; /// Device busy
- +pub const EEXIST = 17; /// File exists
- +pub const EXDEV = 18; /// Cross-device link
- +pub const ENODEV = 19; /// Operation not supported by device
- +pub const ENOTDIR = 20; /// Not a directory
- +pub const EISDIR = 21; /// Is a directory
- +pub const EINVAL = 22; /// Invalid argument
- +pub const ENFILE = 23; /// Too many open files in system
- +pub const EMFILE = 24; /// Too many open files
- +pub const ENOTTY = 25; /// Inappropriate ioctl for device
- +pub const ETXTBSY = 26; /// Text file busy
- +pub const EFBIG = 27; /// File too large
- +pub const ENOSPC = 28; /// No space left on device
- +pub const ESPIPE = 29; /// Illegal seek
- +pub const EROFS = 30; /// Read-only file system
- +pub const EMLINK = 31; /// Too many links
- +pub const EPIPE = 32; /// Broken pipe
- +
- +pub const EDOM = 33; /// Numerical argument out of domain
- +pub const ERANGE = 34; /// Result too large
- +
- +pub const EAGAIN = 35; /// Resource temporarily unavailable
- +pub const EWOULDBLOCK = EAGAIN; /// Operation would block
- +pub const EINPROGRESS= 36; /// Operation now in progress
- +pub const EALREADY = 37; /// Operation already in progress
- +
- +pub const ENOTSOCK = 38; /// Socket operation on non-socket
- +pub const EDESTADDRREQ = 39; /// Destination address required
- +pub const EMSGSIZE = 40; /// Message too long
- +pub const EPROTOTYPE = 41; /// Protocol wrong type for socket
- +pub const ENOPROTOOPT = 42; /// Protocol not available
- +pub const EPROTONOSUPPORT = 43; /// Protocol not supported
- +pub const ESOCKTNOSUPPORT = 44; /// Socket type not supported
- +pub const EOPNOTSUPP = 45; /// Operation not supported
- +pub const EPFNOSUPPORT = 46; /// Protocol family not supported
- +pub const EAFNOSUPPORT = 47; /// Address family not supported by protocol family
- +pub const EADDRINUSE = 48; /// Address already in use
- +pub const EADDRNOTAVAIL = 49; /// Can't assign requested address
- +
- +pub const ENETDOWN = 50; /// Network is down
- +pub const ENETUNREACH = 51; /// Network is unreachable
- +pub const ENETRESET = 52; /// Network dropped connection on reset
- +pub const ECONNABORTED = 53; /// Software caused connection abort
- +pub const ECONNRESET = 54; /// Connection reset by peer
- +pub const ENOBUFS = 55; /// No buffer space available
- +pub const EISCONN = 56; /// Socket is already connected
- +pub const ENOTCONN = 57; /// Socket is not connected
- +pub const ESHUTDOWN = 58; /// Can't send after socket shutdown
- +pub const ETOOMANYREFS = 59; /// Too many references: can't splice
- +pub const ETIMEDOUT = 60; /// Operation timed out
- +pub const ECONNREFUSED = 61; /// Connection refused
- +
- +pub const ELOOP = 62; /// Too many levels of symbolic links
- +pub const ENAMETOOLONG = 63; /// File name too long
- +
- +pub const EHOSTDOWN = 64; /// Host is down
- +pub const EHOSTUNREACH = 65; /// No route to host
- +pub const ENOTEMPTY = 66; /// Directory not empty
- +
- +pub const EPROCLIM = 67; /// Too many processes
- +pub const EUSERS = 68; /// Too many users
- +pub const EDQUOT = 69; ///
- +
- +pub const ESTALE = 70; /// Stale NFS file handle
- +pub const EREMOTE = 71; /// Too many levels of remote in path
- +pub const EBADRPC = 72; /// RPC struct is bad
- +pub const ERPCMISMATCH = 73; /// RPC version wrong
- +pub const EPROGUNAVAIL = 74; /// RPC program not available
- +pub const EPROGMISMATCH = 75; /// Program version wrong
- +pub const EPROCUNAVAIL = 76; /// Bad procedure for program
- +pub const ENOLCK = 77; /// No locks available
- +pub const ENOSYS = 78; /// Function not implemented
- +pub const EFTYPE = 79; /// Inappropriate file type or format
- +pub const EAUTH = 80; /// Authentication error
- +pub const ENEEDAUTH = 81; /// Need authenticator
- +pub const EIPSEC = 82; /// IPsec processing failure
- +pub const ENOATTR = 83; /// Attribute not found
- +pub const EILSEQ = 84; /// Illegal byte sequence
- +pub const ENOMEDIUM = 85; /// No medium found
- +pub const EMEDIUMTYPE = 86; /// Wrong medium type
- +pub const EOVERFLOW = 87; /// Value too large to be stored in data type
- +pub const ECANCELED = 88; /// Operation canceled
- +pub const EIDRM = 89; /// Identifier removed
- +pub const ENOMSG = 90; /// No message of desired type
- +pub const ENOTSUP = 91; /// Not supported
- +pub const EBADMSG = 92; /// Bad message
- +pub const ENOTRECOVERABLE = 93; /// State not recoverable
- +pub const EOWNERDEAD = 94; /// Previous owner died
- +pub const EPROTO = 95; /// Protocol error
- +pub const ELAST = 95; /// Must be equal largest errno
- +
- +pub const ERESTART = -1; /// restart syscall
- +pub const EJUSTRETURN = -2; /// don't modify regs, just return
- +
- +
- +
- +
- diff --git a/std/os/openbsd/index.zig b/std/os/openbsd/index.zig
- new file mode 100644
- index 00000000..921af403
- --- /dev/null
- +++ b/std/os/openbsd/index.zig
- @@ -0,0 +1,201 @@
- +const std = @import("../../index.zig");
- +const c = std.c;
- +const assert = std.debug.assert;
- +const builtin = @import("builtin");
- +const vdso = @import("vdso.zig");
- +pub use switch (builtin.arch) {
- + builtin.Arch.x86_64 => @import("x86_64.zig"),
- + else => @compileError("unsupported arch"),
- +};
- +pub use @import("errno.zig");
- +
- +pub const PATH_MAX = 1024;
- +
- +pub const STDIN_FILENO = 0;
- +pub const STDOUT_FILENO = 1;
- +pub const STDERR_FILENO = 2;
- +
- +pub const PROT_READ = 0x01;
- +pub const PROT_WRITE = 0x02;
- +pub const PROT_EXEC = 0x04;
- +
- +pub const MAP_PRIVATE = 0x0002;
- +pub const MAP_ANONYMOUS = 0x1000;
- +pub const MAP_FAILED = @maxValue(usize);
- +
- +pub fn raise(sig: i32) usize {
- + return usize(c.raise(sig));
- +}
- +
- +/// Get the errno from a syscall return value, or 0 for no error.
- +pub fn getErrno(r: usize) usize {
- + const signed_r = @bitCast(isize, r);
- + return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;
- +}
- +
- +pub fn getentropy(buf_ptr: &u8, buf_len: usize) usize {
- + return errnoWrap(c.getentropy(buf_ptr, buf_len));
- +}
- +
- +pub fn open(path: &const u8, flags: u32, mode: usize) usize {
- + return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
- +}
- +
- +pub fn close(fd: i32) usize {
- + return errnoWrap(c.close(fd));
- +}
- +
- +pub fn isatty(fd: i32) bool {
- + return c.isatty(fd) != 0;
- +}
- +
- +pub fn abort() noreturn {
- + c.abort();
- +}
- +
- +pub fn exit(code: i32) noreturn {
- + c.exit(code);
- +}
- +
- +pub fn read(fd: i32, buf: &u8, nbyte: usize) usize {
- + return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte));
- +}
- +
- +pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {
- + return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
- +}
- +
- +pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
- + return errnoWrap(c.lseek(fd, offset, whence));
- +}
- +
- +pub fn fstat(fd: i32, buf: &c.Stat) usize {
- + return errnoWrap(c.fstat(fd, buf));
- +}
- +
- +fn errnoWrap(value: isize) usize {
- + return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value);
- +}
- +
- +pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
- + const ptr_result = c.mmap(@ptrCast(&c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
- + const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
- + return errnoWrap(isize_result);
- +}
- +
- +pub fn munmap(address: usize, length: usize) usize {
- + return errnoWrap(c.munmap(@intToPtr(&c_void, address), length));
- +}
- +
- +
- +pub fn unlink(path: &const u8) usize {
- + return errnoWrap(c.unlink(path));
- +}
- +
- +pub fn getcwd(buf: &u8, size: usize) usize {
- + return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
- +}
- +
- +pub fn waitpid(pid: i32, status: &i32, options: u32) usize {
- + comptime assert(i32.bit_count == c_int.bit_count);
- + return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options)));
- +}
- +
- +pub fn fork() usize {
- + return errnoWrap(c.fork());
- +}
- +
- +pub fn access(path: &const u8, mode: u32) usize {
- + return errnoWrap(c.access(path, mode));
- +}
- +
- +pub fn pipe(fds: &[2]i32) usize {
- + comptime assert(i32.bit_count == c_int.bit_count);
- + return errnoWrap(c.pipe(@ptrCast(&c_int, fds)));
- +}
- +
- +pub fn getdirentries64(fd: i32, buf_ptr: &u8, buf_len: usize, basep: &i64) usize {
- + return errnoWrap(@bitCast(isize, c.__getdirentries64(fd, buf_ptr, buf_len, basep)));
- +}
- +
- +pub fn mkdir(path: &const u8, mode: u32) usize {
- + return errnoWrap(c.mkdir(path, mode));
- +}
- +
- +pub fn symlink(existing: &const u8, new: &const u8) usize {
- + return errnoWrap(c.symlink(existing, new));
- +}
- +
- +pub fn rename(old: &const u8, new: &const u8) usize {
- + return errnoWrap(c.rename(old, new));
- +}
- +
- +pub fn rmdir(path: &const u8) usize {
- + return errnoWrap(c.rmdir(path));
- +}
- +
- +pub fn chdir(path: &const u8) usize {
- + return errnoWrap(c.chdir(path));
- +}
- +
- +pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {
- + return errnoWrap(c.execve(path, argv, envp));
- +}
- +
- +pub fn dup2(old: i32, new: i32) usize {
- + return errnoWrap(c.dup2(old, new));
- +}
- +
- +pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {
- + return errnoWrap(c.readlink(path, buf_ptr, buf_len));
- +}
- +
- +pub fn gettimeofday(tv: ?&timeval, tz: ?&timezone) usize {
- + return errnoWrap(c.gettimeofday(tv, tz));
- +}
- +
- +pub fn nanosleep(req: &const timespec, rem: ?×pec) usize {
- + return errnoWrap(c.nanosleep(req, rem));
- +}
- +
- +pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) usize {
- + return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
- +}
- +
- +pub fn setreuid(ruid: u32, euid: u32) usize {
- + return errnoWrap(c.setreuid(ruid, euid));
- +}
- +
- +pub fn setregid(rgid: u32, egid: u32) usize {
- + return errnoWrap(c.setregid(rgid, egid));
- +}
- +
- +pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
- + return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset));
- +}
- +
- +pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
- + assert(sig != SIGKILL);
- + assert(sig != SIGSTOP);
- + var cact = c.Sigaction{
- + .handler = @ptrCast(extern fn(c_int) void, act.handler),
- + .sa_flags = @bitCast(c_int, act.flags),
- + .sa_mask = act.mask,
- + };
- + var coact: c.Sigaction = undefined;
- + const result = errnoWrap(c.sigaction(sig, &cact, &coact));
- + if (result != 0) {
- + return result;
- + }
- + if (oact) |old| {
- + old.* = Sigaction{
- + .handler = @ptrCast(extern fn(i32) void, coact.handler),
- + .flags = @bitCast(u32, coact.sa_flags),
- + .mask = coact.sa_mask,
- + };
- + }
- + return result;
- +}
- +
- +const sigset_t = [128 / @sizeOf(usize)]usize;
- +pub const Stat = c.Stat;
- diff --git a/std/os/openbsd/x86_64.zig b/std/os/openbsd/x86_64.zig
- new file mode 100644
- index 00000000..c0da9ed6
- --- /dev/null
- +++ b/std/os/openbsd/x86_64.zig
- @@ -0,0 +1,348 @@
- +const std = @import("../../index.zig");
- +const openbsd = std.os.openbsd;
- +const socklen_t = openbsd.socklen_t;
- +const iovec = openbsd.iovec;
- +
- +pub const SYS_syscall = 0;
- +pub const SYS_exit = 1;
- +pub const SYS_fork = 2;
- +pub const SYS_read = 3;
- +pub const SYS_write = 4;
- +pub const SYS_open = 5;
- +pub const SYS_close = 6;
- +pub const SYS_getentropy = 7;
- +pub const SYS___tfork = 8;
- +pub const SYS_link = 9;
- +pub const SYS_unlink = 10;
- +pub const SYS_wait4 = 11;
- +pub const SYS_chdir = 12;
- +pub const SYS_fchdir = 13;
- +pub const SYS_mknod = 14;
- +pub const SYS_chmod = 15;
- +pub const SYS_chown = 16;
- +pub const SYS_break = 17;
- +pub const SYS_getdtablecount = 18;
- +pub const SYS_getrusage = 19;
- +pub const SYS_getpid = 20;
- +pub const SYS_mount = 21;
- +pub const SYS_unmount = 22;
- +pub const SYS_setuid = 23;
- +pub const SYS_getuid = 24;
- +pub const SYS_geteuid = 25;
- +pub const SYS_ptrace = 26;
- +pub const SYS_recvmsg = 27;
- +pub const SYS_sendmsg = 28;
- +pub const SYS_recvfrom = 29;
- +pub const SYS_accept = 30;
- +pub const SYS_getpeername = 31;
- +pub const SYS_getsockname = 32;
- +pub const SYS_access = 33;
- +pub const SYS_chflags = 34;
- +pub const SYS_fchflags = 35;
- +pub const SYS_sync = 36;
- +pub const SYS_stat = 38;
- +pub const SYS_getppid = 39;
- +pub const SYS_lstat = 40;
- +pub const SYS_dup = 41;
- +pub const SYS_fstatat = 42;
- +pub const SYS_getegid = 43;
- +pub const SYS_profil = 44;
- +pub const SYS_ktrace = 45;
- +pub const SYS_sigaction = 46;
- +pub const SYS_getgid = 47;
- +pub const SYS_sigprocmask = 48;
- +pub const SYS_setlogin = 50;
- +pub const SYS_acct = 51;
- +pub const SYS_sigpending = 52;
- +pub const SYS_fstat = 53;
- +pub const SYS_ioctl = 54;
- +pub const SYS_reboot = 55;
- +pub const SYS_revoke = 56;
- +pub const SYS_symlink = 57;
- +pub const SYS_readlink = 58;
- +pub const SYS_execve = 59;
- +pub const SYS_umask = 60;
- +pub const SYS_chroot = 61;
- +pub const SYS_getfsstat = 62;
- +pub const SYS_statfs = 63;
- +pub const SYS_fstatfs = 64;
- +pub const SYS_fhstatfs = 65;
- +pub const SYS_vfork = 66;
- +pub const SYS_gettimeofday = 67;
- +pub const SYS_settimeofday = 68;
- +pub const SYS_setitimer = 69;
- +pub const SYS_getitimer = 70;
- +pub const SYS_select = 71;
- +pub const SYS_kevent = 72;
- +pub const SYS_munmap = 73;
- +pub const SYS_mprotect = 74;
- +pub const SYS_madvise = 75;
- +pub const SYS_utimes = 76;
- +pub const SYS_futimes = 77;
- +pub const SYS_mincore = 78;
- +pub const SYS_getgroups = 79;
- +pub const SYS_setgroups = 80;
- +pub const SYS_getpgrp = 81;
- +pub const SYS_setpgid = 82;
- +pub const SYS_futex = 83;
- +pub const SYS_utimensat = 84;
- +pub const SYS_futimens = 85;
- +pub const SYS_kbind = 86;
- +pub const SYS_clock_gettime = 87;
- +pub const SYS_clock_settime = 88;
- +pub const SYS_clock_getres = 89;
- +pub const SYS_dup2 = 90;
- +pub const SYS_nanosleep = 91;
- +pub const SYS_fcntl = 92;
- +pub const SYS_accept4 = 93;
- +pub const SYS___thrsleep = 94;
- +pub const SYS_fsync = 95;
- +pub const SYS_setpriority = 96;
- +pub const SYS_socket = 97;
- +pub const SYS_connect = 98;
- +pub const SYS_getdents = 99;
- +pub const SYS_getpriority = 100;
- +pub const SYS_pipe2 = 101;
- +pub const SYS_dup3 = 102;
- +pub const SYS_sigreturn = 103;
- +pub const SYS_bind = 104;
- +pub const SYS_setsockopt = 105;
- +pub const SYS_listen = 106;
- +pub const SYS_chflagsat = 107;
- +pub const SYS_pledge = 108;
- +pub const SYS_ppoll = 109;
- +pub const SYS_pselect = 110;
- +pub const SYS_sigsuspend = 111;
- +pub const SYS_sendsyslog = 112;
- +pub const SYS_getsockopt = 118;
- +pub const SYS_thrkill = 119;
- +pub const SYS_readv = 120;
- +pub const SYS_writev = 121;
- +pub const SYS_kill = 122;
- +pub const SYS_fchown = 123;
- +pub const SYS_fchmod = 124;
- +pub const SYS_setreuid = 126;
- +pub const SYS_setregid = 127;
- +pub const SYS_rename = 128;
- +pub const SYS_flock = 131;
- +pub const SYS_mkfifo = 132;
- +pub const SYS_sendto = 133;
- +pub const SYS_shutdown = 134;
- +pub const SYS_socketpair = 135;
- +pub const SYS_mkdir = 136;
- +pub const SYS_rmdir = 137;
- +pub const SYS_adjtime = 140;
- +pub const SYS_getlogin_r = 141;
- +pub const SYS_setsid = 147;
- +pub const SYS_quotactl = 148;
- +pub const SYS_nfssvc = 155;
- +pub const SYS_getfh = 161;
- +pub const SYS_sysarch = 165;
- +pub const SYS_pread = 173;
- +pub const SYS_pwrite = 174;
- +pub const SYS_setgid = 181;
- +pub const SYS_setegid = 182;
- +pub const SYS_seteuid = 183;
- +pub const SYS_pathconf = 191;
- +pub const SYS_fpathconf = 192;
- +pub const SYS_swapctl = 193;
- +pub const SYS_getrlimit = 194;
- +pub const SYS_setrlimit = 195;
- +pub const SYS_mmap = 197;
- +pub const SYS___syscall = 198;
- +pub const SYS_lseek = 199;
- +pub const SYS_truncate = 200;
- +pub const SYS_ftruncate = 201;
- +pub const SYS_sysctl = 202;
- +pub const SYS_mlock = 203;
- +pub const SYS_munlock = 204;
- +pub const SYS_getpgid = 207;
- +pub const SYS_utrace = 209;
- +pub const SYS_semget = 221;
- +pub const SYS_msgget = 225;
- +pub const SYS_msgsnd = 226;
- +pub const SYS_msgrcv = 227;
- +pub const SYS_shmat = 228;
- +pub const SYS_shmdt = 230;
- +pub const SYS_minherit = 250;
- +pub const SYS_poll = 252;
- +pub const SYS_issetugid = 253;
- +pub const SYS_lchown = 254;
- +pub const SYS_getsid = 255;
- +pub const SYS_msync = 256;
- +pub const SYS_pipe = 263;
- +pub const SYS_fhopen = 264;
- +pub const SYS_preadv = 267;
- +pub const SYS_pwritev = 268;
- +pub const SYS_kqueue = 269;
- +pub const SYS_mlockall = 271;
- +pub const SYS_munlockall = 272;
- +pub const SYS_getresuid = 281;
- +pub const SYS_setresuid = 282;
- +pub const SYS_getresgid = 283;
- +pub const SYS_setresgid = 284;
- +pub const SYS_mquery = 286;
- +pub const SYS_closefrom = 287;
- +pub const SYS_sigaltstack = 288;
- +pub const SYS_shmget = 289;
- +pub const SYS_semop = 290;
- +pub const SYS_fhstat = 294;
- +pub const SYS___semctl = 295;
- +pub const SYS_shmctl = 296;
- +pub const SYS_msgctl = 297;
- +pub const SYS_sched_yield = 298;
- +pub const SYS_getthrid = 299;
- +pub const SYS___thrwakeup = 301;
- +pub const SYS___threxit = 302;
- +pub const SYS___thrsigdivert = 303;
- +pub const SYS___getcwd = 304;
- +pub const SYS_adjfreq = 305;
- +pub const SYS_setrtable = 310;
- +pub const SYS_getrtable = 311;
- +pub const SYS_faccessat = 313;
- +pub const SYS_fchmodat = 314;
- +pub const SYS_fchownat = 315;
- +pub const SYS_linkat = 317;
- +pub const SYS_mkdirat = 318;
- +pub const SYS_mkfifoat = 319;
- +pub const SYS_mknodat = 320;
- +pub const SYS_openat = 321;
- +pub const SYS_readlinkat = 322;
- +pub const SYS_renameat = 323;
- +pub const SYS_symlinkat = 324;
- +pub const SYS_unlinkat = 325;
- +pub const SYS___set_tcb = 329;
- +pub const SYS___get_tcb = 330;
- +pub const SYS_MAXSYSCALL = 331;
- +
- +pub const O_RDONLY = 0x0000;
- +pub const O_WRONLY = 0x0001;
- +pub const O_RDWR = 0x0002;
- +pub const O_ACCMODE = 0x0003;
- +pub const O_NONBLOCK = 0x0004;
- +pub const O_APPEND = 0x0008;
- +pub const O_SHLOCK = 0x0010;
- +pub const O_EXLOCK = 0x0020;
- +pub const O_ASYNC = 0x0040;
- +pub const O_FSYNC = 0x0080;
- +pub const O_NOFOLLOW = 0x0100;
- +pub const O_SYNC = 0x0080;
- +pub const O_CREAT = 0x0200;
- +pub const O_TRUNC = 0x0400;
- +pub const O_EXCL = 0x0800;
- +pub const O_DSYNC = O_SYNC;
- +pub const O_RSYNC = O_SYNC;
- +pub const O_NOCTTY = 0x8000;
- +pub const O_CLOEXEC = 0x10000;
- +pub const O_DIRECTORY = 0x20000;
- +pub const O_LARGEFILE = 0;
- +
- +pub const FAPPEND = O_APPEND;
- +pub const FASYNC = O_ASYNC;
- +pub const FFSYNC = O_SYNC;
- +pub const FNONBLOCK = O_NONBLOCK;
- +pub const FNDELAY = O_NONBLOCK;
- +pub const O_NDELAY = O_NONBLOCK;
- +
- +pub const F_DUPFD = 0;
- +pub const F_GETFD = 1;
- +pub const F_SETFD = 2;
- +pub const F_GETFL = 3;
- +pub const F_SETFL = 4;
- +pub const F_GETOWN = 5;
- +pub const F_SETOWN = 6;
- +pub const F_GETLK = 7;
- +pub const F_SETLK = 8;
- +pub const F_SETLKW = 9;
- +pub const F_DUPFD_CLOEXEC = 10;
- +pub const F_ISATTY = 11;
- +
- +pub const FD_CLOEXEC = 1;
- +
- +pub const F_RDLCK = 1;
- +pub const F_UNLCK = 2;
- +pub const F_WRLCK = 3;
- +pub const F_WAIT = 0x010;
- +pub const F_FLOCK = 0x020;
- +pub const F_POSIX = 0x040;
- +
- +pub const SEEK_SET = 0;
- +pub const SEEK_CUR = 1;
- +pub const SEEK_END = 2;
- +
- +pub const DT_UNKNOWN = 0;
- +pub const DT_FIFO = 1;
- +pub const DT_CHR = 2;
- +pub const DT_DIR = 4;
- +pub const DT_BLK = 6;
- +pub const DT_REG = 8;
- +pub const DT_LNK = 10;
- +pub const DT_SOCK = 12;
- +
- +pub const SIG_BLOCK = 1;
- +pub const SIG_UNBLOCK = 2;
- +pub const SIG_SETMASK = 3;
- +
- +pub const SIGHUP = 1;
- +pub const SIGINT = 2;
- +pub const SIGQUIT = 3;
- +pub const SIGILL = 4;
- +pub const SIGTRAP = 5;
- +pub const SIGABRT = 6;
- +pub const SIGPOLL = 7;
- +pub const SIGIOT = SIGABRT;
- +pub const SIGEMT = 7;
- +pub const SIGFPE = 8;
- +pub const SIGKILL = 9;
- +pub const SIGBUS = 10;
- +pub const SIGSEGV = 11;
- +pub const SIGSYS = 12;
- +pub const SIGPIPE = 13;
- +pub const SIGALRM = 14;
- +pub const SIGTERM = 15;
- +pub const SIGURG = 16;
- +pub const SIGSTOP = 17;
- +pub const SIGTSTP = 18;
- +pub const SIGCONT = 19;
- +pub const SIGCHLD = 20;
- +pub const SIGTTIN = 21;
- +pub const SIGTTOU = 22;
- +pub const SIGIO = 23;
- +pub const SIGXCPU = 24;
- +pub const SIGXFSZ = 25;
- +pub const SIGVTALRM = 26;
- +pub const SIGPROF = 27;
- +pub const SIGWINCH = 28;
- +pub const SIGINFO = 29;
- +pub const SIGUSR1 = 30;
- +pub const SIGUSR2 = 31;
- +
- +const wstopped = 0o177;
- +const wcontinued = 0o177777;
- +
- +fn wstatus(x: i32) i32 {
- + return x & 0o177;
- +}
- +
- +pub fn WEXITSTATUS(x: i32) i32 {
- + return x >> 8;
- +}
- +pub fn WTERMSIG(x: i32) i32 {
- + return wstatus(x);
- +}
- +pub fn WSTOPSIG(x: i32) i32 {
- + return x >> 8;
- +}
- +pub fn WIFEXITED(x: i32) bool {
- + return wstatus(x) == 0;
- +}
- +pub fn WIFSTOPPED(x: i32) bool {
- + return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13;
- +}
- +pub fn WIFSIGNALED(x: i32) bool {
- + return wstatus(x) != wstopped and wstatus(x) != 0;
- +}
- +
- +
- +
- +
- diff --git a/std/os/path.zig b/std/os/path.zig
- index 0ea5d5a7..db69543e 100644
- --- a/std/os/path.zig
- +++ b/std/os/path.zig
- @@ -1130,7 +1130,9 @@ pub fn real(allocator: &Allocator, pathname: []const u8) ![]u8 {
- return allocator.shrink(u8, buf, final_len);
- }
- },
- - Os.macosx, Os.ios => {
- + Os.macosx,
- + Os.ios,
- + Os.openbsd => {
- // TODO instead of calling the libc function here, port the implementation
- // to Zig, and then remove the NameTooLong error possibility.
- const pathname_buf = try allocator.alloc(u8, pathname.len + 1);
- diff --git a/std/special/builtin.zig b/std/special/builtin.zig
- index a5126bc4..60426244 100644
- --- a/std/special/builtin.zig
- +++ b/std/special/builtin.zig
- @@ -53,6 +53,8 @@ export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 {
- return dest;
- }
- +extern var __guard_local: c_long section(".openbsd.randomdata");
- +
- comptime {
- if (builtin.mode != builtin.Mode.ReleaseFast and
- builtin.mode != builtin.Mode.ReleaseSmall and
- @@ -62,6 +64,9 @@ comptime {
- if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
- @export("clone", clone, builtin.GlobalLinkage.Strong);
- }
- + if (builtin.os == builtin.Os.openbsd) {
- + @export("__guard_local", __guard_local, builtin.GlobalLinkage.Strong);
- + }
- }
- extern fn __stack_chk_fail() noreturn {
- @panic("stack smashing detected");
Advertisement
Add Comment
Please, Sign In to add comment