summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-14 16:57:15 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-14 16:57:15 -0700
commit4c08e7b46eb4bcf159da14f9bd481d413f479224 (patch)
tree00bf0c979f362cf401a41fc37a4f5717edb9094f /libstd
parentedcb09d03294c0f3701d0ded490996a160c7985f (diff)
downloadmc-4c08e7b46eb4bcf159da14f9bd481d413f479224.tar.gz
Get much closer to getting this whole mess working on OSX.
It looks like the last missing piece is a working getcwd.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/getcwd.myr1
-rw-r--r--libstd/sys+osx-x64.myr47
-rw-r--r--libstd/syscall+linux-x64.s1
-rw-r--r--libstd/syscall+osx-x64.s13
-rw-r--r--libstd/syswrap+posixy.myr2
-rw-r--r--libstd/syswrap-ss+posixy-linux.myr2
-rw-r--r--libstd/syswrap-ss+posixy-osx.myr16
7 files changed, 74 insertions, 8 deletions
diff --git a/libstd/getcwd.myr b/libstd/getcwd.myr
index 406c6a4..3e9bb03 100644
--- a/libstd/getcwd.myr
+++ b/libstd/getcwd.myr
@@ -3,6 +3,7 @@ use "alloc.use"
use "errno.use"
use "extremum.use"
use "syswrap.use"
+use "syswrap-ss.use"
pkg std =
const getcwd : (-> byte[:])
;;
diff --git a/libstd/sys+osx-x64.myr b/libstd/sys+osx-x64.myr
index a84c006..566274c 100644
--- a/libstd/sys+osx-x64.myr
+++ b/libstd/sys+osx-x64.myr
@@ -13,6 +13,7 @@ pkg sys =
type filemode = uint16 /* file permission bits */
type kflags = uint16 /* kqueue flags */
type whence = int64
+ type fcntlcmd = int64
type timespec = struct
sec : uint64
@@ -129,6 +130,49 @@ pkg sys =
const Seekcur : whence = 1
const Seekend : whence = 2
+ /* system specific constants */
+ const Maxpathlen : size = 1024
+
+ /* fcntl constants */
+ const Fdupfd : fcntlcmd = 0 /* duplicate file descriptor */
+ const Fgetfd : fcntlcmd = 1 /* get file descriptor flags */
+ const Fsetfd : fcntlcmd = 2 /* set file descriptor flags */
+ const Fgetfl : fcntlcmd = 3 /* get file status flags */
+ const Fsetfl : fcntlcmd = 4 /* set file status flags */
+ const Fgetown : fcntlcmd = 5 /* get SIGIO/SIGURG proc/pgrp */
+ const Fsetown : fcntlcmd = 6 /* set SIGIO/SIGURG proc/pgrp */
+ const Fgetlk : fcntlcmd = 7 /* get record locking information */
+ const Fsetlk : fcntlcmd = 8 /* set record locking information */
+ const Fsetlkw : fcntlcmd = 9 /* F_SETLK; wait if blocked */
+ const Fsetlkwtimeout : fcntlcmd = 10 /* F_SETLK; wait if blocked, return on timeout */
+ const Fflush_data : fcntlcmd = 40
+ const Fchkclean : fcntlcmd = 41 /* Used for regression test */
+ const Fpreallocate : fcntlcmd = 42 /* Preallocate storage */
+ const Fsetsize : fcntlcmd = 43 /* Truncate a file without zeroing space */
+ const Frdadvise : fcntlcmd = 44 /* Issue an advisory read async with no copy to user */
+ const Frdahead : fcntlcmd = 45 /* turn read ahead off/on for this fd */
+ /* 46,47 used to be F_READBOOTSTRAP and F_WRITEBOOTSTRAP */
+ const Fnocache : fcntlcmd = 48 /* turn data caching off/on for this fd */
+ const Flog2phys : fcntlcmd = 49 /* file offset to device offset */
+ const Fgetpath : fcntlcmd = 50 /* return the full path of the fd */
+ const Ffullfsync : fcntlcmd = 51 /* fsync + ask the drive to flush to the media */
+ const Fpathpkg_check : fcntlcmd = 52 /* find which component (if any) is a package */
+ const Ffreeze_fs : fcntlcmd = 53 /* "freeze" all fs operations */
+ const Fthaw_fs : fcntlcmd = 54 /* "thaw" all fs operations */
+ const Fglobal_nocache : fcntlcmd = 55 /* turn data caching off/on (globally) for this file */
+ const Faddsigs : fcntlcmd = 59 /* add detached signatures */
+ const Faddfilesigs : fcntlcmd = 61 /* add signature from same file (used by dyld for shared libs) */
+ const Fgetprotclass : fcntlcmd = 63 /* Get the protection class of a file from the EA, returns int */
+ const Fsetprotclass : fcntlcmd = 64 /* Set the protection class of a file for the EA, requires int */
+ const Flog2phys_ext : fcntlcmd = 65 /* file offset to device offset, extended */
+ const Fgetlkpid : fcntlcmd = 66 /* get record locking information, per-process */
+ /* See F_DUPFD_CLOEXEC below for 67 */
+ const Fsetbacktore : fcntlcmd = 70 /* Mark the file as being the backing store for another filesystem */
+ const Fgetpath_mtminfo : fcntlcmd = 71 /* return the full path of the FD, but error in specific mtmd circumstances */
+ /* 72 is free. It used to be F_GETENCRYPTEDDATA, which is now removed. */
+ const Fsetnosigpipe : fcntlcmd = 73 /* No SIGPIPE generated on EPIPE */
+ const Fgetnosigpipe : fcntlcmd = 74 /* Status of SIGPIPE for this fd */
+
/* kqueue events */
const Kevadd : kflags = 0x0001 /* add event to kq (implies enable) */
const Kevdelete : kflags = 0x0002 /* delete event from kq */
@@ -595,6 +639,8 @@ pkg sys =
const pipe : (fd : fd[2]# -> int64)
const dup : (fd : fd -> fd)
const dup2 : (src : fd, dst : fd -> fd)
+ /* NB: the C ABI uses '...' for the args. */
+ const fcntl : (fd : fd, cmd : fcntlcmd, args : byte# -> int64)
/* kqueue */
const kqueue : (-> fd)
@@ -733,6 +779,7 @@ const chdir = {dir; -> syscall(Syschdir, cstring(dir))}
const pipe = {fd; -> __osx_pipe(fd)}
const dup = {fd; -> syscall(Sysdup, a(fd)) castto(fd)}
const dup2 = {src, dst; -> syscall(Sysdup2, a(src), a(dst)) castto(fd)}
+const fcntl = {fd, cmd, args; -> syscall(Sysfcntl, a(fd), a(cmd), a(args))}
/* kqueueueueueueue */
const kqueue = {; -> syscall(Syskqueue) castto(fd)}
diff --git a/libstd/syscall+linux-x64.s b/libstd/syscall+linux-x64.s
index d1a3086..0393497 100644
--- a/libstd/syscall+linux-x64.s
+++ b/libstd/syscall+linux-x64.s
@@ -18,6 +18,7 @@ sys$syscall:
harmless.
*/
movq 80 (%rsp),%rax
+ /* 88: hidden type arg */
movq 96 (%rsp),%rdi
movq 104(%rsp),%rsi
movq 112(%rsp),%rdx
diff --git a/libstd/syscall+osx-x64.s b/libstd/syscall+osx-x64.s
index 33b4709..18968e6 100644
--- a/libstd/syscall+osx-x64.s
+++ b/libstd/syscall+osx-x64.s
@@ -17,12 +17,13 @@ _sys$syscall:
harmless.
*/
movq 80 (%rsp),%rax
- movq 88 (%rsp),%rdi
- movq 96 (%rsp),%rsi
- movq 104(%rsp),%rdx
- movq 112(%rsp),%r10
- movq 120(%rsp),%r8
- movq 128(%rsp),%r9
+ /* 88: hidden type arg */
+ movq 96 (%rsp),%rdi
+ movq 104(%rsp),%rsi
+ movq 112(%rsp),%rdx
+ movq 120(%rsp),%r10
+ movq 128(%rsp),%r8
+ movq 136(%rsp),%r9
syscall
jae .success
diff --git a/libstd/syswrap+posixy.myr b/libstd/syswrap+posixy.myr
index c426d1f..31d98b5 100644
--- a/libstd/syswrap+posixy.myr
+++ b/libstd/syswrap+posixy.myr
@@ -68,7 +68,6 @@ pkg std =
pkglocal const getmem : (sz : size -> byte#)
pkglocal const freemem : (p : byte#, sz : size -> void)
pkglocal const curtime : (-> time)
- pkglocal const bgetcwd : (buf : byte[:] -> errno)
;;
/* fd stuff */
@@ -86,7 +85,6 @@ const dup2 = {ofd, nfd; -> sys.dup2(ofd castto(sys.fd), nfd castto(sys.fd)) cast
const mkdir = {path, mode; -> sys.mkdir(path, mode)}
const chdir = {path; -> sys.chdir(path) == 0}
const remove = {path; -> sys.unlink(path) == 0}
-const bgetcwd = {buf; -> sys.getcwd(buf) castto(errno)}
/* useful/portable bits of uname */
const getsysinfo = {si
diff --git a/libstd/syswrap-ss+posixy-linux.myr b/libstd/syswrap-ss+posixy-linux.myr
index 4cd112c..485c0af 100644
--- a/libstd/syswrap-ss+posixy-linux.myr
+++ b/libstd/syswrap-ss+posixy-linux.myr
@@ -2,6 +2,8 @@ use sys
pkg std =
const exit : (status:int -> void)
+ pkglocal const bgetcwd : (buf : byte[:] -> errno)
;;
const exit = {status; sys.exit_group(status)}
+const bgetcwd = {buf; -> sys.getcwd(buf) castto(errno)}
diff --git a/libstd/syswrap-ss+posixy-osx.myr b/libstd/syswrap-ss+posixy-osx.myr
index 62bc6f4..91a5dee 100644
--- a/libstd/syswrap-ss+posixy-osx.myr
+++ b/libstd/syswrap-ss+posixy-osx.myr
@@ -1,7 +1,23 @@
use sys
+use "errno.use"
pkg std =
const exit : (status:int -> void)
+ pkglocal const bgetcwd : (buf : byte[:] -> errno)
;;
const exit = {status; sys.exit(status)}
+const bgetcwd = {buf
+ var path : byte[sys.Maxpathlen]
+ var fd
+
+ fd = sys.open(".", sys.Ordonly)
+ if fd < 0
+ -> fd castto(errno)
+ ;;
+ /*
+ FIXME: if the path is longer than sys.Pathmax, we should fall back to
+ the ugly method of finding the path.
+ */
+ -> sys.fcntl(fd, sys.Fgetpath, path[:] castto(byte#)) castto(errno)
+}