ciphron_pastebin

zig.diff

May 25th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 35.57 KB | None | 0 0
  1. diff --git a/CMakeLists.txt b/CMakeLists.txt
  2. index bda57634..9839218a 100644
  3. --- a/CMakeLists.txt
  4. +++ b/CMakeLists.txt
  5. @@ -426,6 +426,7 @@ set(ZIG_STD_FILES
  6.      "c/darwin.zig"
  7.      "c/index.zig"
  8.      "c/linux.zig"
  9. +    "c/openbsd.zig"
  10.      "c/windows.zig"
  11.      "crypto/blake2.zig"
  12.      "crypto/hmac.zig"
  13. @@ -537,6 +538,9 @@ set(ZIG_STD_FILES
  14.      "os/linux/index.zig"
  15.      "os/linux/vdso.zig"
  16.      "os/linux/x86_64.zig"
  17. +    "os/openbsd/errno.zig"
  18. +    "os/openbsd/index.zig"
  19. +    "os/openbsd/x86_64.zig"
  20.      "os/path.zig"
  21.      "os/time.zig"
  22.      "os/windows/error.zig"
  23. diff --git a/src/analyze.cpp b/src/analyze.cpp
  24. index d6137a42..2c1c1b19 100644
  25. --- a/src/analyze.cpp
  26. +++ b/src/analyze.cpp
  27. @@ -4468,6 +4468,8 @@ void find_libc_lib_path(CodeGen *g) {
  28.  
  29.          } else if (g->zig_target.os == OsLinux) {
  30.              g->libc_lib_dir = get_linux_libc_lib_path("crt1.o");
  31. +        } else if (g->zig_target.os == OsOpenBSD) {
  32. +            g->libc_lib_dir = get_linux_libc_lib_path("crt0.o");
  33.          } else {
  34.              zig_panic("Unable to determine libc lib path.");
  35.          }
  36. @@ -4478,7 +4480,7 @@ void find_libc_lib_path(CodeGen *g) {
  37.      if (g->libc_static_lib_dir == nullptr) {
  38.          if ((g->zig_target.os == OsWindows) && (g->msvc_lib_dir != NULL)) {
  39.              return;
  40. -        } else if (g->zig_target.os == OsLinux) {
  41. +        } else if (g->zig_target.os == OsLinux || g->zig_target.os == OsOpenBSD) {
  42.              g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o");
  43.          } else {
  44.              zig_panic("Unable to determine libc static lib path.");
  45. diff --git a/src/link.cpp b/src/link.cpp
  46. index d454d77a..279fcc8b 100644
  47. --- a/src/link.cpp
  48. +++ b/src/link.cpp
  49. @@ -18,13 +18,13 @@ struct LinkJob {
  50.      bool link_in_crt;
  51.      HashMap<Buf *, bool, buf_hash, buf_eql_buf> rpath_table;
  52.  };
  53. -
  54. +/*
  55.  static const char *get_libc_file(CodeGen *g, const char *file) {
  56.      Buf *out_buf = buf_alloc();
  57.      os_path_join(g->libc_lib_dir, buf_create_from_str(file), out_buf);
  58.      return buf_ptr(out_buf);
  59.  }
  60. -
  61. +*/
  62.  static const char *get_libc_static_file(CodeGen *g, const char *file) {
  63.      Buf *out_buf = buf_alloc();
  64.      os_path_join(g->libc_static_lib_dir, buf_create_from_str(file), out_buf);
  65. @@ -256,11 +256,11 @@ static void construct_linker_job_elf(LinkJob *lj) {
  66.              crt1o = "crt1.o";
  67.              crtbegino = "crtbeginT.o";
  68.          } else {
  69. -            crt1o = "Scrt1.o";
  70. +//            crt1o = "Scrt1.o";
  71.              crtbegino = "crtbegin.o";
  72.          }
  73. -        lj->args.append(get_libc_file(g, crt1o));
  74. -        lj->args.append(get_libc_file(g, "crti.o"));
  75. +//        lj->args.append(get_libc_file(g, crt1o));
  76. +//        ((lj->args.append(get_libc_file(g, "crti.o"))));
  77.          lj->args.append(get_libc_static_file(g, crtbegino));
  78.      }
  79.  
  80. @@ -354,21 +354,23 @@ static void construct_linker_job_elf(LinkJob *lj) {
  81.      if (g->libc_link_lib != nullptr) {
  82.          if (g->is_static) {
  83.              lj->args.append("--start-group");
  84. +            lj->args.append("-L /usr/local/lib");
  85.              lj->args.append("-lgcc");
  86.              lj->args.append("-lgcc_eh");
  87.              lj->args.append("-lc");
  88.              lj->args.append("-lm");
  89.              lj->args.append("--end-group");
  90.          } else {
  91. -            lj->args.append("-lgcc");
  92. +            lj->args.append("-L /usr/local/lib");
  93. +//            lj->args.append("-lgcc");
  94.              lj->args.append("--as-needed");
  95. -            lj->args.append("-lgcc_s");
  96. +//            lj->args.append("-lgcc_s");
  97.              lj->args.append("--no-as-needed");
  98.              lj->args.append("-lc");
  99.              lj->args.append("-lm");
  100. -            lj->args.append("-lgcc");
  101. +  //          lj->args.append("-lgcc");
  102.              lj->args.append("--as-needed");
  103. -            lj->args.append("-lgcc_s");
  104. +    //        lj->args.append("-lgcc_s");
  105.              lj->args.append("--no-as-needed");
  106.          }
  107.      }
  108. @@ -376,7 +378,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
  109.      // crt end
  110.      if (lj->link_in_crt) {
  111.          lj->args.append(get_libc_static_file(g, "crtend.o"));
  112. -        lj->args.append(get_libc_file(g, "crtn.o"));
  113. +//        lj->args.append(get_libc_file(g, "crtn.O"));
  114.      }
  115.  
  116.      if (!g->is_native_target) {
  117. diff --git a/src/os.cpp b/src/os.cpp
  118. index 97462bd6..113439f0 100644
  119. --- a/src/os.cpp
  120. +++ b/src/os.cpp
  121. @@ -1010,6 +1010,12 @@ int os_self_exe_path(Buf *out_path) {
  122.          buf_resize(out_path, amt);
  123.          return 0;
  124.      }
  125. +#elif defined(ZIG_OS_OPENBSD)
  126. +    buf_resize(out_path, 256);
  127. +    if (realpath(getprogname(), buf_ptr(out_path)) == NULL) {
  128. +        return ErrorUnexpected;
  129. +    }
  130. +    return 0;
  131.  #endif
  132.      return ErrorFileNotFound;
  133.  }
  134. diff --git a/src/os.hpp b/src/os.hpp
  135. index b94e98ec..91a72d89 100644
  136. --- a/src/os.hpp
  137. +++ b/src/os.hpp
  138. @@ -98,6 +98,8 @@ int os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchTy
  139.  #define ZIG_OS_WINDOWS
  140.  #elif defined(__linux__)
  141.  #define ZIG_OS_LINUX
  142. +#elif defined(__OpenBSD__)
  143. +#define ZIG_OS_OPENBSD
  144.  #else
  145.  #define ZIG_OS_UNKNOWN
  146.  #endif
  147. diff --git a/std/c/index.zig b/std/c/index.zig
  148. index 34269d2a..3390a5c8 100644
  149. --- a/std/c/index.zig
  150. +++ b/std/c/index.zig
  151. @@ -5,6 +5,7 @@ pub use switch(builtin.os) {
  152.      Os.linux => @import("linux.zig"),
  153.      Os.windows => @import("windows.zig"),
  154.      Os.macosx, Os.ios => @import("darwin.zig"),
  155. +    Os.openbsd => @import("openbsd.zig"),
  156.      else => empty_import,
  157.  };
  158.  const empty_import = @import("../empty.zig");
  159. @@ -42,6 +43,7 @@ pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: u
  160.  pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
  161.  pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;
  162.  pub extern "c" fn gettimeofday(tv: ?&timeval, tz: ?&timezone) c_int;
  163. +pub extern "c" fn getprogname() &const u8;
  164.  pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
  165.  pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int;
  166.  pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
  167. diff --git a/std/c/openbsd.zig b/std/c/openbsd.zig
  168. new file mode 100644
  169. index 00000000..da2a3b9b
  170. --- /dev/null
  171. +++ b/std/c/openbsd.zig
  172. @@ -0,0 +1,24 @@
  173. +pub use @import("../os/openbsd/errno.zig");
  174. +
  175. +pub extern "c" fn getentropy(buf_ptr: &u8, buf_len: usize) c_int;
  176. +extern "c" fn __errno() &c_int;
  177. +pub const _errno = __errno;
  178. +
  179. +/// Renamed to Stat to not conflict with the stat function.
  180. +pub const Stat = extern struct {
  181. +    dev: i32,
  182. +    ino: u64,
  183. +    mode: u16,
  184. +    nlink: u16,
  185. +    uid: u32,
  186. +    gid: u32,
  187. +    rdev: i32,
  188. +    atime: usize,
  189. +    mtime: usize,
  190. +    ctime: usize,
  191. +    size: i64,
  192. +    blocks: i64,
  193. +    blksize: i32,
  194. +    flags: u32,
  195. +    gen: u32
  196. +};
  197. diff --git a/std/heap.zig b/std/heap.zig
  198. index 7b753524..40978ed6 100644
  199. --- a/std/heap.zig
  200. +++ b/std/heap.zig
  201. @@ -70,7 +70,8 @@ pub const DirectAllocator = struct {
  202.          switch (builtin.os) {
  203.              Os.linux,
  204.              Os.macosx,
  205. -            Os.ios => {
  206. +            Os.ios,
  207. +            Os.openbsd => {
  208.                  const p = os.posix;
  209.                  const alloc_size = if (alignment <= os.page_size) n else n + alignment;
  210.                  const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
  211. @@ -123,7 +124,8 @@ pub const DirectAllocator = struct {
  212.          switch (builtin.os) {
  213.              Os.linux,
  214.              Os.macosx,
  215. -            Os.ios => {
  216. +            Os.ios,
  217. +            Os.openbsd => {
  218.                  if (new_size <= old_mem.len) {
  219.                      const base_addr = @ptrToInt(old_mem.ptr);
  220.                      const old_addr_end = base_addr + old_mem.len;
  221. @@ -170,7 +172,8 @@ pub const DirectAllocator = struct {
  222.          switch (builtin.os) {
  223.              Os.linux,
  224.              Os.macosx,
  225. -            Os.ios => {
  226. +            Os.ios,
  227. +            Os.openbsd => {
  228.                  _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
  229.              },
  230.              Os.windows => {
  231. diff --git a/std/os/file.zig b/std/os/file.zig
  232. index 61fc2b14..3a8536ae 100644
  233. --- a/std/os/file.zig
  234. +++ b/std/os/file.zig
  235. @@ -141,7 +141,10 @@ pub const File = struct {
  236.  
  237.      pub fn seekForward(self: &File, amount: isize) !void {
  238.          switch (builtin.os) {
  239. -            Os.linux, Os.macosx, Os.ios => {
  240. +            Os.linux,
  241. +            Os.macosx,
  242. +            Os.ios,
  243. +            Os.openbsd => {
  244.                  const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);
  245.                  const err = posix.getErrno(result);
  246.                  if (err > 0) {
  247. @@ -170,7 +173,10 @@ pub const File = struct {
  248.  
  249.      pub fn seekTo(self: &File, pos: usize) !void {
  250.          switch (builtin.os) {
  251. -            Os.linux, Os.macosx, Os.ios => {
  252. +            Os.linux,
  253. +            Os.macosx,
  254. +            Os.ios,
  255. +            Os.openbsd => {
  256.                  const ipos = try math.cast(isize, pos);
  257.                  const result = posix.lseek(self.handle, ipos, posix.SEEK_SET);
  258.                  const err = posix.getErrno(result);
  259. @@ -201,7 +207,10 @@ pub const File = struct {
  260.  
  261.      pub fn getPos(self: &File) !usize {
  262.          switch (builtin.os) {
  263. -            Os.linux, Os.macosx, Os.ios => {
  264. +            Os.linux,
  265. +            Os.macosx,
  266. +            Os.ios,
  267. +            Os.openbsd => {
  268.                  const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);
  269.                  const err = posix.getErrno(result);
  270.                  if (err > 0) {
  271. diff --git a/std/os/get_user_id.zig b/std/os/get_user_id.zig
  272. index 11410ffa..1eafde9d 100644
  273. --- a/std/os/get_user_id.zig
  274. +++ b/std/os/get_user_id.zig
  275. @@ -11,7 +11,7 @@ pub const UserInfo = struct {
  276.  /// POSIX function which gets a uid from username.
  277.  pub fn getUserInfo(name: []const u8) !UserInfo {
  278.      return switch (builtin.os) {
  279. -        Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name),
  280. +        Os.linux, Os.macosx, Os.ios, Os.openbsd => posixGetUserInfo(name),
  281.          else => @compileError("Unsupported OS"),
  282.      };
  283.  }
  284. diff --git a/std/os/index.zig b/std/os/index.zig
  285. index 7d19cd82..d9672bdf 100644
  286. --- a/std/os/index.zig
  287. +++ b/std/os/index.zig
  288. @@ -4,7 +4,8 @@ const Os = builtin.Os;
  289.  const is_windows = builtin.os == Os.windows;
  290.  const is_posix = switch (builtin.os) {
  291.      builtin.Os.linux,
  292. -    builtin.Os.macosx => true,
  293. +    builtin.Os.macosx,
  294. +    builtin.Os.openbsd => true,
  295.      else => false,
  296.  };
  297.  const os = this;
  298. @@ -15,6 +16,7 @@ test "std.os" {
  299.      _ = @import("darwin_errno.zig");
  300.      _ = @import("get_user_id.zig");
  301.      _ = @import("linux/index.zig");
  302. +    _ = @import("openbsd/index.zig");
  303.      _ = @import("path.zig");
  304.      _ = @import("test.zig");
  305.      _ = @import("time.zig");
  306. @@ -25,11 +27,13 @@ pub const windows = @import("windows/index.zig");
  307.  pub const darwin = @import("darwin.zig");
  308.  pub const linux = @import("linux/index.zig");
  309.  pub const zen = @import("zen.zig");
  310. +pub const openbsd = @import("openbsd/index.zig");
  311.  pub const posix = switch (builtin.os) {
  312.      Os.linux => linux,
  313.      Os.macosx,
  314.      Os.ios => darwin,
  315.      Os.zen => zen,
  316. +    Os.openbsd => openbsd,
  317.      else => @compileError("Unsupported OS"),
  318.  };
  319.  pub const net = @import("net.zig");
  320. @@ -157,6 +161,17 @@ pub fn getRandomBytes(buf: []u8) !void {
  321.                  buf[i] = randomness[i];
  322.              }
  323.          },
  324. +        Os.openbsd => {
  325. +            const err = posix.getErrno(posix.getentropy(buf.ptr, buf.len));
  326. +            if (err > 0) {
  327. +                return switch (err) {
  328. +                    posix.EFAULT => unreachable,
  329. +                    posix.EIO    => unreachable,
  330. +                    else         => unexpectedErrorPosix(err),
  331. +                };
  332. +            }
  333. +            return;
  334. +        },
  335.          else => @compileError("Unsupported OS"),
  336.      }
  337.  }
  338. @@ -177,7 +192,8 @@ pub fn abort() noreturn {
  339.      switch (builtin.os) {
  340.          Os.linux,
  341.          Os.macosx,
  342. -        Os.ios => {
  343. +        Os.ios,
  344. +        Os.openbsd => {
  345.              _ = posix.raise(posix.SIGABRT);
  346.              _ = posix.raise(posix.SIGKILL);
  347.              while (true) {}
  348. @@ -201,7 +217,8 @@ pub fn exit(status: u8) noreturn {
  349.      switch (builtin.os) {
  350.          Os.linux,
  351.          Os.macosx,
  352. -        Os.ios => {
  353. +        Os.ios,
  354. +        Os.openbsd => {
  355.              posix.exit(status);
  356.          },
  357.          Os.windows => {
  358. @@ -1847,6 +1864,12 @@ pub fn openSelfExe() !os.File {
  359.              const self_exe_path = try selfExePath(&fixed_allocator.allocator);
  360.              return os.File.openRead(&fixed_allocator.allocator, self_exe_path);
  361.          },
  362. +        Os.openbsd => {
  363. +            var fixed_buffer_mem: [openbsd.PATH_MAX * 2]u8 = undefined;
  364. +            var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
  365. +            const self_exe_path = try selfExePath(&fixed_allocator.allocator);
  366. +            return os.File.openRead(&fixed_allocator.allocator, self_exe_path);
  367. +        },
  368.          else => @compileError("Unsupported OS"),
  369.      }
  370.  }
  371. @@ -1855,7 +1878,8 @@ test "openSelfExe" {
  372.      switch (builtin.os) {
  373.          Os.linux,
  374.          Os.macosx,
  375. -        Os.ios => (try openSelfExe()).close(),
  376. +        Os.ios,
  377. +        Os.openbsd => (try openSelfExe()).close(),
  378.          else => return, // Unsupported OS.
  379.      }
  380.  }
  381. @@ -1904,6 +1928,14 @@ pub fn selfExePath(allocator: &mem.Allocator) ![]u8 {
  382.              assert(ret2 == 0);
  383.              return bytes;
  384.          },
  385. +        Os.openbsd => {
  386. +            const ret1 = c.getprogname();
  387. +            const bytes = try allocator.alloc(u8, 256);
  388. +            errdefer allocator.free(bytes);
  389. +            const ret2 = c.realpath(ret1, bytes.ptr);
  390. +            assert(ret2 != null);
  391. +            return bytes;
  392. +        },
  393.          else => @compileError("Unsupported OS"),
  394.      }
  395.  }
  396. diff --git a/std/os/openbsd/errno.zig b/std/os/openbsd/errno.zig
  397. new file mode 100644
  398. index 00000000..f56b413b
  399. --- /dev/null
  400. +++ b/std/os/openbsd/errno.zig
  401. @@ -0,0 +1,112 @@
  402. +pub const EPERM = 1; /// Operation not permitted
  403. +pub const ENOENT = 2; /// No such file or directory
  404. +pub const ESRCH = 3; /// No such process
  405. +pub const EINTR = 4; /// Interrupted system call
  406. +pub const EIO = 5; /// Input/output error
  407. +pub const ENXIO = 6; /// Device not configured
  408. +pub const E2BIG = 7; /// Arg list too long
  409. +pub const ENOEXEC = 8; /// Exec format error
  410. +pub const EBADF = 9; /// Bad file descriptor
  411. +pub const ECHILD = 10; /// No child processes
  412. +pub const EDEADLK = 11; /// Ressource deadlock avoided
  413. +pub const ENOMEM = 12; /// Cannot allocate memory
  414. +pub const EACCES = 13; /// Permission denied
  415. +pub const EFAULT = 14; /// Bad address
  416. +pub const ENOTBLK = 15; /// Block device required
  417. +pub const EBUSY = 16; /// Device busy
  418. +pub const EEXIST = 17; /// File exists
  419. +pub const EXDEV = 18; /// Cross-device link
  420. +pub const ENODEV = 19; /// Operation not supported by device
  421. +pub const ENOTDIR = 20; /// Not a directory
  422. +pub const EISDIR = 21; /// Is a directory
  423. +pub const EINVAL = 22; /// Invalid argument
  424. +pub const ENFILE = 23; /// Too many open files in system
  425. +pub const EMFILE = 24; /// Too many open files
  426. +pub const ENOTTY = 25; /// Inappropriate ioctl for device
  427. +pub const ETXTBSY = 26; /// Text file busy
  428. +pub const EFBIG = 27; /// File too large
  429. +pub const ENOSPC = 28; /// No space left on device
  430. +pub const ESPIPE = 29; /// Illegal seek
  431. +pub const EROFS = 30; /// Read-only file system
  432. +pub const EMLINK = 31; /// Too many links
  433. +pub const EPIPE = 32; /// Broken pipe
  434. +
  435. +pub const EDOM = 33; /// Numerical argument out of domain
  436. +pub const ERANGE = 34; /// Result too large
  437. +
  438. +pub const EAGAIN = 35; /// Resource temporarily unavailable
  439. +pub const EWOULDBLOCK = EAGAIN; /// Operation would block
  440. +pub const EINPROGRESS= 36; /// Operation now in progress
  441. +pub const EALREADY = 37; /// Operation already in progress
  442. +
  443. +pub const ENOTSOCK = 38; /// Socket operation on non-socket
  444. +pub const EDESTADDRREQ = 39; /// Destination address required
  445. +pub const EMSGSIZE = 40; /// Message too long
  446. +pub const EPROTOTYPE = 41; /// Protocol wrong type for socket
  447. +pub const ENOPROTOOPT = 42; /// Protocol not available
  448. +pub const EPROTONOSUPPORT = 43; /// Protocol not supported
  449. +pub const ESOCKTNOSUPPORT = 44; /// Socket type not supported
  450. +pub const EOPNOTSUPP = 45; /// Operation not supported
  451. +pub const EPFNOSUPPORT = 46; /// Protocol family not supported
  452. +pub const EAFNOSUPPORT = 47; /// Address family not supported by protocol family
  453. +pub const EADDRINUSE = 48; /// Address already in use
  454. +pub const EADDRNOTAVAIL = 49; /// Can't assign requested address
  455. +
  456. +pub const ENETDOWN = 50; /// Network is down
  457. +pub const ENETUNREACH = 51; /// Network is unreachable
  458. +pub const ENETRESET = 52; /// Network dropped connection on reset
  459. +pub const ECONNABORTED = 53; /// Software caused connection abort
  460. +pub const ECONNRESET = 54; /// Connection reset by peer
  461. +pub const ENOBUFS = 55; /// No buffer space available
  462. +pub const EISCONN = 56; /// Socket is already connected
  463. +pub const ENOTCONN = 57; /// Socket is not connected
  464. +pub const ESHUTDOWN = 58; /// Can't send after socket shutdown
  465. +pub const ETOOMANYREFS = 59; /// Too many references: can't splice
  466. +pub const ETIMEDOUT = 60; /// Operation timed out
  467. +pub const ECONNREFUSED = 61; /// Connection refused
  468. +
  469. +pub const ELOOP = 62; /// Too many levels of symbolic links
  470. +pub const ENAMETOOLONG = 63; /// File name too long
  471. +
  472. +pub const EHOSTDOWN = 64; /// Host is down
  473. +pub const EHOSTUNREACH = 65; /// No route to host
  474. +pub const ENOTEMPTY = 66; /// Directory not empty
  475. +
  476. +pub const EPROCLIM = 67; /// Too many processes
  477. +pub const EUSERS = 68; /// Too many users
  478. +pub const EDQUOT = 69; ///
  479. +
  480. +pub const ESTALE = 70; /// Stale NFS file handle
  481. +pub const EREMOTE = 71; /// Too many levels of remote in path
  482. +pub const EBADRPC = 72; /// RPC struct is bad
  483. +pub const ERPCMISMATCH = 73; /// RPC version wrong
  484. +pub const EPROGUNAVAIL = 74; /// RPC program not available
  485. +pub const EPROGMISMATCH = 75; /// Program version wrong
  486. +pub const EPROCUNAVAIL = 76; /// Bad procedure for program
  487. +pub const ENOLCK = 77; /// No locks available
  488. +pub const ENOSYS = 78; /// Function not implemented
  489. +pub const EFTYPE = 79; /// Inappropriate file type or format
  490. +pub const EAUTH = 80; /// Authentication error
  491. +pub const ENEEDAUTH = 81; /// Need authenticator
  492. +pub const EIPSEC = 82; /// IPsec processing failure
  493. +pub const ENOATTR = 83; /// Attribute not found
  494. +pub const EILSEQ = 84; /// Illegal byte sequence
  495. +pub const ENOMEDIUM = 85; /// No medium found
  496. +pub const EMEDIUMTYPE = 86; /// Wrong medium type
  497. +pub const EOVERFLOW = 87; /// Value too large to be stored in data type
  498. +pub const ECANCELED = 88; /// Operation canceled
  499. +pub const EIDRM = 89; /// Identifier removed
  500. +pub const ENOMSG = 90; /// No message of desired type
  501. +pub const ENOTSUP = 91; /// Not supported
  502. +pub const EBADMSG = 92; /// Bad message
  503. +pub const ENOTRECOVERABLE = 93; /// State not recoverable
  504. +pub const EOWNERDEAD = 94; /// Previous owner died
  505. +pub const EPROTO = 95; /// Protocol error
  506. +pub const ELAST = 95; /// Must be equal largest errno
  507. +
  508. +pub const ERESTART = -1; /// restart syscall
  509. +pub const EJUSTRETURN = -2; /// don't modify regs, just return
  510. +
  511. +
  512. +
  513. +
  514. diff --git a/std/os/openbsd/index.zig b/std/os/openbsd/index.zig
  515. new file mode 100644
  516. index 00000000..921af403
  517. --- /dev/null
  518. +++ b/std/os/openbsd/index.zig
  519. @@ -0,0 +1,201 @@
  520. +const std = @import("../../index.zig");
  521. +const c = std.c;
  522. +const assert = std.debug.assert;
  523. +const builtin = @import("builtin");
  524. +const vdso = @import("vdso.zig");
  525. +pub use switch (builtin.arch) {
  526. +    builtin.Arch.x86_64 => @import("x86_64.zig"),
  527. +      else => @compileError("unsupported arch"),
  528. +};
  529. +pub use @import("errno.zig");
  530. +
  531. +pub const PATH_MAX = 1024;
  532. +
  533. +pub const STDIN_FILENO = 0;
  534. +pub const STDOUT_FILENO = 1;
  535. +pub const STDERR_FILENO = 2;
  536. +
  537. +pub const PROT_READ = 0x01;
  538. +pub const PROT_WRITE = 0x02;
  539. +pub const PROT_EXEC = 0x04;
  540. +
  541. +pub const MAP_PRIVATE = 0x0002;
  542. +pub const MAP_ANONYMOUS = 0x1000;
  543. +pub const MAP_FAILED = @maxValue(usize);
  544. +
  545. +pub fn raise(sig: i32) usize {
  546. +    return usize(c.raise(sig));
  547. +}
  548. +
  549. +/// Get the errno from a syscall return value, or 0 for no error.
  550. +pub fn getErrno(r: usize) usize {
  551. +    const signed_r = @bitCast(isize, r);
  552. +    return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;
  553. +}
  554. +
  555. +pub fn getentropy(buf_ptr: &u8, buf_len: usize) usize {
  556. +    return errnoWrap(c.getentropy(buf_ptr, buf_len));
  557. +}
  558. +
  559. +pub fn open(path: &const u8, flags: u32, mode: usize) usize {
  560. +    return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
  561. +}
  562. +
  563. +pub fn close(fd: i32) usize {
  564. +    return errnoWrap(c.close(fd));
  565. +}
  566. +
  567. +pub fn isatty(fd: i32) bool {
  568. +    return c.isatty(fd) != 0;
  569. +}
  570. +
  571. +pub fn abort() noreturn {
  572. +    c.abort();
  573. +}
  574. +
  575. +pub fn exit(code: i32) noreturn {
  576. +    c.exit(code);
  577. +}
  578. +
  579. +pub fn read(fd: i32, buf: &u8, nbyte: usize) usize {
  580. +    return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte));
  581. +}
  582. +
  583. +pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {
  584. +    return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
  585. +}
  586. +
  587. +pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
  588. +    return errnoWrap(c.lseek(fd, offset, whence));
  589. +}
  590. +
  591. +pub fn fstat(fd: i32, buf: &c.Stat) usize {
  592. +    return errnoWrap(c.fstat(fd, buf));
  593. +}
  594. +
  595. +fn errnoWrap(value: isize) usize {
  596. +    return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value);
  597. +}
  598. +
  599. +pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
  600. +    const ptr_result = c.mmap(@ptrCast(&c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
  601. +    const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
  602. +    return errnoWrap(isize_result);
  603. +}
  604. +
  605. +pub fn munmap(address: usize, length: usize) usize {
  606. +    return errnoWrap(c.munmap(@intToPtr(&c_void, address), length));
  607. +}
  608. +
  609. +
  610. +pub fn unlink(path: &const u8) usize {
  611. +    return errnoWrap(c.unlink(path));
  612. +}
  613. +
  614. +pub fn getcwd(buf: &u8, size: usize) usize {
  615. +    return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
  616. +}
  617. +
  618. +pub fn waitpid(pid: i32, status: &i32, options: u32) usize {
  619. +    comptime assert(i32.bit_count == c_int.bit_count);
  620. +    return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options)));
  621. +}
  622. +
  623. +pub fn fork() usize {
  624. +    return errnoWrap(c.fork());
  625. +}
  626. +
  627. +pub fn access(path: &const u8, mode: u32) usize {
  628. +    return errnoWrap(c.access(path, mode));
  629. +}
  630. +
  631. +pub fn pipe(fds: &[2]i32) usize {
  632. +    comptime assert(i32.bit_count == c_int.bit_count);
  633. +    return errnoWrap(c.pipe(@ptrCast(&c_int, fds)));
  634. +}
  635. +
  636. +pub fn getdirentries64(fd: i32, buf_ptr: &u8, buf_len: usize, basep: &i64) usize {
  637. +    return errnoWrap(@bitCast(isize, c.__getdirentries64(fd, buf_ptr, buf_len, basep)));
  638. +}
  639. +
  640. +pub fn mkdir(path: &const u8, mode: u32) usize {
  641. +    return errnoWrap(c.mkdir(path, mode));
  642. +}
  643. +
  644. +pub fn symlink(existing: &const u8, new: &const u8) usize {
  645. +    return errnoWrap(c.symlink(existing, new));
  646. +}
  647. +
  648. +pub fn rename(old: &const u8, new: &const u8) usize {
  649. +    return errnoWrap(c.rename(old, new));
  650. +}
  651. +
  652. +pub fn rmdir(path: &const u8) usize {
  653. +    return errnoWrap(c.rmdir(path));
  654. +}
  655. +
  656. +pub fn chdir(path: &const u8) usize {
  657. +    return errnoWrap(c.chdir(path));
  658. +}
  659. +
  660. +pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {
  661. +    return errnoWrap(c.execve(path, argv, envp));
  662. +}
  663. +
  664. +pub fn dup2(old: i32, new: i32) usize {
  665. +    return errnoWrap(c.dup2(old, new));
  666. +}
  667. +
  668. +pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {
  669. +    return errnoWrap(c.readlink(path, buf_ptr, buf_len));
  670. +}
  671. +
  672. +pub fn gettimeofday(tv: ?&timeval, tz: ?&timezone) usize {
  673. +    return errnoWrap(c.gettimeofday(tv, tz));
  674. +}
  675. +
  676. +pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {
  677. +    return errnoWrap(c.nanosleep(req, rem));
  678. +}
  679. +
  680. +pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) usize {
  681. +    return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
  682. +}
  683. +
  684. +pub fn setreuid(ruid: u32, euid: u32) usize {
  685. +    return errnoWrap(c.setreuid(ruid, euid));
  686. +}
  687. +
  688. +pub fn setregid(rgid: u32, egid: u32) usize {
  689. +    return errnoWrap(c.setregid(rgid, egid));
  690. +}
  691. +
  692. +pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
  693. +    return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset));
  694. +}
  695. +
  696. +pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
  697. +    assert(sig != SIGKILL);
  698. +    assert(sig != SIGSTOP);
  699. +    var cact = c.Sigaction{
  700. +        .handler = @ptrCast(extern fn(c_int) void, act.handler),
  701. +        .sa_flags = @bitCast(c_int, act.flags),
  702. +        .sa_mask = act.mask,
  703. +    };
  704. +    var coact: c.Sigaction = undefined;
  705. +    const result = errnoWrap(c.sigaction(sig, &cact, &coact));
  706. +    if (result != 0) {
  707. +        return result;
  708. +    }
  709. +    if (oact) |old| {
  710. +        old.* = Sigaction{
  711. +            .handler = @ptrCast(extern fn(i32) void, coact.handler),
  712. +            .flags = @bitCast(u32, coact.sa_flags),
  713. +            .mask = coact.sa_mask,
  714. +        };
  715. +    }
  716. +    return result;
  717. +}
  718. +
  719. +const sigset_t = [128 / @sizeOf(usize)]usize;
  720. +pub const Stat = c.Stat;
  721. diff --git a/std/os/openbsd/x86_64.zig b/std/os/openbsd/x86_64.zig
  722. new file mode 100644
  723. index 00000000..c0da9ed6
  724. --- /dev/null
  725. +++ b/std/os/openbsd/x86_64.zig
  726. @@ -0,0 +1,348 @@
  727. +const std = @import("../../index.zig");
  728. +const openbsd = std.os.openbsd;
  729. +const socklen_t = openbsd.socklen_t;
  730. +const iovec = openbsd.iovec;
  731. +
  732. +pub const SYS_syscall = 0;
  733. +pub const SYS_exit = 1;
  734. +pub const SYS_fork = 2;
  735. +pub const SYS_read = 3;
  736. +pub const SYS_write = 4;
  737. +pub const SYS_open = 5;
  738. +pub const SYS_close = 6;
  739. +pub const SYS_getentropy = 7;
  740. +pub const SYS___tfork = 8;
  741. +pub const SYS_link = 9;
  742. +pub const SYS_unlink = 10;
  743. +pub const SYS_wait4 = 11;
  744. +pub const SYS_chdir = 12;
  745. +pub const SYS_fchdir = 13;
  746. +pub const SYS_mknod = 14;
  747. +pub const SYS_chmod = 15;
  748. +pub const SYS_chown = 16;
  749. +pub const SYS_break = 17;
  750. +pub const SYS_getdtablecount = 18;
  751. +pub const SYS_getrusage = 19;
  752. +pub const SYS_getpid = 20;
  753. +pub const SYS_mount = 21;
  754. +pub const SYS_unmount = 22;
  755. +pub const SYS_setuid = 23;
  756. +pub const SYS_getuid = 24;
  757. +pub const SYS_geteuid = 25;
  758. +pub const SYS_ptrace = 26;
  759. +pub const SYS_recvmsg = 27;
  760. +pub const SYS_sendmsg = 28;
  761. +pub const SYS_recvfrom = 29;
  762. +pub const SYS_accept = 30;
  763. +pub const SYS_getpeername = 31;
  764. +pub const SYS_getsockname = 32;
  765. +pub const SYS_access = 33;
  766. +pub const SYS_chflags = 34;
  767. +pub const SYS_fchflags = 35;
  768. +pub const SYS_sync = 36;
  769. +pub const SYS_stat = 38;
  770. +pub const SYS_getppid = 39;
  771. +pub const SYS_lstat = 40;
  772. +pub const SYS_dup = 41;
  773. +pub const SYS_fstatat = 42;
  774. +pub const SYS_getegid = 43;
  775. +pub const SYS_profil = 44;
  776. +pub const SYS_ktrace = 45;
  777. +pub const SYS_sigaction = 46;
  778. +pub const SYS_getgid = 47;
  779. +pub const SYS_sigprocmask = 48;
  780. +pub const SYS_setlogin = 50;
  781. +pub const SYS_acct = 51;
  782. +pub const SYS_sigpending = 52;
  783. +pub const SYS_fstat = 53;
  784. +pub const SYS_ioctl = 54;
  785. +pub const SYS_reboot = 55;
  786. +pub const SYS_revoke = 56;
  787. +pub const SYS_symlink = 57;
  788. +pub const SYS_readlink = 58;
  789. +pub const SYS_execve = 59;
  790. +pub const SYS_umask = 60;
  791. +pub const SYS_chroot = 61;
  792. +pub const SYS_getfsstat = 62;
  793. +pub const SYS_statfs = 63;
  794. +pub const SYS_fstatfs = 64;
  795. +pub const SYS_fhstatfs = 65;
  796. +pub const SYS_vfork = 66;
  797. +pub const SYS_gettimeofday = 67;
  798. +pub const SYS_settimeofday = 68;
  799. +pub const SYS_setitimer = 69;
  800. +pub const SYS_getitimer = 70;
  801. +pub const SYS_select = 71;
  802. +pub const SYS_kevent = 72;
  803. +pub const SYS_munmap = 73;
  804. +pub const SYS_mprotect = 74;
  805. +pub const SYS_madvise = 75;
  806. +pub const SYS_utimes = 76;
  807. +pub const SYS_futimes = 77;
  808. +pub const SYS_mincore = 78;
  809. +pub const SYS_getgroups = 79;
  810. +pub const SYS_setgroups = 80;
  811. +pub const SYS_getpgrp = 81;
  812. +pub const SYS_setpgid = 82;
  813. +pub const SYS_futex = 83;
  814. +pub const SYS_utimensat = 84;
  815. +pub const SYS_futimens = 85;
  816. +pub const SYS_kbind = 86;
  817. +pub const SYS_clock_gettime = 87;
  818. +pub const SYS_clock_settime = 88;
  819. +pub const SYS_clock_getres = 89;
  820. +pub const SYS_dup2 = 90;
  821. +pub const SYS_nanosleep = 91;
  822. +pub const SYS_fcntl = 92;
  823. +pub const SYS_accept4 = 93;
  824. +pub const SYS___thrsleep = 94;
  825. +pub const SYS_fsync = 95;
  826. +pub const SYS_setpriority = 96;
  827. +pub const SYS_socket = 97;
  828. +pub const SYS_connect = 98;
  829. +pub const SYS_getdents = 99;
  830. +pub const SYS_getpriority = 100;
  831. +pub const SYS_pipe2 = 101;
  832. +pub const SYS_dup3 = 102;
  833. +pub const SYS_sigreturn = 103;
  834. +pub const SYS_bind = 104;
  835. +pub const SYS_setsockopt = 105;
  836. +pub const SYS_listen = 106;
  837. +pub const SYS_chflagsat = 107;
  838. +pub const SYS_pledge = 108;
  839. +pub const SYS_ppoll = 109;
  840. +pub const SYS_pselect = 110;
  841. +pub const SYS_sigsuspend = 111;
  842. +pub const SYS_sendsyslog = 112;
  843. +pub const SYS_getsockopt = 118;
  844. +pub const SYS_thrkill = 119;
  845. +pub const SYS_readv = 120;
  846. +pub const SYS_writev = 121;
  847. +pub const SYS_kill = 122;
  848. +pub const SYS_fchown = 123;
  849. +pub const SYS_fchmod = 124;
  850. +pub const SYS_setreuid = 126;
  851. +pub const SYS_setregid = 127;
  852. +pub const SYS_rename = 128;
  853. +pub const SYS_flock = 131;
  854. +pub const SYS_mkfifo = 132;
  855. +pub const SYS_sendto = 133;
  856. +pub const SYS_shutdown = 134;
  857. +pub const SYS_socketpair = 135;
  858. +pub const SYS_mkdir = 136;
  859. +pub const SYS_rmdir = 137;
  860. +pub const SYS_adjtime = 140;
  861. +pub const SYS_getlogin_r = 141;
  862. +pub const SYS_setsid = 147;
  863. +pub const SYS_quotactl = 148;
  864. +pub const SYS_nfssvc = 155;
  865. +pub const SYS_getfh = 161;
  866. +pub const SYS_sysarch = 165;
  867. +pub const SYS_pread = 173;
  868. +pub const SYS_pwrite = 174;
  869. +pub const SYS_setgid = 181;
  870. +pub const SYS_setegid = 182;
  871. +pub const SYS_seteuid = 183;
  872. +pub const SYS_pathconf = 191;
  873. +pub const SYS_fpathconf = 192;
  874. +pub const SYS_swapctl = 193;
  875. +pub const SYS_getrlimit = 194;
  876. +pub const SYS_setrlimit = 195;
  877. +pub const SYS_mmap = 197;
  878. +pub const SYS___syscall = 198;
  879. +pub const SYS_lseek = 199;
  880. +pub const SYS_truncate = 200;
  881. +pub const SYS_ftruncate = 201;
  882. +pub const SYS_sysctl = 202;
  883. +pub const SYS_mlock = 203;
  884. +pub const SYS_munlock = 204;
  885. +pub const SYS_getpgid = 207;
  886. +pub const SYS_utrace = 209;
  887. +pub const SYS_semget = 221;
  888. +pub const SYS_msgget = 225;
  889. +pub const SYS_msgsnd = 226;
  890. +pub const SYS_msgrcv = 227;
  891. +pub const SYS_shmat = 228;
  892. +pub const SYS_shmdt = 230;
  893. +pub const SYS_minherit = 250;
  894. +pub const SYS_poll = 252;
  895. +pub const SYS_issetugid = 253;
  896. +pub const SYS_lchown = 254;
  897. +pub const SYS_getsid = 255;
  898. +pub const SYS_msync = 256;
  899. +pub const SYS_pipe = 263;
  900. +pub const SYS_fhopen = 264;
  901. +pub const SYS_preadv = 267;
  902. +pub const SYS_pwritev = 268;
  903. +pub const SYS_kqueue = 269;
  904. +pub const SYS_mlockall = 271;
  905. +pub const SYS_munlockall = 272;
  906. +pub const SYS_getresuid = 281;
  907. +pub const SYS_setresuid = 282;
  908. +pub const SYS_getresgid = 283;
  909. +pub const SYS_setresgid = 284;
  910. +pub const SYS_mquery = 286;
  911. +pub const SYS_closefrom = 287;
  912. +pub const SYS_sigaltstack = 288;
  913. +pub const SYS_shmget = 289;
  914. +pub const SYS_semop = 290;
  915. +pub const SYS_fhstat = 294;
  916. +pub const SYS___semctl = 295;
  917. +pub const SYS_shmctl = 296;
  918. +pub const SYS_msgctl = 297;
  919. +pub const SYS_sched_yield = 298;
  920. +pub const SYS_getthrid = 299;
  921. +pub const SYS___thrwakeup = 301;
  922. +pub const SYS___threxit = 302;
  923. +pub const SYS___thrsigdivert = 303;
  924. +pub const SYS___getcwd = 304;
  925. +pub const SYS_adjfreq = 305;
  926. +pub const SYS_setrtable = 310;
  927. +pub const SYS_getrtable = 311;
  928. +pub const SYS_faccessat = 313;
  929. +pub const SYS_fchmodat = 314;
  930. +pub const SYS_fchownat = 315;
  931. +pub const SYS_linkat = 317;
  932. +pub const SYS_mkdirat = 318;
  933. +pub const SYS_mkfifoat = 319;
  934. +pub const SYS_mknodat = 320;
  935. +pub const SYS_openat = 321;
  936. +pub const SYS_readlinkat = 322;
  937. +pub const SYS_renameat = 323;
  938. +pub const SYS_symlinkat = 324;
  939. +pub const SYS_unlinkat = 325;
  940. +pub const SYS___set_tcb = 329;
  941. +pub const SYS___get_tcb = 330;
  942. +pub const SYS_MAXSYSCALL = 331;
  943. +
  944. +pub const O_RDONLY = 0x0000;
  945. +pub const O_WRONLY = 0x0001;
  946. +pub const O_RDWR = 0x0002;
  947. +pub const O_ACCMODE = 0x0003;
  948. +pub const O_NONBLOCK = 0x0004;
  949. +pub const O_APPEND = 0x0008;
  950. +pub const O_SHLOCK = 0x0010;
  951. +pub const O_EXLOCK = 0x0020;
  952. +pub const O_ASYNC = 0x0040;
  953. +pub const O_FSYNC = 0x0080;
  954. +pub const O_NOFOLLOW = 0x0100;
  955. +pub const O_SYNC = 0x0080;
  956. +pub const O_CREAT = 0x0200;
  957. +pub const O_TRUNC = 0x0400;
  958. +pub const O_EXCL = 0x0800;
  959. +pub const O_DSYNC = O_SYNC;
  960. +pub const O_RSYNC = O_SYNC;
  961. +pub const O_NOCTTY = 0x8000;
  962. +pub const O_CLOEXEC = 0x10000;
  963. +pub const O_DIRECTORY = 0x20000;
  964. +pub const O_LARGEFILE = 0;
  965. +
  966. +pub const FAPPEND = O_APPEND;
  967. +pub const FASYNC = O_ASYNC;
  968. +pub const FFSYNC = O_SYNC;
  969. +pub const FNONBLOCK = O_NONBLOCK;
  970. +pub const FNDELAY = O_NONBLOCK;
  971. +pub const O_NDELAY = O_NONBLOCK;
  972. +
  973. +pub const F_DUPFD = 0;
  974. +pub const F_GETFD = 1;
  975. +pub const F_SETFD = 2;
  976. +pub const F_GETFL = 3;
  977. +pub const F_SETFL = 4;
  978. +pub const F_GETOWN = 5;
  979. +pub const F_SETOWN = 6;
  980. +pub const F_GETLK = 7;
  981. +pub const F_SETLK = 8;
  982. +pub const F_SETLKW = 9;
  983. +pub const F_DUPFD_CLOEXEC = 10;
  984. +pub const F_ISATTY = 11;
  985. +
  986. +pub const FD_CLOEXEC = 1;
  987. +
  988. +pub const F_RDLCK = 1;
  989. +pub const F_UNLCK = 2;
  990. +pub const F_WRLCK = 3;
  991. +pub const F_WAIT = 0x010;
  992. +pub const F_FLOCK = 0x020;
  993. +pub const F_POSIX = 0x040;
  994. +
  995. +pub const SEEK_SET = 0;
  996. +pub const SEEK_CUR = 1;
  997. +pub const SEEK_END = 2;
  998. +
  999. +pub const DT_UNKNOWN = 0;
  1000. +pub const DT_FIFO = 1;
  1001. +pub const DT_CHR = 2;
  1002. +pub const DT_DIR = 4;
  1003. +pub const DT_BLK = 6;
  1004. +pub const DT_REG = 8;
  1005. +pub const DT_LNK = 10;
  1006. +pub const DT_SOCK = 12;
  1007. +
  1008. +pub const SIG_BLOCK = 1;
  1009. +pub const SIG_UNBLOCK = 2;
  1010. +pub const SIG_SETMASK = 3;
  1011. +
  1012. +pub const SIGHUP = 1;
  1013. +pub const SIGINT = 2;
  1014. +pub const SIGQUIT = 3;
  1015. +pub const SIGILL = 4;
  1016. +pub const SIGTRAP = 5;
  1017. +pub const SIGABRT = 6;
  1018. +pub const SIGPOLL = 7;
  1019. +pub const SIGIOT = SIGABRT;
  1020. +pub const SIGEMT = 7;
  1021. +pub const SIGFPE = 8;
  1022. +pub const SIGKILL = 9;
  1023. +pub const SIGBUS = 10;
  1024. +pub const SIGSEGV = 11;
  1025. +pub const SIGSYS = 12;
  1026. +pub const SIGPIPE = 13;
  1027. +pub const SIGALRM = 14;
  1028. +pub const SIGTERM = 15;
  1029. +pub const SIGURG = 16;
  1030. +pub const SIGSTOP = 17;
  1031. +pub const SIGTSTP = 18;
  1032. +pub const SIGCONT = 19;
  1033. +pub const SIGCHLD = 20;
  1034. +pub const SIGTTIN = 21;
  1035. +pub const SIGTTOU = 22;
  1036. +pub const SIGIO = 23;
  1037. +pub const SIGXCPU = 24;
  1038. +pub const SIGXFSZ = 25;
  1039. +pub const SIGVTALRM = 26;
  1040. +pub const SIGPROF = 27;
  1041. +pub const SIGWINCH = 28;
  1042. +pub const SIGINFO = 29;
  1043. +pub const SIGUSR1 = 30;
  1044. +pub const SIGUSR2 = 31;
  1045. +
  1046. +const wstopped = 0o177;
  1047. +const wcontinued = 0o177777;
  1048. +
  1049. +fn wstatus(x: i32) i32 {
  1050. +    return x & 0o177;
  1051. +}
  1052. +
  1053. +pub fn WEXITSTATUS(x: i32) i32 {
  1054. +    return x >> 8;
  1055. +}
  1056. +pub fn WTERMSIG(x: i32) i32 {
  1057. +    return wstatus(x);
  1058. +}
  1059. +pub fn WSTOPSIG(x: i32) i32 {
  1060. +    return x >> 8;
  1061. +}
  1062. +pub fn WIFEXITED(x: i32) bool {
  1063. +    return wstatus(x) == 0;
  1064. +}
  1065. +pub fn WIFSTOPPED(x: i32) bool {
  1066. +    return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13;
  1067. +}
  1068. +pub fn WIFSIGNALED(x: i32) bool {
  1069. +    return wstatus(x) != wstopped and wstatus(x) != 0;
  1070. +}
  1071. +
  1072. +
  1073. +
  1074. +
  1075. diff --git a/std/os/path.zig b/std/os/path.zig
  1076. index 0ea5d5a7..db69543e 100644
  1077. --- a/std/os/path.zig
  1078. +++ b/std/os/path.zig
  1079. @@ -1130,7 +1130,9 @@ pub fn real(allocator: &Allocator, pathname: []const u8) ![]u8 {
  1080.                  return allocator.shrink(u8, buf, final_len);
  1081.              }
  1082.          },
  1083. -        Os.macosx, Os.ios => {
  1084. +        Os.macosx,
  1085. +        Os.ios,
  1086. +        Os.openbsd => {
  1087.              // TODO instead of calling the libc function here, port the implementation
  1088.              // to Zig, and then remove the NameTooLong error possibility.
  1089.              const pathname_buf = try allocator.alloc(u8, pathname.len + 1);
  1090. diff --git a/std/special/builtin.zig b/std/special/builtin.zig
  1091. index a5126bc4..60426244 100644
  1092. --- a/std/special/builtin.zig
  1093. +++ b/std/special/builtin.zig
  1094. @@ -53,6 +53,8 @@ export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 {
  1095.      return dest;
  1096.  }
  1097.  
  1098. +extern var __guard_local: c_long section(".openbsd.randomdata");
  1099. +
  1100.  comptime {
  1101.      if (builtin.mode != builtin.Mode.ReleaseFast and
  1102.          builtin.mode != builtin.Mode.ReleaseSmall and
  1103. @@ -62,6 +64,9 @@ comptime {
  1104.      if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
  1105.          @export("clone", clone, builtin.GlobalLinkage.Strong);
  1106.      }
  1107. +    if (builtin.os == builtin.Os.openbsd) {
  1108. +        @export("__guard_local", __guard_local, builtin.GlobalLinkage.Strong);
  1109. +    }
  1110.  }
  1111.  extern fn __stack_chk_fail() noreturn {
  1112.      @panic("stack smashing detected");
Advertisement
Add Comment
Please, Sign In to add comment