From 24e54799fddf7c88e0feebeeef6ac2cc2f6543a0 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 16:24:12 +0300 Subject: Fix CMake finding LLVM/clang/lld on FreeBSD --- cmake/Findclang.cmake | 2 ++ cmake/Findlld.cmake | 7 ++++++- cmake/Findllvm.cmake | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmake/Findclang.cmake b/cmake/Findclang.cmake index ea1bc91d7b..9268f19730 100644 --- a/cmake/Findclang.cmake +++ b/cmake/Findclang.cmake @@ -30,6 +30,7 @@ else() /usr/lib/llvm/7/include /usr/lib/llvm-7/include /usr/lib/llvm-7.0/include + /usr/local/llvm70/include /mingw64/include) macro(FIND_AND_ADD_CLANG_LIB _libname_) @@ -40,6 +41,7 @@ else() /usr/lib/llvm/7/lib /usr/lib/llvm-7/lib /usr/lib/llvm-7.0/lib + /usr/local/llvm70/lib /mingw64/lib /c/msys64/mingw64/lib c:\\msys64\\mingw64\\lib) diff --git a/cmake/Findlld.cmake b/cmake/Findlld.cmake index 1c4e9163a3..4e5b0c9a19 100644 --- a/cmake/Findlld.cmake +++ b/cmake/Findlld.cmake @@ -9,9 +9,13 @@ find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h PATHS /usr/lib/llvm-6.0/include + /usr/local/llvm60/include /mingw64/include) -find_library(LLD_LIBRARY NAMES lld-6.0 lld PATHS /usr/lib/llvm-6.0/lib) +find_library(LLD_LIBRARY NAMES lld-6.0 lld60 lld + PATHS + /usr/lib/llvm-6.0/lib + /usr/local/llvm70/lib) if(EXISTS ${LLD_LIBRARY}) set(LLD_LIBRARIES ${LLD_LIBRARY}) else() @@ -20,6 +24,7 @@ else() find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_} PATHS /usr/lib/llvm-6.0/lib + /usr/local/llvm70/lib /mingw64/lib /c/msys64/mingw64/lib c:/msys64/mingw64/lib) diff --git a/cmake/Findllvm.cmake b/cmake/Findllvm.cmake index 150f2a2528..b847813682 100644 --- a/cmake/Findllvm.cmake +++ b/cmake/Findllvm.cmake @@ -8,7 +8,7 @@ # LLVM_LIBDIRS find_program(LLVM_CONFIG_EXE - NAMES llvm-config-7 llvm-config-7.0 llvm-config + NAMES llvm-config-7 llvm-config-7.0 llvm-config70 llvm-config PATHS "/mingw64/bin" "/c/msys64/mingw64/bin" -- cgit v1.2.3 From 9a541c12140e8768fabbbd8834cd0e1570df344b Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 16:48:17 +0300 Subject: Add FreeBSD support to os.cpp --- src/os.cpp | 26 ++++++++++++++++++++------ src/os.hpp | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/os.cpp b/src/os.cpp index 6df463d8a5..86bef6d5e8 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -50,10 +50,13 @@ typedef SSIZE_T ssize_t; #endif -#if defined(ZIG_OS_LINUX) +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) #include #endif +#if defined(ZIG_OS_FREEBSD) +#include +#endif #if defined(__MACH__) #include @@ -75,7 +78,9 @@ static clock_serv_t cclock; #if defined(__APPLE__) && !defined(environ) #include #define environ (*_NSGetEnviron()) -#endif +#elif defined(ZIG_OS_FREEBSD) +extern char **environ; +#endif #if defined(ZIG_OS_POSIX) static void populate_termination(Termination *term, int status) { @@ -1442,6 +1447,15 @@ Error os_self_exe_path(Buf *out_path) { } buf_resize(out_path, amt); return ErrorNone; +#elif defined(ZIG_OS_FREEBSD) + buf_resize(out_path, PATH_MAX); + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + size_t cb = PATH_MAX; + if (sysctl(mib, 4, buf_ptr(out_path), &cb, nullptr, 0) != 0) { + return ErrorUnexpected; + } + buf_resize(out_path, cb); + return ErrorNone; #endif return ErrorFileNotFound; } @@ -1747,7 +1761,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { buf_resize(out_path, 0); buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname); return ErrorNone; -#elif defined(ZIG_OS_LINUX) +#elif defined(ZIG_OS_POSIX) const char *home_dir = getenv("HOME"); if (home_dir == nullptr) { // TODO use /etc/passwd @@ -1760,7 +1774,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { } -#if defined(ZIG_OS_LINUX) +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) { ZigList *libs = reinterpret_cast< ZigList *>(data); if (info->dlpi_name[0] == '/') { @@ -1771,7 +1785,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, #endif Error os_self_exe_shared_libs(ZigList &paths) { -#if defined(ZIG_OS_LINUX) +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) paths.resize(0); dl_iterate_phdr(self_exe_shared_libs_callback, &paths); return ErrorNone; @@ -1940,7 +1954,7 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) { mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; mtime->nsec = 0; return ErrorNone; -#elif defined(ZIG_OS_LINUX) +#elif defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) struct stat statbuf; if (fstat(file, &statbuf) == -1) return ErrorFileSystem; diff --git a/src/os.hpp b/src/os.hpp index 30083971eb..a552c4461c 100644 --- a/src/os.hpp +++ b/src/os.hpp @@ -24,6 +24,8 @@ #define ZIG_OS_WINDOWS #elif defined(__linux__) #define ZIG_OS_LINUX +#elif defined(__FreeBSD__) +#define ZIG_OS_FREEBSD #else #define ZIG_OS_UNKNOWN #endif -- cgit v1.2.3 From e2b9c153bdfa2c5e4005d5957062e0eaf3b339a2 Mon Sep 17 00:00:00 2001 From: Marc Tiehuis Date: Fri, 20 Oct 2017 06:16:56 +0000 Subject: Add initial freebsd stdlib functionality Trivial program now compiles with now warnings. --- src/target.cpp | 2 +- std/os/freebsd.zig | 733 ++++++++++++++++++++++++++++++++++++++++++++++ std/os/freebsd_errno.zig | 121 ++++++++ std/os/freebsd_i386.zig | 614 ++++++++++++++++++++++++++++++++++++++ std/os/freebsd_x86_64.zig | 637 ++++++++++++++++++++++++++++++++++++++++ std/os/get_user_id.zig | 2 +- std/os/index.zig | 6 +- std/os/path.zig | 4 +- 8 files changed, 2113 insertions(+), 6 deletions(-) create mode 100644 std/os/freebsd.zig create mode 100644 std/os/freebsd_errno.zig create mode 100644 std/os/freebsd_i386.zig create mode 100644 std/os/freebsd_x86_64.zig diff --git a/src/target.cpp b/src/target.cpp index 25dfa9d3cb..e93465ba40 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -738,6 +738,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { case OsLinux: case OsMacOSX: case OsZen: + case OsFreeBSD: case OsOpenBSD: switch (id) { case CIntTypeShort: @@ -774,7 +775,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { case OsAnanas: case OsCloudABI: case OsDragonFly: - case OsFreeBSD: case OsIOS: case OsKFreeBSD: case OsLv2: diff --git a/std/os/freebsd.zig b/std/os/freebsd.zig new file mode 100644 index 0000000000..7fd233aef7 --- /dev/null +++ b/std/os/freebsd.zig @@ -0,0 +1,733 @@ +const assert = @import("../debug.zig").assert; +const builtin = @import("builtin"); +const arch = switch (builtin.arch) { + builtin.Arch.x86_64 => @import("freebsd_x86_64.zig"), + builtin.Arch.i386 => @import("freebsd_i386.zig"), + else => @compileError("unsupported arch"), +}; +pub use @import("freebsd_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_NONE = 0; +pub const PROT_READ = 1; +pub const PROT_WRITE = 2; +pub const PROT_EXEC = 4; + +pub const MAP_FAILED = @maxValue(usize); +pub const MAP_SHARED = 0x0001; +pub const MAP_PRIVATE = 0x0002; +pub const MAP_FIXED = 0x0010; +pub const MAP_STACK = 0x0400; +pub const MAP_NOSYNC = 0x0800; +pub const MAP_ANON = 0x1000; +pub const MAP_ANONYMOUS = MAP_ANON; +pub const MAP_FILE = 0; + +pub const MAP_GUARD = 0x00002000; +pub const MAP_EXCL = 0x00004000; +pub const MAP_NOCORE = 0x00020000; +pub const MAP_PREFAULT_READ = 0x00040000; +pub const MAP_32BIT = 0x00080000; + +pub const WNOHANG = 1; +pub const WUNTRACED = 2; +pub const WSTOPPED = WUNTRACED; +pub const WCONTINUED = 4; +pub const WNOWAIT = 8; +pub const WEXITED = 16; +pub const WTRAPPED = 32; + +pub const SA_ONSTACK = 0x0001; +pub const SA_RESTART = 0x0002; +pub const SA_RESETHAND = 0x0004; +pub const SA_NOCLDSTOP = 0x0008; +pub const SA_NODEFER = 0x0010; +pub const SA_NOCLDWAIT = 0x0020; +pub const SA_SIGINFO = 0x0040; + +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 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; +pub const SIGTHR = 32; +pub const SIGLWP = SIGTHR; +pub const SIGLIBRT = 33; + +pub const SIGRTMIN = 65; +pub const SIGRTMAX = 126; + +pub const O_RDONLY = 0o0; +pub const O_WRONLY = 0o1; +pub const O_RDWR = 0o2; +pub const O_ACCMODE = 0o3; + +pub const O_CREAT = arch.O_CREAT; +pub const O_EXCL = arch.O_EXCL; +pub const O_NOCTTY = arch.O_NOCTTY; +pub const O_TRUNC = arch.O_TRUNC; +pub const O_APPEND = arch.O_APPEND; +pub const O_NONBLOCK = arch.O_NONBLOCK; +pub const O_DSYNC = arch.O_DSYNC; +pub const O_SYNC = arch.O_SYNC; +pub const O_RSYNC = arch.O_RSYNC; +pub const O_DIRECTORY = arch.O_DIRECTORY; +pub const O_NOFOLLOW = arch.O_NOFOLLOW; +pub const O_CLOEXEC = arch.O_CLOEXEC; + +pub const O_ASYNC = arch.O_ASYNC; +pub const O_DIRECT = arch.O_DIRECT; +pub const O_LARGEFILE = arch.O_LARGEFILE; +pub const O_NOATIME = arch.O_NOATIME; +pub const O_PATH = arch.O_PATH; +pub const O_TMPFILE = arch.O_TMPFILE; +pub const O_NDELAY = arch.O_NDELAY; + +pub const SEEK_SET = 0; +pub const SEEK_CUR = 1; +pub const SEEK_END = 2; + +pub const SIG_BLOCK = 1; +pub const SIG_UNBLOCK = 2; +pub const SIG_SETMASK = 3; + +pub const SOCK_STREAM = 1; +pub const SOCK_DGRAM = 2; +pub const SOCK_RAW = 3; +pub const SOCK_RDM = 4; +pub const SOCK_SEQPACKET = 5; + +pub const SOCK_CLOEXEC = 0x10000000; +pub const SOCK_NONBLOCK = 0x20000000; + +// TODO: From here +pub const PROTO_ip = 0o000; +pub const PROTO_icmp = 0o001; +pub const PROTO_igmp = 0o002; +pub const PROTO_ggp = 0o003; +pub const PROTO_ipencap = 0o004; +pub const PROTO_st = 0o005; +pub const PROTO_tcp = 0o006; +pub const PROTO_egp = 0o010; +pub const PROTO_pup = 0o014; +pub const PROTO_udp = 0o021; +pub const PROTO_hmp = 0o024; +pub const PROTO_xns_idp = 0o026; +pub const PROTO_rdp = 0o033; +pub const PROTO_iso_tp4 = 0o035; +pub const PROTO_xtp = 0o044; +pub const PROTO_ddp = 0o045; +pub const PROTO_idpr_cmtp = 0o046; +pub const PROTO_ipv6 = 0o051; +pub const PROTO_ipv6_route = 0o053; +pub const PROTO_ipv6_frag = 0o054; +pub const PROTO_idrp = 0o055; +pub const PROTO_rsvp = 0o056; +pub const PROTO_gre = 0o057; +pub const PROTO_esp = 0o062; +pub const PROTO_ah = 0o063; +pub const PROTO_skip = 0o071; +pub const PROTO_ipv6_icmp = 0o072; +pub const PROTO_ipv6_nonxt = 0o073; +pub const PROTO_ipv6_opts = 0o074; +pub const PROTO_rspf = 0o111; +pub const PROTO_vmtp = 0o121; +pub const PROTO_ospf = 0o131; +pub const PROTO_ipip = 0o136; +pub const PROTO_encap = 0o142; +pub const PROTO_pim = 0o147; +pub const PROTO_raw = 0o377; + +pub const PF_UNSPEC = 0; +pub const PF_LOCAL = 1; +pub const PF_UNIX = PF_LOCAL; +pub const PF_FILE = PF_LOCAL; +pub const PF_INET = 2; +pub const PF_AX25 = 3; +pub const PF_IPX = 4; +pub const PF_APPLETALK = 5; +pub const PF_NETROM = 6; +pub const PF_BRIDGE = 7; +pub const PF_ATMPVC = 8; +pub const PF_X25 = 9; +pub const PF_INET6 = 10; +pub const PF_ROSE = 11; +pub const PF_DECnet = 12; +pub const PF_NETBEUI = 13; +pub const PF_SECURITY = 14; +pub const PF_KEY = 15; +pub const PF_NETLINK = 16; +pub const PF_ROUTE = PF_NETLINK; +pub const PF_PACKET = 17; +pub const PF_ASH = 18; +pub const PF_ECONET = 19; +pub const PF_ATMSVC = 20; +pub const PF_RDS = 21; +pub const PF_SNA = 22; +pub const PF_IRDA = 23; +pub const PF_PPPOX = 24; +pub const PF_WANPIPE = 25; +pub const PF_LLC = 26; +pub const PF_IB = 27; +pub const PF_MPLS = 28; +pub const PF_CAN = 29; +pub const PF_TIPC = 30; +pub const PF_BLUETOOTH = 31; +pub const PF_IUCV = 32; +pub const PF_RXRPC = 33; +pub const PF_ISDN = 34; +pub const PF_PHONET = 35; +pub const PF_IEEE802154 = 36; +pub const PF_CAIF = 37; +pub const PF_ALG = 38; +pub const PF_NFC = 39; +pub const PF_VSOCK = 40; +pub const PF_MAX = 41; + +pub const AF_UNSPEC = PF_UNSPEC; +pub const AF_LOCAL = PF_LOCAL; +pub const AF_UNIX = AF_LOCAL; +pub const AF_FILE = AF_LOCAL; +pub const AF_INET = PF_INET; +pub const AF_AX25 = PF_AX25; +pub const AF_IPX = PF_IPX; +pub const AF_APPLETALK = PF_APPLETALK; +pub const AF_NETROM = PF_NETROM; +pub const AF_BRIDGE = PF_BRIDGE; +pub const AF_ATMPVC = PF_ATMPVC; +pub const AF_X25 = PF_X25; +pub const AF_INET6 = PF_INET6; +pub const AF_ROSE = PF_ROSE; +pub const AF_DECnet = PF_DECnet; +pub const AF_NETBEUI = PF_NETBEUI; +pub const AF_SECURITY = PF_SECURITY; +pub const AF_KEY = PF_KEY; +pub const AF_NETLINK = PF_NETLINK; +pub const AF_ROUTE = PF_ROUTE; +pub const AF_PACKET = PF_PACKET; +pub const AF_ASH = PF_ASH; +pub const AF_ECONET = PF_ECONET; +pub const AF_ATMSVC = PF_ATMSVC; +pub const AF_RDS = PF_RDS; +pub const AF_SNA = PF_SNA; +pub const AF_IRDA = PF_IRDA; +pub const AF_PPPOX = PF_PPPOX; +pub const AF_WANPIPE = PF_WANPIPE; +pub const AF_LLC = PF_LLC; +pub const AF_IB = PF_IB; +pub const AF_MPLS = PF_MPLS; +pub const AF_CAN = PF_CAN; +pub const AF_TIPC = PF_TIPC; +pub const AF_BLUETOOTH = PF_BLUETOOTH; +pub const AF_IUCV = PF_IUCV; +pub const AF_RXRPC = PF_RXRPC; +pub const AF_ISDN = PF_ISDN; +pub const AF_PHONET = PF_PHONET; +pub const AF_IEEE802154 = PF_IEEE802154; +pub const AF_CAIF = PF_CAIF; +pub const AF_ALG = PF_ALG; +pub const AF_NFC = PF_NFC; +pub const AF_VSOCK = PF_VSOCK; +pub const AF_MAX = PF_MAX; + +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 DT_WHT = 14; + + +pub const TCGETS = 0x5401; +pub const TCSETS = 0x5402; +pub const TCSETSW = 0x5403; +pub const TCSETSF = 0x5404; +pub const TCGETA = 0x5405; +pub const TCSETA = 0x5406; +pub const TCSETAW = 0x5407; +pub const TCSETAF = 0x5408; +pub const TCSBRK = 0x5409; +pub const TCXONC = 0x540A; +pub const TCFLSH = 0x540B; +pub const TIOCEXCL = 0x540C; +pub const TIOCNXCL = 0x540D; +pub const TIOCSCTTY = 0x540E; +pub const TIOCGPGRP = 0x540F; +pub const TIOCSPGRP = 0x5410; +pub const TIOCOUTQ = 0x5411; +pub const TIOCSTI = 0x5412; +pub const TIOCGWINSZ = 0x5413; +pub const TIOCSWINSZ = 0x5414; +pub const TIOCMGET = 0x5415; +pub const TIOCMBIS = 0x5416; +pub const TIOCMBIC = 0x5417; +pub const TIOCMSET = 0x5418; +pub const TIOCGSOFTCAR = 0x5419; +pub const TIOCSSOFTCAR = 0x541A; +pub const FIONREAD = 0x541B; +pub const TIOCINQ = FIONREAD; +pub const TIOCLINUX = 0x541C; +pub const TIOCCONS = 0x541D; +pub const TIOCGSERIAL = 0x541E; +pub const TIOCSSERIAL = 0x541F; +pub const TIOCPKT = 0x5420; +pub const FIONBIO = 0x5421; +pub const TIOCNOTTY = 0x5422; +pub const TIOCSETD = 0x5423; +pub const TIOCGETD = 0x5424; +pub const TCSBRKP = 0x5425; +pub const TIOCSBRK = 0x5427; +pub const TIOCCBRK = 0x5428; +pub const TIOCGSID = 0x5429; +pub const TIOCGRS485 = 0x542E; +pub const TIOCSRS485 = 0x542F; +pub const TIOCGPTN = 0x80045430; +pub const TIOCSPTLCK = 0x40045431; +pub const TIOCGDEV = 0x80045432; +pub const TCGETX = 0x5432; +pub const TCSETX = 0x5433; +pub const TCSETXF = 0x5434; +pub const TCSETXW = 0x5435; +pub const TIOCSIG = 0x40045436; +pub const TIOCVHANGUP = 0x5437; +pub const TIOCGPKT = 0x80045438; +pub const TIOCGPTLCK = 0x80045439; +pub const TIOCGEXCL = 0x80045440; + +fn unsigned(s: i32) -> u32 { @bitCast(u32, s) } +fn signed(s: u32) -> i32 { @bitCast(i32, s) } +pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) } +pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) } +pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) } +pub fn WIFEXITED(s: i32) -> bool { WTERMSIG(s) == 0 } +pub fn WIFSTOPPED(s: i32) -> bool { (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00 } +pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff } + + +pub const winsize = extern struct { + ws_row: u16, + ws_col: u16, + ws_xpixel: u16, + ws_ypixel: u16, +}; + +/// 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); + if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0 +} + +pub fn dup2(old: i32, new: i32) -> usize { + arch.syscall2(arch.SYS_dup2, usize(old), usize(new)) +} + +pub fn chdir(path: &const u8) -> usize { + arch.syscall1(arch.SYS_chdir, @ptrToInt(path)) +} + +pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize { + arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)) +} + +pub fn fork() -> usize { + arch.syscall0(arch.SYS_fork) +} + +pub fn getcwd(buf: &u8, size: usize) -> usize { + arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size) +} + +pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize { + arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count) +} + +pub fn isatty(fd: i32) -> bool { + var wsz: winsize = undefined; + return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; +} + +pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize { + arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len) +} + +pub fn mkdir(path: &const u8, mode: u32) -> usize { + arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode) +} + +pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) + -> usize +{ + arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), + @bitCast(usize, offset)) +} + +pub fn munmap(address: &u8, length: usize) -> usize { + arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length) +} + +pub fn read(fd: i32, buf: &u8, count: usize) -> usize { + arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count) +} + +pub fn rmdir(path: &const u8) -> usize { + arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)) +} + +pub fn symlink(existing: &const u8, new: &const u8) -> usize { + arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)) +} + +pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize { + arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset) +} + +pub fn pipe(fd: &[2]i32) -> usize { + pipe2(fd, 0) +} + +pub fn pipe2(fd: &[2]i32, flags: usize) -> usize { + arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags) +} + +pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { + arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count) +} + +pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize { + arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset) +} + +pub fn rename(old: &const u8, new: &const u8) -> usize { + arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)) +} + +pub fn open(path: &const u8, flags: u32, perm: usize) -> usize { + arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm) +} + +pub fn create(path: &const u8, perm: usize) -> usize { + arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm) +} + +pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize { + arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode) +} + +pub fn close(fd: i32) -> usize { + arch.syscall1(arch.SYS_close, usize(fd)) +} + +pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize { + arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos) +} + +pub fn exit(status: i32) -> noreturn { + _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); + unreachable +} + +pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize { + arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags)) +} + +pub fn kill(pid: i32, sig: i32) -> usize { + arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig)) +} + +pub fn unlink(path: &const u8) -> usize { + arch.syscall1(arch.SYS_unlink, @ptrToInt(path)) +} + +pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize { + arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0) +} + +pub fn nanosleep(req: &const timespec, rem: ?×pec) -> usize { + arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)) +} + +pub fn setuid(uid: u32) -> usize { + arch.syscall1(arch.SYS_setuid, uid) +} + +pub fn setgid(gid: u32) -> usize { + arch.syscall1(arch.SYS_setgid, gid) +} + +pub fn setreuid(ruid: u32, euid: u32) -> usize { + arch.syscall2(arch.SYS_setreuid, ruid, euid) +} + +pub fn setregid(rgid: u32, egid: u32) -> usize { + arch.syscall2(arch.SYS_setregid, rgid, egid) +} + +pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize { + arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8) +} + +pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize { + assert(sig >= 1); + assert(sig != SIGKILL); + assert(sig != SIGSTOP); + var ksa = k_sigaction { + .handler = act.handler, + .flags = act.flags | SA_RESTORER, + .mask = undefined, + .restorer = @ptrCast(extern fn(), arch.restore_rt), + }; + var ksa_old: k_sigaction = undefined; + @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8); + const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask))); + const err = getErrno(result); + if (err != 0) { + return result; + } + if (oact) |old| { + old.handler = ksa_old.handler; + old.flags = @truncate(u32, ksa_old.flags); + @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask))); + } + return 0; +} + +const NSIG = 65; +const sigset_t = [128 / @sizeOf(usize)]usize; +const all_mask = []usize{@maxValue(usize)}; +const app_mask = []usize{0xfffffffc7fffffff}; + +const k_sigaction = extern struct { + handler: extern fn(i32), + flags: usize, + restorer: extern fn(), + mask: [2]u32, +}; + +/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. +pub const Sigaction = struct { + handler: extern fn(i32), + mask: sigset_t, + flags: u32, +}; + +pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize)); +pub const SIG_DFL = @intToPtr(extern fn(i32), 0); +pub const SIG_IGN = @intToPtr(extern fn(i32), 1); +pub const empty_sigset = []usize{0} ** sigset_t.len; + +pub fn raise(sig: i32) -> usize { + // TODO implement, see linux equivalent for what we want to try and do + return 0; +} + +fn blockAllSignals(set: &sigset_t) { + // TODO implement +} + +fn blockAppSignals(set: &sigset_t) { + // TODO implement +} + +fn restoreSignals(set: &sigset_t) { + // TODO implement +} + +pub fn sigaddset(set: &sigset_t, sig: u6) { + const s = sig - 1; + (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); +} + +pub fn sigismember(set: &const sigset_t, sig: u6) -> bool { + const s = sig - 1; + return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; +} + + +pub const sa_family_t = u16; +pub const socklen_t = u32; +pub const in_addr = u32; +pub const in6_addr = [16]u8; + +pub const sockaddr = extern struct { + family: sa_family_t, + port: u16, + data: [12]u8, +}; + +pub const sockaddr_in = extern struct { + family: sa_family_t, + port: u16, + addr: in_addr, + zero: [8]u8, +}; + +pub const sockaddr_in6 = extern struct { + family: sa_family_t, + port: u16, + flowinfo: u32, + addr: in6_addr, + scope_id: u32, +}; + +pub const iovec = extern struct { + iov_base: &u8, + iov_len: usize, +}; + +// +//const IF_NAMESIZE = 16; +// +//export struct ifreq { +// ifrn_name: [IF_NAMESIZE]u8, +// union { +// ifru_addr: sockaddr, +// ifru_dstaddr: sockaddr, +// ifru_broadaddr: sockaddr, +// ifru_netmask: sockaddr, +// ifru_hwaddr: sockaddr, +// ifru_flags: i16, +// ifru_ivalue: i32, +// ifru_mtu: i32, +// ifru_map: ifmap, +// ifru_slave: [IF_NAMESIZE]u8, +// ifru_newname: [IF_NAMESIZE]u8, +// ifru_data: &u8, +// } ifr_ifru; +//} +// + +pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { + arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len)) +} + +pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { + arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len)) +} + +pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize { + arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol)) +} + +pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize { + arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen)) +} + +pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize { + arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen)) +} + +pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize { + arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags) +} + +pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { + arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len)) +} + +pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize { + arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags) +} + +pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, + noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize +{ + arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)) +} + +pub fn shutdown(fd: i32, how: i32) -> usize { + arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)) +} + +pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { + arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len)) +} + +pub fn listen(fd: i32, backlog: i32) -> usize { + arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)) +} + +pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize { + arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen)) +} + +pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize { + arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0])) +} + +pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { + accept4(fd, addr, len, 0) +} + +pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize { + arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags) +} + +// error NameTooLong; +// error SystemResources; +// error Io; +// +// pub fn if_nametoindex(name: []u8) -> %u32 { +// var ifr: ifreq = undefined; +// +// if (name.len >= ifr.ifr_name.len) { +// return error.NameTooLong; +// } +// +// const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); +// const socket_err = getErrno(socket_ret); +// if (socket_err > 0) { +// return error.SystemResources; +// } +// const socket_fd = i32(socket_ret); +// @memcpy(&ifr.ifr_name[0], &name[0], name.len); +// ifr.ifr_name[name.len] = 0; +// const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr); +// close(socket_fd); +// const ioctl_err = getErrno(ioctl_ret); +// if (ioctl_err > 0) { +// return error.Io; +// } +// return ifr.ifr_ifindex; +// } + +pub const Stat = arch.Stat; +pub const timespec = arch.timespec; + +pub fn fstat(fd: i32, stat_buf: &Stat) -> usize { + arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)) +} diff --git a/std/os/freebsd_errno.zig b/std/os/freebsd_errno.zig new file mode 100644 index 0000000000..132683de1d --- /dev/null +++ b/std/os/freebsd_errno.zig @@ -0,0 +1,121 @@ +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; // Argument 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; // Resource deadlock avoided + // 11 was EAGAIN +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 filesystem +pub const EMLINK = 31; // Too many links +pub const EPIPE = 32; // Broken pipe + +// math software +pub const EDOM = 33; // Numerical argument out of domain +pub const ERANGE = 34; // Result too large + +// non-blocking and interrupt i/o +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 + +// ipc/network software -- argument errors +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 ENOTSUP = EOPNOTSUPP; // 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 + +// ipc/network software -- operational errors +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 + +// should be rearranged +pub const EHOSTDOWN = 64; // Host is down +pub const EHOSTUNREACH = 65; // No route to host +pub const ENOTEMPTY = 66; // Directory not empty + +// quotas & mush +pub const EPROCLIM = 67; // Too many processes +pub const EUSERS = 68; // Too many users +pub const EDQUOT = 69; // Disc quota exceeded + +// Network File System +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 prog. not avail +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 EIDRM = 82; // Identifier removed +pub const ENOMSG = 83; // No message of desired type +pub const EOVERFLOW = 84; // Value too large to be stored in data type +pub const ECANCELED = 85; // Operation canceled +pub const EILSEQ = 86; // Illegal byte sequence +pub const ENOATTR = 87; // Attribute not found + +pub const EDOOFUS = 88; // Programming error + +pub const EBADMSG = 89; // Bad message +pub const EMULTIHOP = 90; // Multihop attempted +pub const ENOLINK = 91; // Link has been severed +pub const EPROTO = 92; // Protocol error + +pub const ENOTCAPABLE = 93; // Capabilities insufficient +pub const ECAPMODE = 94; // Not permitted in capability mode +pub const ENOTRECOVERABLE = 95; // State not recoverable +pub const EOWNERDEAD = 96; // Previous owner died + +pub const ELAST = 96; // Must be equal largest errno diff --git a/std/os/freebsd_i386.zig b/std/os/freebsd_i386.zig new file mode 100644 index 0000000000..fd1f58639b --- /dev/null +++ b/std/os/freebsd_i386.zig @@ -0,0 +1,614 @@ +const freebsd = @import("freebsd.zig"); +const socklen_t = freebsd.socklen_t; +const iovec = freebsd.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_wait4 = 7; +// 8 is old creat +pub const SYS_link = 9; +pub const SYS_unlink = 10; +// 11 is obsolete execv +pub const SYS_chdir = 12; +pub const SYS_fchdir = 13; +pub const SYS_freebsd11_mknod = 14; +pub const SYS_chmod = 15; +pub const SYS_chown = 16; +pub const SYS_break = 17; +// 18 is freebsd4 getfsstat +// 19 is old lseek +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_kill = 37; +// 38 is old stat +pub const SYS_getppid = 39; +// 40 is old lstat +pub const SYS_dup = 41; +pub const SYS_freebsd10_pipe = 42; +pub const SYS_getegid = 43; +pub const SYS_profil = 44; +pub const SYS_ktrace = 45; +// 46 is old sigaction +pub const SYS_getgid = 47; +// 48 is old sigprocmask +pub const SYS_getlogin = 49; +pub const SYS_setlogin = 50; +pub const SYS_acct = 51; +// 52 is old sigpending +pub const SYS_sigaltstack = 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; +// 62 is old fstat +// 63 is old getkerninfo +// 64 is old getpagesize +pub const SYS_msync = 65; +pub const SYS_vfork = 66; +// 67 is obsolete vread +// 68 is obsolete vwrite +pub const SYS_sbrk = 69; +pub const SYS_sstk = 70; +// 71 is old mmap +pub const SYS_vadvise = 72; +pub const SYS_munmap = 73; +pub const SYS_mprotect = 74; +pub const SYS_madvise = 75; +// 76 is obsolete vhangup +// 77 is obsolete vlimit +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_setitimer = 83; +// 84 is old wait +pub const SYS_swapon = 85; +pub const SYS_getitimer = 86; +// 87 is old gethostname +// 88 is old sethostname +pub const SYS_getdtablesize = 89; +pub const SYS_dup2 = 90; +pub const SYS_fcntl = 92; +pub const SYS_select = 93; +pub const SYS_fsync = 95; +pub const SYS_setpriority = 96; +pub const SYS_socket = 97; +pub const SYS_connect = 98; +// 99 is old accept +pub const SYS_getpriority = 100; +// 101 is old send +// 102 is old recv +// 103 is old sigreturn +pub const SYS_bind = 104; +pub const SYS_setsockopt = 105; +pub const SYS_listen = 106; +// 107 is obsolete vtimes +// 108 is old sigvec +// 109 is old sigblock +// 110 is old sigsetmask +// 111 is old sigsuspend +// 112 is old sigstack +// 113 is old recvmsg +// 114 is old sendmsg +// 115 is obsolete vtrace +pub const SYS_gettimeofday = 116; +pub const SYS_getrusage = 117; +pub const SYS_getsockopt = 118; +pub const SYS_readv = 120; +pub const SYS_writev = 121; +pub const SYS_settimeofday = 122; +pub const SYS_fchown = 123; +pub const SYS_fchmod = 124; +// 125 is old recvfrom +pub const SYS_setreuid = 126; +pub const SYS_setregid = 127; +pub const SYS_rename = 128; +// 129 is old truncate +// 130 is old ftruncate +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_utimes = 138; +// 139 is obsolete 4.2 sigreturn +pub const SYS_adjtime = 140; +// 141 is old getpeername +// 142 is old gethostid +// 143 is old sethostid +// 144 is old getrlimit +// 145 is old setrlimit +// 146 is old killpg +pub const SYS_setsid = 147; +pub const SYS_quotactl = 148; +// 149 is old quota +// 150 is old getsockname +pub const SYS_nlm_syscall = 154; +pub const SYS_nfssvc = 155; +// 156 is old getdirentries +// 157 is freebsd4 statfs +// 158 is freebsd4 fstatfs +pub const SYS_lgetfh = 160; +pub const SYS_getfh = 161; +// 162 is freebsd4 getdomainname +// 163 is freebsd4 setdomainname +// 164 is freebsd4 uname +pub const SYS_sysarch = 165; +pub const SYS_rtprio = 166; +pub const SYS_semsys = 169; +pub const SYS_msgsys = 170; +pub const SYS_shmsys = 171; +// 173 is freebsd6 pread +// 174 is freebsd6 pwrite +pub const SYS_setfib = 175; +pub const SYS_ntp_adjtime = 176; +pub const SYS_setgid = 181; +pub const SYS_setegid = 182; +pub const SYS_seteuid = 183; +pub const SYS_freebsd11_stat = 188; +pub const SYS_freebsd11_fstat = 189; +pub const SYS_freebsd11_lstat = 190; +pub const SYS_pathconf = 191; +pub const SYS_fpathconf = 192; +pub const SYS_getrlimit = 194; +pub const SYS_setrlimit = 195; +pub const SYS_freebsd11_getdirentries = 196; +// 197 is freebsd6 mmap +pub const SYS___syscall = 198; +// 199 is freebsd6 lseek +// 200 is freebsd6 truncate +// 201 is freebsd6 ftruncate +pub const SYS___sysctl = 202; +pub const SYS_mlock = 203; +pub const SYS_munlock = 204; +pub const SYS_undelete = 205; +pub const SYS_futimes = 206; +pub const SYS_getpgid = 207; +pub const SYS_poll = 209; +pub const SYS_freebsd7___semctl = 220; +pub const SYS_semget = 221; +pub const SYS_semop = 222; +pub const SYS_freebsd7_msgctl = 224; +pub const SYS_msgget = 225; +pub const SYS_msgsnd = 226; +pub const SYS_msgrcv = 227; +pub const SYS_shmat = 228; +pub const SYS_freebsd7_shmctl = 229; +pub const SYS_shmdt = 230; +pub const SYS_shmget = 231; +pub const SYS_clock_gettime = 232; +pub const SYS_clock_settime = 233; +pub const SYS_clock_getres = 234; +pub const SYS_ktimer_create = 235; +pub const SYS_ktimer_delete = 236; +pub const SYS_ktimer_settime = 237; +pub const SYS_ktimer_gettime = 238; +pub const SYS_ktimer_getoverrun = 239; +pub const SYS_nanosleep = 240; +pub const SYS_ffclock_getcounter = 241; +pub const SYS_ffclock_setestimate = 242; +pub const SYS_ffclock_getestimate = 243; +pub const SYS_clock_nanosleep = 244; +pub const SYS_clock_getcpuclockid2 = 247; +pub const SYS_ntp_gettime = 248; +pub const SYS_minherit = 250; +pub const SYS_rfork = 251; +// 252 is obsolete openbsd_poll +pub const SYS_issetugid = 253; +pub const SYS_lchown = 254; +pub const SYS_aio_read = 255; +pub const SYS_aio_write = 256; +pub const SYS_lio_listio = 257; +pub const SYS_freebsd11_getdents = 272; +pub const SYS_lchmod = 274; +pub const SYS_netbsd_lchown = 275; +pub const SYS_lutimes = 276; +pub const SYS_netbsd_msync = 277; +pub const SYS_freebsd11_nstat = 278; +pub const SYS_freebsd11_nfstat = 279; +pub const SYS_freebsd11_nlstat = 280; +pub const SYS_preadv = 289; +pub const SYS_pwritev = 290; +// 297 is freebsd4 fhstatfs +pub const SYS_fhopen = 298; +pub const SYS_freebsd11_fhstat = 299; +pub const SYS_modnext = 300; +pub const SYS_modstat = 301; +pub const SYS_modfnext = 302; +pub const SYS_modfind = 303; +pub const SYS_kldload = 304; +pub const SYS_kldunload = 305; +pub const SYS_kldfind = 306; +pub const SYS_kldnext = 307; +pub const SYS_kldstat = 308; +pub const SYS_kldfirstmod = 309; +pub const SYS_getsid = 310; +pub const SYS_setresuid = 311; +pub const SYS_setresgid = 312; +// 313 is obsolete signanosleep +pub const SYS_aio_return = 314; +pub const SYS_aio_suspend = 315; +pub const SYS_aio_cancel = 316; +pub const SYS_aio_error = 317; +// 318 is freebsd6 aio_read +// 319 is freebsd6 aio_write +// 320 is freebsd6 lio_listio +pub const SYS_yield = 321; +// 322 is obsolete thr_sleep +// 323 is obsolete thr_wakeup +pub const SYS_mlockall = 324; +pub const SYS_munlockall = 325; +pub const SYS___getcwd = 326; +pub const SYS_sched_setparam = 327; +pub const SYS_sched_getparam = 328; +pub const SYS_sched_setscheduler = 329; +pub const SYS_sched_getscheduler = 330; +pub const SYS_sched_yield = 331; +pub const SYS_sched_get_priority_max = 332; +pub const SYS_sched_get_priority_min = 333; +pub const SYS_sched_rr_get_interval = 334; +pub const SYS_utrace = 335; +// 336 is freebsd4 sendfile +pub const SYS_kldsym = 337; +pub const SYS_jail = 338; +pub const SYS_nnpfs_syscall = 339; +pub const SYS_sigprocmask = 340; +pub const SYS_sigsuspend = 341; +// 342 is freebsd4 sigaction +pub const SYS_sigpending = 343; +// 344 is freebsd4 sigreturn +pub const SYS_sigtimedwait = 345; +pub const SYS_sigwaitinfo = 346; +pub const SYS___acl_get_file = 347; +pub const SYS___acl_set_file = 348; +pub const SYS___acl_get_fd = 349; +pub const SYS___acl_set_fd = 350; +pub const SYS___acl_delete_file = 351; +pub const SYS___acl_delete_fd = 352; +pub const SYS___acl_aclcheck_file = 353; +pub const SYS___acl_aclcheck_fd = 354; +pub const SYS_extattrctl = 355; +pub const SYS_extattr_set_file = 356; +pub const SYS_extattr_get_file = 357; +pub const SYS_extattr_delete_file = 358; +pub const SYS_aio_waitcomplete = 359; +pub const SYS_getresuid = 360; +pub const SYS_getresgid = 361; +pub const SYS_kqueue = 362; +pub const SYS_freebsd11_kevent = 363; +pub const SYS_extattr_set_fd = 371; +pub const SYS_extattr_get_fd = 372; +pub const SYS_extattr_delete_fd = 373; +pub const SYS___setugid = 374; +pub const SYS_eaccess = 376; +pub const SYS_afs3_syscall = 377; +pub const SYS_nmount = 378; +pub const SYS___mac_get_proc = 384; +pub const SYS___mac_set_proc = 385; +pub const SYS___mac_get_fd = 386; +pub const SYS___mac_get_file = 387; +pub const SYS___mac_set_fd = 388; +pub const SYS___mac_set_file = 389; +pub const SYS_kenv = 390; +pub const SYS_lchflags = 391; +pub const SYS_uuidgen = 392; +pub const SYS_sendfile = 393; +pub const SYS_mac_syscall = 394; +pub const SYS_freebsd11_getfsstat = 395; +pub const SYS_freebsd11_statfs = 396; +pub const SYS_freebsd11_fstatfs = 397; +pub const SYS_freebsd11_fhstatfs = 398; +pub const SYS_ksem_close = 400; +pub const SYS_ksem_post = 401; +pub const SYS_ksem_wait = 402; +pub const SYS_ksem_trywait = 403; +pub const SYS_ksem_init = 404; +pub const SYS_ksem_open = 405; +pub const SYS_ksem_unlink = 406; +pub const SYS_ksem_getvalue = 407; +pub const SYS_ksem_destroy = 408; +pub const SYS___mac_get_pid = 409; +pub const SYS___mac_get_link = 410; +pub const SYS___mac_set_link = 411; +pub const SYS_extattr_set_link = 412; +pub const SYS_extattr_get_link = 413; +pub const SYS_extattr_delete_link = 414; +pub const SYS___mac_execve = 415; +pub const SYS_sigaction = 416; +pub const SYS_sigreturn = 417; +pub const SYS_getcontext = 421; +pub const SYS_setcontext = 422; +pub const SYS_swapcontext = 423; +pub const SYS_swapoff = 424; +pub const SYS___acl_get_link = 425; +pub const SYS___acl_set_link = 426; +pub const SYS___acl_delete_link = 427; +pub const SYS___acl_aclcheck_link = 428; +pub const SYS_sigwait = 429; +pub const SYS_thr_create = 430; +pub const SYS_thr_exit = 431; +pub const SYS_thr_self = 432; +pub const SYS_thr_kill = 433; +pub const SYS_jail_attach = 436; +pub const SYS_extattr_list_fd = 437; +pub const SYS_extattr_list_file = 438; +pub const SYS_extattr_list_link = 439; +pub const SYS_ksem_timedwait = 441; +pub const SYS_thr_suspend = 442; +pub const SYS_thr_wake = 443; +pub const SYS_kldunloadf = 444; +pub const SYS_audit = 445; +pub const SYS_auditon = 446; +pub const SYS_getauid = 447; +pub const SYS_setauid = 448; +pub const SYS_getaudit = 449; +pub const SYS_setaudit = 450; +pub const SYS_getaudit_addr = 451; +pub const SYS_setaudit_addr = 452; +pub const SYS_auditctl = 453; +pub const SYS__umtx_op = 454; +pub const SYS_thr_new = 455; +pub const SYS_sigqueue = 456; +pub const SYS_kmq_open = 457; +pub const SYS_kmq_setattr = 458; +pub const SYS_kmq_timedreceive = 459; +pub const SYS_kmq_timedsend = 460; +pub const SYS_kmq_notify = 461; +pub const SYS_kmq_unlink = 462; +pub const SYS_abort2 = 463; +pub const SYS_thr_set_name = 464; +pub const SYS_aio_fsync = 465; +pub const SYS_rtprio_thread = 466; +pub const SYS_sctp_peeloff = 471; +pub const SYS_sctp_generic_sendmsg = 472; +pub const SYS_sctp_generic_sendmsg_iov = 473; +pub const SYS_sctp_generic_recvmsg = 474; +pub const SYS_pread = 475; +pub const SYS_pwrite = 476; +pub const SYS_mmap = 477; +pub const SYS_lseek = 478; +pub const SYS_truncate = 479; +pub const SYS_ftruncate = 480; +pub const SYS_thr_kill2 = 481; +pub const SYS_shm_open = 482; +pub const SYS_shm_unlink = 483; +pub const SYS_cpuset = 484; +pub const SYS_cpuset_setid = 485; +pub const SYS_cpuset_getid = 486; +pub const SYS_cpuset_getaffinity = 487; +pub const SYS_cpuset_setaffinity = 488; +pub const SYS_faccessat = 489; +pub const SYS_fchmodat = 490; +pub const SYS_fchownat = 491; +pub const SYS_fexecve = 492; +pub const SYS_freebsd11_fstatat = 493; +pub const SYS_futimesat = 494; +pub const SYS_linkat = 495; +pub const SYS_mkdirat = 496; +pub const SYS_mkfifoat = 497; +pub const SYS_freebsd11_mknodat = 498; +pub const SYS_openat = 499; +pub const SYS_readlinkat = 500; +pub const SYS_renameat = 501; +pub const SYS_symlinkat = 502; +pub const SYS_unlinkat = 503; +pub const SYS_posix_openpt = 504; +pub const SYS_gssd_syscall = 505; +pub const SYS_jail_get = 506; +pub const SYS_jail_set = 507; +pub const SYS_jail_remove = 508; +pub const SYS_closefrom = 509; +pub const SYS___semctl = 510; +pub const SYS_msgctl = 511; +pub const SYS_shmctl = 512; +pub const SYS_lpathconf = 513; +// 514 is obsolete cap_new +pub const SYS___cap_rights_get = 515; +pub const SYS_cap_enter = 516; +pub const SYS_cap_getmode = 517; +pub const SYS_pdfork = 518; +pub const SYS_pdkill = 519; +pub const SYS_pdgetpid = 520; +pub const SYS_pselect = 522; +pub const SYS_getloginclass = 523; +pub const SYS_setloginclass = 524; +pub const SYS_rctl_get_racct = 525; +pub const SYS_rctl_get_rules = 526; +pub const SYS_rctl_get_limits = 527; +pub const SYS_rctl_add_rule = 528; +pub const SYS_rctl_remove_rule = 529; +pub const SYS_posix_fallocate = 530; +pub const SYS_posix_fadvise = 531; +pub const SYS_wait6 = 532; +pub const SYS_cap_rights_limit = 533; +pub const SYS_cap_ioctls_limit = 534; +pub const SYS_cap_ioctls_get = 535; +pub const SYS_cap_fcntls_limit = 536; +pub const SYS_cap_fcntls_get = 537; +pub const SYS_bindat = 538; +pub const SYS_connectat = 539; +pub const SYS_chflagsat = 540; +pub const SYS_accept4 = 541; +pub const SYS_pipe2 = 542; +pub const SYS_aio_mlock = 543; +pub const SYS_procctl = 544; +pub const SYS_ppoll = 545; +pub const SYS_futimens = 546; +pub const SYS_utimensat = 547; +pub const SYS_numa_getaffinity = 548; +pub const SYS_numa_setaffinity = 549; +pub const SYS_fdatasync = 550; +pub const SYS_fstat = 551; +pub const SYS_fstatat = 552; +pub const SYS_fhstat = 553; +pub const SYS_getdirentries = 554; +pub const SYS_statfs = 555; +pub const SYS_fstatfs = 556; +pub const SYS_getfsstat = 557; +pub const SYS_fhstatfs = 558; +pub const SYS_mknodat = 559; +pub const SYS_kevent = 560; +pub const SYS_MAXSYSCALL = 561; + +// From here +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o200000; +pub const O_NOFOLLOW = 0o400000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o40000; +pub const O_LARGEFILE = 0o100000; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20200000; +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_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 12; +pub const F_SETLK = 13; +pub const F_SETLKW = 14; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +pub inline fn syscall0(number: usize) -> usize { + asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number)) +} + +pub inline fn syscall1(number: usize, arg1: usize) -> usize { + asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ebx}" (arg1)) +} + +pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { + asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ebx}" (arg1), + [arg2] "{ecx}" (arg2)) +} + +pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { + asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ebx}" (arg1), + [arg2] "{ecx}" (arg2), + [arg3] "{edx}" (arg3)) +} + +pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { + asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ebx}" (arg1), + [arg2] "{ecx}" (arg2), + [arg3] "{edx}" (arg3), + [arg4] "{esi}" (arg4)) +} + +pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, + arg4: usize, arg5: usize) -> usize +{ + asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ebx}" (arg1), + [arg2] "{ecx}" (arg2), + [arg3] "{edx}" (arg3), + [arg4] "{esi}" (arg4), + [arg5] "{edi}" (arg5)) +} + +pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, + arg4: usize, arg5: usize, arg6: usize) -> usize +{ + asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ebx}" (arg1), + [arg2] "{ecx}" (arg2), + [arg3] "{edx}" (arg3), + [arg4] "{esi}" (arg4), + [arg5] "{edi}" (arg5), + [arg6] "{ebp}" (arg6)) +} + +pub nakedcc fn restore() { + asm volatile ( + \\popl %%eax + \\movl $119, %%eax + \\int $0x80 + : + : + : "rcx", "r11") +} + +pub nakedcc fn restore_rt() { + asm volatile ("int $0x80" + : + : [number] "{eax}" (usize(SYS_rt_sigreturn)) + : "rcx", "r11") +} + +export struct msghdr { + msg_name: &u8, + msg_namelen: socklen_t, + msg_iov: &iovec, + msg_iovlen: i32, + msg_control: &u8, + msg_controllen: socklen_t, + msg_flags: i32, +} diff --git a/std/os/freebsd_x86_64.zig b/std/os/freebsd_x86_64.zig new file mode 100644 index 0000000000..ec3b93be14 --- /dev/null +++ b/std/os/freebsd_x86_64.zig @@ -0,0 +1,637 @@ +const freebsd = @import("freebsd.zig"); +const socklen_t = freebsd.socklen_t; +const iovec = freebsd.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_wait4 = 7; +// 8 is old creat +pub const SYS_link = 9; +pub const SYS_unlink = 10; +// 11 is obsolete execv +pub const SYS_chdir = 12; +pub const SYS_fchdir = 13; +pub const SYS_freebsd11_mknod = 14; +pub const SYS_chmod = 15; +pub const SYS_chown = 16; +pub const SYS_break = 17; +// 18 is freebsd4 getfsstat +// 19 is old lseek +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_kill = 37; +// 38 is old stat +pub const SYS_getppid = 39; +// 40 is old lstat +pub const SYS_dup = 41; +pub const SYS_freebsd10_pipe = 42; +pub const SYS_getegid = 43; +pub const SYS_profil = 44; +pub const SYS_ktrace = 45; +// 46 is old sigaction +pub const SYS_getgid = 47; +// 48 is old sigprocmask +pub const SYS_getlogin = 49; +pub const SYS_setlogin = 50; +pub const SYS_acct = 51; +// 52 is old sigpending +pub const SYS_sigaltstack = 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; +// 62 is old fstat +// 63 is old getkerninfo +// 64 is old getpagesize +pub const SYS_msync = 65; +pub const SYS_vfork = 66; +// 67 is obsolete vread +// 68 is obsolete vwrite +pub const SYS_sbrk = 69; +pub const SYS_sstk = 70; +// 71 is old mmap +pub const SYS_vadvise = 72; +pub const SYS_munmap = 73; +pub const SYS_mprotect = 74; +pub const SYS_madvise = 75; +// 76 is obsolete vhangup +// 77 is obsolete vlimit +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_setitimer = 83; +// 84 is old wait +pub const SYS_swapon = 85; +pub const SYS_getitimer = 86; +// 87 is old gethostname +// 88 is old sethostname +pub const SYS_getdtablesize = 89; +pub const SYS_dup2 = 90; +pub const SYS_fcntl = 92; +pub const SYS_select = 93; +pub const SYS_fsync = 95; +pub const SYS_setpriority = 96; +pub const SYS_socket = 97; +pub const SYS_connect = 98; +// 99 is old accept +pub const SYS_getpriority = 100; +// 101 is old send +// 102 is old recv +// 103 is old sigreturn +pub const SYS_bind = 104; +pub const SYS_setsockopt = 105; +pub const SYS_listen = 106; +// 107 is obsolete vtimes +// 108 is old sigvec +// 109 is old sigblock +// 110 is old sigsetmask +// 111 is old sigsuspend +// 112 is old sigstack +// 113 is old recvmsg +// 114 is old sendmsg +// 115 is obsolete vtrace +pub const SYS_gettimeofday = 116; +pub const SYS_getrusage = 117; +pub const SYS_getsockopt = 118; +pub const SYS_readv = 120; +pub const SYS_writev = 121; +pub const SYS_settimeofday = 122; +pub const SYS_fchown = 123; +pub const SYS_fchmod = 124; +// 125 is old recvfrom +pub const SYS_setreuid = 126; +pub const SYS_setregid = 127; +pub const SYS_rename = 128; +// 129 is old truncate +// 130 is old ftruncate +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_utimes = 138; +// 139 is obsolete 4.2 sigreturn +pub const SYS_adjtime = 140; +// 141 is old getpeername +// 142 is old gethostid +// 143 is old sethostid +// 144 is old getrlimit +// 145 is old setrlimit +// 146 is old killpg +pub const SYS_setsid = 147; +pub const SYS_quotactl = 148; +// 149 is old quota +// 150 is old getsockname +pub const SYS_nlm_syscall = 154; +pub const SYS_nfssvc = 155; +// 156 is old getdirentries +// 157 is freebsd4 statfs +// 158 is freebsd4 fstatfs +pub const SYS_lgetfh = 160; +pub const SYS_getfh = 161; +// 162 is freebsd4 getdomainname +// 163 is freebsd4 setdomainname +// 164 is freebsd4 uname +pub const SYS_sysarch = 165; +pub const SYS_rtprio = 166; +pub const SYS_semsys = 169; +pub const SYS_msgsys = 170; +pub const SYS_shmsys = 171; +// 173 is freebsd6 pread +// 174 is freebsd6 pwrite +pub const SYS_setfib = 175; +pub const SYS_ntp_adjtime = 176; +pub const SYS_setgid = 181; +pub const SYS_setegid = 182; +pub const SYS_seteuid = 183; +pub const SYS_freebsd11_stat = 188; +pub const SYS_freebsd11_fstat = 189; +pub const SYS_freebsd11_lstat = 190; +pub const SYS_pathconf = 191; +pub const SYS_fpathconf = 192; +pub const SYS_getrlimit = 194; +pub const SYS_setrlimit = 195; +pub const SYS_freebsd11_getdirentries = 196; +// 197 is freebsd6 mmap +pub const SYS___syscall = 198; +// 199 is freebsd6 lseek +// 200 is freebsd6 truncate +// 201 is freebsd6 ftruncate +pub const SYS___sysctl = 202; +pub const SYS_mlock = 203; +pub const SYS_munlock = 204; +pub const SYS_undelete = 205; +pub const SYS_futimes = 206; +pub const SYS_getpgid = 207; +pub const SYS_poll = 209; +pub const SYS_freebsd7___semctl = 220; +pub const SYS_semget = 221; +pub const SYS_semop = 222; +pub const SYS_freebsd7_msgctl = 224; +pub const SYS_msgget = 225; +pub const SYS_msgsnd = 226; +pub const SYS_msgrcv = 227; +pub const SYS_shmat = 228; +pub const SYS_freebsd7_shmctl = 229; +pub const SYS_shmdt = 230; +pub const SYS_shmget = 231; +pub const SYS_clock_gettime = 232; +pub const SYS_clock_settime = 233; +pub const SYS_clock_getres = 234; +pub const SYS_ktimer_create = 235; +pub const SYS_ktimer_delete = 236; +pub const SYS_ktimer_settime = 237; +pub const SYS_ktimer_gettime = 238; +pub const SYS_ktimer_getoverrun = 239; +pub const SYS_nanosleep = 240; +pub const SYS_ffclock_getcounter = 241; +pub const SYS_ffclock_setestimate = 242; +pub const SYS_ffclock_getestimate = 243; +pub const SYS_clock_nanosleep = 244; +pub const SYS_clock_getcpuclockid2 = 247; +pub const SYS_ntp_gettime = 248; +pub const SYS_minherit = 250; +pub const SYS_rfork = 251; +// 252 is obsolete openbsd_poll +pub const SYS_issetugid = 253; +pub const SYS_lchown = 254; +pub const SYS_aio_read = 255; +pub const SYS_aio_write = 256; +pub const SYS_lio_listio = 257; +pub const SYS_freebsd11_getdents = 272; +pub const SYS_lchmod = 274; +pub const SYS_netbsd_lchown = 275; +pub const SYS_lutimes = 276; +pub const SYS_netbsd_msync = 277; +pub const SYS_freebsd11_nstat = 278; +pub const SYS_freebsd11_nfstat = 279; +pub const SYS_freebsd11_nlstat = 280; +pub const SYS_preadv = 289; +pub const SYS_pwritev = 290; +// 297 is freebsd4 fhstatfs +pub const SYS_fhopen = 298; +pub const SYS_freebsd11_fhstat = 299; +pub const SYS_modnext = 300; +pub const SYS_modstat = 301; +pub const SYS_modfnext = 302; +pub const SYS_modfind = 303; +pub const SYS_kldload = 304; +pub const SYS_kldunload = 305; +pub const SYS_kldfind = 306; +pub const SYS_kldnext = 307; +pub const SYS_kldstat = 308; +pub const SYS_kldfirstmod = 309; +pub const SYS_getsid = 310; +pub const SYS_setresuid = 311; +pub const SYS_setresgid = 312; +// 313 is obsolete signanosleep +pub const SYS_aio_return = 314; +pub const SYS_aio_suspend = 315; +pub const SYS_aio_cancel = 316; +pub const SYS_aio_error = 317; +// 318 is freebsd6 aio_read +// 319 is freebsd6 aio_write +// 320 is freebsd6 lio_listio +pub const SYS_yield = 321; +// 322 is obsolete thr_sleep +// 323 is obsolete thr_wakeup +pub const SYS_mlockall = 324; +pub const SYS_munlockall = 325; +pub const SYS___getcwd = 326; +pub const SYS_sched_setparam = 327; +pub const SYS_sched_getparam = 328; +pub const SYS_sched_setscheduler = 329; +pub const SYS_sched_getscheduler = 330; +pub const SYS_sched_yield = 331; +pub const SYS_sched_get_priority_max = 332; +pub const SYS_sched_get_priority_min = 333; +pub const SYS_sched_rr_get_interval = 334; +pub const SYS_utrace = 335; +// 336 is freebsd4 sendfile +pub const SYS_kldsym = 337; +pub const SYS_jail = 338; +pub const SYS_nnpfs_syscall = 339; +pub const SYS_sigprocmask = 340; +pub const SYS_sigsuspend = 341; +// 342 is freebsd4 sigaction +pub const SYS_sigpending = 343; +// 344 is freebsd4 sigreturn +pub const SYS_sigtimedwait = 345; +pub const SYS_sigwaitinfo = 346; +pub const SYS___acl_get_file = 347; +pub const SYS___acl_set_file = 348; +pub const SYS___acl_get_fd = 349; +pub const SYS___acl_set_fd = 350; +pub const SYS___acl_delete_file = 351; +pub const SYS___acl_delete_fd = 352; +pub const SYS___acl_aclcheck_file = 353; +pub const SYS___acl_aclcheck_fd = 354; +pub const SYS_extattrctl = 355; +pub const SYS_extattr_set_file = 356; +pub const SYS_extattr_get_file = 357; +pub const SYS_extattr_delete_file = 358; +pub const SYS_aio_waitcomplete = 359; +pub const SYS_getresuid = 360; +pub const SYS_getresgid = 361; +pub const SYS_kqueue = 362; +pub const SYS_freebsd11_kevent = 363; +pub const SYS_extattr_set_fd = 371; +pub const SYS_extattr_get_fd = 372; +pub const SYS_extattr_delete_fd = 373; +pub const SYS___setugid = 374; +pub const SYS_eaccess = 376; +pub const SYS_afs3_syscall = 377; +pub const SYS_nmount = 378; +pub const SYS___mac_get_proc = 384; +pub const SYS___mac_set_proc = 385; +pub const SYS___mac_get_fd = 386; +pub const SYS___mac_get_file = 387; +pub const SYS___mac_set_fd = 388; +pub const SYS___mac_set_file = 389; +pub const SYS_kenv = 390; +pub const SYS_lchflags = 391; +pub const SYS_uuidgen = 392; +pub const SYS_sendfile = 393; +pub const SYS_mac_syscall = 394; +pub const SYS_freebsd11_getfsstat = 395; +pub const SYS_freebsd11_statfs = 396; +pub const SYS_freebsd11_fstatfs = 397; +pub const SYS_freebsd11_fhstatfs = 398; +pub const SYS_ksem_close = 400; +pub const SYS_ksem_post = 401; +pub const SYS_ksem_wait = 402; +pub const SYS_ksem_trywait = 403; +pub const SYS_ksem_init = 404; +pub const SYS_ksem_open = 405; +pub const SYS_ksem_unlink = 406; +pub const SYS_ksem_getvalue = 407; +pub const SYS_ksem_destroy = 408; +pub const SYS___mac_get_pid = 409; +pub const SYS___mac_get_link = 410; +pub const SYS___mac_set_link = 411; +pub const SYS_extattr_set_link = 412; +pub const SYS_extattr_get_link = 413; +pub const SYS_extattr_delete_link = 414; +pub const SYS___mac_execve = 415; +pub const SYS_sigaction = 416; +pub const SYS_sigreturn = 417; +pub const SYS_getcontext = 421; +pub const SYS_setcontext = 422; +pub const SYS_swapcontext = 423; +pub const SYS_swapoff = 424; +pub const SYS___acl_get_link = 425; +pub const SYS___acl_set_link = 426; +pub const SYS___acl_delete_link = 427; +pub const SYS___acl_aclcheck_link = 428; +pub const SYS_sigwait = 429; +pub const SYS_thr_create = 430; +pub const SYS_thr_exit = 431; +pub const SYS_thr_self = 432; +pub const SYS_thr_kill = 433; +pub const SYS_jail_attach = 436; +pub const SYS_extattr_list_fd = 437; +pub const SYS_extattr_list_file = 438; +pub const SYS_extattr_list_link = 439; +pub const SYS_ksem_timedwait = 441; +pub const SYS_thr_suspend = 442; +pub const SYS_thr_wake = 443; +pub const SYS_kldunloadf = 444; +pub const SYS_audit = 445; +pub const SYS_auditon = 446; +pub const SYS_getauid = 447; +pub const SYS_setauid = 448; +pub const SYS_getaudit = 449; +pub const SYS_setaudit = 450; +pub const SYS_getaudit_addr = 451; +pub const SYS_setaudit_addr = 452; +pub const SYS_auditctl = 453; +pub const SYS__umtx_op = 454; +pub const SYS_thr_new = 455; +pub const SYS_sigqueue = 456; +pub const SYS_kmq_open = 457; +pub const SYS_kmq_setattr = 458; +pub const SYS_kmq_timedreceive = 459; +pub const SYS_kmq_timedsend = 460; +pub const SYS_kmq_notify = 461; +pub const SYS_kmq_unlink = 462; +pub const SYS_abort2 = 463; +pub const SYS_thr_set_name = 464; +pub const SYS_aio_fsync = 465; +pub const SYS_rtprio_thread = 466; +pub const SYS_sctp_peeloff = 471; +pub const SYS_sctp_generic_sendmsg = 472; +pub const SYS_sctp_generic_sendmsg_iov = 473; +pub const SYS_sctp_generic_recvmsg = 474; +pub const SYS_pread = 475; +pub const SYS_pwrite = 476; +pub const SYS_mmap = 477; +pub const SYS_lseek = 478; +pub const SYS_truncate = 479; +pub const SYS_ftruncate = 480; +pub const SYS_thr_kill2 = 481; +pub const SYS_shm_open = 482; +pub const SYS_shm_unlink = 483; +pub const SYS_cpuset = 484; +pub const SYS_cpuset_setid = 485; +pub const SYS_cpuset_getid = 486; +pub const SYS_cpuset_getaffinity = 487; +pub const SYS_cpuset_setaffinity = 488; +pub const SYS_faccessat = 489; +pub const SYS_fchmodat = 490; +pub const SYS_fchownat = 491; +pub const SYS_fexecve = 492; +pub const SYS_freebsd11_fstatat = 493; +pub const SYS_futimesat = 494; +pub const SYS_linkat = 495; +pub const SYS_mkdirat = 496; +pub const SYS_mkfifoat = 497; +pub const SYS_freebsd11_mknodat = 498; +pub const SYS_openat = 499; +pub const SYS_readlinkat = 500; +pub const SYS_renameat = 501; +pub const SYS_symlinkat = 502; +pub const SYS_unlinkat = 503; +pub const SYS_posix_openpt = 504; +pub const SYS_gssd_syscall = 505; +pub const SYS_jail_get = 506; +pub const SYS_jail_set = 507; +pub const SYS_jail_remove = 508; +pub const SYS_closefrom = 509; +pub const SYS___semctl = 510; +pub const SYS_msgctl = 511; +pub const SYS_shmctl = 512; +pub const SYS_lpathconf = 513; +// 514 is obsolete cap_new +pub const SYS___cap_rights_get = 515; +pub const SYS_cap_enter = 516; +pub const SYS_cap_getmode = 517; +pub const SYS_pdfork = 518; +pub const SYS_pdkill = 519; +pub const SYS_pdgetpid = 520; +pub const SYS_pselect = 522; +pub const SYS_getloginclass = 523; +pub const SYS_setloginclass = 524; +pub const SYS_rctl_get_racct = 525; +pub const SYS_rctl_get_rules = 526; +pub const SYS_rctl_get_limits = 527; +pub const SYS_rctl_add_rule = 528; +pub const SYS_rctl_remove_rule = 529; +pub const SYS_posix_fallocate = 530; +pub const SYS_posix_fadvise = 531; +pub const SYS_wait6 = 532; +pub const SYS_cap_rights_limit = 533; +pub const SYS_cap_ioctls_limit = 534; +pub const SYS_cap_ioctls_get = 535; +pub const SYS_cap_fcntls_limit = 536; +pub const SYS_cap_fcntls_get = 537; +pub const SYS_bindat = 538; +pub const SYS_connectat = 539; +pub const SYS_chflagsat = 540; +pub const SYS_accept4 = 541; +pub const SYS_pipe2 = 542; +pub const SYS_aio_mlock = 543; +pub const SYS_procctl = 544; +pub const SYS_ppoll = 545; +pub const SYS_futimens = 546; +pub const SYS_utimensat = 547; +pub const SYS_numa_getaffinity = 548; +pub const SYS_numa_setaffinity = 549; +pub const SYS_fdatasync = 550; +pub const SYS_fstat = 551; +pub const SYS_fstatat = 552; +pub const SYS_fhstat = 553; +pub const SYS_getdirentries = 554; +pub const SYS_statfs = 555; +pub const SYS_fstatfs = 556; +pub const SYS_getfsstat = 557; +pub const SYS_fhstatfs = 558; +pub const SYS_mknodat = 559; +pub const SYS_kevent = 560; +pub const SYS_MAXSYSCALL = 561; + +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o200000; +pub const O_NOFOLLOW = 0o400000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o40000; +pub const O_LARGEFILE = 0; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20200000; +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_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 5; +pub const F_SETLK = 6; +pub const F_SETLKW = 7; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +pub fn syscall0(number: usize) -> usize { + asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number) + : "rcx", "r11") +} + +pub fn syscall1(number: usize, arg1: usize) -> usize { + asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1) + : "rcx", "r11") +} + +pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { + asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2) + : "rcx", "r11") +} + +pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { + asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3) + : "rcx", "r11") +} + +pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { + asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4) + : "rcx", "r11") +} + +pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize { + asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4), + [arg5] "{r8}" (arg5) + : "rcx", "r11") +} + +pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, + arg5: usize, arg6: usize) -> usize +{ + asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4), + [arg5] "{r8}" (arg5), + [arg6] "{r9}" (arg6) + : "rcx", "r11") +} + +pub nakedcc fn restore_rt() { + asm volatile ("syscall" + : + : [number] "{rax}" (usize(SYS_rt_sigreturn)) + : "rcx", "r11") +} + + +pub const msghdr = extern struct { + msg_name: &u8, + msg_namelen: socklen_t, + msg_iov: &iovec, + msg_iovlen: i32, + __pad1: i32, + msg_control: &u8, + msg_controllen: socklen_t, + __pad2: socklen_t, + msg_flags: i32, +}; + +/// Renamed to Stat to not conflict with the stat function. +pub const Stat = extern struct { + dev: u64, + ino: u64, + nlink: usize, + + mode: u32, + uid: u32, + gid: u32, + __pad0: u32, + rdev: u64, + size: i64, + blksize: isize, + blocks: i64, + + atim: timespec, + mtim: timespec, + ctim: timespec, + __unused: [3]isize, +}; + +pub const timespec = extern struct { + tv_sec: isize, + tv_nsec: isize, +}; diff --git a/std/os/get_user_id.zig b/std/os/get_user_id.zig index 1bcf69478f..b56b0fd1fc 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.freebsd => posixGetUserInfo(name), else => @compileError("Unsupported OS"), }; } diff --git a/std/os/index.zig b/std/os/index.zig index d9e6c3c81d..f332e8212a 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -24,10 +24,12 @@ test "std.os" { pub const windows = @import("windows/index.zig"); pub const darwin = @import("darwin.zig"); pub const linux = @import("linux/index.zig"); +pub const freebsd = @import("freebsd.zig"); pub const zen = @import("zen.zig"); pub const posix = switch (builtin.os) { Os.linux => linux, Os.macosx, Os.ios => darwin, + Os.freebsd => freebsd, Os.zen => zen, else => @compileError("Unsupported OS"), }; @@ -174,7 +176,7 @@ pub fn abort() noreturn { c.abort(); } switch (builtin.os) { - Os.linux, Os.macosx, Os.ios => { + Os.linux, Os.macosx, Os.ios, Os.freebsd => { _ = posix.raise(posix.SIGABRT); _ = posix.raise(posix.SIGKILL); while (true) {} @@ -196,7 +198,7 @@ pub fn exit(status: u8) noreturn { c.exit(status); } switch (builtin.os) { - Os.linux, Os.macosx, Os.ios => { + Os.linux, Os.macosx, Os.ios, Os.freebsd => { posix.exit(status); }, Os.windows => { diff --git a/std/os/path.zig b/std/os/path.zig index 01409abb88..8096cdd0d2 100644 --- a/std/os/path.zig +++ b/std/os/path.zig @@ -1161,7 +1161,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro const pathname_w = try windows_util.cStrToPrefixedFileW(pathname); return realW(out_buffer, pathname_w); }, - Os.macosx, Os.ios => { + Os.macosx, Os.ios, Os.freebsd => { // TODO instead of calling the libc function here, port the implementation to Zig const err = posix.getErrno(posix.realpath(pathname, out_buffer)); switch (err) { @@ -1202,7 +1202,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError! const pathname_w = try windows_util.sliceToPrefixedFileW(pathname); return realW(out_buffer, &pathname_w); }, - Os.macosx, Os.ios, Os.linux => { + Os.macosx, Os.ios, Os.linux, Os.freebsd => { const pathname_c = try os.toPosixPath(pathname); return realC(out_buffer, &pathname_c); }, -- cgit v1.2.3 From 264dd2eb579e78471c639baf698f7665ea016349 Mon Sep 17 00:00:00 2001 From: Marc Tiehuis Date: Sat, 21 Oct 2017 22:24:15 +0000 Subject: Set FreeBSD ELF OS/ABI when targeting Closes #553. --- src/link.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/link.cpp b/src/link.cpp index 424b06169e..613768cec8 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -150,6 +150,10 @@ static const char *getLDMOption(const ZigTarget *t) { if (t->env_type == ZigLLVM_GNUX32) { return "elf32_x86_64"; } + // Any target elf will use the freebsd osabi if suffixed with "_fbsd". + if (t->os == OsFreeBSD) { + return "elf_x86_64_fbsd"; + } return "elf_x86_64"; default: zig_unreachable(); -- cgit v1.2.3 From 102cb61e401ba2266938882d8a7d751a31a49ab2 Mon Sep 17 00:00:00 2001 From: Marc Tiehuis Date: Mon, 9 Jul 2018 20:54:36 +1200 Subject: Get freebsd std compiling again --- std/os/freebsd.zig | 535 ++++++++++++++++------------------------------ std/os/freebsd_errno.zig | 200 ++++++++--------- std/os/freebsd_x86_64.zig | 143 +++++++------ std/os/index.zig | 2 +- 4 files changed, 366 insertions(+), 514 deletions(-) diff --git a/std/os/freebsd.zig b/std/os/freebsd.zig index 7fd233aef7..ee7e93d653 100644 --- a/std/os/freebsd.zig +++ b/std/os/freebsd.zig @@ -1,11 +1,11 @@ +const c = @import("../c/index.zig"); const assert = @import("../debug.zig").assert; const builtin = @import("builtin"); const arch = switch (builtin.arch) { - builtin.Arch.x86_64 => @import("freebsd_x86_64.zig"), - builtin.Arch.i386 => @import("freebsd_i386.zig"), + builtin.Arch.x86_64 => @import("x86_64.zig"), else => @compileError("unsupported arch"), }; -pub use @import("freebsd_errno.zig"); +pub use @import("errno.zig"); pub const PATH_MAX = 1024; @@ -13,85 +13,86 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; - -pub const MAP_FAILED = @maxValue(usize); -pub const MAP_SHARED = 0x0001; -pub const MAP_PRIVATE = 0x0002; -pub const MAP_FIXED = 0x0010; -pub const MAP_STACK = 0x0400; -pub const MAP_NOSYNC = 0x0800; -pub const MAP_ANON = 0x1000; -pub const MAP_ANONYMOUS = MAP_ANON; -pub const MAP_FILE = 0; - -pub const MAP_GUARD = 0x00002000; -pub const MAP_EXCL = 0x00004000; -pub const MAP_NOCORE = 0x00020000; +pub const PROT_NONE = 0; +pub const PROT_READ = 1; +pub const PROT_WRITE = 2; +pub const PROT_EXEC = 4; + +pub const MAP_FAILED = @maxValue(usize); +pub const MAP_SHARED = 0x0001; +pub const MAP_PRIVATE = 0x0002; +pub const MAP_FIXED = 0x0010; +pub const MAP_STACK = 0x0400; +pub const MAP_NOSYNC = 0x0800; +pub const MAP_ANON = 0x1000; +pub const MAP_ANONYMOUS = MAP_ANON; +pub const MAP_FILE = 0; +pub const MAP_NORESERVE = 0; + +pub const MAP_GUARD = 0x00002000; +pub const MAP_EXCL = 0x00004000; +pub const MAP_NOCORE = 0x00020000; pub const MAP_PREFAULT_READ = 0x00040000; -pub const MAP_32BIT = 0x00080000; +pub const MAP_32BIT = 0x00080000; -pub const WNOHANG = 1; -pub const WUNTRACED = 2; -pub const WSTOPPED = WUNTRACED; +pub const WNOHANG = 1; +pub const WUNTRACED = 2; +pub const WSTOPPED = WUNTRACED; pub const WCONTINUED = 4; -pub const WNOWAIT = 8; -pub const WEXITED = 16; -pub const WTRAPPED = 32; +pub const WNOWAIT = 8; +pub const WEXITED = 16; +pub const WTRAPPED = 32; -pub const SA_ONSTACK = 0x0001; -pub const SA_RESTART = 0x0002; +pub const SA_ONSTACK = 0x0001; +pub const SA_RESTART = 0x0002; pub const SA_RESETHAND = 0x0004; pub const SA_NOCLDSTOP = 0x0008; -pub const SA_NODEFER = 0x0010; +pub const SA_NODEFER = 0x0010; pub const SA_NOCLDWAIT = 0x0020; -pub const SA_SIGINFO = 0x0040; - -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 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 SA_SIGINFO = 0x0040; + +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 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; -pub const SIGTHR = 32; -pub const SIGLWP = SIGTHR; -pub const SIGLIBRT = 33; - -pub const SIGRTMIN = 65; -pub const SIGRTMAX = 126; +pub const SIGPROF = 27; +pub const SIGWINCH = 28; +pub const SIGINFO = 29; +pub const SIGUSR1 = 30; +pub const SIGUSR2 = 31; +pub const SIGTHR = 32; +pub const SIGLWP = SIGTHR; +pub const SIGLIBRT = 33; + +pub const SIGRTMIN = 65; +pub const SIGRTMAX = 126; pub const O_RDONLY = 0o0; pub const O_WRONLY = 0o1; -pub const O_RDWR = 0o2; +pub const O_RDWR = 0o2; pub const O_ACCMODE = 0o3; pub const O_CREAT = arch.O_CREAT; @@ -119,7 +120,7 @@ pub const SEEK_SET = 0; pub const SEEK_CUR = 1; pub const SEEK_END = 2; -pub const SIG_BLOCK = 1; +pub const SIG_BLOCK = 1; pub const SIG_UNBLOCK = 2; pub const SIG_SETMASK = 3; @@ -272,7 +273,6 @@ pub const DT_LNK = 10; pub const DT_SOCK = 12; pub const DT_WHT = 14; - pub const TCGETS = 0x5401; pub const TCSETS = 0x5402; pub const TCSETSW = 0x5403; @@ -329,15 +329,30 @@ pub const TIOCGPKT = 0x80045438; pub const TIOCGPTLCK = 0x80045439; pub const TIOCGEXCL = 0x80045440; -fn unsigned(s: i32) -> u32 { @bitCast(u32, s) } -fn signed(s: u32) -> i32 { @bitCast(i32, s) } -pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) } -pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) } -pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) } -pub fn WIFEXITED(s: i32) -> bool { WTERMSIG(s) == 0 } -pub fn WIFSTOPPED(s: i32) -> bool { (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00 } -pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff } - +fn unsigned(s: i32) u32 { + return @bitCast(u32, s); +} +fn signed(s: u32) i32 { + return @bitCast(i32, s); +} +pub fn WEXITSTATUS(s: i32) i32 { + return signed((unsigned(s) & 0xff00) >> 8); +} +pub fn WTERMSIG(s: i32) i32 { + return signed(unsigned(s) & 0x7f); +} +pub fn WSTOPSIG(s: i32) i32 { + return WEXITSTATUS(s); +} +pub fn WIFEXITED(s: i32) bool { + return WTERMSIG(s) == 0; +} +pub fn WIFSTOPPED(s: i32) bool { + return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; +} +pub fn WIFSIGNALED(s: i32) bool { + return (unsigned(s) & 0xffff) -% 1 < 0xff; +} pub const winsize = extern struct { ws_row: u16, @@ -347,182 +362,160 @@ pub const winsize = extern struct { }; /// Get the errno from a syscall return value, or 0 for no error. -pub fn getErrno(r: usize) -> usize { +pub fn getErrno(r: usize) usize { const signed_r = @bitCast(isize, r); - if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0 + return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; } -pub fn dup2(old: i32, new: i32) -> usize { - arch.syscall2(arch.SYS_dup2, usize(old), usize(new)) +pub fn dup2(old: i32, new: i32) usize { + return arch.syscall2(arch.SYS_dup2, usize(old), usize(new)); } -pub fn chdir(path: &const u8) -> usize { - arch.syscall1(arch.SYS_chdir, @ptrToInt(path)) +pub fn chdir(path: [*]const u8) usize { + return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); } -pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize { - arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)) +pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { + return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); } -pub fn fork() -> usize { - arch.syscall0(arch.SYS_fork) +pub fn fork() usize { + return arch.syscall0(arch.SYS_fork); } -pub fn getcwd(buf: &u8, size: usize) -> usize { - arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size) +pub fn getcwd(buf: [*]u8, size: usize) usize { + return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size); } -pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize { - arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count) +pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { + return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count); } -pub fn isatty(fd: i32) -> bool { +pub fn isatty(fd: i32) bool { var wsz: winsize = undefined; - return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; + return arch.syscall3(arch.SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; } -pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize { - arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len) +pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { + return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); } -pub fn mkdir(path: &const u8, mode: u32) -> usize { - arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode) +pub fn mkdir(path: [*]const u8, mode: u32) usize { + return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); } -pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) - -> usize -{ - arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), - @bitCast(usize, offset)) +pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { + return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset)); } -pub fn munmap(address: &u8, length: usize) -> usize { - arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length) +pub fn munmap(address: usize, length: usize) usize { + return arch.syscall2(arch.SYS_munmap, address, length); } -pub fn read(fd: i32, buf: &u8, count: usize) -> usize { - arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count) +pub fn read(fd: i32, buf: [*]u8, count: usize) usize { + return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count); } -pub fn rmdir(path: &const u8) -> usize { - arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)) +pub fn rmdir(path: [*]const u8) usize { + return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); } -pub fn symlink(existing: &const u8, new: &const u8) -> usize { - arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)) +pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { + return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); } -pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize { - arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset) +pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { + return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); } -pub fn pipe(fd: &[2]i32) -> usize { - pipe2(fd, 0) +pub fn pipe(fd: *[2]i32) usize { + return pipe2(fd, 0); } -pub fn pipe2(fd: &[2]i32, flags: usize) -> usize { - arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags) +pub fn pipe2(fd: *[2]i32, flags: usize) usize { + return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); } -pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { - arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count) +pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { + return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count); } -pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize { - arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset) +pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { + return arch.syscall4(arch.SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset); } -pub fn rename(old: &const u8, new: &const u8) -> usize { - arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)) +pub fn rename(old: [*]const u8, new: [*]const u8) usize { + return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); } -pub fn open(path: &const u8, flags: u32, perm: usize) -> usize { - arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm) +pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { + return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); } -pub fn create(path: &const u8, perm: usize) -> usize { - arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm) +pub fn create(path: [*]const u8, perm: usize) usize { + return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); } -pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize { - arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode) +pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { + return arch.syscall4(arch.SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode); } -pub fn close(fd: i32) -> usize { - arch.syscall1(arch.SYS_close, usize(fd)) +pub fn close(fd: i32) usize { + return arch.syscall1(arch.SYS_close, @intCast(usize, fd)); } -pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize { - arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos) +pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { + return arch.syscall3(arch.SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos); } -pub fn exit(status: i32) -> noreturn { +pub fn exit(status: i32) noreturn { _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); - unreachable + unreachable; } -pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize { - arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags)) +pub fn getrandom(buf: &u8, count: usize, flags: u32) usize { + return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @bitCast(usize, flags)); } -pub fn kill(pid: i32, sig: i32) -> usize { - arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig)) +pub fn kill(pid: i32, sig: i32) usize { + return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig)); } -pub fn unlink(path: &const u8) -> usize { - arch.syscall1(arch.SYS_unlink, @ptrToInt(path)) +pub fn unlink(path: [*]const u8) usize { + return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); } -pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize { - arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0) +pub fn waitpid(pid: i32, status: *i32, options: i32) usize { + return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); } -pub fn nanosleep(req: &const timespec, rem: ?×pec) -> usize { - arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)) +pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { + return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); } -pub fn setuid(uid: u32) -> usize { - arch.syscall1(arch.SYS_setuid, uid) +pub fn setuid(uid: u32) usize { + return arch.syscall1(arch.SYS_setuid, uid); } -pub fn setgid(gid: u32) -> usize { - arch.syscall1(arch.SYS_setgid, gid) +pub fn setgid(gid: u32) usize { + return arch.syscall1(arch.SYS_setgid, gid); } -pub fn setreuid(ruid: u32, euid: u32) -> usize { - arch.syscall2(arch.SYS_setreuid, ruid, euid) +pub fn setreuid(ruid: u32, euid: u32) usize { + return arch.syscall2(arch.SYS_setreuid, ruid, euid); } -pub fn setregid(rgid: u32, egid: u32) -> usize { - arch.syscall2(arch.SYS_setregid, rgid, egid) +pub fn setregid(rgid: u32, egid: u32) usize { + return arch.syscall2(arch.SYS_setregid, rgid, egid); } -pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize { - arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8) +pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize { + // TODO: Implement + return 0; } -pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize { - assert(sig >= 1); - assert(sig != SIGKILL); - assert(sig != SIGSTOP); - var ksa = k_sigaction { - .handler = act.handler, - .flags = act.flags | SA_RESTORER, - .mask = undefined, - .restorer = @ptrCast(extern fn(), arch.restore_rt), - }; - var ksa_old: k_sigaction = undefined; - @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8); - const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask))); - const err = getErrno(result); - if (err != 0) { - return result; - } - if (oact) |old| { - old.handler = ksa_old.handler; - old.flags = @truncate(u32, ksa_old.flags); - @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask))); - } +pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { + // TODO: Implement return 0; } @@ -531,203 +524,49 @@ const sigset_t = [128 / @sizeOf(usize)]usize; const all_mask = []usize{@maxValue(usize)}; const app_mask = []usize{0xfffffffc7fffffff}; -const k_sigaction = extern struct { - handler: extern fn(i32), - flags: usize, - restorer: extern fn(), - mask: [2]u32, -}; - /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. pub const Sigaction = struct { - handler: extern fn(i32), + // TODO: Adjust to use freebsd struct layout + handler: extern fn (i32) void, mask: sigset_t, flags: u32, }; -pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize)); -pub const SIG_DFL = @intToPtr(extern fn(i32), 0); -pub const SIG_IGN = @intToPtr(extern fn(i32), 1); +pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize)); +pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); +pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); pub const empty_sigset = []usize{0} ** sigset_t.len; -pub fn raise(sig: i32) -> usize { +pub fn raise(sig: i32) usize { // TODO implement, see linux equivalent for what we want to try and do return 0; } -fn blockAllSignals(set: &sigset_t) { +fn blockAllSignals(set: *sigset_t) void { // TODO implement } -fn blockAppSignals(set: &sigset_t) { +fn blockAppSignals(set: *sigset_t) void { // TODO implement } -fn restoreSignals(set: &sigset_t) { +fn restoreSignals(set: *sigset_t) void { // TODO implement } -pub fn sigaddset(set: &sigset_t, sig: u6) { +pub fn sigaddset(set: *sigset_t, sig: u6) void { const s = sig - 1; (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); } -pub fn sigismember(set: &const sigset_t, sig: u6) -> bool { +pub fn sigismember(set: *const sigset_t, sig: u6) bool { const s = sig - 1; return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; } - -pub const sa_family_t = u16; -pub const socklen_t = u32; -pub const in_addr = u32; -pub const in6_addr = [16]u8; - -pub const sockaddr = extern struct { - family: sa_family_t, - port: u16, - data: [12]u8, -}; - -pub const sockaddr_in = extern struct { - family: sa_family_t, - port: u16, - addr: in_addr, - zero: [8]u8, -}; - -pub const sockaddr_in6 = extern struct { - family: sa_family_t, - port: u16, - flowinfo: u32, - addr: in6_addr, - scope_id: u32, -}; - -pub const iovec = extern struct { - iov_base: &u8, - iov_len: usize, -}; - -// -//const IF_NAMESIZE = 16; -// -//export struct ifreq { -// ifrn_name: [IF_NAMESIZE]u8, -// union { -// ifru_addr: sockaddr, -// ifru_dstaddr: sockaddr, -// ifru_broadaddr: sockaddr, -// ifru_netmask: sockaddr, -// ifru_hwaddr: sockaddr, -// ifru_flags: i16, -// ifru_ivalue: i32, -// ifru_mtu: i32, -// ifru_map: ifmap, -// ifru_slave: [IF_NAMESIZE]u8, -// ifru_newname: [IF_NAMESIZE]u8, -// ifru_data: &u8, -// } ifr_ifru; -//} -// - -pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { - arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len)) -} - -pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { - arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len)) -} - -pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize { - arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol)) -} - -pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize { - arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen)) -} - -pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize { - arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen)) -} - -pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize { - arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags) -} - -pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { - arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len)) -} - -pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize { - arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags) -} - -pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, - noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize -{ - arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)) -} - -pub fn shutdown(fd: i32, how: i32) -> usize { - arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)) -} - -pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { - arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len)) -} - -pub fn listen(fd: i32, backlog: i32) -> usize { - arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)) -} - -pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize { - arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen)) -} - -pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize { - arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0])) -} - -pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { - accept4(fd, addr, len, 0) -} - -pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize { - arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags) -} - -// error NameTooLong; -// error SystemResources; -// error Io; -// -// pub fn if_nametoindex(name: []u8) -> %u32 { -// var ifr: ifreq = undefined; -// -// if (name.len >= ifr.ifr_name.len) { -// return error.NameTooLong; -// } -// -// const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); -// const socket_err = getErrno(socket_ret); -// if (socket_err > 0) { -// return error.SystemResources; -// } -// const socket_fd = i32(socket_ret); -// @memcpy(&ifr.ifr_name[0], &name[0], name.len); -// ifr.ifr_name[name.len] = 0; -// const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr); -// close(socket_fd); -// const ioctl_err = getErrno(ioctl_ret); -// if (ioctl_err > 0) { -// return error.Io; -// } -// return ifr.ifr_ifindex; -// } - pub const Stat = arch.Stat; pub const timespec = arch.timespec; -pub fn fstat(fd: i32, stat_buf: &Stat) -> usize { - arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)) +pub fn fstat(fd: i32, stat_buf: *Stat) usize { + return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); } diff --git a/std/os/freebsd_errno.zig b/std/os/freebsd_errno.zig index 132683de1d..0a0d825f5a 100644 --- a/std/os/freebsd_errno.zig +++ b/std/os/freebsd_errno.zig @@ -1,121 +1,121 @@ -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; // Argument 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; // Resource deadlock avoided - // 11 was EAGAIN -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 filesystem -pub const EMLINK = 31; // Too many links -pub const EPIPE = 32; // Broken pipe +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; // Argument 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; // Resource deadlock avoided +// 11 was EAGAIN +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 filesystem +pub const EMLINK = 31; // Too many links +pub const EPIPE = 32; // Broken pipe // math software -pub const EDOM = 33; // Numerical argument out of domain -pub const ERANGE = 34; // Result too large +pub const EDOM = 33; // Numerical argument out of domain +pub const ERANGE = 34; // Result too large // non-blocking and interrupt i/o -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 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 // ipc/network software -- argument errors -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 ENOTSUP = EOPNOTSUPP; // 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 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 ENOTSUP = EOPNOTSUPP; // 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 // ipc/network software -- operational errors -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 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 ELOOP = 62; // Too many levels of symbolic links +pub const ENAMETOOLONG = 63; // File name too long // should be rearranged -pub const EHOSTDOWN = 64; // Host is down -pub const EHOSTUNREACH = 65; // No route to host -pub const ENOTEMPTY = 66; // Directory not empty +pub const EHOSTDOWN = 64; // Host is down +pub const EHOSTUNREACH = 65; // No route to host +pub const ENOTEMPTY = 66; // Directory not empty // quotas & mush -pub const EPROCLIM = 67; // Too many processes -pub const EUSERS = 68; // Too many users -pub const EDQUOT = 69; // Disc quota exceeded +pub const EPROCLIM = 67; // Too many processes +pub const EUSERS = 68; // Too many users +pub const EDQUOT = 69; // Disc quota exceeded // Network File System -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 prog. not avail -pub const EPROGMISMATCH = 75; // Program version wrong -pub const EPROCUNAVAIL = 76; // Bad procedure for program +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 prog. not avail +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 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 EIDRM = 82; // Identifier removed -pub const ENOMSG = 83; // No message of desired type -pub const EOVERFLOW = 84; // Value too large to be stored in data type -pub const ECANCELED = 85; // Operation canceled -pub const EILSEQ = 86; // Illegal byte sequence -pub const ENOATTR = 87; // Attribute not found +pub const EFTYPE = 79; // Inappropriate file type or format +pub const EAUTH = 80; // Authentication error +pub const ENEEDAUTH = 81; // Need authenticator +pub const EIDRM = 82; // Identifier removed +pub const ENOMSG = 83; // No message of desired type +pub const EOVERFLOW = 84; // Value too large to be stored in data type +pub const ECANCELED = 85; // Operation canceled +pub const EILSEQ = 86; // Illegal byte sequence +pub const ENOATTR = 87; // Attribute not found -pub const EDOOFUS = 88; // Programming error +pub const EDOOFUS = 88; // Programming error -pub const EBADMSG = 89; // Bad message -pub const EMULTIHOP = 90; // Multihop attempted -pub const ENOLINK = 91; // Link has been severed -pub const EPROTO = 92; // Protocol error +pub const EBADMSG = 89; // Bad message +pub const EMULTIHOP = 90; // Multihop attempted +pub const ENOLINK = 91; // Link has been severed +pub const EPROTO = 92; // Protocol error -pub const ENOTCAPABLE = 93; // Capabilities insufficient -pub const ECAPMODE = 94; // Not permitted in capability mode -pub const ENOTRECOVERABLE = 95; // State not recoverable -pub const EOWNERDEAD = 96; // Previous owner died +pub const ENOTCAPABLE = 93; // Capabilities insufficient +pub const ECAPMODE = 94; // Not permitted in capability mode +pub const ENOTRECOVERABLE = 95; // State not recoverable +pub const EOWNERDEAD = 96; // Previous owner died -pub const ELAST = 96; // Must be equal largest errno +pub const ELAST = 96; // Must be equal largest errno diff --git a/std/os/freebsd_x86_64.zig b/std/os/freebsd_x86_64.zig index ec3b93be14..09b4680329 100644 --- a/std/os/freebsd_x86_64.zig +++ b/std/os/freebsd_x86_64.zig @@ -1,4 +1,4 @@ -const freebsd = @import("freebsd.zig"); +const freebsd = @import("index.zig"); const socklen_t = freebsd.socklen_t; const iovec = freebsd.iovec; @@ -477,26 +477,26 @@ pub const SYS_mknodat = 559; pub const SYS_kevent = 560; pub const SYS_MAXSYSCALL = 561; -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; pub const O_DIRECTORY = 0o200000; -pub const O_NOFOLLOW = 0o400000; -pub const O_CLOEXEC = 0o2000000; +pub const O_NOFOLLOW = 0o400000; +pub const O_CLOEXEC = 0o2000000; -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o40000; -pub const O_LARGEFILE = 0; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o40000; +pub const O_LARGEFILE = 0; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; +pub const O_NDELAY = O_NONBLOCK; pub const F_DUPFD = 0; pub const F_GETFD = 1; @@ -518,86 +518,99 @@ pub const F_GETOWN_EX = 16; pub const F_GETOWNER_UIDS = 17; -pub fn syscall0(number: usize) -> usize { - asm volatile ("syscall" +pub fn syscall0(number: usize) usize { + return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number) - : "rcx", "r11") + : "rcx", "r11" + ); } -pub fn syscall1(number: usize, arg1: usize) -> usize { - asm volatile ("syscall" +pub fn syscall1(number: usize, arg1: usize) usize { + return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1) - : "rcx", "r11") + [arg1] "{rdi}" (arg1) + : "rcx", "r11" + ); } -pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { - asm volatile ("syscall" +pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { + return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2) - : "rcx", "r11") + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2) + : "rcx", "r11" + ); } -pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { - asm volatile ("syscall" +pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { + return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2), - [arg3] "{rdx}" (arg3) - : "rcx", "r11") + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3) + : "rcx", "r11" + ); } -pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { - asm volatile ("syscall" +pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { + return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2), - [arg3] "{rdx}" (arg3), - [arg4] "{r10}" (arg4) - : "rcx", "r11") + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4) + : "rcx", "r11" + ); } -pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize { - asm volatile ("syscall" +pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { + return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2), - [arg3] "{rdx}" (arg3), - [arg4] "{r10}" (arg4), - [arg5] "{r8}" (arg5) - : "rcx", "r11") + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4), + [arg5] "{r8}" (arg5) + : "rcx", "r11" + ); } -pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, - arg5: usize, arg6: usize) -> usize -{ - asm volatile ("syscall" +pub fn syscall6( + number: usize, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, + arg6: usize, +) usize { + return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2), - [arg3] "{rdx}" (arg3), - [arg4] "{r10}" (arg4), - [arg5] "{r8}" (arg5), - [arg6] "{r9}" (arg6) - : "rcx", "r11") + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4), + [arg5] "{r8}" (arg5), + [arg6] "{r9}" (arg6) + : "rcx", "r11" + ); } -pub nakedcc fn restore_rt() { +pub nakedcc fn restore_rt() void { asm volatile ("syscall" : : [number] "{rax}" (usize(SYS_rt_sigreturn)) - : "rcx", "r11") + : "rcx", "r11" + ); } - pub const msghdr = extern struct { msg_name: &u8, msg_namelen: socklen_t, diff --git a/std/os/index.zig b/std/os/index.zig index f332e8212a..ba3771c15e 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -24,7 +24,7 @@ test "std.os" { pub const windows = @import("windows/index.zig"); pub const darwin = @import("darwin.zig"); pub const linux = @import("linux/index.zig"); -pub const freebsd = @import("freebsd.zig"); +pub const freebsd = @import("freebsd/index.zig"); pub const zen = @import("zen.zig"); pub const posix = switch (builtin.os) { Os.linux => linux, -- cgit v1.2.3 From 19659c3bd347471d3d55597bdc1c141e9e4a1ae1 Mon Sep 17 00:00:00 2001 From: Marc Tiehuis Date: Wed, 11 Jul 2018 21:53:59 +1200 Subject: freebsd: Fix argc resolution in _start FreeBSD appears to use rdi instead of rsp as in other posix systems. According to some loose documentation, x86 passes values on the stack, so amd64 freebsd may be the only exception. --- std/os/freebsd.zig | 8 ++++---- std/special/bootstrap.zig | 15 +++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/std/os/freebsd.zig b/std/os/freebsd.zig index ee7e93d653..8a582db92f 100644 --- a/std/os/freebsd.zig +++ b/std/os/freebsd.zig @@ -348,7 +348,7 @@ pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; } pub fn WIFSTOPPED(s: i32) bool { - return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; + return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; } pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s) & 0xffff) -% 1 < 0xff; @@ -368,7 +368,7 @@ pub fn getErrno(r: usize) usize { } pub fn dup2(old: i32, new: i32) usize { - return arch.syscall2(arch.SYS_dup2, usize(old), usize(new)); + return arch.syscall2(arch.SYS_dup2, @intCast(usize, old), @intCast(usize, new)); } pub fn chdir(path: [*]const u8) usize { @@ -388,7 +388,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { } pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { - return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count); + return arch.syscall3(arch.SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); } pub fn isatty(fd: i32) bool { @@ -425,7 +425,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { } pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { - return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); + return arch.syscall4(arch.SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset); } pub fn pipe(fd: *[2]i32) usize { diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 53c646abdc..1fc80f2439 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -20,10 +20,17 @@ comptime { nakedcc fn _start() noreturn { switch (builtin.arch) { - builtin.Arch.x86_64 => { - argc_ptr = asm ("lea (%%rsp), %[argc]" - : [argc] "=r" (-> [*]usize) - ); + builtin.Arch.x86_64 => switch (builtin.os) { + builtin.Os.freebsd => { + argc_ptr = asm ("lea (%%rdi), %[argc]" + : [argc] "=r" (-> [*]usize) + ); + }, + else => { + argc_ptr = asm ("lea (%%rsp), %[argc]" + : [argc] "=r" (-> [*]usize) + ); + }, }, builtin.Arch.i386 => { argc_ptr = asm ("lea (%%esp), %[argc]" -- cgit v1.2.3 From 1829c093032764ef397a02d0d7512254f5bb4ad0 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 18:00:22 +0300 Subject: Fix os/freebsd files --- CMakeLists.txt | 3 + std/os/freebsd.zig | 572 ---------------------------------------- std/os/freebsd/errno.zig | 121 +++++++++ std/os/freebsd/index.zig | 571 ++++++++++++++++++++++++++++++++++++++++ std/os/freebsd/x86_64.zig | 651 ++++++++++++++++++++++++++++++++++++++++++++++ std/os/freebsd_errno.zig | 121 --------- std/os/freebsd_i386.zig | 614 ------------------------------------------- std/os/freebsd_x86_64.zig | 650 --------------------------------------------- 8 files changed, 1346 insertions(+), 1957 deletions(-) delete mode 100644 std/os/freebsd.zig create mode 100644 std/os/freebsd/errno.zig create mode 100644 std/os/freebsd/index.zig create mode 100644 std/os/freebsd/x86_64.zig delete mode 100644 std/os/freebsd_errno.zig delete mode 100644 std/os/freebsd_i386.zig delete mode 100644 std/os/freebsd_x86_64.zig diff --git a/CMakeLists.txt b/CMakeLists.txt index f39a05109c..8df55a7fbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -580,6 +580,9 @@ set(ZIG_STD_FILES "os/linux/vdso.zig" "os/linux/x86_64.zig" "os/linux/arm64.zig" + "os/freebsd/errno.zig" + "os/freebsd/index.zig" + "os/freebsd/x86_64.zig" "os/path.zig" "os/time.zig" "os/windows/advapi32.zig" diff --git a/std/os/freebsd.zig b/std/os/freebsd.zig deleted file mode 100644 index 8a582db92f..0000000000 --- a/std/os/freebsd.zig +++ /dev/null @@ -1,572 +0,0 @@ -const c = @import("../c/index.zig"); -const assert = @import("../debug.zig").assert; -const builtin = @import("builtin"); -const arch = 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_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; - -pub const MAP_FAILED = @maxValue(usize); -pub const MAP_SHARED = 0x0001; -pub const MAP_PRIVATE = 0x0002; -pub const MAP_FIXED = 0x0010; -pub const MAP_STACK = 0x0400; -pub const MAP_NOSYNC = 0x0800; -pub const MAP_ANON = 0x1000; -pub const MAP_ANONYMOUS = MAP_ANON; -pub const MAP_FILE = 0; -pub const MAP_NORESERVE = 0; - -pub const MAP_GUARD = 0x00002000; -pub const MAP_EXCL = 0x00004000; -pub const MAP_NOCORE = 0x00020000; -pub const MAP_PREFAULT_READ = 0x00040000; -pub const MAP_32BIT = 0x00080000; - -pub const WNOHANG = 1; -pub const WUNTRACED = 2; -pub const WSTOPPED = WUNTRACED; -pub const WCONTINUED = 4; -pub const WNOWAIT = 8; -pub const WEXITED = 16; -pub const WTRAPPED = 32; - -pub const SA_ONSTACK = 0x0001; -pub const SA_RESTART = 0x0002; -pub const SA_RESETHAND = 0x0004; -pub const SA_NOCLDSTOP = 0x0008; -pub const SA_NODEFER = 0x0010; -pub const SA_NOCLDWAIT = 0x0020; -pub const SA_SIGINFO = 0x0040; - -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 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; -pub const SIGTHR = 32; -pub const SIGLWP = SIGTHR; -pub const SIGLIBRT = 33; - -pub const SIGRTMIN = 65; -pub const SIGRTMAX = 126; - -pub const O_RDONLY = 0o0; -pub const O_WRONLY = 0o1; -pub const O_RDWR = 0o2; -pub const O_ACCMODE = 0o3; - -pub const O_CREAT = arch.O_CREAT; -pub const O_EXCL = arch.O_EXCL; -pub const O_NOCTTY = arch.O_NOCTTY; -pub const O_TRUNC = arch.O_TRUNC; -pub const O_APPEND = arch.O_APPEND; -pub const O_NONBLOCK = arch.O_NONBLOCK; -pub const O_DSYNC = arch.O_DSYNC; -pub const O_SYNC = arch.O_SYNC; -pub const O_RSYNC = arch.O_RSYNC; -pub const O_DIRECTORY = arch.O_DIRECTORY; -pub const O_NOFOLLOW = arch.O_NOFOLLOW; -pub const O_CLOEXEC = arch.O_CLOEXEC; - -pub const O_ASYNC = arch.O_ASYNC; -pub const O_DIRECT = arch.O_DIRECT; -pub const O_LARGEFILE = arch.O_LARGEFILE; -pub const O_NOATIME = arch.O_NOATIME; -pub const O_PATH = arch.O_PATH; -pub const O_TMPFILE = arch.O_TMPFILE; -pub const O_NDELAY = arch.O_NDELAY; - -pub const SEEK_SET = 0; -pub const SEEK_CUR = 1; -pub const SEEK_END = 2; - -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; - -pub const SOCK_STREAM = 1; -pub const SOCK_DGRAM = 2; -pub const SOCK_RAW = 3; -pub const SOCK_RDM = 4; -pub const SOCK_SEQPACKET = 5; - -pub const SOCK_CLOEXEC = 0x10000000; -pub const SOCK_NONBLOCK = 0x20000000; - -// TODO: From here -pub const PROTO_ip = 0o000; -pub const PROTO_icmp = 0o001; -pub const PROTO_igmp = 0o002; -pub const PROTO_ggp = 0o003; -pub const PROTO_ipencap = 0o004; -pub const PROTO_st = 0o005; -pub const PROTO_tcp = 0o006; -pub const PROTO_egp = 0o010; -pub const PROTO_pup = 0o014; -pub const PROTO_udp = 0o021; -pub const PROTO_hmp = 0o024; -pub const PROTO_xns_idp = 0o026; -pub const PROTO_rdp = 0o033; -pub const PROTO_iso_tp4 = 0o035; -pub const PROTO_xtp = 0o044; -pub const PROTO_ddp = 0o045; -pub const PROTO_idpr_cmtp = 0o046; -pub const PROTO_ipv6 = 0o051; -pub const PROTO_ipv6_route = 0o053; -pub const PROTO_ipv6_frag = 0o054; -pub const PROTO_idrp = 0o055; -pub const PROTO_rsvp = 0o056; -pub const PROTO_gre = 0o057; -pub const PROTO_esp = 0o062; -pub const PROTO_ah = 0o063; -pub const PROTO_skip = 0o071; -pub const PROTO_ipv6_icmp = 0o072; -pub const PROTO_ipv6_nonxt = 0o073; -pub const PROTO_ipv6_opts = 0o074; -pub const PROTO_rspf = 0o111; -pub const PROTO_vmtp = 0o121; -pub const PROTO_ospf = 0o131; -pub const PROTO_ipip = 0o136; -pub const PROTO_encap = 0o142; -pub const PROTO_pim = 0o147; -pub const PROTO_raw = 0o377; - -pub const PF_UNSPEC = 0; -pub const PF_LOCAL = 1; -pub const PF_UNIX = PF_LOCAL; -pub const PF_FILE = PF_LOCAL; -pub const PF_INET = 2; -pub const PF_AX25 = 3; -pub const PF_IPX = 4; -pub const PF_APPLETALK = 5; -pub const PF_NETROM = 6; -pub const PF_BRIDGE = 7; -pub const PF_ATMPVC = 8; -pub const PF_X25 = 9; -pub const PF_INET6 = 10; -pub const PF_ROSE = 11; -pub const PF_DECnet = 12; -pub const PF_NETBEUI = 13; -pub const PF_SECURITY = 14; -pub const PF_KEY = 15; -pub const PF_NETLINK = 16; -pub const PF_ROUTE = PF_NETLINK; -pub const PF_PACKET = 17; -pub const PF_ASH = 18; -pub const PF_ECONET = 19; -pub const PF_ATMSVC = 20; -pub const PF_RDS = 21; -pub const PF_SNA = 22; -pub const PF_IRDA = 23; -pub const PF_PPPOX = 24; -pub const PF_WANPIPE = 25; -pub const PF_LLC = 26; -pub const PF_IB = 27; -pub const PF_MPLS = 28; -pub const PF_CAN = 29; -pub const PF_TIPC = 30; -pub const PF_BLUETOOTH = 31; -pub const PF_IUCV = 32; -pub const PF_RXRPC = 33; -pub const PF_ISDN = 34; -pub const PF_PHONET = 35; -pub const PF_IEEE802154 = 36; -pub const PF_CAIF = 37; -pub const PF_ALG = 38; -pub const PF_NFC = 39; -pub const PF_VSOCK = 40; -pub const PF_MAX = 41; - -pub const AF_UNSPEC = PF_UNSPEC; -pub const AF_LOCAL = PF_LOCAL; -pub const AF_UNIX = AF_LOCAL; -pub const AF_FILE = AF_LOCAL; -pub const AF_INET = PF_INET; -pub const AF_AX25 = PF_AX25; -pub const AF_IPX = PF_IPX; -pub const AF_APPLETALK = PF_APPLETALK; -pub const AF_NETROM = PF_NETROM; -pub const AF_BRIDGE = PF_BRIDGE; -pub const AF_ATMPVC = PF_ATMPVC; -pub const AF_X25 = PF_X25; -pub const AF_INET6 = PF_INET6; -pub const AF_ROSE = PF_ROSE; -pub const AF_DECnet = PF_DECnet; -pub const AF_NETBEUI = PF_NETBEUI; -pub const AF_SECURITY = PF_SECURITY; -pub const AF_KEY = PF_KEY; -pub const AF_NETLINK = PF_NETLINK; -pub const AF_ROUTE = PF_ROUTE; -pub const AF_PACKET = PF_PACKET; -pub const AF_ASH = PF_ASH; -pub const AF_ECONET = PF_ECONET; -pub const AF_ATMSVC = PF_ATMSVC; -pub const AF_RDS = PF_RDS; -pub const AF_SNA = PF_SNA; -pub const AF_IRDA = PF_IRDA; -pub const AF_PPPOX = PF_PPPOX; -pub const AF_WANPIPE = PF_WANPIPE; -pub const AF_LLC = PF_LLC; -pub const AF_IB = PF_IB; -pub const AF_MPLS = PF_MPLS; -pub const AF_CAN = PF_CAN; -pub const AF_TIPC = PF_TIPC; -pub const AF_BLUETOOTH = PF_BLUETOOTH; -pub const AF_IUCV = PF_IUCV; -pub const AF_RXRPC = PF_RXRPC; -pub const AF_ISDN = PF_ISDN; -pub const AF_PHONET = PF_PHONET; -pub const AF_IEEE802154 = PF_IEEE802154; -pub const AF_CAIF = PF_CAIF; -pub const AF_ALG = PF_ALG; -pub const AF_NFC = PF_NFC; -pub const AF_VSOCK = PF_VSOCK; -pub const AF_MAX = PF_MAX; - -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 DT_WHT = 14; - -pub const TCGETS = 0x5401; -pub const TCSETS = 0x5402; -pub const TCSETSW = 0x5403; -pub const TCSETSF = 0x5404; -pub const TCGETA = 0x5405; -pub const TCSETA = 0x5406; -pub const TCSETAW = 0x5407; -pub const TCSETAF = 0x5408; -pub const TCSBRK = 0x5409; -pub const TCXONC = 0x540A; -pub const TCFLSH = 0x540B; -pub const TIOCEXCL = 0x540C; -pub const TIOCNXCL = 0x540D; -pub const TIOCSCTTY = 0x540E; -pub const TIOCGPGRP = 0x540F; -pub const TIOCSPGRP = 0x5410; -pub const TIOCOUTQ = 0x5411; -pub const TIOCSTI = 0x5412; -pub const TIOCGWINSZ = 0x5413; -pub const TIOCSWINSZ = 0x5414; -pub const TIOCMGET = 0x5415; -pub const TIOCMBIS = 0x5416; -pub const TIOCMBIC = 0x5417; -pub const TIOCMSET = 0x5418; -pub const TIOCGSOFTCAR = 0x5419; -pub const TIOCSSOFTCAR = 0x541A; -pub const FIONREAD = 0x541B; -pub const TIOCINQ = FIONREAD; -pub const TIOCLINUX = 0x541C; -pub const TIOCCONS = 0x541D; -pub const TIOCGSERIAL = 0x541E; -pub const TIOCSSERIAL = 0x541F; -pub const TIOCPKT = 0x5420; -pub const FIONBIO = 0x5421; -pub const TIOCNOTTY = 0x5422; -pub const TIOCSETD = 0x5423; -pub const TIOCGETD = 0x5424; -pub const TCSBRKP = 0x5425; -pub const TIOCSBRK = 0x5427; -pub const TIOCCBRK = 0x5428; -pub const TIOCGSID = 0x5429; -pub const TIOCGRS485 = 0x542E; -pub const TIOCSRS485 = 0x542F; -pub const TIOCGPTN = 0x80045430; -pub const TIOCSPTLCK = 0x40045431; -pub const TIOCGDEV = 0x80045432; -pub const TCGETX = 0x5432; -pub const TCSETX = 0x5433; -pub const TCSETXF = 0x5434; -pub const TCSETXW = 0x5435; -pub const TIOCSIG = 0x40045436; -pub const TIOCVHANGUP = 0x5437; -pub const TIOCGPKT = 0x80045438; -pub const TIOCGPTLCK = 0x80045439; -pub const TIOCGEXCL = 0x80045440; - -fn unsigned(s: i32) u32 { - return @bitCast(u32, s); -} -fn signed(s: u32) i32 { - return @bitCast(i32, s); -} -pub fn WEXITSTATUS(s: i32) i32 { - return signed((unsigned(s) & 0xff00) >> 8); -} -pub fn WTERMSIG(s: i32) i32 { - return signed(unsigned(s) & 0x7f); -} -pub fn WSTOPSIG(s: i32) i32 { - return WEXITSTATUS(s); -} -pub fn WIFEXITED(s: i32) bool { - return WTERMSIG(s) == 0; -} -pub fn WIFSTOPPED(s: i32) bool { - return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; -} -pub fn WIFSIGNALED(s: i32) bool { - return (unsigned(s) & 0xffff) -% 1 < 0xff; -} - -pub const winsize = extern struct { - ws_row: u16, - ws_col: u16, - ws_xpixel: u16, - ws_ypixel: u16, -}; - -/// 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) @intCast(usize, -signed_r) else 0; -} - -pub fn dup2(old: i32, new: i32) usize { - return arch.syscall2(arch.SYS_dup2, @intCast(usize, old), @intCast(usize, new)); -} - -pub fn chdir(path: [*]const u8) usize { - return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); -} - -pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { - return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); -} - -pub fn fork() usize { - return arch.syscall0(arch.SYS_fork); -} - -pub fn getcwd(buf: [*]u8, size: usize) usize { - return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size); -} - -pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { - return arch.syscall3(arch.SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); -} - -pub fn isatty(fd: i32) bool { - var wsz: winsize = undefined; - return arch.syscall3(arch.SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; -} - -pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { - return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); -} - -pub fn mkdir(path: [*]const u8, mode: u32) usize { - return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); -} - -pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { - return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset)); -} - -pub fn munmap(address: usize, length: usize) usize { - return arch.syscall2(arch.SYS_munmap, address, length); -} - -pub fn read(fd: i32, buf: [*]u8, count: usize) usize { - return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count); -} - -pub fn rmdir(path: [*]const u8) usize { - return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); -} - -pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { - return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); -} - -pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { - return arch.syscall4(arch.SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset); -} - -pub fn pipe(fd: *[2]i32) usize { - return pipe2(fd, 0); -} - -pub fn pipe2(fd: *[2]i32, flags: usize) usize { - return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); -} - -pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { - return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count); -} - -pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { - return arch.syscall4(arch.SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset); -} - -pub fn rename(old: [*]const u8, new: [*]const u8) usize { - return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); -} - -pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { - return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); -} - -pub fn create(path: [*]const u8, perm: usize) usize { - return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); -} - -pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { - return arch.syscall4(arch.SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode); -} - -pub fn close(fd: i32) usize { - return arch.syscall1(arch.SYS_close, @intCast(usize, fd)); -} - -pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { - return arch.syscall3(arch.SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos); -} - -pub fn exit(status: i32) noreturn { - _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); - unreachable; -} - -pub fn getrandom(buf: &u8, count: usize, flags: u32) usize { - return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @bitCast(usize, flags)); -} - -pub fn kill(pid: i32, sig: i32) usize { - return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig)); -} - -pub fn unlink(path: [*]const u8) usize { - return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); -} - -pub fn waitpid(pid: i32, status: *i32, options: i32) usize { - return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); -} - -pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { - return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); -} - -pub fn setuid(uid: u32) usize { - return arch.syscall1(arch.SYS_setuid, uid); -} - -pub fn setgid(gid: u32) usize { - return arch.syscall1(arch.SYS_setgid, gid); -} - -pub fn setreuid(ruid: u32, euid: u32) usize { - return arch.syscall2(arch.SYS_setreuid, ruid, euid); -} - -pub fn setregid(rgid: u32, egid: u32) usize { - return arch.syscall2(arch.SYS_setregid, rgid, egid); -} - -pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize { - // TODO: Implement - return 0; -} - -pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { - // TODO: Implement - return 0; -} - -const NSIG = 65; -const sigset_t = [128 / @sizeOf(usize)]usize; -const all_mask = []usize{@maxValue(usize)}; -const app_mask = []usize{0xfffffffc7fffffff}; - -/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. -pub const Sigaction = struct { - // TODO: Adjust to use freebsd struct layout - handler: extern fn (i32) void, - mask: sigset_t, - flags: u32, -}; - -pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize)); -pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); -pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); -pub const empty_sigset = []usize{0} ** sigset_t.len; - -pub fn raise(sig: i32) usize { - // TODO implement, see linux equivalent for what we want to try and do - return 0; -} - -fn blockAllSignals(set: *sigset_t) void { - // TODO implement -} - -fn blockAppSignals(set: *sigset_t) void { - // TODO implement -} - -fn restoreSignals(set: *sigset_t) void { - // TODO implement -} - -pub fn sigaddset(set: *sigset_t, sig: u6) void { - const s = sig - 1; - (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); -} - -pub fn sigismember(set: *const sigset_t, sig: u6) bool { - const s = sig - 1; - return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; -} - -pub const Stat = arch.Stat; -pub const timespec = arch.timespec; - -pub fn fstat(fd: i32, stat_buf: *Stat) usize { - return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); -} diff --git a/std/os/freebsd/errno.zig b/std/os/freebsd/errno.zig new file mode 100644 index 0000000000..0a0d825f5a --- /dev/null +++ b/std/os/freebsd/errno.zig @@ -0,0 +1,121 @@ +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; // Argument 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; // Resource deadlock avoided +// 11 was EAGAIN +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 filesystem +pub const EMLINK = 31; // Too many links +pub const EPIPE = 32; // Broken pipe + +// math software +pub const EDOM = 33; // Numerical argument out of domain +pub const ERANGE = 34; // Result too large + +// non-blocking and interrupt i/o +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 + +// ipc/network software -- argument errors +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 ENOTSUP = EOPNOTSUPP; // 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 + +// ipc/network software -- operational errors +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 + +// should be rearranged +pub const EHOSTDOWN = 64; // Host is down +pub const EHOSTUNREACH = 65; // No route to host +pub const ENOTEMPTY = 66; // Directory not empty + +// quotas & mush +pub const EPROCLIM = 67; // Too many processes +pub const EUSERS = 68; // Too many users +pub const EDQUOT = 69; // Disc quota exceeded + +// Network File System +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 prog. not avail +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 EIDRM = 82; // Identifier removed +pub const ENOMSG = 83; // No message of desired type +pub const EOVERFLOW = 84; // Value too large to be stored in data type +pub const ECANCELED = 85; // Operation canceled +pub const EILSEQ = 86; // Illegal byte sequence +pub const ENOATTR = 87; // Attribute not found + +pub const EDOOFUS = 88; // Programming error + +pub const EBADMSG = 89; // Bad message +pub const EMULTIHOP = 90; // Multihop attempted +pub const ENOLINK = 91; // Link has been severed +pub const EPROTO = 92; // Protocol error + +pub const ENOTCAPABLE = 93; // Capabilities insufficient +pub const ECAPMODE = 94; // Not permitted in capability mode +pub const ENOTRECOVERABLE = 95; // State not recoverable +pub const EOWNERDEAD = 96; // Previous owner died + +pub const ELAST = 96; // Must be equal largest errno diff --git a/std/os/freebsd/index.zig b/std/os/freebsd/index.zig new file mode 100644 index 0000000000..e856f6291c --- /dev/null +++ b/std/os/freebsd/index.zig @@ -0,0 +1,571 @@ +const assert = @import("../debug.zig").assert; +const builtin = @import("builtin"); +const arch = 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_NONE = 0; +pub const PROT_READ = 1; +pub const PROT_WRITE = 2; +pub const PROT_EXEC = 4; + +pub const MAP_FAILED = @maxValue(usize); +pub const MAP_SHARED = 0x0001; +pub const MAP_PRIVATE = 0x0002; +pub const MAP_FIXED = 0x0010; +pub const MAP_STACK = 0x0400; +pub const MAP_NOSYNC = 0x0800; +pub const MAP_ANON = 0x1000; +pub const MAP_ANONYMOUS = MAP_ANON; +pub const MAP_FILE = 0; +pub const MAP_NORESERVE = 0; + +pub const MAP_GUARD = 0x00002000; +pub const MAP_EXCL = 0x00004000; +pub const MAP_NOCORE = 0x00020000; +pub const MAP_PREFAULT_READ = 0x00040000; +pub const MAP_32BIT = 0x00080000; + +pub const WNOHANG = 1; +pub const WUNTRACED = 2; +pub const WSTOPPED = WUNTRACED; +pub const WCONTINUED = 4; +pub const WNOWAIT = 8; +pub const WEXITED = 16; +pub const WTRAPPED = 32; + +pub const SA_ONSTACK = 0x0001; +pub const SA_RESTART = 0x0002; +pub const SA_RESETHAND = 0x0004; +pub const SA_NOCLDSTOP = 0x0008; +pub const SA_NODEFER = 0x0010; +pub const SA_NOCLDWAIT = 0x0020; +pub const SA_SIGINFO = 0x0040; + +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 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; +pub const SIGTHR = 32; +pub const SIGLWP = SIGTHR; +pub const SIGLIBRT = 33; + +pub const SIGRTMIN = 65; +pub const SIGRTMAX = 126; + +pub const O_RDONLY = 0o0; +pub const O_WRONLY = 0o1; +pub const O_RDWR = 0o2; +pub const O_ACCMODE = 0o3; + +pub const O_CREAT = arch.O_CREAT; +pub const O_EXCL = arch.O_EXCL; +pub const O_NOCTTY = arch.O_NOCTTY; +pub const O_TRUNC = arch.O_TRUNC; +pub const O_APPEND = arch.O_APPEND; +pub const O_NONBLOCK = arch.O_NONBLOCK; +pub const O_DSYNC = arch.O_DSYNC; +pub const O_SYNC = arch.O_SYNC; +pub const O_RSYNC = arch.O_RSYNC; +pub const O_DIRECTORY = arch.O_DIRECTORY; +pub const O_NOFOLLOW = arch.O_NOFOLLOW; +pub const O_CLOEXEC = arch.O_CLOEXEC; + +pub const O_ASYNC = arch.O_ASYNC; +pub const O_DIRECT = arch.O_DIRECT; +pub const O_LARGEFILE = arch.O_LARGEFILE; +pub const O_NOATIME = arch.O_NOATIME; +pub const O_PATH = arch.O_PATH; +pub const O_TMPFILE = arch.O_TMPFILE; +pub const O_NDELAY = arch.O_NDELAY; + +pub const SEEK_SET = 0; +pub const SEEK_CUR = 1; +pub const SEEK_END = 2; + +pub const SIG_BLOCK = 1; +pub const SIG_UNBLOCK = 2; +pub const SIG_SETMASK = 3; + +pub const SOCK_STREAM = 1; +pub const SOCK_DGRAM = 2; +pub const SOCK_RAW = 3; +pub const SOCK_RDM = 4; +pub const SOCK_SEQPACKET = 5; + +pub const SOCK_CLOEXEC = 0x10000000; +pub const SOCK_NONBLOCK = 0x20000000; + +// TODO: From here +pub const PROTO_ip = 0o000; +pub const PROTO_icmp = 0o001; +pub const PROTO_igmp = 0o002; +pub const PROTO_ggp = 0o003; +pub const PROTO_ipencap = 0o004; +pub const PROTO_st = 0o005; +pub const PROTO_tcp = 0o006; +pub const PROTO_egp = 0o010; +pub const PROTO_pup = 0o014; +pub const PROTO_udp = 0o021; +pub const PROTO_hmp = 0o024; +pub const PROTO_xns_idp = 0o026; +pub const PROTO_rdp = 0o033; +pub const PROTO_iso_tp4 = 0o035; +pub const PROTO_xtp = 0o044; +pub const PROTO_ddp = 0o045; +pub const PROTO_idpr_cmtp = 0o046; +pub const PROTO_ipv6 = 0o051; +pub const PROTO_ipv6_route = 0o053; +pub const PROTO_ipv6_frag = 0o054; +pub const PROTO_idrp = 0o055; +pub const PROTO_rsvp = 0o056; +pub const PROTO_gre = 0o057; +pub const PROTO_esp = 0o062; +pub const PROTO_ah = 0o063; +pub const PROTO_skip = 0o071; +pub const PROTO_ipv6_icmp = 0o072; +pub const PROTO_ipv6_nonxt = 0o073; +pub const PROTO_ipv6_opts = 0o074; +pub const PROTO_rspf = 0o111; +pub const PROTO_vmtp = 0o121; +pub const PROTO_ospf = 0o131; +pub const PROTO_ipip = 0o136; +pub const PROTO_encap = 0o142; +pub const PROTO_pim = 0o147; +pub const PROTO_raw = 0o377; + +pub const PF_UNSPEC = 0; +pub const PF_LOCAL = 1; +pub const PF_UNIX = PF_LOCAL; +pub const PF_FILE = PF_LOCAL; +pub const PF_INET = 2; +pub const PF_AX25 = 3; +pub const PF_IPX = 4; +pub const PF_APPLETALK = 5; +pub const PF_NETROM = 6; +pub const PF_BRIDGE = 7; +pub const PF_ATMPVC = 8; +pub const PF_X25 = 9; +pub const PF_INET6 = 10; +pub const PF_ROSE = 11; +pub const PF_DECnet = 12; +pub const PF_NETBEUI = 13; +pub const PF_SECURITY = 14; +pub const PF_KEY = 15; +pub const PF_NETLINK = 16; +pub const PF_ROUTE = PF_NETLINK; +pub const PF_PACKET = 17; +pub const PF_ASH = 18; +pub const PF_ECONET = 19; +pub const PF_ATMSVC = 20; +pub const PF_RDS = 21; +pub const PF_SNA = 22; +pub const PF_IRDA = 23; +pub const PF_PPPOX = 24; +pub const PF_WANPIPE = 25; +pub const PF_LLC = 26; +pub const PF_IB = 27; +pub const PF_MPLS = 28; +pub const PF_CAN = 29; +pub const PF_TIPC = 30; +pub const PF_BLUETOOTH = 31; +pub const PF_IUCV = 32; +pub const PF_RXRPC = 33; +pub const PF_ISDN = 34; +pub const PF_PHONET = 35; +pub const PF_IEEE802154 = 36; +pub const PF_CAIF = 37; +pub const PF_ALG = 38; +pub const PF_NFC = 39; +pub const PF_VSOCK = 40; +pub const PF_MAX = 41; + +pub const AF_UNSPEC = PF_UNSPEC; +pub const AF_LOCAL = PF_LOCAL; +pub const AF_UNIX = AF_LOCAL; +pub const AF_FILE = AF_LOCAL; +pub const AF_INET = PF_INET; +pub const AF_AX25 = PF_AX25; +pub const AF_IPX = PF_IPX; +pub const AF_APPLETALK = PF_APPLETALK; +pub const AF_NETROM = PF_NETROM; +pub const AF_BRIDGE = PF_BRIDGE; +pub const AF_ATMPVC = PF_ATMPVC; +pub const AF_X25 = PF_X25; +pub const AF_INET6 = PF_INET6; +pub const AF_ROSE = PF_ROSE; +pub const AF_DECnet = PF_DECnet; +pub const AF_NETBEUI = PF_NETBEUI; +pub const AF_SECURITY = PF_SECURITY; +pub const AF_KEY = PF_KEY; +pub const AF_NETLINK = PF_NETLINK; +pub const AF_ROUTE = PF_ROUTE; +pub const AF_PACKET = PF_PACKET; +pub const AF_ASH = PF_ASH; +pub const AF_ECONET = PF_ECONET; +pub const AF_ATMSVC = PF_ATMSVC; +pub const AF_RDS = PF_RDS; +pub const AF_SNA = PF_SNA; +pub const AF_IRDA = PF_IRDA; +pub const AF_PPPOX = PF_PPPOX; +pub const AF_WANPIPE = PF_WANPIPE; +pub const AF_LLC = PF_LLC; +pub const AF_IB = PF_IB; +pub const AF_MPLS = PF_MPLS; +pub const AF_CAN = PF_CAN; +pub const AF_TIPC = PF_TIPC; +pub const AF_BLUETOOTH = PF_BLUETOOTH; +pub const AF_IUCV = PF_IUCV; +pub const AF_RXRPC = PF_RXRPC; +pub const AF_ISDN = PF_ISDN; +pub const AF_PHONET = PF_PHONET; +pub const AF_IEEE802154 = PF_IEEE802154; +pub const AF_CAIF = PF_CAIF; +pub const AF_ALG = PF_ALG; +pub const AF_NFC = PF_NFC; +pub const AF_VSOCK = PF_VSOCK; +pub const AF_MAX = PF_MAX; + +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 DT_WHT = 14; + +pub const TCGETS = 0x5401; +pub const TCSETS = 0x5402; +pub const TCSETSW = 0x5403; +pub const TCSETSF = 0x5404; +pub const TCGETA = 0x5405; +pub const TCSETA = 0x5406; +pub const TCSETAW = 0x5407; +pub const TCSETAF = 0x5408; +pub const TCSBRK = 0x5409; +pub const TCXONC = 0x540A; +pub const TCFLSH = 0x540B; +pub const TIOCEXCL = 0x540C; +pub const TIOCNXCL = 0x540D; +pub const TIOCSCTTY = 0x540E; +pub const TIOCGPGRP = 0x540F; +pub const TIOCSPGRP = 0x5410; +pub const TIOCOUTQ = 0x5411; +pub const TIOCSTI = 0x5412; +pub const TIOCGWINSZ = 0x5413; +pub const TIOCSWINSZ = 0x5414; +pub const TIOCMGET = 0x5415; +pub const TIOCMBIS = 0x5416; +pub const TIOCMBIC = 0x5417; +pub const TIOCMSET = 0x5418; +pub const TIOCGSOFTCAR = 0x5419; +pub const TIOCSSOFTCAR = 0x541A; +pub const FIONREAD = 0x541B; +pub const TIOCINQ = FIONREAD; +pub const TIOCLINUX = 0x541C; +pub const TIOCCONS = 0x541D; +pub const TIOCGSERIAL = 0x541E; +pub const TIOCSSERIAL = 0x541F; +pub const TIOCPKT = 0x5420; +pub const FIONBIO = 0x5421; +pub const TIOCNOTTY = 0x5422; +pub const TIOCSETD = 0x5423; +pub const TIOCGETD = 0x5424; +pub const TCSBRKP = 0x5425; +pub const TIOCSBRK = 0x5427; +pub const TIOCCBRK = 0x5428; +pub const TIOCGSID = 0x5429; +pub const TIOCGRS485 = 0x542E; +pub const TIOCSRS485 = 0x542F; +pub const TIOCGPTN = 0x80045430; +pub const TIOCSPTLCK = 0x40045431; +pub const TIOCGDEV = 0x80045432; +pub const TCGETX = 0x5432; +pub const TCSETX = 0x5433; +pub const TCSETXF = 0x5434; +pub const TCSETXW = 0x5435; +pub const TIOCSIG = 0x40045436; +pub const TIOCVHANGUP = 0x5437; +pub const TIOCGPKT = 0x80045438; +pub const TIOCGPTLCK = 0x80045439; +pub const TIOCGEXCL = 0x80045440; + +fn unsigned(s: i32) u32 { + return @bitCast(u32, s); +} +fn signed(s: u32) i32 { + return @bitCast(i32, s); +} +pub fn WEXITSTATUS(s: i32) i32 { + return signed((unsigned(s) & 0xff00) >> 8); +} +pub fn WTERMSIG(s: i32) i32 { + return signed(unsigned(s) & 0x7f); +} +pub fn WSTOPSIG(s: i32) i32 { + return WEXITSTATUS(s); +} +pub fn WIFEXITED(s: i32) bool { + return WTERMSIG(s) == 0; +} +pub fn WIFSTOPPED(s: i32) bool { + return @intCast(u16, (((unsigned(s) & 0xffff) *% 0x10001) >> 8)) > 0x7f00; +} +pub fn WIFSIGNALED(s: i32) bool { + return (unsigned(s) & 0xffff) -% 1 < 0xff; +} + +pub const winsize = extern struct.{ + ws_row: u16, + ws_col: u16, + ws_xpixel: u16, + ws_ypixel: u16, +}; + +/// 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) @intCast(usize, -signed_r) else 0; +} + +pub fn dup2(old: i32, new: i32) usize { + return arch.syscall2(arch.SYS_dup2, @intCast(usize, old), @intCast(usize, new)); +} + +pub fn chdir(path: [*]const u8) usize { + return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); +} + +pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { + return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); +} + +pub fn fork() usize { + return arch.syscall0(arch.SYS_fork); +} + +pub fn getcwd(buf: [*]u8, size: usize) usize { + return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size); +} + +pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { + return arch.syscall3(arch.SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); +} + +pub fn isatty(fd: i32) bool { + var wsz: winsize = undefined; + return arch.syscall3(arch.SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; +} + +pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { + return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); +} + +pub fn mkdir(path: [*]const u8, mode: u32) usize { + return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); +} + +pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { + return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset)); +} + +pub fn munmap(address: usize, length: usize) usize { + return arch.syscall2(arch.SYS_munmap, address, length); +} + +pub fn read(fd: i32, buf: [*]u8, count: usize) usize { + return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count); +} + +pub fn rmdir(path: [*]const u8) usize { + return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); +} + +pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { + return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); +} + +pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { + return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); +} + +pub fn pipe(fd: *[2]i32) usize { + return pipe2(fd, 0); +} + +pub fn pipe2(fd: *[2]i32, flags: usize) usize { + return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); +} + +pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { + return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count); +} + +pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { + return arch.syscall4(arch.SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset); +} + +pub fn rename(old: [*]const u8, new: [*]const u8) usize { + return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); +} + +pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { + return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); +} + +pub fn create(path: [*]const u8, perm: usize) usize { + return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); +} + +pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { + return arch.syscall4(arch.SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode); +} + +pub fn close(fd: i32) usize { + return arch.syscall1(arch.SYS_close, @intCast(usize, fd)); +} + +pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { + return arch.syscall3(arch.SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos); +} + +pub fn exit(status: i32) noreturn { + _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); + unreachable; +} + +pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { + return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags)); +} + +pub fn kill(pid: i32, sig: i32) usize { + return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig)); +} + +pub fn unlink(path: [*]const u8) usize { + return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); +} + +pub fn waitpid(pid: i32, status: *i32, options: i32) usize { + return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); +} + +pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { + return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); +} + +pub fn setuid(uid: u32) usize { + return arch.syscall1(arch.SYS_setuid, uid); +} + +pub fn setgid(gid: u32) usize { + return arch.syscall1(arch.SYS_setgid, gid); +} + +pub fn setreuid(ruid: u32, euid: u32) usize { + return arch.syscall2(arch.SYS_setreuid, ruid, euid); +} + +pub fn setregid(rgid: u32, egid: u32) usize { + return arch.syscall2(arch.SYS_setregid, rgid, egid); +} + +pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize { + // TODO: Implement + return 0; +} + +pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { + // TODO: Implement + return 0; +} + +const NSIG = 65; +const sigset_t = [128 / @sizeOf(usize)]usize; +const all_mask = []usize.{@maxValue(usize)}; +const app_mask = []usize.{0xfffffffc7fffffff}; + +/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. +pub const Sigaction = struct.{ + // TODO: Adjust to use freebsd struct layout + handler: extern fn (i32) void, + mask: sigset_t, + flags: u32, +}; + +pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize)); +pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); +pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); +pub const empty_sigset = []usize.{0} ** sigset_t.len; + +pub fn raise(sig: i32) usize { + // TODO implement, see linux equivalent for what we want to try and do + return 0; +} + +fn blockAllSignals(set: *sigset_t) void { + // TODO implement +} + +fn blockAppSignals(set: *sigset_t) void { + // TODO implement +} + +fn restoreSignals(set: *sigset_t) void { + // TODO implement +} + +pub fn sigaddset(set: *sigset_t, sig: u6) void { + const s = sig - 1; + (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); +} + +pub fn sigismember(set: *const sigset_t, sig: u6) bool { + const s = sig - 1; + return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; +} + +pub const Stat = arch.Stat; +pub const timespec = arch.timespec; + +pub fn fstat(fd: i32, stat_buf: *Stat) usize { + return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); +} diff --git a/std/os/freebsd/x86_64.zig b/std/os/freebsd/x86_64.zig new file mode 100644 index 0000000000..cd9104b88a --- /dev/null +++ b/std/os/freebsd/x86_64.zig @@ -0,0 +1,651 @@ +const freebsd = @import("index.zig"); +const socklen_t = freebsd.socklen_t; +const iovec = freebsd.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_wait4 = 7; +// 8 is old creat +pub const SYS_link = 9; +pub const SYS_unlink = 10; +// 11 is obsolete execv +pub const SYS_chdir = 12; +pub const SYS_fchdir = 13; +pub const SYS_freebsd11_mknod = 14; +pub const SYS_chmod = 15; +pub const SYS_chown = 16; +pub const SYS_break = 17; +// 18 is freebsd4 getfsstat +// 19 is old lseek +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_kill = 37; +// 38 is old stat +pub const SYS_getppid = 39; +// 40 is old lstat +pub const SYS_dup = 41; +pub const SYS_freebsd10_pipe = 42; +pub const SYS_getegid = 43; +pub const SYS_profil = 44; +pub const SYS_ktrace = 45; +// 46 is old sigaction +pub const SYS_getgid = 47; +// 48 is old sigprocmask +pub const SYS_getlogin = 49; +pub const SYS_setlogin = 50; +pub const SYS_acct = 51; +// 52 is old sigpending +pub const SYS_sigaltstack = 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; +// 62 is old fstat +// 63 is old getkerninfo +// 64 is old getpagesize +pub const SYS_msync = 65; +pub const SYS_vfork = 66; +// 67 is obsolete vread +// 68 is obsolete vwrite +pub const SYS_sbrk = 69; +pub const SYS_sstk = 70; +// 71 is old mmap +pub const SYS_vadvise = 72; +pub const SYS_munmap = 73; +pub const SYS_mprotect = 74; +pub const SYS_madvise = 75; +// 76 is obsolete vhangup +// 77 is obsolete vlimit +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_setitimer = 83; +// 84 is old wait +pub const SYS_swapon = 85; +pub const SYS_getitimer = 86; +// 87 is old gethostname +// 88 is old sethostname +pub const SYS_getdtablesize = 89; +pub const SYS_dup2 = 90; +pub const SYS_fcntl = 92; +pub const SYS_select = 93; +pub const SYS_fsync = 95; +pub const SYS_setpriority = 96; +pub const SYS_socket = 97; +pub const SYS_connect = 98; +// 99 is old accept +pub const SYS_getpriority = 100; +// 101 is old send +// 102 is old recv +// 103 is old sigreturn +pub const SYS_bind = 104; +pub const SYS_setsockopt = 105; +pub const SYS_listen = 106; +// 107 is obsolete vtimes +// 108 is old sigvec +// 109 is old sigblock +// 110 is old sigsetmask +// 111 is old sigsuspend +// 112 is old sigstack +// 113 is old recvmsg +// 114 is old sendmsg +// 115 is obsolete vtrace +pub const SYS_gettimeofday = 116; +pub const SYS_getrusage = 117; +pub const SYS_getsockopt = 118; +pub const SYS_readv = 120; +pub const SYS_writev = 121; +pub const SYS_settimeofday = 122; +pub const SYS_fchown = 123; +pub const SYS_fchmod = 124; +// 125 is old recvfrom +pub const SYS_setreuid = 126; +pub const SYS_setregid = 127; +pub const SYS_rename = 128; +// 129 is old truncate +// 130 is old ftruncate +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_utimes = 138; +// 139 is obsolete 4.2 sigreturn +pub const SYS_adjtime = 140; +// 141 is old getpeername +// 142 is old gethostid +// 143 is old sethostid +// 144 is old getrlimit +// 145 is old setrlimit +// 146 is old killpg +pub const SYS_setsid = 147; +pub const SYS_quotactl = 148; +// 149 is old quota +// 150 is old getsockname +pub const SYS_nlm_syscall = 154; +pub const SYS_nfssvc = 155; +// 156 is old getdirentries +// 157 is freebsd4 statfs +// 158 is freebsd4 fstatfs +pub const SYS_lgetfh = 160; +pub const SYS_getfh = 161; +// 162 is freebsd4 getdomainname +// 163 is freebsd4 setdomainname +// 164 is freebsd4 uname +pub const SYS_sysarch = 165; +pub const SYS_rtprio = 166; +pub const SYS_semsys = 169; +pub const SYS_msgsys = 170; +pub const SYS_shmsys = 171; +// 173 is freebsd6 pread +// 174 is freebsd6 pwrite +pub const SYS_setfib = 175; +pub const SYS_ntp_adjtime = 176; +pub const SYS_setgid = 181; +pub const SYS_setegid = 182; +pub const SYS_seteuid = 183; +pub const SYS_freebsd11_stat = 188; +pub const SYS_freebsd11_fstat = 189; +pub const SYS_freebsd11_lstat = 190; +pub const SYS_pathconf = 191; +pub const SYS_fpathconf = 192; +pub const SYS_getrlimit = 194; +pub const SYS_setrlimit = 195; +pub const SYS_freebsd11_getdirentries = 196; +// 197 is freebsd6 mmap +pub const SYS___syscall = 198; +// 199 is freebsd6 lseek +// 200 is freebsd6 truncate +// 201 is freebsd6 ftruncate +pub const SYS___sysctl = 202; +pub const SYS_mlock = 203; +pub const SYS_munlock = 204; +pub const SYS_undelete = 205; +pub const SYS_futimes = 206; +pub const SYS_getpgid = 207; +pub const SYS_poll = 209; +pub const SYS_freebsd7___semctl = 220; +pub const SYS_semget = 221; +pub const SYS_semop = 222; +pub const SYS_freebsd7_msgctl = 224; +pub const SYS_msgget = 225; +pub const SYS_msgsnd = 226; +pub const SYS_msgrcv = 227; +pub const SYS_shmat = 228; +pub const SYS_freebsd7_shmctl = 229; +pub const SYS_shmdt = 230; +pub const SYS_shmget = 231; +pub const SYS_clock_gettime = 232; +pub const SYS_clock_settime = 233; +pub const SYS_clock_getres = 234; +pub const SYS_ktimer_create = 235; +pub const SYS_ktimer_delete = 236; +pub const SYS_ktimer_settime = 237; +pub const SYS_ktimer_gettime = 238; +pub const SYS_ktimer_getoverrun = 239; +pub const SYS_nanosleep = 240; +pub const SYS_ffclock_getcounter = 241; +pub const SYS_ffclock_setestimate = 242; +pub const SYS_ffclock_getestimate = 243; +pub const SYS_clock_nanosleep = 244; +pub const SYS_clock_getcpuclockid2 = 247; +pub const SYS_ntp_gettime = 248; +pub const SYS_minherit = 250; +pub const SYS_rfork = 251; +// 252 is obsolete openbsd_poll +pub const SYS_issetugid = 253; +pub const SYS_lchown = 254; +pub const SYS_aio_read = 255; +pub const SYS_aio_write = 256; +pub const SYS_lio_listio = 257; +pub const SYS_freebsd11_getdents = 272; +pub const SYS_lchmod = 274; +pub const SYS_netbsd_lchown = 275; +pub const SYS_lutimes = 276; +pub const SYS_netbsd_msync = 277; +pub const SYS_freebsd11_nstat = 278; +pub const SYS_freebsd11_nfstat = 279; +pub const SYS_freebsd11_nlstat = 280; +pub const SYS_preadv = 289; +pub const SYS_pwritev = 290; +// 297 is freebsd4 fhstatfs +pub const SYS_fhopen = 298; +pub const SYS_freebsd11_fhstat = 299; +pub const SYS_modnext = 300; +pub const SYS_modstat = 301; +pub const SYS_modfnext = 302; +pub const SYS_modfind = 303; +pub const SYS_kldload = 304; +pub const SYS_kldunload = 305; +pub const SYS_kldfind = 306; +pub const SYS_kldnext = 307; +pub const SYS_kldstat = 308; +pub const SYS_kldfirstmod = 309; +pub const SYS_getsid = 310; +pub const SYS_setresuid = 311; +pub const SYS_setresgid = 312; +// 313 is obsolete signanosleep +pub const SYS_aio_return = 314; +pub const SYS_aio_suspend = 315; +pub const SYS_aio_cancel = 316; +pub const SYS_aio_error = 317; +// 318 is freebsd6 aio_read +// 319 is freebsd6 aio_write +// 320 is freebsd6 lio_listio +pub const SYS_yield = 321; +// 322 is obsolete thr_sleep +// 323 is obsolete thr_wakeup +pub const SYS_mlockall = 324; +pub const SYS_munlockall = 325; +pub const SYS___getcwd = 326; +pub const SYS_sched_setparam = 327; +pub const SYS_sched_getparam = 328; +pub const SYS_sched_setscheduler = 329; +pub const SYS_sched_getscheduler = 330; +pub const SYS_sched_yield = 331; +pub const SYS_sched_get_priority_max = 332; +pub const SYS_sched_get_priority_min = 333; +pub const SYS_sched_rr_get_interval = 334; +pub const SYS_utrace = 335; +// 336 is freebsd4 sendfile +pub const SYS_kldsym = 337; +pub const SYS_jail = 338; +pub const SYS_nnpfs_syscall = 339; +pub const SYS_sigprocmask = 340; +pub const SYS_sigsuspend = 341; +// 342 is freebsd4 sigaction +pub const SYS_sigpending = 343; +// 344 is freebsd4 sigreturn +pub const SYS_sigtimedwait = 345; +pub const SYS_sigwaitinfo = 346; +pub const SYS___acl_get_file = 347; +pub const SYS___acl_set_file = 348; +pub const SYS___acl_get_fd = 349; +pub const SYS___acl_set_fd = 350; +pub const SYS___acl_delete_file = 351; +pub const SYS___acl_delete_fd = 352; +pub const SYS___acl_aclcheck_file = 353; +pub const SYS___acl_aclcheck_fd = 354; +pub const SYS_extattrctl = 355; +pub const SYS_extattr_set_file = 356; +pub const SYS_extattr_get_file = 357; +pub const SYS_extattr_delete_file = 358; +pub const SYS_aio_waitcomplete = 359; +pub const SYS_getresuid = 360; +pub const SYS_getresgid = 361; +pub const SYS_kqueue = 362; +pub const SYS_freebsd11_kevent = 363; +pub const SYS_extattr_set_fd = 371; +pub const SYS_extattr_get_fd = 372; +pub const SYS_extattr_delete_fd = 373; +pub const SYS___setugid = 374; +pub const SYS_eaccess = 376; +pub const SYS_afs3_syscall = 377; +pub const SYS_nmount = 378; +pub const SYS___mac_get_proc = 384; +pub const SYS___mac_set_proc = 385; +pub const SYS___mac_get_fd = 386; +pub const SYS___mac_get_file = 387; +pub const SYS___mac_set_fd = 388; +pub const SYS___mac_set_file = 389; +pub const SYS_kenv = 390; +pub const SYS_lchflags = 391; +pub const SYS_uuidgen = 392; +pub const SYS_sendfile = 393; +pub const SYS_mac_syscall = 394; +pub const SYS_freebsd11_getfsstat = 395; +pub const SYS_freebsd11_statfs = 396; +pub const SYS_freebsd11_fstatfs = 397; +pub const SYS_freebsd11_fhstatfs = 398; +pub const SYS_ksem_close = 400; +pub const SYS_ksem_post = 401; +pub const SYS_ksem_wait = 402; +pub const SYS_ksem_trywait = 403; +pub const SYS_ksem_init = 404; +pub const SYS_ksem_open = 405; +pub const SYS_ksem_unlink = 406; +pub const SYS_ksem_getvalue = 407; +pub const SYS_ksem_destroy = 408; +pub const SYS___mac_get_pid = 409; +pub const SYS___mac_get_link = 410; +pub const SYS___mac_set_link = 411; +pub const SYS_extattr_set_link = 412; +pub const SYS_extattr_get_link = 413; +pub const SYS_extattr_delete_link = 414; +pub const SYS___mac_execve = 415; +pub const SYS_sigaction = 416; +pub const SYS_sigreturn = 417; +pub const SYS_getcontext = 421; +pub const SYS_setcontext = 422; +pub const SYS_swapcontext = 423; +pub const SYS_swapoff = 424; +pub const SYS___acl_get_link = 425; +pub const SYS___acl_set_link = 426; +pub const SYS___acl_delete_link = 427; +pub const SYS___acl_aclcheck_link = 428; +pub const SYS_sigwait = 429; +pub const SYS_thr_create = 430; +pub const SYS_thr_exit = 431; +pub const SYS_thr_self = 432; +pub const SYS_thr_kill = 433; +pub const SYS_jail_attach = 436; +pub const SYS_extattr_list_fd = 437; +pub const SYS_extattr_list_file = 438; +pub const SYS_extattr_list_link = 439; +pub const SYS_ksem_timedwait = 441; +pub const SYS_thr_suspend = 442; +pub const SYS_thr_wake = 443; +pub const SYS_kldunloadf = 444; +pub const SYS_audit = 445; +pub const SYS_auditon = 446; +pub const SYS_getauid = 447; +pub const SYS_setauid = 448; +pub const SYS_getaudit = 449; +pub const SYS_setaudit = 450; +pub const SYS_getaudit_addr = 451; +pub const SYS_setaudit_addr = 452; +pub const SYS_auditctl = 453; +pub const SYS__umtx_op = 454; +pub const SYS_thr_new = 455; +pub const SYS_sigqueue = 456; +pub const SYS_kmq_open = 457; +pub const SYS_kmq_setattr = 458; +pub const SYS_kmq_timedreceive = 459; +pub const SYS_kmq_timedsend = 460; +pub const SYS_kmq_notify = 461; +pub const SYS_kmq_unlink = 462; +pub const SYS_abort2 = 463; +pub const SYS_thr_set_name = 464; +pub const SYS_aio_fsync = 465; +pub const SYS_rtprio_thread = 466; +pub const SYS_sctp_peeloff = 471; +pub const SYS_sctp_generic_sendmsg = 472; +pub const SYS_sctp_generic_sendmsg_iov = 473; +pub const SYS_sctp_generic_recvmsg = 474; +pub const SYS_pread = 475; +pub const SYS_pwrite = 476; +pub const SYS_mmap = 477; +pub const SYS_lseek = 478; +pub const SYS_truncate = 479; +pub const SYS_ftruncate = 480; +pub const SYS_thr_kill2 = 481; +pub const SYS_shm_open = 482; +pub const SYS_shm_unlink = 483; +pub const SYS_cpuset = 484; +pub const SYS_cpuset_setid = 485; +pub const SYS_cpuset_getid = 486; +pub const SYS_cpuset_getaffinity = 487; +pub const SYS_cpuset_setaffinity = 488; +pub const SYS_faccessat = 489; +pub const SYS_fchmodat = 490; +pub const SYS_fchownat = 491; +pub const SYS_fexecve = 492; +pub const SYS_freebsd11_fstatat = 493; +pub const SYS_futimesat = 494; +pub const SYS_linkat = 495; +pub const SYS_mkdirat = 496; +pub const SYS_mkfifoat = 497; +pub const SYS_freebsd11_mknodat = 498; +pub const SYS_openat = 499; +pub const SYS_readlinkat = 500; +pub const SYS_renameat = 501; +pub const SYS_symlinkat = 502; +pub const SYS_unlinkat = 503; +pub const SYS_posix_openpt = 504; +pub const SYS_gssd_syscall = 505; +pub const SYS_jail_get = 506; +pub const SYS_jail_set = 507; +pub const SYS_jail_remove = 508; +pub const SYS_closefrom = 509; +pub const SYS___semctl = 510; +pub const SYS_msgctl = 511; +pub const SYS_shmctl = 512; +pub const SYS_lpathconf = 513; +// 514 is obsolete cap_new +pub const SYS___cap_rights_get = 515; +pub const SYS_cap_enter = 516; +pub const SYS_cap_getmode = 517; +pub const SYS_pdfork = 518; +pub const SYS_pdkill = 519; +pub const SYS_pdgetpid = 520; +pub const SYS_pselect = 522; +pub const SYS_getloginclass = 523; +pub const SYS_setloginclass = 524; +pub const SYS_rctl_get_racct = 525; +pub const SYS_rctl_get_rules = 526; +pub const SYS_rctl_get_limits = 527; +pub const SYS_rctl_add_rule = 528; +pub const SYS_rctl_remove_rule = 529; +pub const SYS_posix_fallocate = 530; +pub const SYS_posix_fadvise = 531; +pub const SYS_wait6 = 532; +pub const SYS_cap_rights_limit = 533; +pub const SYS_cap_ioctls_limit = 534; +pub const SYS_cap_ioctls_get = 535; +pub const SYS_cap_fcntls_limit = 536; +pub const SYS_cap_fcntls_get = 537; +pub const SYS_bindat = 538; +pub const SYS_connectat = 539; +pub const SYS_chflagsat = 540; +pub const SYS_accept4 = 541; +pub const SYS_pipe2 = 542; +pub const SYS_aio_mlock = 543; +pub const SYS_procctl = 544; +pub const SYS_ppoll = 545; +pub const SYS_futimens = 546; +pub const SYS_utimensat = 547; +pub const SYS_numa_getaffinity = 548; +pub const SYS_numa_setaffinity = 549; +pub const SYS_fdatasync = 550; +pub const SYS_fstat = 551; +pub const SYS_fstatat = 552; +pub const SYS_fhstat = 553; +pub const SYS_getdirentries = 554; +pub const SYS_statfs = 555; +pub const SYS_fstatfs = 556; +pub const SYS_getfsstat = 557; +pub const SYS_fhstatfs = 558; +pub const SYS_mknodat = 559; +pub const SYS_kevent = 560; +pub const SYS_MAXSYSCALL = 561; +pub const SYS_getrandom = 563; + +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o200000; +pub const O_NOFOLLOW = 0o400000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o40000; +pub const O_LARGEFILE = 0; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20200000; +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_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 5; +pub const F_SETLK = 6; +pub const F_SETLKW = 7; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +pub fn syscall0(number: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number) + : "rcx", "r11" + ); +} + +pub fn syscall1(number: usize, arg1: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1) + : "rcx", "r11" + ); +} + +pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2) + : "rcx", "r11" + ); +} + +pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3) + : "rcx", "r11" + ); +} + +pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4) + : "rcx", "r11" + ); +} + +pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4), + [arg5] "{r8}" (arg5) + : "rcx", "r11" + ); +} + +pub fn syscall6( + number: usize, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, + arg6: usize, +) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4), + [arg5] "{r8}" (arg5), + [arg6] "{r9}" (arg6) + : "rcx", "r11" + ); +} + +pub nakedcc fn restore_rt() void { + asm volatile ("syscall" + : + : [number] "{rax}" (usize(SYS_rt_sigreturn)) + : "rcx", "r11" + ); +} + +pub const msghdr = extern struct.{ + msg_name: &u8, + msg_namelen: socklen_t, + msg_iov: &iovec, + msg_iovlen: i32, + __pad1: i32, + msg_control: &u8, + msg_controllen: socklen_t, + __pad2: socklen_t, + msg_flags: i32, +}; + +/// Renamed to Stat to not conflict with the stat function. +pub const Stat = extern struct.{ + dev: u64, + ino: u64, + nlink: usize, + + mode: u32, + uid: u32, + gid: u32, + __pad0: u32, + rdev: u64, + size: i64, + blksize: isize, + blocks: i64, + + atim: timespec, + mtim: timespec, + ctim: timespec, + __unused: [3]isize, +}; + +pub const timespec = extern struct.{ + tv_sec: isize, + tv_nsec: isize, +}; diff --git a/std/os/freebsd_errno.zig b/std/os/freebsd_errno.zig deleted file mode 100644 index 0a0d825f5a..0000000000 --- a/std/os/freebsd_errno.zig +++ /dev/null @@ -1,121 +0,0 @@ -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; // Argument 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; // Resource deadlock avoided -// 11 was EAGAIN -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 filesystem -pub const EMLINK = 31; // Too many links -pub const EPIPE = 32; // Broken pipe - -// math software -pub const EDOM = 33; // Numerical argument out of domain -pub const ERANGE = 34; // Result too large - -// non-blocking and interrupt i/o -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 - -// ipc/network software -- argument errors -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 ENOTSUP = EOPNOTSUPP; // 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 - -// ipc/network software -- operational errors -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 - -// should be rearranged -pub const EHOSTDOWN = 64; // Host is down -pub const EHOSTUNREACH = 65; // No route to host -pub const ENOTEMPTY = 66; // Directory not empty - -// quotas & mush -pub const EPROCLIM = 67; // Too many processes -pub const EUSERS = 68; // Too many users -pub const EDQUOT = 69; // Disc quota exceeded - -// Network File System -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 prog. not avail -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 EIDRM = 82; // Identifier removed -pub const ENOMSG = 83; // No message of desired type -pub const EOVERFLOW = 84; // Value too large to be stored in data type -pub const ECANCELED = 85; // Operation canceled -pub const EILSEQ = 86; // Illegal byte sequence -pub const ENOATTR = 87; // Attribute not found - -pub const EDOOFUS = 88; // Programming error - -pub const EBADMSG = 89; // Bad message -pub const EMULTIHOP = 90; // Multihop attempted -pub const ENOLINK = 91; // Link has been severed -pub const EPROTO = 92; // Protocol error - -pub const ENOTCAPABLE = 93; // Capabilities insufficient -pub const ECAPMODE = 94; // Not permitted in capability mode -pub const ENOTRECOVERABLE = 95; // State not recoverable -pub const EOWNERDEAD = 96; // Previous owner died - -pub const ELAST = 96; // Must be equal largest errno diff --git a/std/os/freebsd_i386.zig b/std/os/freebsd_i386.zig deleted file mode 100644 index fd1f58639b..0000000000 --- a/std/os/freebsd_i386.zig +++ /dev/null @@ -1,614 +0,0 @@ -const freebsd = @import("freebsd.zig"); -const socklen_t = freebsd.socklen_t; -const iovec = freebsd.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_wait4 = 7; -// 8 is old creat -pub const SYS_link = 9; -pub const SYS_unlink = 10; -// 11 is obsolete execv -pub const SYS_chdir = 12; -pub const SYS_fchdir = 13; -pub const SYS_freebsd11_mknod = 14; -pub const SYS_chmod = 15; -pub const SYS_chown = 16; -pub const SYS_break = 17; -// 18 is freebsd4 getfsstat -// 19 is old lseek -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_kill = 37; -// 38 is old stat -pub const SYS_getppid = 39; -// 40 is old lstat -pub const SYS_dup = 41; -pub const SYS_freebsd10_pipe = 42; -pub const SYS_getegid = 43; -pub const SYS_profil = 44; -pub const SYS_ktrace = 45; -// 46 is old sigaction -pub const SYS_getgid = 47; -// 48 is old sigprocmask -pub const SYS_getlogin = 49; -pub const SYS_setlogin = 50; -pub const SYS_acct = 51; -// 52 is old sigpending -pub const SYS_sigaltstack = 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; -// 62 is old fstat -// 63 is old getkerninfo -// 64 is old getpagesize -pub const SYS_msync = 65; -pub const SYS_vfork = 66; -// 67 is obsolete vread -// 68 is obsolete vwrite -pub const SYS_sbrk = 69; -pub const SYS_sstk = 70; -// 71 is old mmap -pub const SYS_vadvise = 72; -pub const SYS_munmap = 73; -pub const SYS_mprotect = 74; -pub const SYS_madvise = 75; -// 76 is obsolete vhangup -// 77 is obsolete vlimit -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_setitimer = 83; -// 84 is old wait -pub const SYS_swapon = 85; -pub const SYS_getitimer = 86; -// 87 is old gethostname -// 88 is old sethostname -pub const SYS_getdtablesize = 89; -pub const SYS_dup2 = 90; -pub const SYS_fcntl = 92; -pub const SYS_select = 93; -pub const SYS_fsync = 95; -pub const SYS_setpriority = 96; -pub const SYS_socket = 97; -pub const SYS_connect = 98; -// 99 is old accept -pub const SYS_getpriority = 100; -// 101 is old send -// 102 is old recv -// 103 is old sigreturn -pub const SYS_bind = 104; -pub const SYS_setsockopt = 105; -pub const SYS_listen = 106; -// 107 is obsolete vtimes -// 108 is old sigvec -// 109 is old sigblock -// 110 is old sigsetmask -// 111 is old sigsuspend -// 112 is old sigstack -// 113 is old recvmsg -// 114 is old sendmsg -// 115 is obsolete vtrace -pub const SYS_gettimeofday = 116; -pub const SYS_getrusage = 117; -pub const SYS_getsockopt = 118; -pub const SYS_readv = 120; -pub const SYS_writev = 121; -pub const SYS_settimeofday = 122; -pub const SYS_fchown = 123; -pub const SYS_fchmod = 124; -// 125 is old recvfrom -pub const SYS_setreuid = 126; -pub const SYS_setregid = 127; -pub const SYS_rename = 128; -// 129 is old truncate -// 130 is old ftruncate -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_utimes = 138; -// 139 is obsolete 4.2 sigreturn -pub const SYS_adjtime = 140; -// 141 is old getpeername -// 142 is old gethostid -// 143 is old sethostid -// 144 is old getrlimit -// 145 is old setrlimit -// 146 is old killpg -pub const SYS_setsid = 147; -pub const SYS_quotactl = 148; -// 149 is old quota -// 150 is old getsockname -pub const SYS_nlm_syscall = 154; -pub const SYS_nfssvc = 155; -// 156 is old getdirentries -// 157 is freebsd4 statfs -// 158 is freebsd4 fstatfs -pub const SYS_lgetfh = 160; -pub const SYS_getfh = 161; -// 162 is freebsd4 getdomainname -// 163 is freebsd4 setdomainname -// 164 is freebsd4 uname -pub const SYS_sysarch = 165; -pub const SYS_rtprio = 166; -pub const SYS_semsys = 169; -pub const SYS_msgsys = 170; -pub const SYS_shmsys = 171; -// 173 is freebsd6 pread -// 174 is freebsd6 pwrite -pub const SYS_setfib = 175; -pub const SYS_ntp_adjtime = 176; -pub const SYS_setgid = 181; -pub const SYS_setegid = 182; -pub const SYS_seteuid = 183; -pub const SYS_freebsd11_stat = 188; -pub const SYS_freebsd11_fstat = 189; -pub const SYS_freebsd11_lstat = 190; -pub const SYS_pathconf = 191; -pub const SYS_fpathconf = 192; -pub const SYS_getrlimit = 194; -pub const SYS_setrlimit = 195; -pub const SYS_freebsd11_getdirentries = 196; -// 197 is freebsd6 mmap -pub const SYS___syscall = 198; -// 199 is freebsd6 lseek -// 200 is freebsd6 truncate -// 201 is freebsd6 ftruncate -pub const SYS___sysctl = 202; -pub const SYS_mlock = 203; -pub const SYS_munlock = 204; -pub const SYS_undelete = 205; -pub const SYS_futimes = 206; -pub const SYS_getpgid = 207; -pub const SYS_poll = 209; -pub const SYS_freebsd7___semctl = 220; -pub const SYS_semget = 221; -pub const SYS_semop = 222; -pub const SYS_freebsd7_msgctl = 224; -pub const SYS_msgget = 225; -pub const SYS_msgsnd = 226; -pub const SYS_msgrcv = 227; -pub const SYS_shmat = 228; -pub const SYS_freebsd7_shmctl = 229; -pub const SYS_shmdt = 230; -pub const SYS_shmget = 231; -pub const SYS_clock_gettime = 232; -pub const SYS_clock_settime = 233; -pub const SYS_clock_getres = 234; -pub const SYS_ktimer_create = 235; -pub const SYS_ktimer_delete = 236; -pub const SYS_ktimer_settime = 237; -pub const SYS_ktimer_gettime = 238; -pub const SYS_ktimer_getoverrun = 239; -pub const SYS_nanosleep = 240; -pub const SYS_ffclock_getcounter = 241; -pub const SYS_ffclock_setestimate = 242; -pub const SYS_ffclock_getestimate = 243; -pub const SYS_clock_nanosleep = 244; -pub const SYS_clock_getcpuclockid2 = 247; -pub const SYS_ntp_gettime = 248; -pub const SYS_minherit = 250; -pub const SYS_rfork = 251; -// 252 is obsolete openbsd_poll -pub const SYS_issetugid = 253; -pub const SYS_lchown = 254; -pub const SYS_aio_read = 255; -pub const SYS_aio_write = 256; -pub const SYS_lio_listio = 257; -pub const SYS_freebsd11_getdents = 272; -pub const SYS_lchmod = 274; -pub const SYS_netbsd_lchown = 275; -pub const SYS_lutimes = 276; -pub const SYS_netbsd_msync = 277; -pub const SYS_freebsd11_nstat = 278; -pub const SYS_freebsd11_nfstat = 279; -pub const SYS_freebsd11_nlstat = 280; -pub const SYS_preadv = 289; -pub const SYS_pwritev = 290; -// 297 is freebsd4 fhstatfs -pub const SYS_fhopen = 298; -pub const SYS_freebsd11_fhstat = 299; -pub const SYS_modnext = 300; -pub const SYS_modstat = 301; -pub const SYS_modfnext = 302; -pub const SYS_modfind = 303; -pub const SYS_kldload = 304; -pub const SYS_kldunload = 305; -pub const SYS_kldfind = 306; -pub const SYS_kldnext = 307; -pub const SYS_kldstat = 308; -pub const SYS_kldfirstmod = 309; -pub const SYS_getsid = 310; -pub const SYS_setresuid = 311; -pub const SYS_setresgid = 312; -// 313 is obsolete signanosleep -pub const SYS_aio_return = 314; -pub const SYS_aio_suspend = 315; -pub const SYS_aio_cancel = 316; -pub const SYS_aio_error = 317; -// 318 is freebsd6 aio_read -// 319 is freebsd6 aio_write -// 320 is freebsd6 lio_listio -pub const SYS_yield = 321; -// 322 is obsolete thr_sleep -// 323 is obsolete thr_wakeup -pub const SYS_mlockall = 324; -pub const SYS_munlockall = 325; -pub const SYS___getcwd = 326; -pub const SYS_sched_setparam = 327; -pub const SYS_sched_getparam = 328; -pub const SYS_sched_setscheduler = 329; -pub const SYS_sched_getscheduler = 330; -pub const SYS_sched_yield = 331; -pub const SYS_sched_get_priority_max = 332; -pub const SYS_sched_get_priority_min = 333; -pub const SYS_sched_rr_get_interval = 334; -pub const SYS_utrace = 335; -// 336 is freebsd4 sendfile -pub const SYS_kldsym = 337; -pub const SYS_jail = 338; -pub const SYS_nnpfs_syscall = 339; -pub const SYS_sigprocmask = 340; -pub const SYS_sigsuspend = 341; -// 342 is freebsd4 sigaction -pub const SYS_sigpending = 343; -// 344 is freebsd4 sigreturn -pub const SYS_sigtimedwait = 345; -pub const SYS_sigwaitinfo = 346; -pub const SYS___acl_get_file = 347; -pub const SYS___acl_set_file = 348; -pub const SYS___acl_get_fd = 349; -pub const SYS___acl_set_fd = 350; -pub const SYS___acl_delete_file = 351; -pub const SYS___acl_delete_fd = 352; -pub const SYS___acl_aclcheck_file = 353; -pub const SYS___acl_aclcheck_fd = 354; -pub const SYS_extattrctl = 355; -pub const SYS_extattr_set_file = 356; -pub const SYS_extattr_get_file = 357; -pub const SYS_extattr_delete_file = 358; -pub const SYS_aio_waitcomplete = 359; -pub const SYS_getresuid = 360; -pub const SYS_getresgid = 361; -pub const SYS_kqueue = 362; -pub const SYS_freebsd11_kevent = 363; -pub const SYS_extattr_set_fd = 371; -pub const SYS_extattr_get_fd = 372; -pub const SYS_extattr_delete_fd = 373; -pub const SYS___setugid = 374; -pub const SYS_eaccess = 376; -pub const SYS_afs3_syscall = 377; -pub const SYS_nmount = 378; -pub const SYS___mac_get_proc = 384; -pub const SYS___mac_set_proc = 385; -pub const SYS___mac_get_fd = 386; -pub const SYS___mac_get_file = 387; -pub const SYS___mac_set_fd = 388; -pub const SYS___mac_set_file = 389; -pub const SYS_kenv = 390; -pub const SYS_lchflags = 391; -pub const SYS_uuidgen = 392; -pub const SYS_sendfile = 393; -pub const SYS_mac_syscall = 394; -pub const SYS_freebsd11_getfsstat = 395; -pub const SYS_freebsd11_statfs = 396; -pub const SYS_freebsd11_fstatfs = 397; -pub const SYS_freebsd11_fhstatfs = 398; -pub const SYS_ksem_close = 400; -pub const SYS_ksem_post = 401; -pub const SYS_ksem_wait = 402; -pub const SYS_ksem_trywait = 403; -pub const SYS_ksem_init = 404; -pub const SYS_ksem_open = 405; -pub const SYS_ksem_unlink = 406; -pub const SYS_ksem_getvalue = 407; -pub const SYS_ksem_destroy = 408; -pub const SYS___mac_get_pid = 409; -pub const SYS___mac_get_link = 410; -pub const SYS___mac_set_link = 411; -pub const SYS_extattr_set_link = 412; -pub const SYS_extattr_get_link = 413; -pub const SYS_extattr_delete_link = 414; -pub const SYS___mac_execve = 415; -pub const SYS_sigaction = 416; -pub const SYS_sigreturn = 417; -pub const SYS_getcontext = 421; -pub const SYS_setcontext = 422; -pub const SYS_swapcontext = 423; -pub const SYS_swapoff = 424; -pub const SYS___acl_get_link = 425; -pub const SYS___acl_set_link = 426; -pub const SYS___acl_delete_link = 427; -pub const SYS___acl_aclcheck_link = 428; -pub const SYS_sigwait = 429; -pub const SYS_thr_create = 430; -pub const SYS_thr_exit = 431; -pub const SYS_thr_self = 432; -pub const SYS_thr_kill = 433; -pub const SYS_jail_attach = 436; -pub const SYS_extattr_list_fd = 437; -pub const SYS_extattr_list_file = 438; -pub const SYS_extattr_list_link = 439; -pub const SYS_ksem_timedwait = 441; -pub const SYS_thr_suspend = 442; -pub const SYS_thr_wake = 443; -pub const SYS_kldunloadf = 444; -pub const SYS_audit = 445; -pub const SYS_auditon = 446; -pub const SYS_getauid = 447; -pub const SYS_setauid = 448; -pub const SYS_getaudit = 449; -pub const SYS_setaudit = 450; -pub const SYS_getaudit_addr = 451; -pub const SYS_setaudit_addr = 452; -pub const SYS_auditctl = 453; -pub const SYS__umtx_op = 454; -pub const SYS_thr_new = 455; -pub const SYS_sigqueue = 456; -pub const SYS_kmq_open = 457; -pub const SYS_kmq_setattr = 458; -pub const SYS_kmq_timedreceive = 459; -pub const SYS_kmq_timedsend = 460; -pub const SYS_kmq_notify = 461; -pub const SYS_kmq_unlink = 462; -pub const SYS_abort2 = 463; -pub const SYS_thr_set_name = 464; -pub const SYS_aio_fsync = 465; -pub const SYS_rtprio_thread = 466; -pub const SYS_sctp_peeloff = 471; -pub const SYS_sctp_generic_sendmsg = 472; -pub const SYS_sctp_generic_sendmsg_iov = 473; -pub const SYS_sctp_generic_recvmsg = 474; -pub const SYS_pread = 475; -pub const SYS_pwrite = 476; -pub const SYS_mmap = 477; -pub const SYS_lseek = 478; -pub const SYS_truncate = 479; -pub const SYS_ftruncate = 480; -pub const SYS_thr_kill2 = 481; -pub const SYS_shm_open = 482; -pub const SYS_shm_unlink = 483; -pub const SYS_cpuset = 484; -pub const SYS_cpuset_setid = 485; -pub const SYS_cpuset_getid = 486; -pub const SYS_cpuset_getaffinity = 487; -pub const SYS_cpuset_setaffinity = 488; -pub const SYS_faccessat = 489; -pub const SYS_fchmodat = 490; -pub const SYS_fchownat = 491; -pub const SYS_fexecve = 492; -pub const SYS_freebsd11_fstatat = 493; -pub const SYS_futimesat = 494; -pub const SYS_linkat = 495; -pub const SYS_mkdirat = 496; -pub const SYS_mkfifoat = 497; -pub const SYS_freebsd11_mknodat = 498; -pub const SYS_openat = 499; -pub const SYS_readlinkat = 500; -pub const SYS_renameat = 501; -pub const SYS_symlinkat = 502; -pub const SYS_unlinkat = 503; -pub const SYS_posix_openpt = 504; -pub const SYS_gssd_syscall = 505; -pub const SYS_jail_get = 506; -pub const SYS_jail_set = 507; -pub const SYS_jail_remove = 508; -pub const SYS_closefrom = 509; -pub const SYS___semctl = 510; -pub const SYS_msgctl = 511; -pub const SYS_shmctl = 512; -pub const SYS_lpathconf = 513; -// 514 is obsolete cap_new -pub const SYS___cap_rights_get = 515; -pub const SYS_cap_enter = 516; -pub const SYS_cap_getmode = 517; -pub const SYS_pdfork = 518; -pub const SYS_pdkill = 519; -pub const SYS_pdgetpid = 520; -pub const SYS_pselect = 522; -pub const SYS_getloginclass = 523; -pub const SYS_setloginclass = 524; -pub const SYS_rctl_get_racct = 525; -pub const SYS_rctl_get_rules = 526; -pub const SYS_rctl_get_limits = 527; -pub const SYS_rctl_add_rule = 528; -pub const SYS_rctl_remove_rule = 529; -pub const SYS_posix_fallocate = 530; -pub const SYS_posix_fadvise = 531; -pub const SYS_wait6 = 532; -pub const SYS_cap_rights_limit = 533; -pub const SYS_cap_ioctls_limit = 534; -pub const SYS_cap_ioctls_get = 535; -pub const SYS_cap_fcntls_limit = 536; -pub const SYS_cap_fcntls_get = 537; -pub const SYS_bindat = 538; -pub const SYS_connectat = 539; -pub const SYS_chflagsat = 540; -pub const SYS_accept4 = 541; -pub const SYS_pipe2 = 542; -pub const SYS_aio_mlock = 543; -pub const SYS_procctl = 544; -pub const SYS_ppoll = 545; -pub const SYS_futimens = 546; -pub const SYS_utimensat = 547; -pub const SYS_numa_getaffinity = 548; -pub const SYS_numa_setaffinity = 549; -pub const SYS_fdatasync = 550; -pub const SYS_fstat = 551; -pub const SYS_fstatat = 552; -pub const SYS_fhstat = 553; -pub const SYS_getdirentries = 554; -pub const SYS_statfs = 555; -pub const SYS_fstatfs = 556; -pub const SYS_getfsstat = 557; -pub const SYS_fhstatfs = 558; -pub const SYS_mknodat = 559; -pub const SYS_kevent = 560; -pub const SYS_MAXSYSCALL = 561; - -// From here -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0o200000; -pub const O_NOFOLLOW = 0o400000; -pub const O_CLOEXEC = 0o2000000; - -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o40000; -pub const O_LARGEFILE = 0o100000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -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_SETOWN = 8; -pub const F_GETOWN = 9; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; - -pub const F_GETLK = 12; -pub const F_SETLK = 13; -pub const F_SETLKW = 14; - -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - -pub inline fn syscall0(number: usize) -> usize { - asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number)) -} - -pub inline fn syscall1(number: usize, arg1: usize) -> usize { - asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ebx}" (arg1)) -} - -pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { - asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ebx}" (arg1), - [arg2] "{ecx}" (arg2)) -} - -pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { - asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ebx}" (arg1), - [arg2] "{ecx}" (arg2), - [arg3] "{edx}" (arg3)) -} - -pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { - asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ebx}" (arg1), - [arg2] "{ecx}" (arg2), - [arg3] "{edx}" (arg3), - [arg4] "{esi}" (arg4)) -} - -pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, - arg4: usize, arg5: usize) -> usize -{ - asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ebx}" (arg1), - [arg2] "{ecx}" (arg2), - [arg3] "{edx}" (arg3), - [arg4] "{esi}" (arg4), - [arg5] "{edi}" (arg5)) -} - -pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, - arg4: usize, arg5: usize, arg6: usize) -> usize -{ - asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ebx}" (arg1), - [arg2] "{ecx}" (arg2), - [arg3] "{edx}" (arg3), - [arg4] "{esi}" (arg4), - [arg5] "{edi}" (arg5), - [arg6] "{ebp}" (arg6)) -} - -pub nakedcc fn restore() { - asm volatile ( - \\popl %%eax - \\movl $119, %%eax - \\int $0x80 - : - : - : "rcx", "r11") -} - -pub nakedcc fn restore_rt() { - asm volatile ("int $0x80" - : - : [number] "{eax}" (usize(SYS_rt_sigreturn)) - : "rcx", "r11") -} - -export struct msghdr { - msg_name: &u8, - msg_namelen: socklen_t, - msg_iov: &iovec, - msg_iovlen: i32, - msg_control: &u8, - msg_controllen: socklen_t, - msg_flags: i32, -} diff --git a/std/os/freebsd_x86_64.zig b/std/os/freebsd_x86_64.zig deleted file mode 100644 index 09b4680329..0000000000 --- a/std/os/freebsd_x86_64.zig +++ /dev/null @@ -1,650 +0,0 @@ -const freebsd = @import("index.zig"); -const socklen_t = freebsd.socklen_t; -const iovec = freebsd.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_wait4 = 7; -// 8 is old creat -pub const SYS_link = 9; -pub const SYS_unlink = 10; -// 11 is obsolete execv -pub const SYS_chdir = 12; -pub const SYS_fchdir = 13; -pub const SYS_freebsd11_mknod = 14; -pub const SYS_chmod = 15; -pub const SYS_chown = 16; -pub const SYS_break = 17; -// 18 is freebsd4 getfsstat -// 19 is old lseek -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_kill = 37; -// 38 is old stat -pub const SYS_getppid = 39; -// 40 is old lstat -pub const SYS_dup = 41; -pub const SYS_freebsd10_pipe = 42; -pub const SYS_getegid = 43; -pub const SYS_profil = 44; -pub const SYS_ktrace = 45; -// 46 is old sigaction -pub const SYS_getgid = 47; -// 48 is old sigprocmask -pub const SYS_getlogin = 49; -pub const SYS_setlogin = 50; -pub const SYS_acct = 51; -// 52 is old sigpending -pub const SYS_sigaltstack = 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; -// 62 is old fstat -// 63 is old getkerninfo -// 64 is old getpagesize -pub const SYS_msync = 65; -pub const SYS_vfork = 66; -// 67 is obsolete vread -// 68 is obsolete vwrite -pub const SYS_sbrk = 69; -pub const SYS_sstk = 70; -// 71 is old mmap -pub const SYS_vadvise = 72; -pub const SYS_munmap = 73; -pub const SYS_mprotect = 74; -pub const SYS_madvise = 75; -// 76 is obsolete vhangup -// 77 is obsolete vlimit -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_setitimer = 83; -// 84 is old wait -pub const SYS_swapon = 85; -pub const SYS_getitimer = 86; -// 87 is old gethostname -// 88 is old sethostname -pub const SYS_getdtablesize = 89; -pub const SYS_dup2 = 90; -pub const SYS_fcntl = 92; -pub const SYS_select = 93; -pub const SYS_fsync = 95; -pub const SYS_setpriority = 96; -pub const SYS_socket = 97; -pub const SYS_connect = 98; -// 99 is old accept -pub const SYS_getpriority = 100; -// 101 is old send -// 102 is old recv -// 103 is old sigreturn -pub const SYS_bind = 104; -pub const SYS_setsockopt = 105; -pub const SYS_listen = 106; -// 107 is obsolete vtimes -// 108 is old sigvec -// 109 is old sigblock -// 110 is old sigsetmask -// 111 is old sigsuspend -// 112 is old sigstack -// 113 is old recvmsg -// 114 is old sendmsg -// 115 is obsolete vtrace -pub const SYS_gettimeofday = 116; -pub const SYS_getrusage = 117; -pub const SYS_getsockopt = 118; -pub const SYS_readv = 120; -pub const SYS_writev = 121; -pub const SYS_settimeofday = 122; -pub const SYS_fchown = 123; -pub const SYS_fchmod = 124; -// 125 is old recvfrom -pub const SYS_setreuid = 126; -pub const SYS_setregid = 127; -pub const SYS_rename = 128; -// 129 is old truncate -// 130 is old ftruncate -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_utimes = 138; -// 139 is obsolete 4.2 sigreturn -pub const SYS_adjtime = 140; -// 141 is old getpeername -// 142 is old gethostid -// 143 is old sethostid -// 144 is old getrlimit -// 145 is old setrlimit -// 146 is old killpg -pub const SYS_setsid = 147; -pub const SYS_quotactl = 148; -// 149 is old quota -// 150 is old getsockname -pub const SYS_nlm_syscall = 154; -pub const SYS_nfssvc = 155; -// 156 is old getdirentries -// 157 is freebsd4 statfs -// 158 is freebsd4 fstatfs -pub const SYS_lgetfh = 160; -pub const SYS_getfh = 161; -// 162 is freebsd4 getdomainname -// 163 is freebsd4 setdomainname -// 164 is freebsd4 uname -pub const SYS_sysarch = 165; -pub const SYS_rtprio = 166; -pub const SYS_semsys = 169; -pub const SYS_msgsys = 170; -pub const SYS_shmsys = 171; -// 173 is freebsd6 pread -// 174 is freebsd6 pwrite -pub const SYS_setfib = 175; -pub const SYS_ntp_adjtime = 176; -pub const SYS_setgid = 181; -pub const SYS_setegid = 182; -pub const SYS_seteuid = 183; -pub const SYS_freebsd11_stat = 188; -pub const SYS_freebsd11_fstat = 189; -pub const SYS_freebsd11_lstat = 190; -pub const SYS_pathconf = 191; -pub const SYS_fpathconf = 192; -pub const SYS_getrlimit = 194; -pub const SYS_setrlimit = 195; -pub const SYS_freebsd11_getdirentries = 196; -// 197 is freebsd6 mmap -pub const SYS___syscall = 198; -// 199 is freebsd6 lseek -// 200 is freebsd6 truncate -// 201 is freebsd6 ftruncate -pub const SYS___sysctl = 202; -pub const SYS_mlock = 203; -pub const SYS_munlock = 204; -pub const SYS_undelete = 205; -pub const SYS_futimes = 206; -pub const SYS_getpgid = 207; -pub const SYS_poll = 209; -pub const SYS_freebsd7___semctl = 220; -pub const SYS_semget = 221; -pub const SYS_semop = 222; -pub const SYS_freebsd7_msgctl = 224; -pub const SYS_msgget = 225; -pub const SYS_msgsnd = 226; -pub const SYS_msgrcv = 227; -pub const SYS_shmat = 228; -pub const SYS_freebsd7_shmctl = 229; -pub const SYS_shmdt = 230; -pub const SYS_shmget = 231; -pub const SYS_clock_gettime = 232; -pub const SYS_clock_settime = 233; -pub const SYS_clock_getres = 234; -pub const SYS_ktimer_create = 235; -pub const SYS_ktimer_delete = 236; -pub const SYS_ktimer_settime = 237; -pub const SYS_ktimer_gettime = 238; -pub const SYS_ktimer_getoverrun = 239; -pub const SYS_nanosleep = 240; -pub const SYS_ffclock_getcounter = 241; -pub const SYS_ffclock_setestimate = 242; -pub const SYS_ffclock_getestimate = 243; -pub const SYS_clock_nanosleep = 244; -pub const SYS_clock_getcpuclockid2 = 247; -pub const SYS_ntp_gettime = 248; -pub const SYS_minherit = 250; -pub const SYS_rfork = 251; -// 252 is obsolete openbsd_poll -pub const SYS_issetugid = 253; -pub const SYS_lchown = 254; -pub const SYS_aio_read = 255; -pub const SYS_aio_write = 256; -pub const SYS_lio_listio = 257; -pub const SYS_freebsd11_getdents = 272; -pub const SYS_lchmod = 274; -pub const SYS_netbsd_lchown = 275; -pub const SYS_lutimes = 276; -pub const SYS_netbsd_msync = 277; -pub const SYS_freebsd11_nstat = 278; -pub const SYS_freebsd11_nfstat = 279; -pub const SYS_freebsd11_nlstat = 280; -pub const SYS_preadv = 289; -pub const SYS_pwritev = 290; -// 297 is freebsd4 fhstatfs -pub const SYS_fhopen = 298; -pub const SYS_freebsd11_fhstat = 299; -pub const SYS_modnext = 300; -pub const SYS_modstat = 301; -pub const SYS_modfnext = 302; -pub const SYS_modfind = 303; -pub const SYS_kldload = 304; -pub const SYS_kldunload = 305; -pub const SYS_kldfind = 306; -pub const SYS_kldnext = 307; -pub const SYS_kldstat = 308; -pub const SYS_kldfirstmod = 309; -pub const SYS_getsid = 310; -pub const SYS_setresuid = 311; -pub const SYS_setresgid = 312; -// 313 is obsolete signanosleep -pub const SYS_aio_return = 314; -pub const SYS_aio_suspend = 315; -pub const SYS_aio_cancel = 316; -pub const SYS_aio_error = 317; -// 318 is freebsd6 aio_read -// 319 is freebsd6 aio_write -// 320 is freebsd6 lio_listio -pub const SYS_yield = 321; -// 322 is obsolete thr_sleep -// 323 is obsolete thr_wakeup -pub const SYS_mlockall = 324; -pub const SYS_munlockall = 325; -pub const SYS___getcwd = 326; -pub const SYS_sched_setparam = 327; -pub const SYS_sched_getparam = 328; -pub const SYS_sched_setscheduler = 329; -pub const SYS_sched_getscheduler = 330; -pub const SYS_sched_yield = 331; -pub const SYS_sched_get_priority_max = 332; -pub const SYS_sched_get_priority_min = 333; -pub const SYS_sched_rr_get_interval = 334; -pub const SYS_utrace = 335; -// 336 is freebsd4 sendfile -pub const SYS_kldsym = 337; -pub const SYS_jail = 338; -pub const SYS_nnpfs_syscall = 339; -pub const SYS_sigprocmask = 340; -pub const SYS_sigsuspend = 341; -// 342 is freebsd4 sigaction -pub const SYS_sigpending = 343; -// 344 is freebsd4 sigreturn -pub const SYS_sigtimedwait = 345; -pub const SYS_sigwaitinfo = 346; -pub const SYS___acl_get_file = 347; -pub const SYS___acl_set_file = 348; -pub const SYS___acl_get_fd = 349; -pub const SYS___acl_set_fd = 350; -pub const SYS___acl_delete_file = 351; -pub const SYS___acl_delete_fd = 352; -pub const SYS___acl_aclcheck_file = 353; -pub const SYS___acl_aclcheck_fd = 354; -pub const SYS_extattrctl = 355; -pub const SYS_extattr_set_file = 356; -pub const SYS_extattr_get_file = 357; -pub const SYS_extattr_delete_file = 358; -pub const SYS_aio_waitcomplete = 359; -pub const SYS_getresuid = 360; -pub const SYS_getresgid = 361; -pub const SYS_kqueue = 362; -pub const SYS_freebsd11_kevent = 363; -pub const SYS_extattr_set_fd = 371; -pub const SYS_extattr_get_fd = 372; -pub const SYS_extattr_delete_fd = 373; -pub const SYS___setugid = 374; -pub const SYS_eaccess = 376; -pub const SYS_afs3_syscall = 377; -pub const SYS_nmount = 378; -pub const SYS___mac_get_proc = 384; -pub const SYS___mac_set_proc = 385; -pub const SYS___mac_get_fd = 386; -pub const SYS___mac_get_file = 387; -pub const SYS___mac_set_fd = 388; -pub const SYS___mac_set_file = 389; -pub const SYS_kenv = 390; -pub const SYS_lchflags = 391; -pub const SYS_uuidgen = 392; -pub const SYS_sendfile = 393; -pub const SYS_mac_syscall = 394; -pub const SYS_freebsd11_getfsstat = 395; -pub const SYS_freebsd11_statfs = 396; -pub const SYS_freebsd11_fstatfs = 397; -pub const SYS_freebsd11_fhstatfs = 398; -pub const SYS_ksem_close = 400; -pub const SYS_ksem_post = 401; -pub const SYS_ksem_wait = 402; -pub const SYS_ksem_trywait = 403; -pub const SYS_ksem_init = 404; -pub const SYS_ksem_open = 405; -pub const SYS_ksem_unlink = 406; -pub const SYS_ksem_getvalue = 407; -pub const SYS_ksem_destroy = 408; -pub const SYS___mac_get_pid = 409; -pub const SYS___mac_get_link = 410; -pub const SYS___mac_set_link = 411; -pub const SYS_extattr_set_link = 412; -pub const SYS_extattr_get_link = 413; -pub const SYS_extattr_delete_link = 414; -pub const SYS___mac_execve = 415; -pub const SYS_sigaction = 416; -pub const SYS_sigreturn = 417; -pub const SYS_getcontext = 421; -pub const SYS_setcontext = 422; -pub const SYS_swapcontext = 423; -pub const SYS_swapoff = 424; -pub const SYS___acl_get_link = 425; -pub const SYS___acl_set_link = 426; -pub const SYS___acl_delete_link = 427; -pub const SYS___acl_aclcheck_link = 428; -pub const SYS_sigwait = 429; -pub const SYS_thr_create = 430; -pub const SYS_thr_exit = 431; -pub const SYS_thr_self = 432; -pub const SYS_thr_kill = 433; -pub const SYS_jail_attach = 436; -pub const SYS_extattr_list_fd = 437; -pub const SYS_extattr_list_file = 438; -pub const SYS_extattr_list_link = 439; -pub const SYS_ksem_timedwait = 441; -pub const SYS_thr_suspend = 442; -pub const SYS_thr_wake = 443; -pub const SYS_kldunloadf = 444; -pub const SYS_audit = 445; -pub const SYS_auditon = 446; -pub const SYS_getauid = 447; -pub const SYS_setauid = 448; -pub const SYS_getaudit = 449; -pub const SYS_setaudit = 450; -pub const SYS_getaudit_addr = 451; -pub const SYS_setaudit_addr = 452; -pub const SYS_auditctl = 453; -pub const SYS__umtx_op = 454; -pub const SYS_thr_new = 455; -pub const SYS_sigqueue = 456; -pub const SYS_kmq_open = 457; -pub const SYS_kmq_setattr = 458; -pub const SYS_kmq_timedreceive = 459; -pub const SYS_kmq_timedsend = 460; -pub const SYS_kmq_notify = 461; -pub const SYS_kmq_unlink = 462; -pub const SYS_abort2 = 463; -pub const SYS_thr_set_name = 464; -pub const SYS_aio_fsync = 465; -pub const SYS_rtprio_thread = 466; -pub const SYS_sctp_peeloff = 471; -pub const SYS_sctp_generic_sendmsg = 472; -pub const SYS_sctp_generic_sendmsg_iov = 473; -pub const SYS_sctp_generic_recvmsg = 474; -pub const SYS_pread = 475; -pub const SYS_pwrite = 476; -pub const SYS_mmap = 477; -pub const SYS_lseek = 478; -pub const SYS_truncate = 479; -pub const SYS_ftruncate = 480; -pub const SYS_thr_kill2 = 481; -pub const SYS_shm_open = 482; -pub const SYS_shm_unlink = 483; -pub const SYS_cpuset = 484; -pub const SYS_cpuset_setid = 485; -pub const SYS_cpuset_getid = 486; -pub const SYS_cpuset_getaffinity = 487; -pub const SYS_cpuset_setaffinity = 488; -pub const SYS_faccessat = 489; -pub const SYS_fchmodat = 490; -pub const SYS_fchownat = 491; -pub const SYS_fexecve = 492; -pub const SYS_freebsd11_fstatat = 493; -pub const SYS_futimesat = 494; -pub const SYS_linkat = 495; -pub const SYS_mkdirat = 496; -pub const SYS_mkfifoat = 497; -pub const SYS_freebsd11_mknodat = 498; -pub const SYS_openat = 499; -pub const SYS_readlinkat = 500; -pub const SYS_renameat = 501; -pub const SYS_symlinkat = 502; -pub const SYS_unlinkat = 503; -pub const SYS_posix_openpt = 504; -pub const SYS_gssd_syscall = 505; -pub const SYS_jail_get = 506; -pub const SYS_jail_set = 507; -pub const SYS_jail_remove = 508; -pub const SYS_closefrom = 509; -pub const SYS___semctl = 510; -pub const SYS_msgctl = 511; -pub const SYS_shmctl = 512; -pub const SYS_lpathconf = 513; -// 514 is obsolete cap_new -pub const SYS___cap_rights_get = 515; -pub const SYS_cap_enter = 516; -pub const SYS_cap_getmode = 517; -pub const SYS_pdfork = 518; -pub const SYS_pdkill = 519; -pub const SYS_pdgetpid = 520; -pub const SYS_pselect = 522; -pub const SYS_getloginclass = 523; -pub const SYS_setloginclass = 524; -pub const SYS_rctl_get_racct = 525; -pub const SYS_rctl_get_rules = 526; -pub const SYS_rctl_get_limits = 527; -pub const SYS_rctl_add_rule = 528; -pub const SYS_rctl_remove_rule = 529; -pub const SYS_posix_fallocate = 530; -pub const SYS_posix_fadvise = 531; -pub const SYS_wait6 = 532; -pub const SYS_cap_rights_limit = 533; -pub const SYS_cap_ioctls_limit = 534; -pub const SYS_cap_ioctls_get = 535; -pub const SYS_cap_fcntls_limit = 536; -pub const SYS_cap_fcntls_get = 537; -pub const SYS_bindat = 538; -pub const SYS_connectat = 539; -pub const SYS_chflagsat = 540; -pub const SYS_accept4 = 541; -pub const SYS_pipe2 = 542; -pub const SYS_aio_mlock = 543; -pub const SYS_procctl = 544; -pub const SYS_ppoll = 545; -pub const SYS_futimens = 546; -pub const SYS_utimensat = 547; -pub const SYS_numa_getaffinity = 548; -pub const SYS_numa_setaffinity = 549; -pub const SYS_fdatasync = 550; -pub const SYS_fstat = 551; -pub const SYS_fstatat = 552; -pub const SYS_fhstat = 553; -pub const SYS_getdirentries = 554; -pub const SYS_statfs = 555; -pub const SYS_fstatfs = 556; -pub const SYS_getfsstat = 557; -pub const SYS_fhstatfs = 558; -pub const SYS_mknodat = 559; -pub const SYS_kevent = 560; -pub const SYS_MAXSYSCALL = 561; - -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0o200000; -pub const O_NOFOLLOW = 0o400000; -pub const O_CLOEXEC = 0o2000000; - -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o40000; -pub const O_LARGEFILE = 0; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -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_SETOWN = 8; -pub const F_GETOWN = 9; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; - -pub const F_GETLK = 5; -pub const F_SETLK = 6; -pub const F_SETLKW = 7; - -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - -pub fn syscall0(number: usize) usize { - return asm volatile ("syscall" - : [ret] "={rax}" (-> usize) - : [number] "{rax}" (number) - : "rcx", "r11" - ); -} - -pub fn syscall1(number: usize, arg1: usize) usize { - return asm volatile ("syscall" - : [ret] "={rax}" (-> usize) - : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1) - : "rcx", "r11" - ); -} - -pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { - return asm volatile ("syscall" - : [ret] "={rax}" (-> usize) - : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2) - : "rcx", "r11" - ); -} - -pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { - return asm volatile ("syscall" - : [ret] "={rax}" (-> usize) - : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2), - [arg3] "{rdx}" (arg3) - : "rcx", "r11" - ); -} - -pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { - return asm volatile ("syscall" - : [ret] "={rax}" (-> usize) - : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2), - [arg3] "{rdx}" (arg3), - [arg4] "{r10}" (arg4) - : "rcx", "r11" - ); -} - -pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { - return asm volatile ("syscall" - : [ret] "={rax}" (-> usize) - : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2), - [arg3] "{rdx}" (arg3), - [arg4] "{r10}" (arg4), - [arg5] "{r8}" (arg5) - : "rcx", "r11" - ); -} - -pub fn syscall6( - number: usize, - arg1: usize, - arg2: usize, - arg3: usize, - arg4: usize, - arg5: usize, - arg6: usize, -) usize { - return asm volatile ("syscall" - : [ret] "={rax}" (-> usize) - : [number] "{rax}" (number), - [arg1] "{rdi}" (arg1), - [arg2] "{rsi}" (arg2), - [arg3] "{rdx}" (arg3), - [arg4] "{r10}" (arg4), - [arg5] "{r8}" (arg5), - [arg6] "{r9}" (arg6) - : "rcx", "r11" - ); -} - -pub nakedcc fn restore_rt() void { - asm volatile ("syscall" - : - : [number] "{rax}" (usize(SYS_rt_sigreturn)) - : "rcx", "r11" - ); -} - -pub const msghdr = extern struct { - msg_name: &u8, - msg_namelen: socklen_t, - msg_iov: &iovec, - msg_iovlen: i32, - __pad1: i32, - msg_control: &u8, - msg_controllen: socklen_t, - __pad2: socklen_t, - msg_flags: i32, -}; - -/// Renamed to Stat to not conflict with the stat function. -pub const Stat = extern struct { - dev: u64, - ino: u64, - nlink: usize, - - mode: u32, - uid: u32, - gid: u32, - __pad0: u32, - rdev: u64, - size: i64, - blksize: isize, - blocks: i64, - - atim: timespec, - mtim: timespec, - ctim: timespec, - __unused: [3]isize, -}; - -pub const timespec = extern struct { - tv_sec: isize, - tv_nsec: isize, -}; -- cgit v1.2.3 From 7a3f0a55d9a481f260935f26426ee4508d44cb18 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 18:01:00 +0300 Subject: Add freebsd to more things --- std/debug/index.zig | 2 ++ std/heap.zig | 6 +++--- std/os/file.zig | 6 +++--- std/os/index.zig | 6 +++--- std/os/path.zig | 11 ++++++++++- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/std/debug/index.zig b/std/debug/index.zig index e6d8fe3fc6..cabeba14f7 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -1078,6 +1078,8 @@ pub const DebugInfo = switch (builtin.os) { self.elf.close(); } }, + builtin.Os.freebsd => struct.{ + }, else => @compileError("Unsupported OS"), }; diff --git a/std/heap.zig b/std/heap.zig index 8a68a7b457..34addef094 100644 --- a/std/heap.zig +++ b/std/heap.zig @@ -69,7 +69,7 @@ pub const DirectAllocator = struct.{ const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); switch (builtin.os) { - Os.linux, Os.macosx, Os.ios => { + Os.linux, Os.macosx, Os.ios, Os.freebsd => { 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); @@ -120,7 +120,7 @@ pub const DirectAllocator = struct.{ const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); switch (builtin.os) { - Os.linux, Os.macosx, Os.ios => { + Os.linux, Os.macosx, Os.ios, Os.freebsd => { if (new_size <= old_mem.len) { const base_addr = @ptrToInt(old_mem.ptr); const old_addr_end = base_addr + old_mem.len; @@ -165,7 +165,7 @@ pub const DirectAllocator = struct.{ const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); switch (builtin.os) { - Os.linux, Os.macosx, Os.ios => { + Os.linux, Os.macosx, Os.ios, Os.freebsd => { _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len); }, Os.windows => { diff --git a/std/os/file.zig b/std/os/file.zig index 293d637d19..4c21cc9b5a 100644 --- a/std/os/file.zig +++ b/std/os/file.zig @@ -229,7 +229,7 @@ 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.freebsd => { const result = posix.lseek(self.handle, amount, posix.SEEK_CUR); const err = posix.getErrno(result); if (err > 0) { @@ -260,7 +260,7 @@ 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.freebsd => { const ipos = try math.cast(isize, pos); const result = posix.lseek(self.handle, ipos, posix.SEEK_SET); const err = posix.getErrno(result); @@ -294,7 +294,7 @@ 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.freebsd => { const result = posix.lseek(self.handle, 0, posix.SEEK_CUR); const err = posix.getErrno(result); if (err > 0) { diff --git a/std/os/index.zig b/std/os/index.zig index ba3771c15e..16bc571a83 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -3,7 +3,7 @@ const builtin = @import("builtin"); 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.linux, builtin.Os.macosx, builtin.Os.freebsd => true, else => false, }; const os = @This(); @@ -42,7 +42,7 @@ pub const time = @import("time.zig"); pub const page_size = 4 * 1024; pub const MAX_PATH_BYTES = switch (builtin.os) { - Os.linux, Os.macosx, Os.ios => posix.PATH_MAX, + Os.linux, Os.macosx, Os.ios, Os.freebsd => posix.PATH_MAX, // Each UTF-16LE character may be expanded to 3 UTF-8 bytes. // If it would require 4 UTF-8 bytes, then there would be a surrogate // pair in the UTF-16LE, and we (over)account 3 bytes for it that way. @@ -103,7 +103,7 @@ const math = std.math; /// library implementation. pub fn getRandomBytes(buf: []u8) !void { switch (builtin.os) { - Os.linux => while (true) { + Os.linux, Os.freebsd => while (true) { // TODO check libc version and potentially call c.getrandom. // See #397 const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)); diff --git a/std/os/path.zig b/std/os/path.zig index 8096cdd0d2..e0d8030bcc 100644 --- a/std/os/path.zig +++ b/std/os/path.zig @@ -1161,7 +1161,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro const pathname_w = try windows_util.cStrToPrefixedFileW(pathname); return realW(out_buffer, pathname_w); }, - Os.macosx, Os.ios, Os.freebsd => { + Os.macosx, Os.ios => { // TODO instead of calling the libc function here, port the implementation to Zig const err = posix.getErrno(posix.realpath(pathname, out_buffer)); switch (err) { @@ -1188,6 +1188,15 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro return os.readLinkC(out_buffer, proc_path.ptr); }, + Os.freebsd => { // XXX requires fdescfs + const fd = try os.posixOpenC(pathname, posix.O_PATH | posix.O_NONBLOCK | posix.O_CLOEXEC, 0); + defer os.close(fd); + + var buf: ["/dev/fd/-2147483648".len]u8 = undefined; + const proc_path = fmt.bufPrint(buf[0..], "/dev/fd/{}\x00", fd) catch unreachable; + + return os.readLinkC(out_buffer, proc_path.ptr); + }, else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)), } } -- cgit v1.2.3 From afe26bbcbdfd7d6fc5ed141688dd9baeb2f1c104 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 18:09:44 +0300 Subject: System call numbers on FreeBSD are machine-independent But e.g. sbrk is only removed in new architectures (aarch64, riscv), so keep it in x86_64 --- CMakeLists.txt | 1 + std/os/freebsd/index.zig | 71 +++---- std/os/freebsd/syscall.zig | 493 +++++++++++++++++++++++++++++++++++++++++++++ std/os/freebsd/x86_64.zig | 474 ------------------------------------------- 4 files changed, 530 insertions(+), 509 deletions(-) create mode 100644 std/os/freebsd/syscall.zig diff --git a/CMakeLists.txt b/CMakeLists.txt index 8df55a7fbd..f10fc91b16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -582,6 +582,7 @@ set(ZIG_STD_FILES "os/linux/arm64.zig" "os/freebsd/errno.zig" "os/freebsd/index.zig" + "os/freebsd/syscall.zig" "os/freebsd/x86_64.zig" "os/path.zig" "os/time.zig" diff --git a/std/os/freebsd/index.zig b/std/os/freebsd/index.zig index e856f6291c..c442dd6659 100644 --- a/std/os/freebsd/index.zig +++ b/std/os/freebsd/index.zig @@ -4,6 +4,7 @@ const arch = switch (builtin.arch) { builtin.Arch.x86_64 => @import("x86_64.zig"), else => @compileError("unsupported arch"), }; +pub use @import("syscall.zig"); pub use @import("errno.zig"); pub const PATH_MAX = 1024; @@ -367,64 +368,64 @@ pub fn getErrno(r: usize) usize { } pub fn dup2(old: i32, new: i32) usize { - return arch.syscall2(arch.SYS_dup2, @intCast(usize, old), @intCast(usize, new)); + return arch.syscall2(SYS_dup2, @intCast(usize, old), @intCast(usize, new)); } pub fn chdir(path: [*]const u8) usize { - return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); + return arch.syscall1(SYS_chdir, @ptrToInt(path)); } pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { - return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); + return arch.syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); } pub fn fork() usize { - return arch.syscall0(arch.SYS_fork); + return arch.syscall0(SYS_fork); } pub fn getcwd(buf: [*]u8, size: usize) usize { - return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size); + return arch.syscall2(SYS___getcwd, @ptrToInt(buf), size); } pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { - return arch.syscall3(arch.SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); + return arch.syscall3(SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); } pub fn isatty(fd: i32) bool { var wsz: winsize = undefined; - return arch.syscall3(arch.SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; + return arch.syscall3(SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; } pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { - return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); + return arch.syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); } pub fn mkdir(path: [*]const u8, mode: u32) usize { - return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); + return arch.syscall2(SYS_mkdir, @ptrToInt(path), mode); } pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { - return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset)); + return arch.syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset)); } pub fn munmap(address: usize, length: usize) usize { - return arch.syscall2(arch.SYS_munmap, address, length); + return arch.syscall2(SYS_munmap, address, length); } pub fn read(fd: i32, buf: [*]u8, count: usize) usize { - return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count); + return arch.syscall3(SYS_read, @intCast(usize, fd), @ptrToInt(buf), count); } pub fn rmdir(path: [*]const u8) usize { - return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); + return arch.syscall1(SYS_rmdir, @ptrToInt(path)); } pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { - return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); + return arch.syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); } pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { - return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); + return arch.syscall4(SYS_pread, usize(fd), @ptrToInt(buf), count, offset); } pub fn pipe(fd: *[2]i32) usize { @@ -432,80 +433,80 @@ pub fn pipe(fd: *[2]i32) usize { } pub fn pipe2(fd: *[2]i32, flags: usize) usize { - return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); + return arch.syscall2(SYS_pipe2, @ptrToInt(fd), flags); } pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { - return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count); + return arch.syscall3(SYS_write, @intCast(usize, fd), @ptrToInt(buf), count); } pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { - return arch.syscall4(arch.SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset); + return arch.syscall4(SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset); } pub fn rename(old: [*]const u8, new: [*]const u8) usize { - return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); + return arch.syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); } pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { - return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); + return arch.syscall3(SYS_open, @ptrToInt(path), flags, perm); } pub fn create(path: [*]const u8, perm: usize) usize { - return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); + return arch.syscall2(SYS_creat, @ptrToInt(path), perm); } pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { - return arch.syscall4(arch.SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode); + return arch.syscall4(SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode); } pub fn close(fd: i32) usize { - return arch.syscall1(arch.SYS_close, @intCast(usize, fd)); + return arch.syscall1(SYS_close, @intCast(usize, fd)); } pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { - return arch.syscall3(arch.SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos); + return arch.syscall3(SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos); } pub fn exit(status: i32) noreturn { - _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); + _ = arch.syscall1(SYS_exit, @bitCast(usize, isize(status))); unreachable; } pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { - return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags)); + return arch.syscall3(SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags)); } pub fn kill(pid: i32, sig: i32) usize { - return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig)); + return arch.syscall2(SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig)); } pub fn unlink(path: [*]const u8) usize { - return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); + return arch.syscall1(SYS_unlink, @ptrToInt(path)); } pub fn waitpid(pid: i32, status: *i32, options: i32) usize { - return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); + return arch.syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); } pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { - return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); + return arch.syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); } pub fn setuid(uid: u32) usize { - return arch.syscall1(arch.SYS_setuid, uid); + return arch.syscall1(SYS_setuid, uid); } pub fn setgid(gid: u32) usize { - return arch.syscall1(arch.SYS_setgid, gid); + return arch.syscall1(SYS_setgid, gid); } pub fn setreuid(ruid: u32, euid: u32) usize { - return arch.syscall2(arch.SYS_setreuid, ruid, euid); + return arch.syscall2(SYS_setreuid, ruid, euid); } pub fn setregid(rgid: u32, egid: u32) usize { - return arch.syscall2(arch.SYS_setregid, rgid, egid); + return arch.syscall2(SYS_setregid, rgid, egid); } pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize { @@ -567,5 +568,5 @@ pub const Stat = arch.Stat; pub const timespec = arch.timespec; pub fn fstat(fd: i32, stat_buf: *Stat) usize { - return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); + return arch.syscall2(SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); } diff --git a/std/os/freebsd/syscall.zig b/std/os/freebsd/syscall.zig new file mode 100644 index 0000000000..6cdd71de3b --- /dev/null +++ b/std/os/freebsd/syscall.zig @@ -0,0 +1,493 @@ +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_wait4 = 7; +// 8 is old creat +pub const SYS_link = 9; +pub const SYS_unlink = 10; +// 11 is obsolete execv +pub const SYS_chdir = 12; +pub const SYS_fchdir = 13; +pub const SYS_freebsd11_mknod = 14; +pub const SYS_chmod = 15; +pub const SYS_chown = 16; +pub const SYS_break = 17; +// 18 is freebsd4 getfsstat +// 19 is old lseek +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_kill = 37; +// 38 is old stat +pub const SYS_getppid = 39; +// 40 is old lstat +pub const SYS_dup = 41; +pub const SYS_freebsd10_pipe = 42; +pub const SYS_getegid = 43; +pub const SYS_profil = 44; +pub const SYS_ktrace = 45; +// 46 is old sigaction +pub const SYS_getgid = 47; +// 48 is old sigprocmask +pub const SYS_getlogin = 49; +pub const SYS_setlogin = 50; +pub const SYS_acct = 51; +// 52 is old sigpending +pub const SYS_sigaltstack = 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; +// 62 is old fstat +// 63 is old getkerninfo +// 64 is old getpagesize +pub const SYS_msync = 65; +pub const SYS_vfork = 66; +// 67 is obsolete vread +// 68 is obsolete vwrite +// 69 is obsolete sbrk (still present on some platforms) +pub const SYS_sstk = 70; +// 71 is old mmap +pub const SYS_vadvise = 72; +pub const SYS_munmap = 73; +pub const SYS_mprotect = 74; +pub const SYS_madvise = 75; +// 76 is obsolete vhangup +// 77 is obsolete vlimit +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_setitimer = 83; +// 84 is old wait +pub const SYS_swapon = 85; +pub const SYS_getitimer = 86; +// 87 is old gethostname +// 88 is old sethostname +pub const SYS_getdtablesize = 89; +pub const SYS_dup2 = 90; +pub const SYS_fcntl = 92; +pub const SYS_select = 93; +pub const SYS_fsync = 95; +pub const SYS_setpriority = 96; +pub const SYS_socket = 97; +pub const SYS_connect = 98; +// 99 is old accept +pub const SYS_getpriority = 100; +// 101 is old send +// 102 is old recv +// 103 is old sigreturn +pub const SYS_bind = 104; +pub const SYS_setsockopt = 105; +pub const SYS_listen = 106; +// 107 is obsolete vtimes +// 108 is old sigvec +// 109 is old sigblock +// 110 is old sigsetmask +// 111 is old sigsuspend +// 112 is old sigstack +// 113 is old recvmsg +// 114 is old sendmsg +// 115 is obsolete vtrace +pub const SYS_gettimeofday = 116; +pub const SYS_getrusage = 117; +pub const SYS_getsockopt = 118; +pub const SYS_readv = 120; +pub const SYS_writev = 121; +pub const SYS_settimeofday = 122; +pub const SYS_fchown = 123; +pub const SYS_fchmod = 124; +// 125 is old recvfrom +pub const SYS_setreuid = 126; +pub const SYS_setregid = 127; +pub const SYS_rename = 128; +// 129 is old truncate +// 130 is old ftruncate +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_utimes = 138; +// 139 is obsolete 4.2 sigreturn +pub const SYS_adjtime = 140; +// 141 is old getpeername +// 142 is old gethostid +// 143 is old sethostid +// 144 is old getrlimit +// 145 is old setrlimit +// 146 is old killpg +pub const SYS_setsid = 147; +pub const SYS_quotactl = 148; +// 149 is old quota +// 150 is old getsockname +pub const SYS_nlm_syscall = 154; +pub const SYS_nfssvc = 155; +// 156 is old getdirentries +// 157 is freebsd4 statfs +// 158 is freebsd4 fstatfs +pub const SYS_lgetfh = 160; +pub const SYS_getfh = 161; +// 162 is freebsd4 getdomainname +// 163 is freebsd4 setdomainname +// 164 is freebsd4 uname +pub const SYS_sysarch = 165; +pub const SYS_rtprio = 166; +pub const SYS_semsys = 169; +pub const SYS_msgsys = 170; +pub const SYS_shmsys = 171; +// 173 is freebsd6 pread +// 174 is freebsd6 pwrite +pub const SYS_setfib = 175; +pub const SYS_ntp_adjtime = 176; +pub const SYS_setgid = 181; +pub const SYS_setegid = 182; +pub const SYS_seteuid = 183; +// 184 is obsolete lfs_bmapv +// 185 is obsolete lfs_markv +// 186 is obsolete lfs_segclean +// 187 is obsolete lfs_segwait +pub const SYS_freebsd11_stat = 188; +pub const SYS_freebsd11_fstat = 189; +pub const SYS_freebsd11_lstat = 190; +pub const SYS_pathconf = 191; +pub const SYS_fpathconf = 192; +pub const SYS_getrlimit = 194; +pub const SYS_setrlimit = 195; +pub const SYS_freebsd11_getdirentries = 196; +// 197 is freebsd6 mmap +pub const SYS___syscall = 198; +// 199 is freebsd6 lseek +// 200 is freebsd6 truncate +// 201 is freebsd6 ftruncate +pub const SYS___sysctl = 202; +pub const SYS_mlock = 203; +pub const SYS_munlock = 204; +pub const SYS_undelete = 205; +pub const SYS_futimes = 206; +pub const SYS_getpgid = 207; +pub const SYS_poll = 209; +pub const SYS_freebsd7___semctl = 220; +pub const SYS_semget = 221; +pub const SYS_semop = 222; +pub const SYS_freebsd7_msgctl = 224; +pub const SYS_msgget = 225; +pub const SYS_msgsnd = 226; +pub const SYS_msgrcv = 227; +pub const SYS_shmat = 228; +pub const SYS_freebsd7_shmctl = 229; +pub const SYS_shmdt = 230; +pub const SYS_shmget = 231; +pub const SYS_clock_gettime = 232; +pub const SYS_clock_settime = 233; +pub const SYS_clock_getres = 234; +pub const SYS_ktimer_create = 235; +pub const SYS_ktimer_delete = 236; +pub const SYS_ktimer_settime = 237; +pub const SYS_ktimer_gettime = 238; +pub const SYS_ktimer_getoverrun = 239; +pub const SYS_nanosleep = 240; +pub const SYS_ffclock_getcounter = 241; +pub const SYS_ffclock_setestimate = 242; +pub const SYS_ffclock_getestimate = 243; +pub const SYS_clock_nanosleep = 244; +pub const SYS_clock_getcpuclockid2 = 247; +pub const SYS_ntp_gettime = 248; +pub const SYS_minherit = 250; +pub const SYS_rfork = 251; +// 252 is obsolete openbsd_poll +pub const SYS_issetugid = 253; +pub const SYS_lchown = 254; +pub const SYS_aio_read = 255; +pub const SYS_aio_write = 256; +pub const SYS_lio_listio = 257; +pub const SYS_freebsd11_getdents = 272; +pub const SYS_lchmod = 274; +// 275 is obsolete netbsd_lchown +pub const SYS_lutimes = 276; +// 277 is obsolete netbsd_msync +pub const SYS_freebsd11_nstat = 278; +pub const SYS_freebsd11_nfstat = 279; +pub const SYS_freebsd11_nlstat = 280; +pub const SYS_preadv = 289; +pub const SYS_pwritev = 290; +// 297 is freebsd4 fhstatfs +pub const SYS_fhopen = 298; +pub const SYS_freebsd11_fhstat = 299; +pub const SYS_modnext = 300; +pub const SYS_modstat = 301; +pub const SYS_modfnext = 302; +pub const SYS_modfind = 303; +pub const SYS_kldload = 304; +pub const SYS_kldunload = 305; +pub const SYS_kldfind = 306; +pub const SYS_kldnext = 307; +pub const SYS_kldstat = 308; +pub const SYS_kldfirstmod = 309; +pub const SYS_getsid = 310; +pub const SYS_setresuid = 311; +pub const SYS_setresgid = 312; +// 313 is obsolete signanosleep +pub const SYS_aio_return = 314; +pub const SYS_aio_suspend = 315; +pub const SYS_aio_cancel = 316; +pub const SYS_aio_error = 317; +// 318 is freebsd6 aio_read +// 319 is freebsd6 aio_write +// 320 is freebsd6 lio_listio +pub const SYS_yield = 321; +// 322 is obsolete thr_sleep +// 323 is obsolete thr_wakeup +pub const SYS_mlockall = 324; +pub const SYS_munlockall = 325; +pub const SYS___getcwd = 326; +pub const SYS_sched_setparam = 327; +pub const SYS_sched_getparam = 328; +pub const SYS_sched_setscheduler = 329; +pub const SYS_sched_getscheduler = 330; +pub const SYS_sched_yield = 331; +pub const SYS_sched_get_priority_max = 332; +pub const SYS_sched_get_priority_min = 333; +pub const SYS_sched_rr_get_interval = 334; +pub const SYS_utrace = 335; +// 336 is freebsd4 sendfile +pub const SYS_kldsym = 337; +pub const SYS_jail = 338; +pub const SYS_nnpfs_syscall = 339; +pub const SYS_sigprocmask = 340; +pub const SYS_sigsuspend = 341; +// 342 is freebsd4 sigaction +pub const SYS_sigpending = 343; +// 344 is freebsd4 sigreturn +pub const SYS_sigtimedwait = 345; +pub const SYS_sigwaitinfo = 346; +pub const SYS___acl_get_file = 347; +pub const SYS___acl_set_file = 348; +pub const SYS___acl_get_fd = 349; +pub const SYS___acl_set_fd = 350; +pub const SYS___acl_delete_file = 351; +pub const SYS___acl_delete_fd = 352; +pub const SYS___acl_aclcheck_file = 353; +pub const SYS___acl_aclcheck_fd = 354; +pub const SYS_extattrctl = 355; +pub const SYS_extattr_set_file = 356; +pub const SYS_extattr_get_file = 357; +pub const SYS_extattr_delete_file = 358; +pub const SYS_aio_waitcomplete = 359; +pub const SYS_getresuid = 360; +pub const SYS_getresgid = 361; +pub const SYS_kqueue = 362; +pub const SYS_freebsd11_kevent = 363; +// 364 is obsolete __cap_get_proc +// 365 is obsolete __cap_set_proc +// 366 is obsolete __cap_get_fd +// 367 is obsolete __cap_get_file +// 368 is obsolete __cap_set_fd +// 369 is obsolete __cap_set_file +pub const SYS_extattr_set_fd = 371; +pub const SYS_extattr_get_fd = 372; +pub const SYS_extattr_delete_fd = 373; +pub const SYS___setugid = 374; +pub const SYS_eaccess = 376; +pub const SYS_afs3_syscall = 377; +pub const SYS_nmount = 378; +// 379 is obsolete kse_exit +// 380 is obsolete kse_wakeup +// 381 is obsolete kse_create +// 382 is obsolete kse_thr_interrupt +// 383 is obsolete kse_release +pub const SYS___mac_get_proc = 384; +pub const SYS___mac_set_proc = 385; +pub const SYS___mac_get_fd = 386; +pub const SYS___mac_get_file = 387; +pub const SYS___mac_set_fd = 388; +pub const SYS___mac_set_file = 389; +pub const SYS_kenv = 390; +pub const SYS_lchflags = 391; +pub const SYS_uuidgen = 392; +pub const SYS_sendfile = 393; +pub const SYS_mac_syscall = 394; +pub const SYS_freebsd11_getfsstat = 395; +pub const SYS_freebsd11_statfs = 396; +pub const SYS_freebsd11_fstatfs = 397; +pub const SYS_freebsd11_fhstatfs = 398; +pub const SYS_ksem_close = 400; +pub const SYS_ksem_post = 401; +pub const SYS_ksem_wait = 402; +pub const SYS_ksem_trywait = 403; +pub const SYS_ksem_init = 404; +pub const SYS_ksem_open = 405; +pub const SYS_ksem_unlink = 406; +pub const SYS_ksem_getvalue = 407; +pub const SYS_ksem_destroy = 408; +pub const SYS___mac_get_pid = 409; +pub const SYS___mac_get_link = 410; +pub const SYS___mac_set_link = 411; +pub const SYS_extattr_set_link = 412; +pub const SYS_extattr_get_link = 413; +pub const SYS_extattr_delete_link = 414; +pub const SYS___mac_execve = 415; +pub const SYS_sigaction = 416; +pub const SYS_sigreturn = 417; +pub const SYS_getcontext = 421; +pub const SYS_setcontext = 422; +pub const SYS_swapcontext = 423; +pub const SYS_swapoff = 424; +pub const SYS___acl_get_link = 425; +pub const SYS___acl_set_link = 426; +pub const SYS___acl_delete_link = 427; +pub const SYS___acl_aclcheck_link = 428; +pub const SYS_sigwait = 429; +pub const SYS_thr_create = 430; +pub const SYS_thr_exit = 431; +pub const SYS_thr_self = 432; +pub const SYS_thr_kill = 433; +pub const SYS_jail_attach = 436; +pub const SYS_extattr_list_fd = 437; +pub const SYS_extattr_list_file = 438; +pub const SYS_extattr_list_link = 439; +// 440 is obsolete kse_switchin +pub const SYS_ksem_timedwait = 441; +pub const SYS_thr_suspend = 442; +pub const SYS_thr_wake = 443; +pub const SYS_kldunloadf = 444; +pub const SYS_audit = 445; +pub const SYS_auditon = 446; +pub const SYS_getauid = 447; +pub const SYS_setauid = 448; +pub const SYS_getaudit = 449; +pub const SYS_setaudit = 450; +pub const SYS_getaudit_addr = 451; +pub const SYS_setaudit_addr = 452; +pub const SYS_auditctl = 453; +pub const SYS__umtx_op = 454; +pub const SYS_thr_new = 455; +pub const SYS_sigqueue = 456; +pub const SYS_kmq_open = 457; +pub const SYS_kmq_setattr = 458; +pub const SYS_kmq_timedreceive = 459; +pub const SYS_kmq_timedsend = 460; +pub const SYS_kmq_notify = 461; +pub const SYS_kmq_unlink = 462; +pub const SYS_abort2 = 463; +pub const SYS_thr_set_name = 464; +pub const SYS_aio_fsync = 465; +pub const SYS_rtprio_thread = 466; +pub const SYS_sctp_peeloff = 471; +pub const SYS_sctp_generic_sendmsg = 472; +pub const SYS_sctp_generic_sendmsg_iov = 473; +pub const SYS_sctp_generic_recvmsg = 474; +pub const SYS_pread = 475; +pub const SYS_pwrite = 476; +pub const SYS_mmap = 477; +pub const SYS_lseek = 478; +pub const SYS_truncate = 479; +pub const SYS_ftruncate = 480; +pub const SYS_thr_kill2 = 481; +pub const SYS_shm_open = 482; +pub const SYS_shm_unlink = 483; +pub const SYS_cpuset = 484; +pub const SYS_cpuset_setid = 485; +pub const SYS_cpuset_getid = 486; +pub const SYS_cpuset_getaffinity = 487; +pub const SYS_cpuset_setaffinity = 488; +pub const SYS_faccessat = 489; +pub const SYS_fchmodat = 490; +pub const SYS_fchownat = 491; +pub const SYS_fexecve = 492; +pub const SYS_freebsd11_fstatat = 493; +pub const SYS_futimesat = 494; +pub const SYS_linkat = 495; +pub const SYS_mkdirat = 496; +pub const SYS_mkfifoat = 497; +pub const SYS_freebsd11_mknodat = 498; +pub const SYS_openat = 499; +pub const SYS_readlinkat = 500; +pub const SYS_renameat = 501; +pub const SYS_symlinkat = 502; +pub const SYS_unlinkat = 503; +pub const SYS_posix_openpt = 504; +pub const SYS_gssd_syscall = 505; +pub const SYS_jail_get = 506; +pub const SYS_jail_set = 507; +pub const SYS_jail_remove = 508; +pub const SYS_closefrom = 509; +pub const SYS___semctl = 510; +pub const SYS_msgctl = 511; +pub const SYS_shmctl = 512; +pub const SYS_lpathconf = 513; +// 514 is obsolete cap_new +pub const SYS___cap_rights_get = 515; +pub const SYS_cap_enter = 516; +pub const SYS_cap_getmode = 517; +pub const SYS_pdfork = 518; +pub const SYS_pdkill = 519; +pub const SYS_pdgetpid = 520; +pub const SYS_pselect = 522; +pub const SYS_getloginclass = 523; +pub const SYS_setloginclass = 524; +pub const SYS_rctl_get_racct = 525; +pub const SYS_rctl_get_rules = 526; +pub const SYS_rctl_get_limits = 527; +pub const SYS_rctl_add_rule = 528; +pub const SYS_rctl_remove_rule = 529; +pub const SYS_posix_fallocate = 530; +pub const SYS_posix_fadvise = 531; +pub const SYS_wait6 = 532; +pub const SYS_cap_rights_limit = 533; +pub const SYS_cap_ioctls_limit = 534; +pub const SYS_cap_ioctls_get = 535; +pub const SYS_cap_fcntls_limit = 536; +pub const SYS_cap_fcntls_get = 537; +pub const SYS_bindat = 538; +pub const SYS_connectat = 539; +pub const SYS_chflagsat = 540; +pub const SYS_accept4 = 541; +pub const SYS_pipe2 = 542; +pub const SYS_aio_mlock = 543; +pub const SYS_procctl = 544; +pub const SYS_ppoll = 545; +pub const SYS_futimens = 546; +pub const SYS_utimensat = 547; +// 548 is obsolete numa_getaffinity +// 549 is obsolete numa_setaffinity +pub const SYS_fdatasync = 550; +pub const SYS_fstat = 551; +pub const SYS_fstatat = 552; +pub const SYS_fhstat = 553; +pub const SYS_getdirentries = 554; +pub const SYS_statfs = 555; +pub const SYS_fstatfs = 556; +pub const SYS_getfsstat = 557; +pub const SYS_fhstatfs = 558; +pub const SYS_mknodat = 559; +pub const SYS_kevent = 560; +pub const SYS_cpuset_getdomain = 561; +pub const SYS_cpuset_setdomain = 562; +pub const SYS_getrandom = 563; +pub const SYS_MAXSYSCALL = 564; diff --git a/std/os/freebsd/x86_64.zig b/std/os/freebsd/x86_64.zig index cd9104b88a..63255a902a 100644 --- a/std/os/freebsd/x86_64.zig +++ b/std/os/freebsd/x86_64.zig @@ -2,481 +2,7 @@ const freebsd = @import("index.zig"); const socklen_t = freebsd.socklen_t; const iovec = freebsd.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_wait4 = 7; -// 8 is old creat -pub const SYS_link = 9; -pub const SYS_unlink = 10; -// 11 is obsolete execv -pub const SYS_chdir = 12; -pub const SYS_fchdir = 13; -pub const SYS_freebsd11_mknod = 14; -pub const SYS_chmod = 15; -pub const SYS_chown = 16; -pub const SYS_break = 17; -// 18 is freebsd4 getfsstat -// 19 is old lseek -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_kill = 37; -// 38 is old stat -pub const SYS_getppid = 39; -// 40 is old lstat -pub const SYS_dup = 41; -pub const SYS_freebsd10_pipe = 42; -pub const SYS_getegid = 43; -pub const SYS_profil = 44; -pub const SYS_ktrace = 45; -// 46 is old sigaction -pub const SYS_getgid = 47; -// 48 is old sigprocmask -pub const SYS_getlogin = 49; -pub const SYS_setlogin = 50; -pub const SYS_acct = 51; -// 52 is old sigpending -pub const SYS_sigaltstack = 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; -// 62 is old fstat -// 63 is old getkerninfo -// 64 is old getpagesize -pub const SYS_msync = 65; -pub const SYS_vfork = 66; -// 67 is obsolete vread -// 68 is obsolete vwrite pub const SYS_sbrk = 69; -pub const SYS_sstk = 70; -// 71 is old mmap -pub const SYS_vadvise = 72; -pub const SYS_munmap = 73; -pub const SYS_mprotect = 74; -pub const SYS_madvise = 75; -// 76 is obsolete vhangup -// 77 is obsolete vlimit -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_setitimer = 83; -// 84 is old wait -pub const SYS_swapon = 85; -pub const SYS_getitimer = 86; -// 87 is old gethostname -// 88 is old sethostname -pub const SYS_getdtablesize = 89; -pub const SYS_dup2 = 90; -pub const SYS_fcntl = 92; -pub const SYS_select = 93; -pub const SYS_fsync = 95; -pub const SYS_setpriority = 96; -pub const SYS_socket = 97; -pub const SYS_connect = 98; -// 99 is old accept -pub const SYS_getpriority = 100; -// 101 is old send -// 102 is old recv -// 103 is old sigreturn -pub const SYS_bind = 104; -pub const SYS_setsockopt = 105; -pub const SYS_listen = 106; -// 107 is obsolete vtimes -// 108 is old sigvec -// 109 is old sigblock -// 110 is old sigsetmask -// 111 is old sigsuspend -// 112 is old sigstack -// 113 is old recvmsg -// 114 is old sendmsg -// 115 is obsolete vtrace -pub const SYS_gettimeofday = 116; -pub const SYS_getrusage = 117; -pub const SYS_getsockopt = 118; -pub const SYS_readv = 120; -pub const SYS_writev = 121; -pub const SYS_settimeofday = 122; -pub const SYS_fchown = 123; -pub const SYS_fchmod = 124; -// 125 is old recvfrom -pub const SYS_setreuid = 126; -pub const SYS_setregid = 127; -pub const SYS_rename = 128; -// 129 is old truncate -// 130 is old ftruncate -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_utimes = 138; -// 139 is obsolete 4.2 sigreturn -pub const SYS_adjtime = 140; -// 141 is old getpeername -// 142 is old gethostid -// 143 is old sethostid -// 144 is old getrlimit -// 145 is old setrlimit -// 146 is old killpg -pub const SYS_setsid = 147; -pub const SYS_quotactl = 148; -// 149 is old quota -// 150 is old getsockname -pub const SYS_nlm_syscall = 154; -pub const SYS_nfssvc = 155; -// 156 is old getdirentries -// 157 is freebsd4 statfs -// 158 is freebsd4 fstatfs -pub const SYS_lgetfh = 160; -pub const SYS_getfh = 161; -// 162 is freebsd4 getdomainname -// 163 is freebsd4 setdomainname -// 164 is freebsd4 uname -pub const SYS_sysarch = 165; -pub const SYS_rtprio = 166; -pub const SYS_semsys = 169; -pub const SYS_msgsys = 170; -pub const SYS_shmsys = 171; -// 173 is freebsd6 pread -// 174 is freebsd6 pwrite -pub const SYS_setfib = 175; -pub const SYS_ntp_adjtime = 176; -pub const SYS_setgid = 181; -pub const SYS_setegid = 182; -pub const SYS_seteuid = 183; -pub const SYS_freebsd11_stat = 188; -pub const SYS_freebsd11_fstat = 189; -pub const SYS_freebsd11_lstat = 190; -pub const SYS_pathconf = 191; -pub const SYS_fpathconf = 192; -pub const SYS_getrlimit = 194; -pub const SYS_setrlimit = 195; -pub const SYS_freebsd11_getdirentries = 196; -// 197 is freebsd6 mmap -pub const SYS___syscall = 198; -// 199 is freebsd6 lseek -// 200 is freebsd6 truncate -// 201 is freebsd6 ftruncate -pub const SYS___sysctl = 202; -pub const SYS_mlock = 203; -pub const SYS_munlock = 204; -pub const SYS_undelete = 205; -pub const SYS_futimes = 206; -pub const SYS_getpgid = 207; -pub const SYS_poll = 209; -pub const SYS_freebsd7___semctl = 220; -pub const SYS_semget = 221; -pub const SYS_semop = 222; -pub const SYS_freebsd7_msgctl = 224; -pub const SYS_msgget = 225; -pub const SYS_msgsnd = 226; -pub const SYS_msgrcv = 227; -pub const SYS_shmat = 228; -pub const SYS_freebsd7_shmctl = 229; -pub const SYS_shmdt = 230; -pub const SYS_shmget = 231; -pub const SYS_clock_gettime = 232; -pub const SYS_clock_settime = 233; -pub const SYS_clock_getres = 234; -pub const SYS_ktimer_create = 235; -pub const SYS_ktimer_delete = 236; -pub const SYS_ktimer_settime = 237; -pub const SYS_ktimer_gettime = 238; -pub const SYS_ktimer_getoverrun = 239; -pub const SYS_nanosleep = 240; -pub const SYS_ffclock_getcounter = 241; -pub const SYS_ffclock_setestimate = 242; -pub const SYS_ffclock_getestimate = 243; -pub const SYS_clock_nanosleep = 244; -pub const SYS_clock_getcpuclockid2 = 247; -pub const SYS_ntp_gettime = 248; -pub const SYS_minherit = 250; -pub const SYS_rfork = 251; -// 252 is obsolete openbsd_poll -pub const SYS_issetugid = 253; -pub const SYS_lchown = 254; -pub const SYS_aio_read = 255; -pub const SYS_aio_write = 256; -pub const SYS_lio_listio = 257; -pub const SYS_freebsd11_getdents = 272; -pub const SYS_lchmod = 274; -pub const SYS_netbsd_lchown = 275; -pub const SYS_lutimes = 276; -pub const SYS_netbsd_msync = 277; -pub const SYS_freebsd11_nstat = 278; -pub const SYS_freebsd11_nfstat = 279; -pub const SYS_freebsd11_nlstat = 280; -pub const SYS_preadv = 289; -pub const SYS_pwritev = 290; -// 297 is freebsd4 fhstatfs -pub const SYS_fhopen = 298; -pub const SYS_freebsd11_fhstat = 299; -pub const SYS_modnext = 300; -pub const SYS_modstat = 301; -pub const SYS_modfnext = 302; -pub const SYS_modfind = 303; -pub const SYS_kldload = 304; -pub const SYS_kldunload = 305; -pub const SYS_kldfind = 306; -pub const SYS_kldnext = 307; -pub const SYS_kldstat = 308; -pub const SYS_kldfirstmod = 309; -pub const SYS_getsid = 310; -pub const SYS_setresuid = 311; -pub const SYS_setresgid = 312; -// 313 is obsolete signanosleep -pub const SYS_aio_return = 314; -pub const SYS_aio_suspend = 315; -pub const SYS_aio_cancel = 316; -pub const SYS_aio_error = 317; -// 318 is freebsd6 aio_read -// 319 is freebsd6 aio_write -// 320 is freebsd6 lio_listio -pub const SYS_yield = 321; -// 322 is obsolete thr_sleep -// 323 is obsolete thr_wakeup -pub const SYS_mlockall = 324; -pub const SYS_munlockall = 325; -pub const SYS___getcwd = 326; -pub const SYS_sched_setparam = 327; -pub const SYS_sched_getparam = 328; -pub const SYS_sched_setscheduler = 329; -pub const SYS_sched_getscheduler = 330; -pub const SYS_sched_yield = 331; -pub const SYS_sched_get_priority_max = 332; -pub const SYS_sched_get_priority_min = 333; -pub const SYS_sched_rr_get_interval = 334; -pub const SYS_utrace = 335; -// 336 is freebsd4 sendfile -pub const SYS_kldsym = 337; -pub const SYS_jail = 338; -pub const SYS_nnpfs_syscall = 339; -pub const SYS_sigprocmask = 340; -pub const SYS_sigsuspend = 341; -// 342 is freebsd4 sigaction -pub const SYS_sigpending = 343; -// 344 is freebsd4 sigreturn -pub const SYS_sigtimedwait = 345; -pub const SYS_sigwaitinfo = 346; -pub const SYS___acl_get_file = 347; -pub const SYS___acl_set_file = 348; -pub const SYS___acl_get_fd = 349; -pub const SYS___acl_set_fd = 350; -pub const SYS___acl_delete_file = 351; -pub const SYS___acl_delete_fd = 352; -pub const SYS___acl_aclcheck_file = 353; -pub const SYS___acl_aclcheck_fd = 354; -pub const SYS_extattrctl = 355; -pub const SYS_extattr_set_file = 356; -pub const SYS_extattr_get_file = 357; -pub const SYS_extattr_delete_file = 358; -pub const SYS_aio_waitcomplete = 359; -pub const SYS_getresuid = 360; -pub const SYS_getresgid = 361; -pub const SYS_kqueue = 362; -pub const SYS_freebsd11_kevent = 363; -pub const SYS_extattr_set_fd = 371; -pub const SYS_extattr_get_fd = 372; -pub const SYS_extattr_delete_fd = 373; -pub const SYS___setugid = 374; -pub const SYS_eaccess = 376; -pub const SYS_afs3_syscall = 377; -pub const SYS_nmount = 378; -pub const SYS___mac_get_proc = 384; -pub const SYS___mac_set_proc = 385; -pub const SYS___mac_get_fd = 386; -pub const SYS___mac_get_file = 387; -pub const SYS___mac_set_fd = 388; -pub const SYS___mac_set_file = 389; -pub const SYS_kenv = 390; -pub const SYS_lchflags = 391; -pub const SYS_uuidgen = 392; -pub const SYS_sendfile = 393; -pub const SYS_mac_syscall = 394; -pub const SYS_freebsd11_getfsstat = 395; -pub const SYS_freebsd11_statfs = 396; -pub const SYS_freebsd11_fstatfs = 397; -pub const SYS_freebsd11_fhstatfs = 398; -pub const SYS_ksem_close = 400; -pub const SYS_ksem_post = 401; -pub const SYS_ksem_wait = 402; -pub const SYS_ksem_trywait = 403; -pub const SYS_ksem_init = 404; -pub const SYS_ksem_open = 405; -pub const SYS_ksem_unlink = 406; -pub const SYS_ksem_getvalue = 407; -pub const SYS_ksem_destroy = 408; -pub const SYS___mac_get_pid = 409; -pub const SYS___mac_get_link = 410; -pub const SYS___mac_set_link = 411; -pub const SYS_extattr_set_link = 412; -pub const SYS_extattr_get_link = 413; -pub const SYS_extattr_delete_link = 414; -pub const SYS___mac_execve = 415; -pub const SYS_sigaction = 416; -pub const SYS_sigreturn = 417; -pub const SYS_getcontext = 421; -pub const SYS_setcontext = 422; -pub const SYS_swapcontext = 423; -pub const SYS_swapoff = 424; -pub const SYS___acl_get_link = 425; -pub const SYS___acl_set_link = 426; -pub const SYS___acl_delete_link = 427; -pub const SYS___acl_aclcheck_link = 428; -pub const SYS_sigwait = 429; -pub const SYS_thr_create = 430; -pub const SYS_thr_exit = 431; -pub const SYS_thr_self = 432; -pub const SYS_thr_kill = 433; -pub const SYS_jail_attach = 436; -pub const SYS_extattr_list_fd = 437; -pub const SYS_extattr_list_file = 438; -pub const SYS_extattr_list_link = 439; -pub const SYS_ksem_timedwait = 441; -pub const SYS_thr_suspend = 442; -pub const SYS_thr_wake = 443; -pub const SYS_kldunloadf = 444; -pub const SYS_audit = 445; -pub const SYS_auditon = 446; -pub const SYS_getauid = 447; -pub const SYS_setauid = 448; -pub const SYS_getaudit = 449; -pub const SYS_setaudit = 450; -pub const SYS_getaudit_addr = 451; -pub const SYS_setaudit_addr = 452; -pub const SYS_auditctl = 453; -pub const SYS__umtx_op = 454; -pub const SYS_thr_new = 455; -pub const SYS_sigqueue = 456; -pub const SYS_kmq_open = 457; -pub const SYS_kmq_setattr = 458; -pub const SYS_kmq_timedreceive = 459; -pub const SYS_kmq_timedsend = 460; -pub const SYS_kmq_notify = 461; -pub const SYS_kmq_unlink = 462; -pub const SYS_abort2 = 463; -pub const SYS_thr_set_name = 464; -pub const SYS_aio_fsync = 465; -pub const SYS_rtprio_thread = 466; -pub const SYS_sctp_peeloff = 471; -pub const SYS_sctp_generic_sendmsg = 472; -pub const SYS_sctp_generic_sendmsg_iov = 473; -pub const SYS_sctp_generic_recvmsg = 474; -pub const SYS_pread = 475; -pub const SYS_pwrite = 476; -pub const SYS_mmap = 477; -pub const SYS_lseek = 478; -pub const SYS_truncate = 479; -pub const SYS_ftruncate = 480; -pub const SYS_thr_kill2 = 481; -pub const SYS_shm_open = 482; -pub const SYS_shm_unlink = 483; -pub const SYS_cpuset = 484; -pub const SYS_cpuset_setid = 485; -pub const SYS_cpuset_getid = 486; -pub const SYS_cpuset_getaffinity = 487; -pub const SYS_cpuset_setaffinity = 488; -pub const SYS_faccessat = 489; -pub const SYS_fchmodat = 490; -pub const SYS_fchownat = 491; -pub const SYS_fexecve = 492; -pub const SYS_freebsd11_fstatat = 493; -pub const SYS_futimesat = 494; -pub const SYS_linkat = 495; -pub const SYS_mkdirat = 496; -pub const SYS_mkfifoat = 497; -pub const SYS_freebsd11_mknodat = 498; -pub const SYS_openat = 499; -pub const SYS_readlinkat = 500; -pub const SYS_renameat = 501; -pub const SYS_symlinkat = 502; -pub const SYS_unlinkat = 503; -pub const SYS_posix_openpt = 504; -pub const SYS_gssd_syscall = 505; -pub const SYS_jail_get = 506; -pub const SYS_jail_set = 507; -pub const SYS_jail_remove = 508; -pub const SYS_closefrom = 509; -pub const SYS___semctl = 510; -pub const SYS_msgctl = 511; -pub const SYS_shmctl = 512; -pub const SYS_lpathconf = 513; -// 514 is obsolete cap_new -pub const SYS___cap_rights_get = 515; -pub const SYS_cap_enter = 516; -pub const SYS_cap_getmode = 517; -pub const SYS_pdfork = 518; -pub const SYS_pdkill = 519; -pub const SYS_pdgetpid = 520; -pub const SYS_pselect = 522; -pub const SYS_getloginclass = 523; -pub const SYS_setloginclass = 524; -pub const SYS_rctl_get_racct = 525; -pub const SYS_rctl_get_rules = 526; -pub const SYS_rctl_get_limits = 527; -pub const SYS_rctl_add_rule = 528; -pub const SYS_rctl_remove_rule = 529; -pub const SYS_posix_fallocate = 530; -pub const SYS_posix_fadvise = 531; -pub const SYS_wait6 = 532; -pub const SYS_cap_rights_limit = 533; -pub const SYS_cap_ioctls_limit = 534; -pub const SYS_cap_ioctls_get = 535; -pub const SYS_cap_fcntls_limit = 536; -pub const SYS_cap_fcntls_get = 537; -pub const SYS_bindat = 538; -pub const SYS_connectat = 539; -pub const SYS_chflagsat = 540; -pub const SYS_accept4 = 541; -pub const SYS_pipe2 = 542; -pub const SYS_aio_mlock = 543; -pub const SYS_procctl = 544; -pub const SYS_ppoll = 545; -pub const SYS_futimens = 546; -pub const SYS_utimensat = 547; -pub const SYS_numa_getaffinity = 548; -pub const SYS_numa_setaffinity = 549; -pub const SYS_fdatasync = 550; -pub const SYS_fstat = 551; -pub const SYS_fstatat = 552; -pub const SYS_fhstat = 553; -pub const SYS_getdirentries = 554; -pub const SYS_statfs = 555; -pub const SYS_fstatfs = 556; -pub const SYS_getfsstat = 557; -pub const SYS_fhstatfs = 558; -pub const SYS_mknodat = 559; -pub const SYS_kevent = 560; -pub const SYS_MAXSYSCALL = 561; -pub const SYS_getrandom = 563; pub const O_CREAT = 0o100; pub const O_EXCL = 0o200; -- cgit v1.2.3 From d6cab0d4b653b1f6d7340b9a24766abae4f208a8 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 18:12:53 +0300 Subject: Various fcntl flags are also machine-independent on FreeBSD --- std/os/freebsd/index.zig | 60 +++++++++++++++++++++++++++++++---------------- std/os/freebsd/x86_64.zig | 41 -------------------------------- 2 files changed, 40 insertions(+), 61 deletions(-) diff --git a/std/os/freebsd/index.zig b/std/os/freebsd/index.zig index c442dd6659..1df773b04b 100644 --- a/std/os/freebsd/index.zig +++ b/std/os/freebsd/index.zig @@ -95,26 +95,46 @@ pub const O_WRONLY = 0o1; pub const O_RDWR = 0o2; pub const O_ACCMODE = 0o3; -pub const O_CREAT = arch.O_CREAT; -pub const O_EXCL = arch.O_EXCL; -pub const O_NOCTTY = arch.O_NOCTTY; -pub const O_TRUNC = arch.O_TRUNC; -pub const O_APPEND = arch.O_APPEND; -pub const O_NONBLOCK = arch.O_NONBLOCK; -pub const O_DSYNC = arch.O_DSYNC; -pub const O_SYNC = arch.O_SYNC; -pub const O_RSYNC = arch.O_RSYNC; -pub const O_DIRECTORY = arch.O_DIRECTORY; -pub const O_NOFOLLOW = arch.O_NOFOLLOW; -pub const O_CLOEXEC = arch.O_CLOEXEC; - -pub const O_ASYNC = arch.O_ASYNC; -pub const O_DIRECT = arch.O_DIRECT; -pub const O_LARGEFILE = arch.O_LARGEFILE; -pub const O_NOATIME = arch.O_NOATIME; -pub const O_PATH = arch.O_PATH; -pub const O_TMPFILE = arch.O_TMPFILE; -pub const O_NDELAY = arch.O_NDELAY; +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o200000; +pub const O_NOFOLLOW = 0o400000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o40000; +pub const O_LARGEFILE = 0; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20200000; +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_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 5; +pub const F_SETLK = 6; +pub const F_SETLKW = 7; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; pub const SEEK_SET = 0; pub const SEEK_CUR = 1; diff --git a/std/os/freebsd/x86_64.zig b/std/os/freebsd/x86_64.zig index 63255a902a..28ae2d5471 100644 --- a/std/os/freebsd/x86_64.zig +++ b/std/os/freebsd/x86_64.zig @@ -4,47 +4,6 @@ const iovec = freebsd.iovec; pub const SYS_sbrk = 69; -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0o200000; -pub const O_NOFOLLOW = 0o400000; -pub const O_CLOEXEC = 0o2000000; - -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o40000; -pub const O_LARGEFILE = 0; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -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_SETOWN = 8; -pub const F_GETOWN = 9; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; - -pub const F_GETLK = 5; -pub const F_SETLK = 6; -pub const F_SETLKW = 7; - -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - pub fn syscall0(number: usize) usize { return asm volatile ("syscall" : [ret] "={rax}" (-> usize) -- cgit v1.2.3 From a983a0a59b348a885f24656a8646707554170574 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 22:18:50 +0300 Subject: Add /usr/local/lib path for libxml2 and link libc++ on FreeBSD --- build.zig | 6 +++++- std/build.zig | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index c2a20015a7..fc460df129 100644 --- a/build.zig +++ b/build.zig @@ -284,7 +284,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void { exe.addObjectFile(libstdcxx_path); exe.linkSystemLibrary("pthread"); - } else if (exe.target.isDarwin()) { + } else if (exe.target.isDarwin() or exe.target.isFreeBSD()) { exe.linkSystemLibrary("c++"); } @@ -293,6 +293,10 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void { } if (exe.target.getOs() != builtin.Os.windows) { + if (exe.target.isFreeBSD()) { + exe.addLibPath("/usr/local/lib"); + // TODO use pkg-config + } exe.linkSystemLibrary("xml2"); } exe.linkSystemLibrary("c"); diff --git a/std/build.zig b/std/build.zig index a80580a383..743535eb10 100644 --- a/std/build.zig +++ b/std/build.zig @@ -795,6 +795,13 @@ pub const Target = union(enum).{ }; } + pub fn isFreeBSD(self: *const Target) bool { + return switch (self.getOs()) { + builtin.Os.freebsd => true, + else => false, + }; + } + pub fn wantSharedLibSymLinks(self: *const Target) bool { return !self.isWindows(); } -- cgit v1.2.3 From 831bb668955fa9d332f7beb1ea11f1c8028e5235 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 22:21:16 +0300 Subject: Set up libc/rtld paths for FreeBSD --- src-self-hosted/libc_installation.zig | 2 +- src-self-hosted/target.zig | 9 ++++++++- src/analyze.cpp | 6 +++++- src/link.cpp | 3 +++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src-self-hosted/libc_installation.zig b/src-self-hosted/libc_installation.zig index daab058223..86672a2b95 100644 --- a/src-self-hosted/libc_installation.zig +++ b/src-self-hosted/libc_installation.zig @@ -172,7 +172,7 @@ pub const LibCInstallation = struct.{ try group.call(findNativeStaticLibDir, self, loop); try group.call(findNativeDynamicLinker, self, loop); }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include"); }, else => @compileError("unimplemented: find libc for this OS"), diff --git a/src-self-hosted/target.zig b/src-self-hosted/target.zig index 44c98e79bf..0b6842490d 100644 --- a/src-self-hosted/target.zig +++ b/src-self-hosted/target.zig @@ -299,6 +299,13 @@ pub const Target = union(enum).{ pub fn getDynamicLinkerPath(self: Target) ?[]const u8 { const env = self.getEnviron(); const arch = self.getArch(); + const os = self.getOs(); + switch (os) { + builtin.Os.freebsd => { + return "/libexec/ld-elf.so.1"; + }, + else => {}, + } switch (env) { builtin.Environ.android => { if (self.is64bit()) { @@ -493,6 +500,7 @@ pub const Target = union(enum).{ builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, builtin.Os.openbsd, builtin.Os.zen, => switch (id) { @@ -527,7 +535,6 @@ pub const Target = union(enum).{ builtin.Os.ananas, builtin.Os.cloudabi, builtin.Os.dragonfly, - builtin.Os.freebsd, builtin.Os.fuchsia, builtin.Os.ios, builtin.Os.kfreebsd, diff --git a/src/analyze.cpp b/src/analyze.cpp index e71369eac9..4d7fe1a656 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4606,7 +4606,7 @@ void find_libc_include_path(CodeGen *g) { } } else if (g->zig_target.os == OsLinux) { g->libc_include_dir = get_linux_libc_include_path(); - } else if (g->zig_target.os == OsMacOSX) { + } else if (g->zig_target.os == OsMacOSX || g->zig_target.os == OsFreeBSD) { g->libc_include_dir = buf_create_from_str("/usr/include"); } else { // TODO find libc at runtime for other operating systems @@ -4652,6 +4652,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 == OsFreeBSD) { + g->libc_lib_dir = buf_create_from_str("/usr/lib"); } else { zig_panic("Unable to determine libc lib path."); } @@ -4664,6 +4666,8 @@ void find_libc_lib_path(CodeGen *g) { return; } else if (g->zig_target.os == OsLinux) { g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o"); + } else if (g->zig_target.os == OsFreeBSD) { + g->libc_static_lib_dir = buf_create_from_str("/usr/lib"); } else { zig_panic("Unable to determine libc static lib path."); } diff --git a/src/link.cpp b/src/link.cpp index 613768cec8..0913b96a01 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -195,6 +195,9 @@ static Buf *try_dynamic_linker_path(const char *ld_name) { } static Buf *get_dynamic_linker_path(CodeGen *g) { + if (g->zig_target.os == OsFreeBSD) { + return buf_create_from_str("/libexec/ld-elf.so.1"); + } if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) { static const char *ld_names[] = { "ld-linux-x86-64.so.2", -- cgit v1.2.3 From e5627f8e635c05a91edeb97b6d0e392d095ce39f Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 22:21:48 +0300 Subject: Support more of std on FreeBSD --- CMakeLists.txt | 1 + std/c/freebsd.zig | 36 ++++++++ std/c/index.zig | 1 + std/event/fs.zig | 32 ++++--- std/event/loop.zig | 27 +++--- std/os/freebsd/index.zig | 212 +++++++++++++++++++++++++++++++++++++++++++- std/os/get_app_data_dir.zig | 2 +- std/os/index.zig | 34 ++++--- 8 files changed, 308 insertions(+), 37 deletions(-) create mode 100644 std/c/freebsd.zig diff --git a/CMakeLists.txt b/CMakeLists.txt index f10fc91b16..4ee9bcad1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -444,6 +444,7 @@ set(ZIG_STD_FILES "buffer.zig" "build.zig" "c/darwin.zig" + "c/freebsd.zig" "c/index.zig" "c/linux.zig" "c/windows.zig" diff --git a/std/c/freebsd.zig b/std/c/freebsd.zig new file mode 100644 index 0000000000..6eb34929b5 --- /dev/null +++ b/std/c/freebsd.zig @@ -0,0 +1,36 @@ + +const timespec = @import("../os/freebsd/index.zig").timespec; + +extern "c" fn __error() *c_int; +pub const _errno = __error; + +pub extern "c" fn kqueue() c_int; +pub extern "c" fn kevent( + kq: c_int, + changelist: [*]const Kevent, + nchanges: c_int, + eventlist: [*]Kevent, + nevents: c_int, + timeout: ?*const timespec, +) c_int; +pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; +pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; +pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; + +/// Renamed from `kevent` to `Kevent` to avoid conflict with function name. +pub const Kevent = extern struct.{ + ident: usize, + filter: i16, + flags: u16, + fflags: u32, + data: i64, + udata: usize, + // TODO ext +}; + + +pub const pthread_attr_t = extern struct.{ + __size: [56]u8, + __align: c_long, +}; + diff --git a/std/c/index.zig b/std/c/index.zig index 6b20d718ef..4aab39d931 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.freebsd => @import("freebsd.zig"), else => empty_import, }; const empty_import = @import("../empty.zig"); diff --git a/std/event/fs.zig b/std/event/fs.zig index 56eee387b2..b20272dcb0 100644 --- a/std/event/fs.zig +++ b/std/event/fs.zig @@ -83,6 +83,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o switch (builtin.os) { builtin.Os.macosx, builtin.Os.linux, + builtin.Os.freebsd, => { const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); defer loop.allocator.free(iovecs); @@ -219,6 +220,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: switch (builtin.os) { builtin.Os.macosx, builtin.Os.linux, + builtin.Os.freebsd, => { const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); defer loop.allocator.free(iovecs); @@ -399,7 +401,7 @@ pub async fn openPosix( pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle { switch (builtin.os) { - builtin.Os.macosx, builtin.Os.linux => { + builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => { const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC; return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); }, @@ -427,6 +429,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os switch (builtin.os) { builtin.Os.macosx, builtin.Os.linux, + builtin.Os.freebsd, => { const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC; return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); @@ -449,7 +452,7 @@ pub async fn openReadWrite( mode: os.File.Mode, ) os.File.OpenError!os.FileHandle { switch (builtin.os) { - builtin.Os.macosx, builtin.Os.linux => { + builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => { const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC; return await (async openPosix(loop, path, flags, mode) catch unreachable); }, @@ -477,7 +480,7 @@ pub const CloseOperation = struct.{ os_data: OsData, const OsData = switch (builtin.os) { - builtin.Os.linux, builtin.Os.macosx => OsDataPosix, + builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => OsDataPosix, builtin.Os.windows => struct.{ handle: ?os.FileHandle, @@ -496,7 +499,7 @@ pub const CloseOperation = struct.{ self.* = CloseOperation.{ .loop = loop, .os_data = switch (builtin.os) { - builtin.Os.linux, builtin.Os.macosx => initOsDataPosix(self), + builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => initOsDataPosix(self), builtin.Os.windows => OsData.{ .handle = null }, else => @compileError("Unsupported OS"), }, @@ -525,6 +528,7 @@ pub const CloseOperation = struct.{ switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => { if (self.os_data.have_fd) { self.loop.posixFsRequest(&self.os_data.close_req_node); @@ -546,6 +550,7 @@ pub const CloseOperation = struct.{ switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => { self.os_data.close_req_node.data.msg.Close.fd = handle; self.os_data.have_fd = true; @@ -562,6 +567,7 @@ pub const CloseOperation = struct.{ switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => { self.os_data.have_fd = false; }, @@ -576,6 +582,7 @@ pub const CloseOperation = struct.{ switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => { assert(self.os_data.have_fd); return self.os_data.close_req_node.data.msg.Close.fd; @@ -599,6 +606,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable), builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable), else => @compileError("Unsupported OS"), @@ -704,7 +712,7 @@ pub fn Watch(comptime V: type) type { os_data: OsData, const OsData = switch (builtin.os) { - builtin.Os.macosx => struct.{ + builtin.Os.macosx, builtin.Os.freebsd => struct.{ file_table: FileTable, table_lock: event.Lock, @@ -793,7 +801,7 @@ pub fn Watch(comptime V: type) type { return self; }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { const self = try loop.allocator.createOne(Self); errdefer loop.allocator.destroy(self); @@ -813,7 +821,7 @@ pub fn Watch(comptime V: type) type { /// All addFile calls and removeFile calls must have completed. pub fn destroy(self: *Self) void { switch (builtin.os) { - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { // TODO we need to cancel the coroutines before destroying the lock self.os_data.table_lock.deinit(); var it = self.os_data.file_table.iterator(); @@ -855,14 +863,14 @@ pub fn Watch(comptime V: type) type { pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V { switch (builtin.os) { - builtin.Os.macosx => return await (async addFileMacosx(self, file_path, value) catch unreachable), + builtin.Os.macosx, builtin.Os.freebsd => return await (async addFileKEvent(self, file_path, value) catch unreachable), builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable), builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable), else => @compileError("Unsupported OS"), } } - async fn addFileMacosx(self: *Self, file_path: []const u8, value: V) !?V { + async fn addFileKEvent(self: *Self, file_path: []const u8, value: V) !?V { const resolved_path = try os.path.resolve(self.channel.loop.allocator, file_path); var resolved_path_consumed = false; defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path); @@ -871,7 +879,11 @@ pub fn Watch(comptime V: type) type { var close_op_consumed = false; defer if (!close_op_consumed) close_op.finish(); - const flags = posix.O_SYMLINK | posix.O_EVTONLY; + + const flags = switch (builtin.os) { + builtin.Os.macosx => posix.O_SYMLINK | posix.O_EVTONLY, + else => 0, + }; const mode = 0; const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable); close_op.setHandle(fd); diff --git a/std/event/loop.zig b/std/event/loop.zig index 73d1d8975f..68c22f38b9 100644 --- a/std/event/loop.zig +++ b/std/event/loop.zig @@ -48,7 +48,7 @@ pub const Loop = struct.{ }; pub const EventFd = switch (builtin.os) { - builtin.Os.macosx => MacOsEventFd, + builtin.Os.macosx, builtin.Os.freebsd => KEventFd, builtin.Os.linux => struct.{ base: ResumeNode, epoll_op: u32, @@ -61,13 +61,13 @@ pub const Loop = struct.{ else => @compileError("unsupported OS"), }; - const MacOsEventFd = struct.{ + const KEventFd = struct.{ base: ResumeNode, kevent: posix.Kevent, }; pub const Basic = switch (builtin.os) { - builtin.Os.macosx => MacOsBasic, + builtin.Os.macosx, builtin.Os.freebsd => KEventBasic, builtin.Os.linux => struct.{ base: ResumeNode, }, @@ -77,7 +77,7 @@ pub const Loop = struct.{ else => @compileError("unsupported OS"), }; - const MacOsBasic = struct.{ + const KEventBasic = struct.{ base: ResumeNode, kev: posix.Kevent, }; @@ -213,7 +213,7 @@ pub const Loop = struct.{ self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun); } }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { self.os_data.kqfd = try os.bsdKQueue(); errdefer os.close(self.os_data.kqfd); @@ -368,7 +368,7 @@ pub const Loop = struct.{ os.close(self.os_data.epollfd); self.allocator.free(self.eventfd_resume_nodes); }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { os.close(self.os_data.kqfd); os.close(self.os_data.fs_kqfd); }, @@ -483,7 +483,7 @@ pub const Loop = struct.{ const eventfd_node = &resume_stack_node.data; eventfd_node.base.handle = next_tick_node.data; switch (builtin.os) { - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent); const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { @@ -545,6 +545,7 @@ pub const Loop = struct.{ switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => self.os_data.fs_thread.wait(), else => {}, } @@ -609,7 +610,7 @@ pub const Loop = struct.{ os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable; return; }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { self.posixFsRequest(&self.os_data.fs_end_request); const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent); const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; @@ -667,7 +668,7 @@ pub const Loop = struct.{ } } }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { var eventlist: [1]posix.Kevent = undefined; const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; @@ -730,7 +731,7 @@ pub const Loop = struct.{ self.beginOneEvent(); // finished in posixFsRun after processing the msg self.os_data.fs_queue.put(request_node); switch (builtin.os) { - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake); const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; @@ -800,7 +801,7 @@ pub const Loop = struct.{ else => unreachable, } }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait); var out_kevs: [1]posix.Kevent = undefined; _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; @@ -812,7 +813,7 @@ pub const Loop = struct.{ const OsData = switch (builtin.os) { builtin.Os.linux => LinuxOsData, - builtin.Os.macosx => MacOsData, + builtin.Os.macosx, builtin.Os.freebsd => KEventData, builtin.Os.windows => struct.{ io_port: windows.HANDLE, extra_thread_count: usize, @@ -820,7 +821,7 @@ pub const Loop = struct.{ else => struct.{}, }; - const MacOsData = struct.{ + const KEventData = struct.{ kqfd: i32, final_kevent: posix.Kevent, fs_kevent_wake: posix.Kevent, diff --git a/std/os/freebsd/index.zig b/std/os/freebsd/index.zig index 1df773b04b..1793379fb5 100644 --- a/std/os/freebsd/index.zig +++ b/std/os/freebsd/index.zig @@ -7,6 +7,10 @@ const arch = switch (builtin.arch) { pub use @import("syscall.zig"); pub use @import("errno.zig"); +const std = @import("../../index.zig"); +const c = std.c; +pub const Kevent = c.Kevent; + pub const PATH_MAX = 1024; pub const STDIN_FILENO = 0; @@ -293,6 +297,156 @@ pub const DT_LNK = 10; pub const DT_SOCK = 12; pub const DT_WHT = 14; +/// add event to kq (implies enable) +pub const EV_ADD = 0x0001; + +/// delete event from kq +pub const EV_DELETE = 0x0002; + +/// enable event +pub const EV_ENABLE = 0x0004; + +/// disable event (not reported) +pub const EV_DISABLE = 0x0008; + +/// only report one occurrence +pub const EV_ONESHOT = 0x0010; + +/// clear event state after reporting +pub const EV_CLEAR = 0x0020; + +/// force immediate event output +/// ... with or without EV_ERROR +/// ... use KEVENT_FLAG_ERROR_EVENTS +/// on syscalls supporting flags +pub const EV_RECEIPT = 0x0040; + +/// disable event after reporting +pub const EV_DISPATCH = 0x0080; + +pub const EVFILT_READ = -1; +pub const EVFILT_WRITE = -2; + +/// attached to aio requests +pub const EVFILT_AIO = -3; + +/// attached to vnodes +pub const EVFILT_VNODE = -4; + +/// attached to struct proc +pub const EVFILT_PROC = -5; + +/// attached to struct proc +pub const EVFILT_SIGNAL = -6; + +/// timers +pub const EVFILT_TIMER = -7; + +/// Process descriptors +pub const EVFILT_PROCDESC = -8; + +/// Filesystem events +pub const EVFILT_FS = -9; + +pub const EVFILT_LIO = -10; + +/// User events +pub const EVFILT_USER = -11; + +/// Sendfile events +pub const EVFILT_SENDFILE = -12; + +pub const EVFILT_EMPTY = -13; + +/// On input, NOTE_TRIGGER causes the event to be triggered for output. +pub const NOTE_TRIGGER = 0x01000000; + +/// ignore input fflags +pub const NOTE_FFNOP = 0x00000000; + +/// and fflags +pub const NOTE_FFAND = 0x40000000; + +/// or fflags +pub const NOTE_FFOR = 0x80000000; + +/// copy fflags +pub const NOTE_FFCOPY = 0xc0000000; + +/// mask for operations +pub const NOTE_FFCTRLMASK = 0xc0000000; +pub const NOTE_FFLAGSMASK = 0x00ffffff; + + +/// low water mark +pub const NOTE_LOWAT = 0x00000001; + +/// behave like poll() +pub const NOTE_FILE_POLL = 0x00000002; + +/// vnode was removed +pub const NOTE_DELETE = 0x00000001; + +/// data contents changed +pub const NOTE_WRITE = 0x00000002; + +/// size increased +pub const NOTE_EXTEND = 0x00000004; + +/// attributes changed +pub const NOTE_ATTRIB = 0x00000008; + +/// link count changed +pub const NOTE_LINK = 0x00000010; + +/// vnode was renamed +pub const NOTE_RENAME = 0x00000020; + +/// vnode access was revoked +pub const NOTE_REVOKE = 0x00000040; + +/// vnode was opened +pub const NOTE_OPEN = 0x00000080; + +/// file closed, fd did not allow write +pub const NOTE_CLOSE = 0x00000100; + +/// file closed, fd did allow write +pub const NOTE_CLOSE_WRITE = 0x00000200; + +/// file was read +pub const NOTE_READ = 0x00000400; + +/// process exited +pub const NOTE_EXIT = 0x80000000; + +/// process forked +pub const NOTE_FORK = 0x40000000; + +/// process exec'd +pub const NOTE_EXEC = 0x20000000; + +/// mask for signal & exit status +pub const NOTE_PDATAMASK = 0x000fffff; +pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK); + +/// data is seconds +pub const NOTE_SECONDS = 0x00000001; + +/// data is milliseconds +pub const NOTE_MSECONDS = 0x00000002; + +/// data is microseconds +pub const NOTE_USECONDS = 0x00000004; + +/// data is nanoseconds +pub const NOTE_NSECONDS = 0x00000008; + +/// timeout is absolute +pub const NOTE_ABSTIME = 0x00000010; + + + pub const TCGETS = 0x5401; pub const TCSETS = 0x5402; pub const TCSETSW = 0x5403; @@ -445,7 +599,11 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { } pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { - return arch.syscall4(SYS_pread, usize(fd), @ptrToInt(buf), count, offset); + return arch.syscall4(SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset); +} + +pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize { + return arch.syscall4(SYS_preadv, @intCast(usize, fd), @ptrToInt(iov), count, offset); } pub fn pipe(fd: *[2]i32) usize { @@ -464,6 +622,10 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { return arch.syscall4(SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset); } +pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize { + return arch.syscall4(SYS_pwritev, @intCast(usize, fd), @ptrToInt(iov), count, offset); +} + pub fn rename(old: [*]const u8, new: [*]const u8) usize { return arch.syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); } @@ -590,3 +752,51 @@ pub const timespec = arch.timespec; pub fn fstat(fd: i32, stat_buf: *Stat) usize { return arch.syscall2(SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); } + +pub const iovec = extern struct.{ + iov_base: [*]u8, + iov_len: usize, +}; + +pub const iovec_const = extern struct.{ + iov_base: [*]const u8, + iov_len: usize, +}; + +pub fn kqueue() usize { + return errnoWrap(c.kqueue()); +} + +pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize { + return errnoWrap(c.kevent( + kq, + changelist.ptr, + @intCast(c_int, changelist.len), + eventlist.ptr, + @intCast(c_int, eventlist.len), + timeout, + )); +} + +pub fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { + return errnoWrap(c.sysctl(name, namelen, oldp, oldlenp, newp, newlen)); +} + +pub fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { + return errnoWrap(c.sysctlbyname(name, oldp, oldlenp, newp, newlen)); +} + +pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize { + return errnoWrap(c.sysctlnametomib(name, wibp, sizep)); +} + + + +/// Takes the return value from a syscall and formats it back in the way +/// that the kernel represents it to libc. Errno was a mistake, let's make +/// it go away forever. +fn errnoWrap(value: isize) usize { + return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value); +} + + diff --git a/std/os/get_app_data_dir.zig b/std/os/get_app_data_dir.zig index 48826f5aed..513978fef6 100644 --- a/std/os/get_app_data_dir.zig +++ b/std/os/get_app_data_dir.zig @@ -43,7 +43,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD }; return os.path.join(allocator, home_dir, "Library", "Application Support", appname); }, - builtin.Os.linux => { + builtin.Os.linux, builtin.Os.freebsd => { const home_dir = os.getEnvPosix("HOME") orelse { // TODO look in /etc/passwd return error.AppDataDirUnavailable; diff --git a/std/os/index.zig b/std/os/index.zig index 16bc571a83..36a7290d7e 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -421,7 +421,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off } } }, - builtin.Os.linux => while (true) { + builtin.Os.linux, builtin.Os.freebsd => while (true) { const rc = posix.pwritev(fd, iov, count, offset); const err = posix.getErrno(rc); switch (err) { @@ -689,7 +689,7 @@ pub fn getBaseAddress() usize { }; return phdr - @sizeOf(ElfHeader); }, - builtin.Os.macosx => return @ptrToInt(&std.c._mh_execute_header), + builtin.Os.macosx, builtin.Os.freebsd => return @ptrToInt(&std.c._mh_execute_header), builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)), else => @compileError("Unsupported OS"), } @@ -1307,7 +1307,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void { const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path); return deleteDirW(&dir_path_w); }, - Os.linux, Os.macosx, Os.ios => { + Os.linux, Os.macosx, Os.ios, Os.freebsd => { const err = posix.getErrno(posix.rmdir(dir_path)); switch (err) { 0 => return, @@ -1350,7 +1350,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void { const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path); return deleteDirW(&dir_path_w); }, - Os.linux, Os.macosx, Os.ios => { + Os.linux, Os.macosx, Os.ios, Os.freebsd => { const dir_path_c = try toPosixPath(dir_path); return deleteDirC(&dir_path_c); }, @@ -1467,7 +1467,7 @@ pub const Dir = struct.{ allocator: *Allocator, pub const Handle = switch (builtin.os) { - Os.macosx, Os.ios => struct.{ + Os.macosx, Os.ios, Os.freebsd => struct.{ fd: i32, seek: i64, buf: []u8, @@ -1543,7 +1543,7 @@ pub const Dir = struct.{ .name_data = undefined, }; }, - Os.macosx, Os.ios => Handle.{ + Os.macosx, Os.ios, Os.freebsd => Handle.{ .fd = try posixOpen( dir_path, posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC, @@ -1574,7 +1574,7 @@ pub const Dir = struct.{ Os.windows => { _ = windows.FindClose(self.handle.handle); }, - Os.macosx, Os.ios, Os.linux => { + Os.macosx, Os.ios, Os.linux, Os.freebsd => { self.allocator.free(self.handle.buf); os.close(self.handle.fd); }, @@ -1589,6 +1589,7 @@ pub const Dir = struct.{ Os.linux => return self.nextLinux(), Os.macosx, Os.ios => return self.nextDarwin(), Os.windows => return self.nextWindows(), + Os.freebsd => return self.nextFreebsd(), else => @compileError("unimplemented"), } } @@ -1728,6 +1729,11 @@ pub const Dir = struct.{ }; } } + + fn nextFreebsd(self: *Dir) !?Entry { + self.handle.buf = try self.allocator.alloc(u8, page_size); + return null; // TODO + } }; pub fn changeCurDir(allocator: *Allocator, dir_path: []const u8) !void { @@ -2166,7 +2172,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError { pub fn openSelfExe() !os.File { switch (builtin.os) { Os.linux => return os.File.openReadC(c"/proc/self/exe"), - Os.macosx, Os.ios => { + Os.macosx, Os.ios, Os.freebsd => { var buf: [MAX_PATH_BYTES]u8 = undefined; const self_exe_path = try selfExePath(&buf); buf[self_exe_path.len] = 0; @@ -2183,7 +2189,7 @@ pub fn openSelfExe() !os.File { test "openSelfExe" { switch (builtin.os) { - Os.linux, Os.macosx, Os.ios, Os.windows => (try openSelfExe()).close(), + Os.linux, Os.macosx, Os.ios, Os.windows, Os.freebsd => (try openSelfExe()).close(), else => return error.SkipZigTest, // Unsupported OS. } } @@ -2214,6 +2220,7 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 { pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { switch (builtin.os) { Os.linux => return readLink(out_buffer, "/proc/self/exe"), + Os.freebsd => return readLink(out_buffer, "/proc/curproc/file"), Os.windows => { var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; const utf16le_slice = try selfExePathW(&utf16le_buf); @@ -2252,7 +2259,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 { // will not return null. return path.dirname(full_exe_path).?; }, - Os.windows, Os.macosx, Os.ios => { + Os.windows, Os.macosx, Os.ios, Os.freebsd => { const self_exe_path = try selfExePath(out_buffer); // Assume that the OS APIs return absolute paths, and therefore dirname // will not return null. @@ -3085,10 +3092,13 @@ pub const CpuCountError = error.{ pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize { switch (builtin.os) { - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { var count: c_int = undefined; var count_len: usize = @sizeOf(c_int); - const rc = posix.sysctlbyname(c"hw.logicalcpu", @ptrCast(*c_void, &count), &count_len, null, 0); + const rc = posix.sysctlbyname(switch (builtin.os) { + builtin.Os.macosx => c"hw.logicalcpu", + else => c"hw.ncpu", + }, @ptrCast(*c_void, &count), &count_len, null, 0); const err = posix.getErrno(rc); switch (err) { 0 => return @intCast(usize, count), -- cgit v1.2.3 From 6a8fb060067685a2ff27d05092f3fcf2ee17e83c Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 18:00:36 +0300 Subject: Split at zero byte in SplitIterator To avoid extra zeros in buffers --- src/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index 192d74e766..f7bda86c42 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -47,7 +47,7 @@ bool ptr_eq(const void *a, const void *b) { // Ported from std/mem.zig. bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) { for (size_t i = 0; i < self->split_bytes.len; i += 1) { - if (byte == self->split_bytes.ptr[i]) { + if (byte == self->split_bytes.ptr[i] || byte == 0) { return true; } } -- cgit v1.2.3 From f3bc1c38bfb35cd588048f248c69100eaf709a4f Mon Sep 17 00:00:00 2001 From: Greg V Date: Sat, 20 Oct 2018 15:15:15 +0300 Subject: Specify 16-byte stack alignment in _start on FreeBSD --- std/special/bootstrap.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 1fc80f2439..070a26bf71 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -57,6 +57,9 @@ extern fn WinMainCRTStartup() noreturn { // TODO https://github.com/ziglang/zig/issues/265 fn posixCallMainAndExit() noreturn { + if (builtin.os == builtin.Os.freebsd) { + @setAlignStack(16); + } const argc = argc_ptr[0]; const argv = @ptrCast([*][*]u8, argc_ptr + 1); -- cgit v1.2.3 From 4dafdc00d5c0d73511d64c5edf7481c8fe254a61 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 19 Nov 2018 17:28:18 -0500 Subject: zig fmt --- std/c/freebsd.zig | 7 ++----- std/debug/index.zig | 3 +-- std/mem.zig | 8 ++++---- std/os/freebsd/index.zig | 21 +++++++-------------- std/os/freebsd/x86_64.zig | 6 +++--- std/special/bootstrap.zig | 2 +- 6 files changed, 18 insertions(+), 29 deletions(-) diff --git a/std/c/freebsd.zig b/std/c/freebsd.zig index 6eb34929b5..421e964827 100644 --- a/std/c/freebsd.zig +++ b/std/c/freebsd.zig @@ -1,4 +1,3 @@ - const timespec = @import("../os/freebsd/index.zig").timespec; extern "c" fn __error() *c_int; @@ -18,7 +17,7 @@ pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usi pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. -pub const Kevent = extern struct.{ +pub const Kevent = extern struct { ident: usize, filter: i16, flags: u16, @@ -28,9 +27,7 @@ pub const Kevent = extern struct.{ // TODO ext }; - -pub const pthread_attr_t = extern struct.{ +pub const pthread_attr_t = extern struct { __size: [56]u8, __align: c_long, }; - diff --git a/std/debug/index.zig b/std/debug/index.zig index a3509b3117..722f95ccb0 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -1101,8 +1101,7 @@ pub const DebugInfo = switch (builtin.os) { self.elf.close(); } }, - builtin.Os.freebsd => struct.{ - }, + builtin.Os.freebsd => struct {}, else => @compileError("Unsupported OS"), }; diff --git a/std/mem.zig b/std/mem.zig index 6b37dfe401..6b115a56f6 100644 --- a/std/mem.zig +++ b/std/mem.zig @@ -475,8 +475,8 @@ test "readIntBE/LE" { assert(readIntBE(u8, []u8{0x32}) == 0x32); assert(readIntLE(u8, []u8{0x12}) == 0x12); - assert(readIntBE(u16, []u8{0x12, 0x34}) == 0x1234); - assert(readIntLE(u16, []u8{0x12, 0x34}) == 0x3412); + assert(readIntBE(u16, []u8{ 0x12, 0x34 }) == 0x1234); + assert(readIntLE(u16, []u8{ 0x12, 0x34 }) == 0x3412); assert(readIntBE(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); assert(readIntLE(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); @@ -484,8 +484,8 @@ test "readIntBE/LE" { assert(readIntBE(i8, []u8{0xff}) == -1); assert(readIntLE(i8, []u8{0xfe}) == -2); - assert(readIntBE(i16, []u8{0xff, 0xfd}) == -3); - assert(readIntLE(i16, []u8{0xfc, 0xff}) == -4); + assert(readIntBE(i16, []u8{ 0xff, 0xfd }) == -3); + assert(readIntLE(i16, []u8{ 0xfc, 0xff }) == -4); } /// Writes an integer to memory with size equal to bytes.len. Pads with zeroes diff --git a/std/os/freebsd/index.zig b/std/os/freebsd/index.zig index 1793379fb5..75389fc403 100644 --- a/std/os/freebsd/index.zig +++ b/std/os/freebsd/index.zig @@ -377,7 +377,6 @@ pub const NOTE_FFCOPY = 0xc0000000; pub const NOTE_FFCTRLMASK = 0xc0000000; pub const NOTE_FFLAGSMASK = 0x00ffffff; - /// low water mark pub const NOTE_LOWAT = 0x00000001; @@ -445,8 +444,6 @@ pub const NOTE_NSECONDS = 0x00000008; /// timeout is absolute pub const NOTE_ABSTIME = 0x00000010; - - pub const TCGETS = 0x5401; pub const TCSETS = 0x5402; pub const TCSETSW = 0x5403; @@ -528,7 +525,7 @@ pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s) & 0xffff) -% 1 < 0xff; } -pub const winsize = extern struct.{ +pub const winsize = extern struct { ws_row: u16, ws_col: u16, ws_xpixel: u16, @@ -703,11 +700,11 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti const NSIG = 65; const sigset_t = [128 / @sizeOf(usize)]usize; -const all_mask = []usize.{@maxValue(usize)}; -const app_mask = []usize.{0xfffffffc7fffffff}; +const all_mask = []usize{@maxValue(usize)}; +const app_mask = []usize{0xfffffffc7fffffff}; /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. -pub const Sigaction = struct.{ +pub const Sigaction = struct { // TODO: Adjust to use freebsd struct layout handler: extern fn (i32) void, mask: sigset_t, @@ -717,7 +714,7 @@ pub const Sigaction = struct.{ pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize)); pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); -pub const empty_sigset = []usize.{0} ** sigset_t.len; +pub const empty_sigset = []usize{0} ** sigset_t.len; pub fn raise(sig: i32) usize { // TODO implement, see linux equivalent for what we want to try and do @@ -753,12 +750,12 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize { return arch.syscall2(SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); } -pub const iovec = extern struct.{ +pub const iovec = extern struct { iov_base: [*]u8, iov_len: usize, }; -pub const iovec_const = extern struct.{ +pub const iovec_const = extern struct { iov_base: [*]const u8, iov_len: usize, }; @@ -790,13 +787,9 @@ pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize { return errnoWrap(c.sysctlnametomib(name, wibp, sizep)); } - - /// Takes the return value from a syscall and formats it back in the way /// that the kernel represents it to libc. Errno was a mistake, let's make /// it go away forever. fn errnoWrap(value: isize) usize { return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value); } - - diff --git a/std/os/freebsd/x86_64.zig b/std/os/freebsd/x86_64.zig index 28ae2d5471..20a6710596 100644 --- a/std/os/freebsd/x86_64.zig +++ b/std/os/freebsd/x86_64.zig @@ -97,7 +97,7 @@ pub nakedcc fn restore_rt() void { ); } -pub const msghdr = extern struct.{ +pub const msghdr = extern struct { msg_name: &u8, msg_namelen: socklen_t, msg_iov: &iovec, @@ -110,7 +110,7 @@ pub const msghdr = extern struct.{ }; /// Renamed to Stat to not conflict with the stat function. -pub const Stat = extern struct.{ +pub const Stat = extern struct { dev: u64, ino: u64, nlink: usize, @@ -130,7 +130,7 @@ pub const Stat = extern struct.{ __unused: [3]isize, }; -pub const timespec = extern struct.{ +pub const timespec = extern struct { tv_sec: isize, tv_nsec: isize, }; diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 070a26bf71..a15be317ab 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -23,7 +23,7 @@ nakedcc fn _start() noreturn { builtin.Arch.x86_64 => switch (builtin.os) { builtin.Os.freebsd => { argc_ptr = asm ("lea (%%rdi), %[argc]" - : [argc] "=r" (-> [*]usize) + : [argc] "=r" (-> [*]usize) ); }, else => { -- cgit v1.2.3 From bb3ac177a83caf52556818e9ea163ac166bb6c07 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 20 Nov 2018 12:37:42 -0500 Subject: fix incorrect buf len --- std/os/path.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/os/path.zig b/std/os/path.zig index 4ef7f3effb..e2ef150ba5 100644 --- a/std/os/path.zig +++ b/std/os/path.zig @@ -1192,7 +1192,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro const fd = try os.posixOpenC(pathname, posix.O_PATH | posix.O_NONBLOCK | posix.O_CLOEXEC, 0); defer os.close(fd); - var buf: ["/dev/fd/-2147483648".len]u8 = undefined; + var buf: ["/dev/fd/-2147483648\x00".len]u8 = undefined; const proc_path = fmt.bufPrint(buf[0..], "/dev/fd/{}\x00", fd) catch unreachable; return os.readLinkC(out_buffer, proc_path.ptr); -- cgit v1.2.3 From dd2450b1b21809c3fe62920498c318fbe519f579 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 27 Nov 2018 20:56:43 -0500 Subject: tier 2 support for freebsd --- README.md | 2 +- cmake/Findlld.cmake | 10 +- src-self-hosted/target.zig | 292 +++++++++++++++++++++++---------------------- src/util.cpp | 2 +- std/os/index.zig | 4 +- 5 files changed, 156 insertions(+), 154 deletions(-) diff --git a/README.md b/README.md index e50d31856d..a19e9eb67a 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ clarity. | | freestanding | linux | macosx | windows | freebsd | other | |--------|--------------|--------|--------|---------|---------|--------| -|x86_64 | Tier 2 | Tier 1 | Tier 1 | Tier 1 | Tier 3 | Tier 3 | +|x86_64 | Tier 2 | Tier 1 | Tier 1 | Tier 1 | Tier 2 | Tier 3 | |i386 | Tier 2 | Tier 2 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | |arm | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | |arm64 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | diff --git a/cmake/Findlld.cmake b/cmake/Findlld.cmake index 4e5b0c9a19..93ed1a9de1 100644 --- a/cmake/Findlld.cmake +++ b/cmake/Findlld.cmake @@ -8,13 +8,13 @@ find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h PATHS - /usr/lib/llvm-6.0/include - /usr/local/llvm60/include + /usr/lib/llvm-7.0/include + /usr/local/llvm70/include /mingw64/include) -find_library(LLD_LIBRARY NAMES lld-6.0 lld60 lld +find_library(LLD_LIBRARY NAMES lld-7.0 lld70 lld PATHS - /usr/lib/llvm-6.0/lib + /usr/lib/llvm-7.0/lib /usr/local/llvm70/lib) if(EXISTS ${LLD_LIBRARY}) set(LLD_LIBRARIES ${LLD_LIBRARY}) @@ -23,7 +23,7 @@ else() string(TOUPPER ${_libname_} _prettylibname_) find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_} PATHS - /usr/lib/llvm-6.0/lib + /usr/lib/llvm-7.0/lib /usr/local/llvm70/lib /mingw64/lib /c/msys64/mingw64/lib diff --git a/src-self-hosted/target.zig b/src-self-hosted/target.zig index eae0a12325..218353c9d7 100644 --- a/src-self-hosted/target.zig +++ b/src-self-hosted/target.zig @@ -304,154 +304,156 @@ pub const Target = union(enum) { builtin.Os.freebsd => { return "/libexec/ld-elf.so.1"; }, - else => {}, - } - switch (env) { - builtin.Environ.android => { - if (self.is64bit()) { - return "/system/bin/linker64"; - } else { - return "/system/bin/linker"; + builtin.Os.linux => { + switch (env) { + builtin.Environ.android => { + if (self.is64bit()) { + return "/system/bin/linker64"; + } else { + return "/system/bin/linker"; + } + }, + builtin.Environ.gnux32 => { + if (arch == builtin.Arch.x86_64) { + return "/libx32/ld-linux-x32.so.2"; + } + }, + builtin.Environ.musl, + builtin.Environ.musleabi, + builtin.Environ.musleabihf, + => { + if (arch == builtin.Arch.x86_64) { + return "/lib/ld-musl-x86_64.so.1"; + } + }, + else => {}, } - }, - builtin.Environ.gnux32 => { - if (arch == builtin.Arch.x86_64) { - return "/libx32/ld-linux-x32.so.2"; + switch (arch) { + builtin.Arch.i386, + builtin.Arch.sparc, + builtin.Arch.sparcel, + => return "/lib/ld-linux.so.2", + + builtin.Arch.aarch64v8_3a, + builtin.Arch.aarch64v8_2a, + builtin.Arch.aarch64v8_1a, + builtin.Arch.aarch64v8, + builtin.Arch.aarch64v8r, + builtin.Arch.aarch64v8m_baseline, + builtin.Arch.aarch64v8m_mainline, + => return "/lib/ld-linux-aarch64.so.1", + + builtin.Arch.aarch64_bev8_3a, + builtin.Arch.aarch64_bev8_2a, + builtin.Arch.aarch64_bev8_1a, + builtin.Arch.aarch64_bev8, + builtin.Arch.aarch64_bev8r, + builtin.Arch.aarch64_bev8m_baseline, + builtin.Arch.aarch64_bev8m_mainline, + => return "/lib/ld-linux-aarch64_be.so.1", + + builtin.Arch.armv8_3a, + builtin.Arch.armv8_2a, + builtin.Arch.armv8_1a, + builtin.Arch.armv8, + builtin.Arch.armv8r, + builtin.Arch.armv8m_baseline, + builtin.Arch.armv8m_mainline, + builtin.Arch.armv7, + builtin.Arch.armv7em, + builtin.Arch.armv7m, + builtin.Arch.armv7s, + builtin.Arch.armv7k, + builtin.Arch.armv7ve, + builtin.Arch.armv6, + builtin.Arch.armv6m, + builtin.Arch.armv6k, + builtin.Arch.armv6t2, + builtin.Arch.armv5, + builtin.Arch.armv5te, + builtin.Arch.armv4t, + builtin.Arch.thumb, + => return switch (self.getFloatAbi()) { + FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3", + else => return "/lib/ld-linux.so.3", + }, + + builtin.Arch.armebv8_3a, + builtin.Arch.armebv8_2a, + builtin.Arch.armebv8_1a, + builtin.Arch.armebv8, + builtin.Arch.armebv8r, + builtin.Arch.armebv8m_baseline, + builtin.Arch.armebv8m_mainline, + builtin.Arch.armebv7, + builtin.Arch.armebv7em, + builtin.Arch.armebv7m, + builtin.Arch.armebv7s, + builtin.Arch.armebv7k, + builtin.Arch.armebv7ve, + builtin.Arch.armebv6, + builtin.Arch.armebv6m, + builtin.Arch.armebv6k, + builtin.Arch.armebv6t2, + builtin.Arch.armebv5, + builtin.Arch.armebv5te, + builtin.Arch.armebv4t, + builtin.Arch.thumbeb, + => return switch (self.getFloatAbi()) { + FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3", + else => return "/lib/ld-linux.so.3", + }, + + builtin.Arch.mips, + builtin.Arch.mipsel, + builtin.Arch.mips64, + builtin.Arch.mips64el, + => return null, + + builtin.Arch.powerpc => return "/lib/ld.so.1", + builtin.Arch.powerpc64 => return "/lib64/ld64.so.2", + builtin.Arch.powerpc64le => return "/lib64/ld64.so.2", + builtin.Arch.s390x => return "/lib64/ld64.so.1", + builtin.Arch.sparcv9 => return "/lib64/ld-linux.so.2", + builtin.Arch.x86_64 => return "/lib64/ld-linux-x86-64.so.2", + + builtin.Arch.arc, + builtin.Arch.avr, + builtin.Arch.bpfel, + builtin.Arch.bpfeb, + builtin.Arch.hexagon, + builtin.Arch.msp430, + builtin.Arch.nios2, + builtin.Arch.r600, + builtin.Arch.amdgcn, + builtin.Arch.riscv32, + builtin.Arch.riscv64, + builtin.Arch.tce, + builtin.Arch.tcele, + builtin.Arch.xcore, + builtin.Arch.nvptx, + builtin.Arch.nvptx64, + builtin.Arch.le32, + builtin.Arch.le64, + builtin.Arch.amdil, + builtin.Arch.amdil64, + builtin.Arch.hsail, + builtin.Arch.hsail64, + builtin.Arch.spir, + builtin.Arch.spir64, + builtin.Arch.kalimbav3, + builtin.Arch.kalimbav4, + builtin.Arch.kalimbav5, + builtin.Arch.shave, + builtin.Arch.lanai, + builtin.Arch.wasm32, + builtin.Arch.wasm64, + builtin.Arch.renderscript32, + builtin.Arch.renderscript64, + => return null, } }, - builtin.Environ.musl, - builtin.Environ.musleabi, - builtin.Environ.musleabihf, - => { - if (arch == builtin.Arch.x86_64) { - return "/lib/ld-musl-x86_64.so.1"; - } - }, - else => {}, - } - switch (arch) { - builtin.Arch.i386, - builtin.Arch.sparc, - builtin.Arch.sparcel, - => return "/lib/ld-linux.so.2", - - builtin.Arch.aarch64v8_3a, - builtin.Arch.aarch64v8_2a, - builtin.Arch.aarch64v8_1a, - builtin.Arch.aarch64v8, - builtin.Arch.aarch64v8r, - builtin.Arch.aarch64v8m_baseline, - builtin.Arch.aarch64v8m_mainline, - => return "/lib/ld-linux-aarch64.so.1", - - builtin.Arch.aarch64_bev8_3a, - builtin.Arch.aarch64_bev8_2a, - builtin.Arch.aarch64_bev8_1a, - builtin.Arch.aarch64_bev8, - builtin.Arch.aarch64_bev8r, - builtin.Arch.aarch64_bev8m_baseline, - builtin.Arch.aarch64_bev8m_mainline, - => return "/lib/ld-linux-aarch64_be.so.1", - - builtin.Arch.armv8_3a, - builtin.Arch.armv8_2a, - builtin.Arch.armv8_1a, - builtin.Arch.armv8, - builtin.Arch.armv8r, - builtin.Arch.armv8m_baseline, - builtin.Arch.armv8m_mainline, - builtin.Arch.armv7, - builtin.Arch.armv7em, - builtin.Arch.armv7m, - builtin.Arch.armv7s, - builtin.Arch.armv7k, - builtin.Arch.armv7ve, - builtin.Arch.armv6, - builtin.Arch.armv6m, - builtin.Arch.armv6k, - builtin.Arch.armv6t2, - builtin.Arch.armv5, - builtin.Arch.armv5te, - builtin.Arch.armv4t, - builtin.Arch.thumb, - => return switch (self.getFloatAbi()) { - FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3", - else => return "/lib/ld-linux.so.3", - }, - - builtin.Arch.armebv8_3a, - builtin.Arch.armebv8_2a, - builtin.Arch.armebv8_1a, - builtin.Arch.armebv8, - builtin.Arch.armebv8r, - builtin.Arch.armebv8m_baseline, - builtin.Arch.armebv8m_mainline, - builtin.Arch.armebv7, - builtin.Arch.armebv7em, - builtin.Arch.armebv7m, - builtin.Arch.armebv7s, - builtin.Arch.armebv7k, - builtin.Arch.armebv7ve, - builtin.Arch.armebv6, - builtin.Arch.armebv6m, - builtin.Arch.armebv6k, - builtin.Arch.armebv6t2, - builtin.Arch.armebv5, - builtin.Arch.armebv5te, - builtin.Arch.armebv4t, - builtin.Arch.thumbeb, - => return switch (self.getFloatAbi()) { - FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3", - else => return "/lib/ld-linux.so.3", - }, - - builtin.Arch.mips, - builtin.Arch.mipsel, - builtin.Arch.mips64, - builtin.Arch.mips64el, - => return null, - - builtin.Arch.powerpc => return "/lib/ld.so.1", - builtin.Arch.powerpc64 => return "/lib64/ld64.so.2", - builtin.Arch.powerpc64le => return "/lib64/ld64.so.2", - builtin.Arch.s390x => return "/lib64/ld64.so.1", - builtin.Arch.sparcv9 => return "/lib64/ld-linux.so.2", - builtin.Arch.x86_64 => return "/lib64/ld-linux-x86-64.so.2", - - builtin.Arch.arc, - builtin.Arch.avr, - builtin.Arch.bpfel, - builtin.Arch.bpfeb, - builtin.Arch.hexagon, - builtin.Arch.msp430, - builtin.Arch.nios2, - builtin.Arch.r600, - builtin.Arch.amdgcn, - builtin.Arch.riscv32, - builtin.Arch.riscv64, - builtin.Arch.tce, - builtin.Arch.tcele, - builtin.Arch.xcore, - builtin.Arch.nvptx, - builtin.Arch.nvptx64, - builtin.Arch.le32, - builtin.Arch.le64, - builtin.Arch.amdil, - builtin.Arch.amdil64, - builtin.Arch.hsail, - builtin.Arch.hsail64, - builtin.Arch.spir, - builtin.Arch.spir64, - builtin.Arch.kalimbav3, - builtin.Arch.kalimbav4, - builtin.Arch.kalimbav5, - builtin.Arch.shave, - builtin.Arch.lanai, - builtin.Arch.wasm32, - builtin.Arch.wasm64, - builtin.Arch.renderscript32, - builtin.Arch.renderscript64, - => return null, + else => return null, } } diff --git a/src/util.cpp b/src/util.cpp index f7bda86c42..192d74e766 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -47,7 +47,7 @@ bool ptr_eq(const void *a, const void *b) { // Ported from std/mem.zig. bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) { for (size_t i = 0; i < self->split_bytes.len; i += 1) { - if (byte == self->split_bytes.ptr[i] || byte == 0) { + if (byte == self->split_bytes.ptr[i]) { return true; } } diff --git a/std/os/index.zig b/std/os/index.zig index ba1fdb2be6..15be08c689 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -1731,8 +1731,8 @@ pub const Dir = struct { } fn nextFreebsd(self: *Dir) !?Entry { - self.handle.buf = try self.allocator.alloc(u8, page_size); - return null; // TODO + //self.handle.buf = try self.allocator.alloc(u8, page_size); + @compileError("TODO implement dirs for FreeBSD"); } }; -- cgit v1.2.3