new syscall stubs
authorbrian <brian@brianweb.net>
Sat, 8 May 2004 07:28:30 +0000 (00:28 -0700)
committerbrian <brian@brianweb.net>
Sat, 8 May 2004 07:28:30 +0000 (00:28 -0700)
darcs-hash:20040508072830-24bed-b87602083226b1dbd47b9550d777b683c98693ae.gz

src/org/ibex/nestedvm/UnixRuntime.java
src/org/ibex/nestedvm/UsermodeConstants.java
src/org/ibex/nestedvm/support.s
src/org/ibex/nestedvm/support_aux.c
src/org/ibex/nestedvm/syscalls.h
upstream/Makefile
upstream/patches/newlib-mips.patch
upstream/patches/newlib-vasprintf.patch [new file with mode: 0644]

index 6c986e5..1466a9b 100644 (file)
@@ -4,6 +4,8 @@ import org.ibex.nestedvm.util.*;
 import java.io.*;
 import java.util.*;
 
+// FEATURE: vfork
+
 public abstract class UnixRuntime extends Runtime implements Cloneable {
     /** The pid of this "process" */
     private int pid;
@@ -114,6 +116,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
             case SYS_exec: return sys_exec(a,b,c);
             case SYS_getdents: return sys_getdents(a,b,c,d);
             case SYS_unlink: return sys_unlink(a);
+            case SYS_getppid: return sys_getppid();
 
             default: return super._syscall(syscall,a,b,c,d);
         }
@@ -122,6 +125,10 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     FD _open(String path, int flags, int mode) throws ErrnoException {
         return gs.open(this,normalizePath(path),flags,mode);
     }
+    
+    private int sys_getppid() {
+        return parent == null ? 1 : parent.pid;
+    }
 
     /** The kill syscall.
        SIGSTOP, SIGTSTO, SIGTTIN, and SIGTTOUT pause the process.
index 5f3d358..75ec440 100644 (file)
@@ -42,6 +42,14 @@ public interface UsermodeConstants {
     public static final int SYS_memcpy = 37;
     public static final int SYS_memset = 38;
     public static final int SYS_dup = 39;
+    public static final int SYS_vfork = 40;
+    public static final int SYS_chroot = 41;
+    public static final int SYS_mknod = 42;
+    public static final int SYS_lchown = 43;
+    public static final int SYS_ftruncate = 44;
+    public static final int SYS_usleep = 45;
+    public static final int SYS_getppid = 46;
+    public static final int SYS_mkfifo = 47;
     public static final int EPERM = 1; /* Not super-user */
     public static final int ENOENT = 2; /* No such file or directory */
     public static final int ESRCH = 3; /* No such process */
index 2af9010..b436306 100644 (file)
@@ -128,3 +128,11 @@ SYSCALL_R(getdents)
 SYSCALL(memcpy)
 SYSCALL(memset)
 SYSCALL_R(dup)
+SYSCALL_R(vfork)
+SYSCALL_R(chroot)
+SYSCALL_R(mknod)
+SYSCALL_R(lchown)
+SYSCALL_R(ftruncate)
+SYSCALL_R(usleep)
+SYSCALL(getppid)
+SYSCALL_R(mkfifo)
index bc32e8e..821769e 100644 (file)
@@ -1,3 +1,4 @@
+#include <string.h>
 #include <sys/stat.h>
 #include <sys/dirent.h>
 #include <sys/types.h>
@@ -7,6 +8,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <signal.h>
 
 int _syscall_set_errno(struct _reent *ptr, int err) {
     ptr->_errno = -err;
@@ -35,6 +37,11 @@ int _fchmod_r(struct _reent *ptr, int fd, mode_t mode) { return 0; }
 int _chown_r(struct _reent *ptr, const char *f, uid_t uid, gid_t gid) { return 0; }
 int _fchown_r(struct _reent *ptr, int fd, uid_t uid, gid_t gid) { return 0; }
 
+#define REENT_WRAPPER0R(f,rt) \
+    extern rt _##f##_r(struct _reent *ptr); \
+    rt f() { return _##f##_r(_REENT); }
+#define REENT_WRAPPER0(f) REENT_WRAPPER0R(f,int)
+
 #define REENT_WRAPPER1R(f,rt,t1) \
     extern rt _##f##_r(struct _reent *ptr, t1 a); \
     rt f(t1 a) { return _##f##_r(_REENT,a); }
@@ -70,12 +77,19 @@ REENT_WRAPPER2(symlink,const char *,const char *)
 REENT_WRAPPER3(readlink,const char *, char *,int)
 REENT_WRAPPER3(chown,const char *,uid_t,gid_t)
 REENT_WRAPPER3(fchown,int,uid_t,gid_t)
+REENT_WRAPPER3(lchown,const char *,uid_t,gid_t)
 REENT_WRAPPER2(chmod,const char *,mode_t)
 REENT_WRAPPER2(fchmod,int,mode_t)
 REENT_WRAPPER2(lstat,const char *,struct stat *)
 REENT_WRAPPER4(getdents,int, char *, size_t,long *)
 REENT_WRAPPER1(dup,int)
 REENT_WRAPPER2R(pathconf,long,const char *,int)
+REENT_WRAPPER0(vfork)
+REENT_WRAPPER1(chroot,const char *)
+REENT_WRAPPER3(mknod,const char *,mode_t,dev_t)
+REENT_WRAPPER2(ftruncate,int,off_t)
+REENT_WRAPPER1(usleep,unsigned int)
+REENT_WRAPPER2(mkfifo,const char *, mode_t)
 
 extern int __execve_r(struct _reent *ptr, const char *path, char *const argv[], char *const envp[]);
 int _execve(const char *path, char *const argv[], char *const envp[]) {
@@ -112,6 +126,47 @@ long _pathconf_r(struct _reent *ptr,const char *path, int name) {
     }
 }
 
+void sync() {
+    /* do nothing*/
+}
+
+int fsync(int fd) {
+    /* do nothing */
+    return 0;
+}
+
+char *ttyname(int fd) {
+    return isatty(fd) ? "/dev/console" : NULL;
+}
+
+int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
+    _sig_func_ptr old;
+    _sig_func_ptr new;
+    if(act) {
+        if(act->sa_flags || act->sa_mask != ~((sigset_t)0)) { errno = EINVAL; return -1; }
+        old = signal(sig,act->sa_handler);
+    } else if(oact) {
+        old = signal(sig,SIG_DFL);
+        signal(sig,old);
+    }
+    if(oact) {
+        oact->sa_handler = old;
+        oact->sa_mask = 0;
+        oact->sa_mask = ~((sigset_t)0);
+    }
+    return 0;
+}
+
+int sigfillset(sigset_t *set) {
+    *set = ~((sigset_t)0);
+    return 0;
+}
+
+int sigemptyset(sigset_t *set) {
+    *set = (sigset_t) 0;
+    return 0;
+}
+
 DIR *opendir(const char *path) {
     struct stat sb;
     int fd;
@@ -165,3 +220,118 @@ int closedir(DIR *dir) {
     free(dir);
     return close(fd);
 }
+
+/*
+ * Other People's Code 
+ */
+
+/* FreeBSD's dirname/basename */
+
+/* FIXME: Put these in a header */
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+char *
+dirname(path)
+const char *path;
+{
+    static char bname[MAXPATHLEN];
+    register const char *endp;
+    
+    /* Empty or NULL string gets treated as "." */
+    if (path == NULL || *path == '\0') {
+        (void)strcpy(bname, ".");
+        return(bname);
+    }
+    
+    /* Strip trailing slashes */
+    endp = path + strlen(path) - 1;
+    while (endp > path && *endp == '/')
+        endp--;
+    
+    /* Find the start of the dir */
+    while (endp > path && *endp != '/')
+        endp--;
+    
+    /* Either the dir is "/" or there are no slashes */
+    if (endp == path) {
+        (void)strcpy(bname, *endp == '/' ? "/" : ".");
+        return(bname);
+    } else {
+        do {
+            endp--;
+        } while (endp > path && *endp == '/');
+    }
+    
+    if (endp - path + 2 > sizeof(bname)) {
+        errno = ENAMETOOLONG;
+        return(NULL);
+    }
+    (void)strncpy(bname, path, endp - path + 1);
+    bname[endp - path + 1] = '\0';
+    return(bname);
+}
+
+char *
+basename(path)
+const char *path;
+{
+    static char bname[MAXPATHLEN];
+    register const char *endp, *startp;
+    
+    /* Empty or NULL string gets treated as "." */
+    if (path == NULL || *path == '\0') {
+        (void)strcpy(bname, ".");
+        return(bname);
+    }
+    
+    /* Strip trailing slashes */
+    endp = path + strlen(path) - 1;
+    while (endp > path && *endp == '/')
+        endp--;
+    
+    /* All slashes becomes "/" */
+    if (endp == path && *endp == '/') {
+        (void)strcpy(bname, "/");
+        return(bname);
+    }
+    
+    /* Find the start of the base */
+    startp = endp;
+    while (startp > path && *(startp - 1) != '/')
+        startp--;
+    
+    if (endp - startp + 2 > sizeof(bname)) {
+        errno = ENAMETOOLONG;
+        return(NULL);
+    }
+    (void)strncpy(bname, startp, endp - startp + 1);
+    bname[endp - startp + 1] = '\0';
+    return(bname);
+}
+
index b4a2c9c..a446886 100644 (file)
 #define SYS_memcpy 37
 #define SYS_memset 38
 #define SYS_dup 39
+#define SYS_vfork 40
+#define SYS_chroot 41
+#define SYS_mknod 42
+#define SYS_lchown 43
+#define SYS_ftruncate 44
+#define SYS_usleep 45
+#define SYS_getppid 46
+#define SYS_mkfifo 47
index 5360084..e8082da 100644 (file)
@@ -14,7 +14,7 @@ configure_binutils = --target=mips-unknown-elf
 
 version_newlib = 1.11.0
 url_newlib = http://mirrors.rcn.net/pub/sourceware/newlib/newlib-$(version_newlib).tar.gz
-patches_newlib = newlib-mips.patch newlib-tzset.patch newlib-malloc.patch
+patches_newlib = newlib-mips.patch newlib-tzset.patch newlib-malloc.patch newlib-vasprintf.patch
 configure_newlib = --enable-multilib --target=mips-unknown-elf
 
 url_openbsdglob = http://www.brianweb.net/xwt/openbsdglob.tar.gz
@@ -97,7 +97,6 @@ tasks/patch_%: tasks/extract_%
 
 tasks/build_%: tasks/patch_%
        mkdir -p $(usr)
-       @[ "$*" = "newlib" ] && rm -f $(usr)/mips-unknown-elf/lib/crt0.o || true
        mkdir -p build/$*-obj && cd build/$*-obj && \
                ../$*-$(version_$*)/configure --prefix=$(usr) $(configure_$*) && \
                $(MAKE) TARGET_CFLAGS="$(MIPS_CFLAGS)" && \
index 889a32f..ad43476 100644 (file)
@@ -237,3 +237,14 @@ diff -rNu ../newlib-1.11.0.orig/newlib/libc/include/sys/dirent.h ./newlib/libc/i
  #ifdef __cplusplus
  }
  #endif
+--- newlib/libc/include/sys/signal.h~  2004-05-07 02:06:28.000000000 -0400
++++ newlib/libc/include/sys/signal.h   2004-05-07 02:06:28.000000000 -0400
+@@ -145,7 +145,7 @@
+ int _EXFUN(kill, (int, int));
+ /* protos for functions found in winsup sources for CYGWIN */
+-#if defined(__CYGWIN__) || defined(__rtems__)
++#if defined(__CYGWIN__) || defined(__rtems__) || 1
+ #undef sigaddset
+ #undef sigemptyset
+ /* The first argument to kill should be pid_t.  Right now
diff --git a/upstream/patches/newlib-vasprintf.patch b/upstream/patches/newlib-vasprintf.patch
new file mode 100644 (file)
index 0000000..dfdf393
--- /dev/null
@@ -0,0 +1,10 @@
+--- newlib/libc/stdio/Makefile.in~     2004-05-07 03:54:24.000000000 -0400
++++ newlib/libc/stdio/Makefile.in      2004-05-07 03:54:24.000000000 -0400
+@@ -183,6 +183,7 @@
+ @ELIX_LEVEL_1_TRUE@LIB_OBJS = 
+ @ELIX_LEVEL_1_FALSE@LIB_OBJS = @ELIX_LEVEL_1_FALSE@\
+ @ELIX_LEVEL_1_FALSE@  asprintf.$(oext)                \
++@ELIX_LEVEL_1_FALSE@  vasprintf.$(oext)               \
+ @ELIX_LEVEL_1_FALSE@  fcloseall.$(oext)               \
+ @ELIX_LEVEL_1_FALSE@  fseeko.$(oext)                  \
+ @ELIX_LEVEL_1_FALSE@  ftello.$(oext)                  \