ref: 5778299b7291336a05a50d7387d99c9f28013937
parent: 410752ea2d5f6661e363379d14bd255521ca46e7
author: Ori Bernstein <[email protected]>
date: Mon Oct 1 21:17:17 EDT 2012
Use C strings for system calls. We used Myrddin strings, which are not nul terminated, when entering the system. Since Posix systems use nul terminated strings for paths and such in system calls, this was wrong. Now, strings are allocated on the stack by an assembly function that does some trickery with stack pointer adjustment, and passed to the kernel that way. This should not be a bottleneck, and allows us to keep slicing strings.
--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -12,7 +12,8 @@
ASMSRC= \
start.s \
- syscall.s
+ syscall.s \
+ util.s
include ../config.mk
--- a/libstd/sys-linux.myr
+++ b/libstd/sys-linux.myr
@@ -369,6 +369,7 @@
const Sysprocess_vm_writev : scno = 311
extern const syscall : (sc:scno, args:... -> int64)
+ extern const cstring : (str : byte[:] -> byte*)
const exit : (status:int64 -> void)
const getpid : ( -> int64)
@@ -387,9 +388,9 @@
const exit = {status; syscall(Sysexit, 1);}
const getpid = {; -> syscall(Sysgetpid, 1);}
const kill = {pid, sig; -> syscall(Syskill, pid, sig);}
-const open = {path, opts, mode; -> syscall(Sysopen, path castto(char*), opts);}
+const open = {path, opts, mode; -> syscall(Sysopen, cstring(path), opts, mode);}
const close = {fd; -> syscall(Sysclose, fd);}
-const creat = {path, mode; -> syscall(Syscreat, path castto(char*), mode);}
+const creat = {path, mode; -> syscall(Syscreat, cstring(path), mode);}
const read = {fd, buf; -> syscall(Sysread, fd, buf castto(char*), buf.len);}
const write = {fd, buf; -> syscall(Syswrite, fd, buf castto(char*), buf.len castto(size));}
const lseek = {fd, off, whence; -> syscall(Syslseek, fd, off, whence);}
--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -433,7 +433,7 @@
const exit = {status; syscall(Sysexit, 1);}
const getpid = {; -> syscall(Sysgetpid, 1);}
const kill = {pid, sig; -> syscall(Syskill, pid, sig);}
-const open = {path, opts, mode; -> syscall(Sysopen, path castto(char*), opts);}
+const open = {path, opts, mode; -> syscall(Sysopen, cstring(path) opts, mode);}
const close = {fd; -> syscall(Sysclose, fd);}
const creat = {path, mode; -> open(path, Ocreat | Otrunc | Owronly, mode);}
const read = {fd, buf; -> syscall(Sysread, fd, buf castto(char*), buf.len);}
--- a/libstd/syscall-linux.s
+++ b/libstd/syscall-linux.s
@@ -20,3 +20,4 @@
popq %rbp
ret
+
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -162,7 +162,7 @@
char *localdep;
char *deps[512];
char buf[1024];
- char *extra[2] = {"-o", "" /* filename */};
+ char *extra[] = {"-g", "-o", "" /* filename */};
if (hassuffix(file, ".myr")) {
getdeps(file, deps, 512, &ndeps);
@@ -189,8 +189,8 @@
} else if (hassuffix(file, ".s")) {
swapsuffix(buf, sizeof buf, file, ".s", ".o");
if (isfresh(file, buf)) {
- extra[1] = buf;
- gencmd(&cmd, &ncmd, as, file, extra, 2);
+ extra[2] = buf;
+ gencmd(&cmd, &ncmd, as, file, extra, 3);
run(cmd);
}
}