Skip to contentSkip to conversation

bsd-user: FreeBSD support for mips/mips64 and arm

PATCH In review Stacey Son 3 participants 41 messages Jun 24, 2013 Kbuild

lore
Share & tools
lore
author
#12 lore raw

PATCH 7/23 bsd-user: find target executable in path when absolute path not given

In reply to Stacey Son

If the target executable's path is not absolute then this code will search the PATH to find it. Save the fullpath to put on to the stack for the runtime linker.

---
 bsd-user/bsdload.c |   84 +++++++++++++++++++++++++++++++++++++++++++++++++--
 bsd-user/qemu.h    |    3 +-
 2 files changed, 82 insertions(+), 5 deletions(-)
bsd-user/bsdload.c +80 -4
index cc4f534..c768855 100644
@@ -169,19 +169,95 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
     return sp;
 }
 
+static int is_there(const char *candidate)
+{
+    struct stat fin;
+
+    /* XXX work around access(2) false positives for superuser */
+    if (access(candidate, X_OK) == 0 && stat(candidate, &fin) == 0 &&
+            S_ISREG(fin.st_mode) && (getuid() != 0 ||
+                (fin.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0)) {
+        return 1;
+    }
+
+    return 0;
+}
+
+static int find_in_path(char *path, const char *filename, char *retpath,
+        size_t rpsize)
+{
+    const char *d;
+    int found;
+
+    if (strchr(filename, '/') != NULL) {
+        if (is_there(filename)) {
+                if (!realpath(filename, retpath)) {
+                    return -1;
+                }
+                return 0;
+        } else {
+            return -1;
+        }
+    }
+
+    found = 0;
+    while ((d = strsep(&path, ":")) != NULL) {
+        if (*d == '\0') {
+            d = ".";
+        }
+        if (snprintf(retpath, rpsize, "%s/%s", d, filename) >= (int)rpsize) {
+            continue;
+        }
+        if (is_there((const char *)retpath)) {
+            found = 1;
+            break;
+        }
+    }
+    return found;
+}
+
 int loader_exec(const char * filename, char ** argv, char ** envp,
              struct target_pt_regs *regs, struct image_info *infop,
              struct bsd_binprm *bprm)
 {
-    int retval;
-    int i;
+    char *p, *path = NULL, fullpath[PATH_MAX];
+    const char *execname = NULL;
+    int retval, i;
 
-    bprm->p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
+    bprm->p = TARGET_PAGE_SIZE * MAX_ARG_PAGES; /* -sizeof(unsigned int); */
     for (i=0 ; i<MAX_ARG_PAGES ; i++)       /* clear page-table */
             bprm->page[i] = NULL;
-    retval = open(filename, O_RDONLY);
+
+    /* Find target executable in path, if not already an absolute path. */
+    p = getenv("PATH");
+    if (p != NULL) {
+        path = g_strdup(p);
+        if (path == NULL) {
+            fprintf(stderr, "Out of memory\n");
+            return -1;
+        }
+        execname = realpath(filename, NULL);
+        if (execname == NULL) {
+            execname = filename;
+        }
+        if (!find_in_path(path, execname, fullpath, sizeof(fullpath))) {
+            retval = open(fullpath, O_RDONLY);
+            bprm->fullpath = g_strdup(fullpath);
+        } else {
+            retval = open(execname, O_RDONLY);
+            bprm->fullpath = NULL;
+        }
+        if (execname) {
+            free((void *)execname);
+        }
+        free(path);
+    } else {
+        retval = open(filename, O_RDONLY);
+        bprm->fullpath = NULL;
+    }
     if (retval < 0)
         return retval;
+
     bprm->fd = retval;
     bprm->filename = (char *)filename;
     bprm->argc = count(argv);
bsd-user/qemu.h +2 -1
index a36e9d2..1e2abd5 100644
@@ -128,7 +128,8 @@ struct bsd_binprm {
         int argc, envc;
         char **argv;
         char **envp;
-        char *filename;        /* Name of binary */
+        char *filename;        /* (Given) Name of binary */
+        char *fullpath;        /* Full path of binary */
         int (*core_dump)(int, const CPUArchState *);
 };
 
Signature · 1 line
1.7.8
author
#10 lore raw

PATCH 5/23 bsd-user: add bsd_binprm to TaskState for core dumping emulation

In reply to Stacey Son

Add the bsd_binprm (formerly linux_binprm) structure to TaskState so it can be used to support core dumping emulation support in the future. Also, make freebsd the default bsd_type, if compiled on a FreeBSD system.

---
 bsd-user/bsdload.c |   36 ++++++++++++++++++------------------
 bsd-user/elfload.c |    6 +++---
 bsd-user/main.c    |   19 ++++++++++++++++++-
 bsd-user/qemu.h    |   22 +++++++++++++---------
 bsd-user/signal.c  |    6 ------
 5 files changed, 52 insertions(+), 37 deletions(-)
bsd-user/bsdload.c +18 -18
index 637a217..cc4f534 100644
@@ -68,7 +68,7 @@ static int count(char ** vec)
     return(i);
 }
 
-static int prepare_binprm(struct linux_binprm *bprm)
+static int prepare_binprm(struct bsd_binprm *bprm)
 {
     struct stat         st;
     int mode;
@@ -170,33 +170,33 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
 }
 
 int loader_exec(const char * filename, char ** argv, char ** envp,
-             struct target_pt_regs * regs, struct image_info *infop)
+             struct target_pt_regs *regs, struct image_info *infop,
+             struct bsd_binprm *bprm)
 {
-    struct linux_binprm bprm;
     int retval;
     int i;
 
-    bprm.p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
+    bprm->p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
     for (i=0 ; i<MAX_ARG_PAGES ; i++)       /* clear page-table */
-            bprm.page[i] = NULL;
+            bprm->page[i] = NULL;
     retval = open(filename, O_RDONLY);
     if (retval < 0)
         return retval;
-    bprm.fd = retval;
-    bprm.filename = (char *)filename;
-    bprm.argc = count(argv);
-    bprm.argv = argv;
-    bprm.envc = count(envp);
-    bprm.envp = envp;
+    bprm->fd = retval;
+    bprm->filename = (char *)filename;
+    bprm->argc = count(argv);
+    bprm->argv = argv;
+    bprm->envc = count(envp);
+    bprm->envp = envp;
 
-    retval = prepare_binprm(&bprm);
+    retval = prepare_binprm(bprm);
 
     if(retval>=0) {
-        if (bprm.buf[0] == 0x7f
-                && bprm.buf[1] == 'E'
-                && bprm.buf[2] == 'L'
-                && bprm.buf[3] == 'F') {
-            retval = load_elf_binary(&bprm,regs,infop);
+        if (bprm->buf[0] == 0x7f
+                && bprm->buf[1] == 'E'
+                && bprm->buf[2] == 'L'
+                && bprm->buf[3] == 'F') {
+            retval = load_elf_binary(bprm, regs, infop);
         } else {
             fprintf(stderr, "Unknown binary format\n");
             return -1;
@@ -211,7 +211,7 @@ int loader_exec(const char * filename, char ** argv, char ** envp,
 
     /* Something went wrong, return the inode and free the argument pages*/
     for (i=0 ; i<MAX_ARG_PAGES ; i++) {
-        g_free(bprm.page[i]);
+        g_free(bprm->page[i]);
     }
     return(retval);
 }
bsd-user/elfload.c +3 -3
index 035bcea..0f6c3db 100644
@@ -679,7 +679,7 @@ static abi_ulong copy_elf_strings(int argc,char ** argv, void **page,
     return p;
 }
 
-static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
+static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm,
                                  struct image_info *info)
 {
     abi_ulong stack_base, size, error;
@@ -1164,8 +1164,8 @@ static void load_symbols(struct elfhdr *hdr, int fd)
     syminfos = s;
 }
 
-int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
-                    struct image_info * info)
+int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
+                    struct image_info *info)
 {
     struct elfhdr elf_ex;
     struct elfhdr interp_elf_ex;
bsd-user/main.c +18 -1
index 2eb4a1b..0442dbe 100644
@@ -884,6 +884,15 @@ static void usage(void)
 
 THREAD CPUArchState *thread_env;
 
+void stop_all_tasks(void)
+{
+    /*
+     * We trust when using NPTL (pthreads) start_exclusive() handles thread
+     * stopping correctly.
+     */
+    start_exclusive();
+}
+
 /* Assumes contents are already zeroed.  */
 void init_task_state(TaskState *ts)
 {
@@ -905,6 +914,7 @@ int main(int argc, char **argv)
     const char *log_mask = NULL;
     struct target_pt_regs regs1, *regs = &regs1;
     struct image_info info1, *info = &info1;
+    struct bsd_binprm bprm;
     TaskState ts1, *ts = &ts1;
     CPUArchState *env;
     int optind;
@@ -912,7 +922,11 @@ int main(int argc, char **argv)
     int gdbstub_port = 0;
     char **target_environ, **wrk;
     envlist_t *envlist = NULL;
+#ifdef __FreeBSD__
+    bsd_type = target_freebsd;
+#else
     bsd_type = target_openbsd;
+#endif
 
     if (argc <= 1)
         usage();
@@ -1054,6 +1068,8 @@ int main(int argc, char **argv)
     /* Zero out regs */
     memset(regs, 0, sizeof(struct target_pt_regs));
 
+    memset(&bprm, 0, sizeof(bprm));
+
     /* Zero out image_info */
     memset(info, 0, sizeof(struct image_info));
 
@@ -1133,7 +1149,7 @@ int main(int argc, char **argv)
     }
 #endif /* CONFIG_USE_GUEST_BASE */
 
-    if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
+    if (loader_exec(filename, argv+optind, target_environ, regs, info, &bprm)) {
         printf("Error loading %s\n", filename);
         _exit(1);
     }
@@ -1178,6 +1194,7 @@ int main(int argc, char **argv)
     memset(ts, 0, sizeof(TaskState));
     init_task_state(ts);
     ts->info = info;
+    ts->bprm = &bprm;
     env->opaque = ts;
 
 #if defined(TARGET_I386)
bsd-user/qemu.h +13 -9
index c0cdfcd..a36e9d2 100644
@@ -90,6 +90,7 @@ typedef struct TaskState {
     struct TaskState *next;
     int used; /* non zero if used */
     struct image_info *info;
+    struct bsd_binprm *bprm;
 
     struct emulated_sigtable sigtab[TARGET_NSIG];
     struct qemu_sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */
@@ -100,6 +101,7 @@ typedef struct TaskState {
 } __attribute__((aligned(16))) TaskState;
 
 void init_task_state(TaskState *ts);
+void stop_all_tasks(void);
 extern const char *qemu_uname_release;
 #if defined(CONFIG_USE_GUEST_BASE)
 extern unsigned long mmap_min_addr;
@@ -117,7 +119,7 @@ extern unsigned long mmap_min_addr;
  * This structure is used to hold the arguments that are
  * used when loading binaries.
  */
-struct linux_binprm {
+struct bsd_binprm {
         char buf[128];
         void *page[MAX_ARG_PAGES];
         abi_ulong p;
@@ -126,19 +128,21 @@ struct linux_binprm {
         int argc, envc;
         char **argv;
         char **envp;
-        char * filename;        /* Name of binary */
+        char *filename;        /* Name of binary */
+        int (*core_dump)(int, const CPUArchState *);
 };
 
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
                               abi_ulong stringp, int push_ptr);
-int loader_exec(const char * filename, char ** argv, char ** envp,
-             struct target_pt_regs * regs, struct image_info *infop);
-
-int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
-                    struct image_info * info);
-int load_flt_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
-                    struct image_info * info);
+int loader_exec(const char *filename, char **argv, char **envp,
+             struct target_pt_regs *regs, struct image_info *infop,
+             struct bsd_binprm *bprm);
+
+int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
+                    struct image_info *info);
+int load_flt_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
+                    struct image_info *info);
 
 abi_long memcpy_to_target(abi_ulong dest, const void *src,
                           unsigned long len);
bsd-user/signal.c +0 -6
index eb452fc..4ee97af 100644
@@ -263,7 +263,6 @@ void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info)
     tswap_siginfo(tinfo, tinfo);
 }
 
-#if 0 /* not yet */
 /* Returns 1 if given signal should dump core if not handled. */
 static int core_dump_signal(int sig)
 {
@@ -280,7 +279,6 @@ static int core_dump_signal(int sig)
         return 0;
     }
 }
-#endif /* not yet */
 
 /* Signal queue handling. */
 static inline struct qemu_sigqueue *alloc_sigqueue(CPUArchState *env)
@@ -306,10 +304,8 @@ static inline void free_sigqueue(CPUArchState *env, struct qemu_sigqueue *q)
 /* Abort execution with signal. */
 void QEMU_NORETURN force_sig(int target_sig)
 {
-#if 0 /* not yet */
     TaskState *ts = (TaskState *)thread_env->opaque;
     int core_dumped = 0;
-#endif
     int host_sig;
     struct sigaction act;
 
@@ -317,7 +313,6 @@ void QEMU_NORETURN force_sig(int target_sig)
     gdb_signalled(thread_env, target_sig);
 
     /* Dump core if supported by target binary format */
-#if 0 /* net yet */
     if (core_dump_signal(target_sig) && (ts->bprm->core_dump != NULL)) {
         stop_all_tasks();
         core_dumped =
@@ -335,7 +330,6 @@ void QEMU_NORETURN force_sig(int target_sig)
          (void) fprintf(stderr, "qemu: uncaught target signal %d (%s) "
              "- %s\n", target_sig, strsignal(host_sig), "core dumped");
     }
-#endif /* not yet */
 
     /*
      * The proper exit code for dying from an uncaught signal is
Signature · 1 line
1.7.8
author
#11 lore raw

PATCH 6/23 bsd-user: fix thread initialization and ELF addresses for mips/mips64

In reply to Stacey Son

Initialize all the registers correctly for mips/mips64 in init_thread(), use the correct ELF_START_MMAP for mips64, use the correct run-time linker, and clean up the code by eliminating some #if's. Also, fix all the checkpatch.pl warnings and errors.

---
 bsd-user/elfload.c |  185 +++++++++++++++++++++++++++++-----------------------
 1 files changed, 103 insertions(+), 82 deletions(-)
bsd-user/elfload.c +103 -82
index 0f6c3db..8c8ed6a 100644
@@ -45,10 +45,11 @@
  * These occupy the top three bytes.
  */
 enum {
-        ADDR_NO_RANDOMIZE =     0x0040000,      /* disable randomization of VA space */
-        FDPIC_FUNCPTRS =        0x0080000,      /* userspace function ptrs point to descriptors
-                                                 * (signal handling)
-                                                 */
+        ADDR_NO_RANDOMIZE =     0x0040000,      /* disable randomization of VA
+                                                   space */
+        FDPIC_FUNCPTRS =        0x0080000,      /* userspace function ptrs
+                                                   point to descriptors
+                                                   (signal handling) */
         MMAP_PAGE_ZERO =        0x0100000,
         ADDR_COMPAT_LAYOUT =    0x0200000,
         READ_IMPLIES_EXEC =     0x0400000,
@@ -163,7 +164,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA        ELFDATA2LSB
 #define ELF_ARCH        EM_386
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
     regs->esp = infop->start_stack;
     regs->eip = infop->entry;
@@ -198,7 +200,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #endif
 #define ELF_ARCH        EM_ARM
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
     abi_long stack = infop->start_stack;
     memset(regs, 0, sizeof(*regs));
@@ -255,7 +258,8 @@ enum
 
 #define STACK_BIAS              2047
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
 #ifndef TARGET_ABI32
     regs->tstate = 0;
@@ -287,7 +291,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA    ELFDATA2MSB
 #define ELF_ARCH    EM_SPARC
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
     regs->psr = 0;
     regs->pc = infop->entry;
@@ -355,7 +360,8 @@ do {                                                                    \
         NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);                        \
  } while (0)
 
-static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *_regs,
+        struct image_info *infop)
 {
     abi_ulong pos = infop->start_stack;
     abi_ulong tmp;
@@ -391,13 +397,13 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info *
 
 #ifdef TARGET_MIPS
 
-#define ELF_START_MMAP 0x80000000
-
 #define elf_check_arch(x) ( (x) == EM_MIPS )
 
 #ifdef TARGET_MIPS64
+#define ELF_START_MMAP 0x2aaaaab000ULL
 #define ELF_CLASS   ELFCLASS64
 #else
+#define ELF_START_MMAP 0x80000000
 #define ELF_CLASS   ELFCLASS32
 #endif
 #ifdef TARGET_WORDS_BIGENDIAN
@@ -407,11 +413,14 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info *
 #endif
 #define ELF_ARCH    EM_MIPS
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
     regs->cp0_status = 2 << CP0St_KSU;
-    regs->cp0_epc = infop->entry;
-    regs->regs[29] = infop->start_stack;
+    regs->regs[25] = regs->cp0_epc = infop->entry & ~3;  /* t9/pc = entry */
+    regs->regs[4] = regs->regs[29] = infop->start_stack; /* a0/sp = stack */
+    regs->regs[5] = regs->regs[6] = 0;                   /* a1/a2 = 0 */
+    regs->regs[7] = TARGET_PS_STRINGS;                   /* a3 = ps_strings */
 }
 
 #define USE_ELF_CORE_DUMP
@@ -429,7 +438,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA  ELFDATA2LSB
 #define ELF_ARCH  EM_SH
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
   /* Check other registers XXXXX */
   regs->pc = infop->entry;
@@ -451,7 +461,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA  ELFDATA2LSB
 #define ELF_ARCH  EM_CRIS
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
   regs->erp = infop->entry;
 }
@@ -474,7 +485,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 /* ??? Does this need to do anything?
 #define ELF_PLAT_INIT(_r) */
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
     regs->usp = infop->start_stack;
     regs->sr = 0;
@@ -496,7 +508,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA       ELFDATA2MSB
 #define ELF_ARCH       EM_ALPHA
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+        struct image_info *infop)
 {
     regs->pc = infop->entry;
     regs->ps = 8;
@@ -555,7 +568,8 @@ struct exec
 
 /* Necessary parameters */
 #define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE
-#define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE-1))
+#define TARGET_ELF_PAGESTART(_v) ((_v) & \
+        ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE-1))
 #define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1))
 
 #define INTERPRETER_NONE 0
@@ -574,7 +588,7 @@ static int load_aout_interp(void * exptr, int interp_fd);
 #ifdef BSWAP_NEEDED
 static void bswap_ehdr(struct elfhdr *ehdr)
 {
-    bswap16s(&ehdr->e_type);                    /* Object file type */
+    bswap16s(&ehdr->e_type);            /* Object file type */
     bswap16s(&ehdr->e_machine);         /* Architecture */
     bswap32s(&ehdr->e_version);         /* Object file version */
     bswaptls(&ehdr->e_entry);           /* Entry point virtual address */
@@ -582,37 +596,45 @@ static void bswap_ehdr(struct elfhdr *ehdr)
     bswaptls(&ehdr->e_shoff);           /* Section header table file offset */
     bswap32s(&ehdr->e_flags);           /* Processor-specific flags */
     bswap16s(&ehdr->e_ehsize);          /* ELF header size in bytes */
-    bswap16s(&ehdr->e_phentsize);               /* Program header table entry size */
+    bswap16s(&ehdr->e_phentsize);       /* Program header table entry size */
     bswap16s(&ehdr->e_phnum);           /* Program header table entry count */
-    bswap16s(&ehdr->e_shentsize);               /* Section header table entry size */
+    bswap16s(&ehdr->e_shentsize);       /* Section header table entry size */
     bswap16s(&ehdr->e_shnum);           /* Section header table entry count */
-    bswap16s(&ehdr->e_shstrndx);                /* Section header string table index */
+    bswap16s(&ehdr->e_shstrndx);        /* Section header string table index */
 }
 
-static void bswap_phdr(struct elf_phdr *phdr)
+static void bswap_phdr(struct elf_phdr *phdr, int phnum)
 {
-    bswap32s(&phdr->p_type);                    /* Segment type */
-    bswaptls(&phdr->p_offset);          /* Segment file offset */
-    bswaptls(&phdr->p_vaddr);           /* Segment virtual address */
-    bswaptls(&phdr->p_paddr);           /* Segment physical address */
-    bswaptls(&phdr->p_filesz);          /* Segment size in file */
-    bswaptls(&phdr->p_memsz);           /* Segment size in memory */
-    bswap32s(&phdr->p_flags);           /* Segment flags */
-    bswaptls(&phdr->p_align);           /* Segment alignment */
+    int i;
+
+    for (i = 0; i < phnum; i++, phdr++) {
+        bswap32s(&phdr->p_type);        /* Segment type */
+        bswaptls(&phdr->p_offset);      /* Segment file offset */
+        bswaptls(&phdr->p_vaddr);       /* Segment virtual address */
+        bswaptls(&phdr->p_paddr);       /* Segment physical address */
+        bswaptls(&phdr->p_filesz);      /* Segment size in file */
+        bswaptls(&phdr->p_memsz);       /* Segment size in memory */
+        bswap32s(&phdr->p_flags);       /* Segment flags */
+        bswaptls(&phdr->p_align);       /* Segment alignment */
+    }
 }
 
-static void bswap_shdr(struct elf_shdr *shdr)
+static void bswap_shdr(struct elf_shdr *shdr, int shnum)
 {
-    bswap32s(&shdr->sh_name);
-    bswap32s(&shdr->sh_type);
-    bswaptls(&shdr->sh_flags);
-    bswaptls(&shdr->sh_addr);
-    bswaptls(&shdr->sh_offset);
-    bswaptls(&shdr->sh_size);
-    bswap32s(&shdr->sh_link);
-    bswap32s(&shdr->sh_info);
-    bswaptls(&shdr->sh_addralign);
-    bswaptls(&shdr->sh_entsize);
+    int i;
+
+    for (i = 0; i < shnum; i++, shdr++) {
+        bswap32s(&shdr->sh_name);
+        bswap32s(&shdr->sh_type);
+        bswaptls(&shdr->sh_flags);
+        bswaptls(&shdr->sh_addr);
+        bswaptls(&shdr->sh_offset);
+        bswaptls(&shdr->sh_size);
+        bswap32s(&shdr->sh_link);
+        bswap32s(&shdr->sh_info);
+        bswaptls(&shdr->sh_addralign);
+        bswaptls(&shdr->sh_entsize);
+    }
 }
 
 static void bswap_sym(struct elf_sym *sym)
@@ -622,7 +644,15 @@ static void bswap_sym(struct elf_sym *sym)
     bswaptls(&sym->st_size);
     bswap16s(&sym->st_shndx);
 }
-#endif
+
+#else /* ! BSWAP_NEEDED */
+
+static void bswap_ehdr(struct elfhdr *ehdr) { }
+static void bswap_phdr(struct elf_phdr *phdr, int phnum) { }
+static void bswap_shdr(struct elf_shdr *shdr, int shnum) { }
+static void bswap_sym(struct elf_sym *sym) { }
+
+#endif /* ! BSWAP_NEEDED */
 
 /*
  * 'copy_elf_strings()' copies argument/envelope strings from user
@@ -868,9 +898,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
         last_bss = 0;
         error = 0;
 
-#ifdef BSWAP_NEEDED
         bswap_ehdr(interp_elf_ex);
-#endif
         /* First of all, some simple consistency checks */
         if ((interp_elf_ex->e_type != ET_EXEC &&
              interp_elf_ex->e_type != ET_DYN) ||
@@ -911,12 +939,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
                 free (elf_phdata);
                 return retval;
         }
-#ifdef BSWAP_NEEDED
-        eppnt = elf_phdata;
-        for (i=0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
-            bswap_phdr(eppnt);
-        }
-#endif
+        bswap_phdr(elf_phdata, interp_elf_ex->e_phnum);
 
         if (interp_elf_ex->e_type == ET_DYN) {
             /* in order to avoid hardcoding the interpreter load
@@ -1065,9 +1088,7 @@ static void load_symbols(struct elfhdr *hdr, int fd)
     for (i = 0; i < hdr->e_shnum; i++) {
         if (read(fd, &sechdr, sizeof(sechdr)) != sizeof(sechdr))
             return;
-#ifdef BSWAP_NEEDED
-        bswap_shdr(&sechdr);
-#endif
+        bswap_shdr(&sechdr, 1);
         if (sechdr.sh_type == SHT_SYMTAB) {
             symtab = sechdr;
             lseek(fd, hdr->e_shoff
@@ -1075,9 +1096,7 @@ static void load_symbols(struct elfhdr *hdr, int fd)
             if (read(fd, &strtab, sizeof(strtab))
                 != sizeof(strtab))
                 return;
-#ifdef BSWAP_NEEDED
-            bswap_shdr(&strtab);
-#endif
+            bswap_shdr(&strtab, 1);
             goto found;
         }
     }
@@ -1110,9 +1129,7 @@ static void load_symbols(struct elfhdr *hdr, int fd)
 
     i = 0;
     while (i < nsyms) {
-#ifdef BSWAP_NEEDED
         bswap_sym(syms + i);
-#endif
         // Throw away entries which we do not need.
         if (syms[i].st_shndx == SHN_UNDEF ||
                 syms[i].st_shndx >= SHN_LORESERVE ||
@@ -1194,9 +1211,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
     load_addr = 0;
     load_bias = 0;
     elf_ex = *((struct elfhdr *) bprm->buf);          /* exec-header */
-#ifdef BSWAP_NEEDED
     bswap_ehdr(&elf_ex);
-#endif
 
     /* First of all, some simple consistency checks */
     if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
@@ -1204,12 +1219,14 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
             return -ENOEXEC;
     }
 
+#ifndef __FreeBSD__
     bprm->p = copy_elf_strings(1, &bprm->filename, bprm->page, bprm->p);
     bprm->p = copy_elf_strings(bprm->envc,bprm->envp,bprm->page,bprm->p);
     bprm->p = copy_elf_strings(bprm->argc,bprm->argv,bprm->page,bprm->p);
     if (!bprm->p) {
         retval = -E2BIG;
     }
+#endif /* ! __FreeBSD__ */
 
     /* Now read in all of the header information */
     elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize*elf_ex.e_phnum);
@@ -1230,12 +1247,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
         return -errno;
     }
 
-#ifdef BSWAP_NEEDED
-    elf_ppnt = elf_phdata;
-    for (i=0; i<elf_ex.e_phnum; i++, elf_ppnt++) {
-        bswap_phdr(elf_ppnt);
-    }
-#endif
+    bswap_phdr(elf_phdata, elf_ex.e_phnum);
     elf_ppnt = elf_phdata;
 
     elf_bss = 0;
@@ -1288,9 +1300,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
 
             /* JRP - Need to add X86 lib dir stuff here... */
 
-            if (strcmp(elf_interpreter,"/usr/lib/libc.so.1") == 0 ||
-                strcmp(elf_interpreter,"/usr/lib/ld.so.1") == 0) {
-              ibcs2_interpreter = 1;
+            if (strcmp(elf_interpreter, "/usr/lib/libc.so.1") == 0 ||
+                    strcmp(elf_interpreter, "/usr/lib/ld-elf.so.1") == 0) {
+                ibcs2_interpreter = 1;
             }
 
 #if 0
@@ -1437,7 +1449,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
         } else if (elf_ex.e_type == ET_DYN) {
             /* Try and get dynamic programs out of the way of the default mmap
                base, as well as whatever program they might try to exec.  This
-               is because the brk will follow the loader, and is not movable.  */
+               is because the brk will follow the loader, and is not movable. */
             /* NOTE: for qemu, we do a big mmap to get enough space
                without hardcoding any address */
             error = target_mmap(0, ET_DYN_MAP_SIZE,
@@ -1550,19 +1562,22 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
     info->end_data = end_data;
     info->start_stack = bprm->p;
 
-    /* Calling set_brk effectively mmaps the pages that we need for the bss and break
-       sections */
+    /*
+     * Calling set_brk effectively mmaps the pages that we need for the bss
+     * and break sections.
+     */
     set_brk(elf_bss, elf_brk);
 
     padzero(elf_bss, elf_brk);
 
 #if 0
-    printf("(start_brk) %x\n" , info->start_brk);
-    printf("(end_code) %x\n" , info->end_code);
-    printf("(start_code) %x\n" , info->start_code);
-    printf("(end_data) %x\n" , info->end_data);
-    printf("(start_stack) %x\n" , info->start_stack);
-    printf("(brk) %x\n" , info->brk);
+    printf("(start_brk) 0x" TARGET_FMT_lx "\n" , info->start_brk);
+    printf("(end_code) 0x" TARGET_FMT_lx "\n" , info->end_code);
+    printf("(start_code) 0x" TARGET_FMT_lx "\n" , info->start_code);
+    printf("(start_data) 0x" TARGET_FMT_lx "\n" , info->start_data);
+    printf("(end_data) 0x" TARGET_FMT_lx "\n" , info->end_data);
+    printf("(start_stack) 0x" TARGET_FMT_lx "\n" , info->start_stack);
+    printf("(brk) 0x" TARGET_FMT_lx "\n" , info->brk);
 #endif
 
     if ( info->personality == PER_SVR4 )
@@ -1571,12 +1586,18 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
                and some applications "depend" upon this behavior.
                Since we do not have the power to recompile these, we
                emulate the SVr4 behavior.  Sigh.  */
-            mapped_addr = target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC,
-                                      MAP_FIXED | MAP_PRIVATE, -1, 0);
+            mapped_addr = target_mmap(0, qemu_host_page_size, PROT_READ |
+                    PROT_EXEC, MAP_FIXED | MAP_PRIVATE, -1, 0);
     }
 
     info->entry = elf_entry;
 
+#ifdef USE_ELF_CORE_DUMP
+    /* not yet */
+    /* bprm->core_dump = &elf_core_dump; */
+    bprm->core_dump = NULL;
+#endif
+
     return 0;
 }
 
Signature · 1 line
1.7.8
author
#19 lore raw

PATCH 13/23 bsd-user: add shims for signal related system calls

In reply to Stacey Son

This change adds support for signal related system calls including sigaction(2), sigprocmask(2), sigpending(2), sigsuspend(2), and so on. The older, obsolete, system calls such as sigvec(2), sigblock(2), sigsetmask(2), and sigstack(2) are not supported.

---
 bsd-user/bsd-signal.h        |  232 ++++++++++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-signal.h |   43 ++++++++
 bsd-user/netbsd/os-signal.h  |   34 ++++++
 bsd-user/openbsd/os-signal.h |   34 ++++++
 bsd-user/syscall.c           |   57 ++++++++++
 5 files changed, 400 insertions(+), 0 deletions(-)
 create mode 100644 bsd-user/bsd-signal.h
 create mode 100644 bsd-user/freebsd/os-signal.h
 create mode 100644 bsd-user/netbsd/os-signal.h
 create mode 100644 bsd-user/openbsd/os-signal.h
bsd-user/bsd-signal.h new file +232 -0
new file mode 100644
index 0000000..48a8b56
@@ -0,0 +1,232 @@
+/*
+ *  signal related system call shims
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __BSD_SIGNAL_H_
+#define __BSD_SIGNAL_H_
+
+/* sigaction(2) */
+static inline abi_long do_bsd_sigaction(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    struct target_sigaction *old_act, act, oact, *pact;
+
+    if (arg2) {
+        if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) {
+            return -TARGET_EFAULT;
+        }
+        act._sa_handler = old_act->_sa_handler;
+        act.sa_flags = old_act->sa_flags;
+        memcpy(&act.sa_mask, &old_act->sa_mask, sizeof(target_sigset_t));
+        unlock_user_struct(old_act, arg2, 0);
+        pact = &act;
+    } else {
+        pact = NULL;
+    }
+    ret = get_errno(do_sigaction(arg1, pact, &oact));
+    if (!is_error(ret) && arg3) {
+        if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) {
+            return -TARGET_EFAULT;
+        }
+        old_act->_sa_handler = oact._sa_handler;
+        old_act->sa_flags = oact.sa_flags;
+        memcpy(&old_act->sa_mask, &oact.sa_mask, sizeof(target_sigset_t));
+        unlock_user_struct(old_act, arg3, 1);
+    }
+    return ret;
+}
+
+
+/* sigprocmask(2) */
+static inline abi_long do_bsd_sigprocmask(abi_long arg1, abi_ulong arg2,
+        abi_ulong arg3)
+{
+    abi_long ret;
+    void *p;
+    sigset_t set, oldset, *set_ptr;
+    int how;
+
+    if (arg2) {
+        switch (arg1) {
+        case TARGET_SIG_BLOCK:
+            how = SIG_BLOCK;
+            break;
+
+        case TARGET_SIG_UNBLOCK:
+            how = SIG_UNBLOCK;
+            break;
+
+        case TARGET_SIG_SETMASK:
+            how = SIG_SETMASK;
+            break;
+
+        default:
+            return -TARGET_EFAULT;
+        }
+        p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1);
+        if (p == NULL) {
+            return -TARGET_EFAULT;
+        }
+        target_to_host_sigset(&set, p);
+        unlock_user(p, arg2, 0);
+        set_ptr = &set;
+    } else {
+        how = 0;
+        set_ptr = NULL;
+    }
+    ret = get_errno(sigprocmask(how, set_ptr, &oldset));
+    if (!is_error(ret) && arg3) {
+        p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0);
+        if (p == NULL) {
+            return -TARGET_EFAULT;
+        }
+        host_to_target_sigset(p, &oldset);
+        unlock_user(p, arg3, sizeof(target_sigset_t));
+    }
+    return ret;
+}
+
+/* sigpending(2) */
+static inline abi_long do_bsd_sigpending(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+    sigset_t set;
+
+    ret = get_errno(sigpending(&set));
+    if (!is_error(ret)) {
+        p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0);
+        if (p == NULL) {
+            return -TARGET_EFAULT;
+        }
+        host_to_target_sigset(p, &set);
+        unlock_user(p, arg1, sizeof(target_sigset_t));
+    }
+    return ret;
+}
+
+/* sigsuspend(2) */
+static inline abi_long do_bsd_sigsuspend(abi_long arg1, abi_long arg2)
+{
+    void *p;
+    sigset_t set;
+
+    p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    target_to_host_sigset(&set, p);
+    unlock_user(p, arg1, 0);
+
+    return get_errno(sigsuspend(&set));
+}
+
+/* sigreturn(2) */
+static inline abi_long do_bsd_sigreturn(void *cpu_env, abi_long arg1)
+{
+
+    return do_sigreturn(cpu_env, arg1);
+}
+
+/* sigvec(2) - not defined */
+/* sigblock(2) - not defined */
+/* sigsetmask(2) - not defined */
+/* sigstack(2) - not defined */
+
+/* sigwait(2) */
+static inline abi_long do_bsd_sigwait(abi_ulong arg1, abi_ulong arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+    sigset_t set;
+    int sig;
+
+    p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    target_to_host_sigset(&set, p);
+    unlock_user(p, arg1, 0);
+    ret = get_errno(sigwait(&set, &sig));
+    if (!is_error(ret) && arg2) {
+        ret = put_user_s32(sig, arg2);
+    }
+    return ret;
+}
+
+/* sigwaitinfo(2) */
+static inline abi_long do_bsd_sigwaitinfo(abi_ulong arg1, abi_ulong arg2)
+{
+    abi_long ret;
+    void *p;
+    sigset_t set;
+    siginfo_t uinfo;
+
+    p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    target_to_host_sigset(&set, p);
+    unlock_user(p, arg1, 0);
+    ret = get_errno(sigwaitinfo(&set, &uinfo));
+    if (!is_error(ret) && arg2) {
+        p = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t), 0);
+        if (p == NULL) {
+            return -TARGET_EFAULT;
+        }
+        host_to_target_siginfo(p, &uinfo);
+        unlock_user(p, arg2, sizeof(target_siginfo_t));
+    }
+    return ret;
+}
+
+/* sigqueue(2) */
+static inline abi_long do_bsd_sigqueue(abi_long arg1, abi_long arg2,
+        abi_ulong arg3)
+{
+    union sigval value;
+
+    value.sival_ptr = (void *)(uintptr_t)arg3;
+    return get_errno(sigqueue(arg1, target_to_host_signal(arg2), value));
+}
+
+/* sigaltstck(2) */
+static inline abi_long do_bsd_sigaltstack(void *cpu_env, abi_ulong arg1,
+        abi_ulong arg2)
+{
+
+    return do_sigaltstack(arg1, arg2, get_sp_from_cpustate(cpu_env));
+}
+
+/* kill(2) */
+static inline abi_long do_bsd_kill(abi_long pid, abi_long sig)
+{
+
+    return get_errno(kill(pid, target_to_host_signal(sig)));
+}
+
+/* killpg(2) */
+static inline abi_long do_bsd_killpg(abi_long pg, abi_long sig)
+{
+
+    return get_errno(killpg(pg, target_to_host_signal(sig)));
+}
+
+#endif /* !  __BSD_SIGNAL_H_ */
bsd-user/freebsd/os-signal.h new file +43 -0

43 lines not on this page · raw message

bsd-user/netbsd/os-signal.h new file +34 -0
new file mode 100644
index 0000000..3ec4dfe
@@ -0,0 +1,34 @@
+/*
+ *  NetBSD signal system call shims
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __NETBSD_OS_SIGNAL_H_
+#define __NETBSD_OS_SIGNAL_H_
+
+/*
+ * XXX To support FreeBSD binaries on NetBSD these syscalls will need
+ * to be emulated.
+ */
+
+static inline abi_long do_freebsd_pdkill(abi_long arg1, abi_long arg2)
+{
+
+    qemu_log("qemu: Unsupported syscall pdkill()\n");
+    return -TARGET_ENOSYS;
+}
+
+#endif /* ! __NETBSD_OS_SIGNAL_H_ */
bsd-user/openbsd/os-signal.h new file +34 -0
new file mode 100644
index 0000000..5ca80b3
@@ -0,0 +1,34 @@
+/*
+ *  OpenBSD signal system call shims
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __OPENBSD_OS_SIGNAL_H_
+#define __OPENBSD_OS_SIGNAL_H_
+
+/*
+ * XXX To support FreeBSD binaries on OpenBSD these syscalls will need
+ * to be emulated.
+ */
+
+static inline abi_long do_freebsd_pdkill(abi_long arg1, abi_long arg2)
+{
+
+    qemu_log("qemu: Unsupported syscall pdkill()\n");
+    return -TARGET_ENOSYS;
+}
+
+#endif /* ! __OPENBSD_OS_SIGNAL_H_ */
bsd-user/syscall.c +57 -0

71 lines not on this page · raw message

Signature · 1 line
1.7.8
author
#13 lore raw

PATCH 8/23 bsd-user: initialize stack with signal trampolin code and canary

In reply to Stacey Son

Put full path for target executable, signal trampolin code, and stack canary on the stack in addition to just simply coping argv and env values.

---
 bsd-user/elfload.c                      |   32 +++-----
 bsd-user/freebsd/target_os_stack.h      |  124 +++++++++++++++++++++++++++++++
 bsd-user/i386/target_arch_sigtramp.h    |   11 +++
 bsd-user/mips/target_arch_signal.h      |    2 +-
 bsd-user/mips/target_arch_sigtramp.h    |   23 ++++++
 bsd-user/mips64/target_arch_sigtramp.h  |   23 ++++++
 bsd-user/netbsd/target_os_stack.h       |   31 ++++++++
 bsd-user/openbsd/target_os_stack.h      |   31 ++++++++
 bsd-user/sparc/target_arch_sigtramp.h   |   11 +++
 bsd-user/sparc64/target_arch_sigtramp.h |   11 +++
 bsd-user/x86_64/target_arch_sigtramp.h  |   11 +++
 11 files changed, 289 insertions(+), 21 deletions(-)
 create mode 100644 bsd-user/freebsd/target_os_stack.h
 create mode 100644 bsd-user/i386/target_arch_sigtramp.h
 create mode 100644 bsd-user/mips/target_arch_sigtramp.h
 create mode 100644 bsd-user/mips64/target_arch_sigtramp.h
 create mode 100644 bsd-user/netbsd/target_os_stack.h
 create mode 100644 bsd-user/openbsd/target_os_stack.h
 create mode 100644 bsd-user/sparc/target_arch_sigtramp.h
 create mode 100644 bsd-user/sparc64/target_arch_sigtramp.h
 create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h
bsd-user/elfload.c +12 -20
index 8c8ed6a..0cd5fc4 100644
@@ -27,6 +27,7 @@
 
 #include "qemu.h"
 #include "disas/disas.h"
+#include "target_os_stack.h"
 
 #ifdef _ARCH_PPC64
 #undef ARCH_DLINFO
@@ -712,38 +713,29 @@ static abi_ulong copy_elf_strings(int argc,char ** argv, void **page,
 static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm,
                                  struct image_info *info)
 {
-    abi_ulong stack_base, size, error;
-    int i;
+    abi_ulong stack_base, size;
+    abi_long addr;
 
     /* Create enough stack to hold everything.  If we don't use
      * it for args, we'll use it for something else...
      */
     size = target_dflssiz;
     stack_base = TARGET_USRSTACK - size;
-    error = target_mmap(0,
-                        size + qemu_host_page_size,
-                        PROT_READ | PROT_WRITE,
-                        MAP_PRIVATE | MAP_ANON,
-                        -1, 0);
-    if (error == -1) {
+    addr = target_mmap(stack_base , size + qemu_host_page_size,
+            PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+    if (addr == -1) {
         perror("stk mmap");
         exit(-1);
     }
     /* we reserve one extra page at the top of the stack as guard */
-    target_mprotect(error + size, qemu_host_page_size, PROT_NONE);
-
-    stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE;
-    p += stack_base;
+    target_mprotect(addr + size, qemu_host_page_size, PROT_NONE);
 
-    for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
-        if (bprm->page[i]) {
-            info->rss++;
-            /* FIXME - check return value of memcpy_to_target() for failure */
-            memcpy_to_target(stack_base, bprm->page[i], TARGET_PAGE_SIZE);
-            g_free(bprm->page[i]);
-        }
-        stack_base += TARGET_PAGE_SIZE;
+    p = setup_initial_stack(p, bprm, stack_base, size, addr);
+    if (p == 0) {
+        perror("stk setup");
+        exit(-1);
     }
+
     return p;
 }
 
bsd-user/freebsd/target_os_stack.h new file +124 -0

124 lines not on this page · raw message

bsd-user/i386/target_arch_sigtramp.h new file +11 -0
new file mode 100644
index 0000000..f0f36d1
@@ -0,0 +1,11 @@
+
+#ifndef _TARGET_ARCH_SIGTRAMP_H_
+#define _TARGET_ARCH_SIGTRAMP_H_
+
+static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
+        unsigned sys_sigreturn)
+{
+
+    return -TARGET_EOPNOTSUPP;
+}
+#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
bsd-user/mips/target_arch_signal.h +1 -1
index cc7e750..f68034f 100644
@@ -22,7 +22,7 @@
 
 #define TARGET_INSN_SIZE    4       /* mips instruction size */
 
-/* Size of the signal trampolin code placed on the stack. */
+/* Size of the signal trampolin code. See insall_sigtramp(). */
 #define TARGET_SZSIGCODE    ((abi_ulong)(4 * TARGET_INSN_SIZE))
 
 /* compare to mips/include/_limits.h */
bsd-user/mips/target_arch_sigtramp.h new file +23 -0
new file mode 100644
index 0000000..5e3c69a
@@ -0,0 +1,23 @@
+
+#ifndef _TARGET_ARCH_SIGTRAMP_H_
+#define _TARGET_ARCH_SIGTRAMP_H_
+
+/* Compare to mips/mips/locore.S sigcode() */
+static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
+        unsigned sys_sigreturn)
+{
+    int i;
+    uint32_t sigtramp_code[TARGET_SZSIGCODE/TARGET_INSN_SIZE] = {
+    /* 1 */ 0x67A40000 + sigf_uc,       /* daddu   $a0, $sp, (sigf_uc) */
+    /* 2 */ 0x24020000 + sys_sigreturn, /* li      $v0, (sys_sigreturn) */
+    /* 3 */ 0x0000000C,                 /* syscall */
+    /* 4 */ 0x0000000D                  /* break */
+    };
+
+    for (i = 0; i < 4; i++) {
+        tswap32s(&sigtramp_code[i]);
+    }
+
+    return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE);
+}
+#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
bsd-user/mips64/target_arch_sigtramp.h new file +23 -0
new file mode 100644
index 0000000..5e3c69a
@@ -0,0 +1,23 @@
+
+#ifndef _TARGET_ARCH_SIGTRAMP_H_
+#define _TARGET_ARCH_SIGTRAMP_H_
+
+/* Compare to mips/mips/locore.S sigcode() */
+static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
+        unsigned sys_sigreturn)
+{
+    int i;
+    uint32_t sigtramp_code[TARGET_SZSIGCODE/TARGET_INSN_SIZE] = {
+    /* 1 */ 0x67A40000 + sigf_uc,       /* daddu   $a0, $sp, (sigf_uc) */
+    /* 2 */ 0x24020000 + sys_sigreturn, /* li      $v0, (sys_sigreturn) */
+    /* 3 */ 0x0000000C,                 /* syscall */
+    /* 4 */ 0x0000000D                  /* break */
+    };
+
+    for (i = 0; i < 4; i++) {
+        tswap32s(&sigtramp_code[i]);
+    }
+
+    return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE);
+}
+#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
bsd-user/netbsd/target_os_stack.h new file +31 -0
new file mode 100644
index 0000000..a852ae6
@@ -0,0 +1,31 @@
+#ifndef _TARGET_OS_STACK_H_
+#define _TARGET_OS_STACK_H_
+
+#include "target_arch_sigtramp.h"
+
+static inline abi_ulong setup_initial_stack(abi_ulong p,
+        struct bsd_binprm *bprm, abi_ulong sbase, abi_ulong size,
+        abi_ulong addr)
+{
+    int i;
+    abi_ulong stack_base;
+
+    stack_base = addr + size - MAX_ARG_PAGES * TARGET_PAGE_SIZE;
+    p += stack_base;
+
+    for (i = 0; i < MAX_ARG_PAGES; i++) {
+        if (bprm->page[i]) {
+            info->rss++;
+            if (!memcpy_to_target(stack_base, bprm->page[i],
+                        TARGET_PAGE_SIZE)) {
+                return 0;
+            }
+            g_free(bprm->page[i]);
+        }
+        stack_base += TARGET_PAGE_SIZE;
+    }
+
+    return p;
+}
+
+#endif /* !_TARGET_OS_STACK_H_ */
bsd-user/openbsd/target_os_stack.h new file +31 -0
new file mode 100644
index 0000000..a852ae6
@@ -0,0 +1,31 @@
+#ifndef _TARGET_OS_STACK_H_
+#define _TARGET_OS_STACK_H_
+
+#include "target_arch_sigtramp.h"
+
+static inline abi_ulong setup_initial_stack(abi_ulong p,
+        struct bsd_binprm *bprm, abi_ulong sbase, abi_ulong size,
+        abi_ulong addr)
+{
+    int i;
+    abi_ulong stack_base;
+
+    stack_base = addr + size - MAX_ARG_PAGES * TARGET_PAGE_SIZE;
+    p += stack_base;
+
+    for (i = 0; i < MAX_ARG_PAGES; i++) {
+        if (bprm->page[i]) {
+            info->rss++;
+            if (!memcpy_to_target(stack_base, bprm->page[i],
+                        TARGET_PAGE_SIZE)) {
+                return 0;
+            }
+            g_free(bprm->page[i]);
+        }
+        stack_base += TARGET_PAGE_SIZE;
+    }
+
+    return p;
+}
+
+#endif /* !_TARGET_OS_STACK_H_ */
bsd-user/sparc/target_arch_sigtramp.h new file +11 -0
new file mode 100644
index 0000000..f0f36d1
@@ -0,0 +1,11 @@
+
+#ifndef _TARGET_ARCH_SIGTRAMP_H_
+#define _TARGET_ARCH_SIGTRAMP_H_
+
+static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
+        unsigned sys_sigreturn)
+{
+
+    return -TARGET_EOPNOTSUPP;
+}
+#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
bsd-user/sparc64/target_arch_sigtramp.h new file +11 -0
new file mode 100644
index 0000000..f0f36d1
@@ -0,0 +1,11 @@
+
+#ifndef _TARGET_ARCH_SIGTRAMP_H_
+#define _TARGET_ARCH_SIGTRAMP_H_
+
+static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
+        unsigned sys_sigreturn)
+{
+
+    return -TARGET_EOPNOTSUPP;
+}
+#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
bsd-user/x86_64/target_arch_sigtramp.h new file +11 -0
new file mode 100644
index 0000000..f0f36d1
@@ -0,0 +1,11 @@
+
+#ifndef _TARGET_ARCH_SIGTRAMP_H_
+#define _TARGET_ARCH_SIGTRAMP_H_
+
+static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
+        unsigned sys_sigreturn)
+{
+
+    return -TARGET_EOPNOTSUPP;
+}
+#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
Signature · 1 line
1.7.8
author
#2 lore raw

PATCH 2/23 bsd-user: add initial support for mips/mips64

In reply to Stacey Son

Add the main cpu loop, cpu_loop(), for mips and mips64 architecture. Set the cpu model. Add some stubs for future code.

---
 bsd-user/errno_defs.h                 |    5 +
 bsd-user/main.c                       |  189 +++++++++++++++++++++++++++++++++
 bsd-user/mips/syscall.h               |   42 +++++++
 bsd-user/mips/target_signal.h         |   38 +++++++
 bsd-user/mips64/syscall.h             |   42 +++++++
 bsd-user/mips64/target_signal.h       |   38 +++++++
 bsd-user/syscall.c                    |    8 ++
 default-configs/mips-bsd-user.mak     |    1 +
 default-configs/mips64-bsd-user.mak   |    1 +
 default-configs/mips64el-bsd-user.mak |    1 +
 default-configs/mipsel-bsd-user.mak   |    1 +
 target-mips/mips-defs.h               |   13 ++-
 12 files changed, 377 insertions(+), 2 deletions(-)
 create mode 100644 bsd-user/mips/syscall.h
 create mode 100644 bsd-user/mips/target_signal.h
 create mode 100644 bsd-user/mips64/syscall.h
 create mode 100644 bsd-user/mips64/target_signal.h
 create mode 100644 default-configs/mips-bsd-user.mak
 create mode 100644 default-configs/mips64-bsd-user.mak
 create mode 100644 default-configs/mips64el-bsd-user.mak
 create mode 100644 default-configs/mipsel-bsd-user.mak
bsd-user/errno_defs.h +5 -0
index fcf95d3..f01181d 100644
@@ -148,4 +148,9 @@
 #define TARGET_ENOMSG           90              /* No message of desired type */
 #define TARGET_ELAST            90              /* Must be equal largest errno */
 
+/* Internal errors: */
+#define TARGET_EJUSTRETURN      254             /* Just return without
+                                                   modifing regs */
+#define TARGET_ERESTART         255             /* Restart syscall */
+
 #endif /* !  _ERRNO_DEFS_H_ */
bsd-user/main.c +189 -0

219 lines not on this page · raw message

bsd-user/mips/syscall.h new file +42 -0

42 lines not on this page · raw message

bsd-user/mips/target_signal.h new file +38 -0
new file mode 100644
index 0000000..8ac3a2f
@@ -0,0 +1,38 @@
+/*
+ *  mips signal definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _MIPS_TARGET_SIGNAL_H_
+#define _MIPS_TARGET_SIGNAL_H_
+
+#include "cpu.h"
+
+#define TARGET_INSN_SIZE    4       /* mips instruction size */
+
+/* this struct defines a stack used during syscall handling */
+
+typedef struct target_sigaltstack {
+    abi_ulong ss_sp;
+    abi_long ss_flags;
+    abi_ulong ss_size;
+} target_stack_t;
+
+static inline abi_ulong get_sp_from_cpustate(CPUMIPSState *state)
+{
+    return state->active_tc.gpr[29];
+}
+
+#endif /* !_MIP64_TARGET_SIGNAL_H_ */
bsd-user/mips64/syscall.h new file +42 -0

42 lines not on this page · raw message

bsd-user/mips64/target_signal.h new file +38 -0
new file mode 100644
index 0000000..fc8674d
@@ -0,0 +1,38 @@
+/*
+ *  mips64 signal definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _MIPS64_TARGET_SIGNAL_H_
+#define _MIPS64_TARGET_SIGNAL_H_
+
+#include "cpu.h"
+
+#define TARGET_INSN_SIZE        4       /* mips64 instruction size */
+
+/* this struct defines a stack used during syscall handling */
+
+typedef struct target_sigaltstack {
+    abi_ulong ss_sp;
+    abi_long ss_flags;
+    abi_ulong ss_size;
+} target_stack_t;
+
+static inline abi_ulong get_sp_from_cpustate(CPUMIPSState *state)
+{
+    return state->active_tc.gpr[29];
+}
+
+#endif /* !_MIP64_TARGET_SIGNAL_H_ */
bsd-user/syscall.c +8 -0
index 8e8107b..02740d5 100644
@@ -146,6 +146,14 @@ static abi_long do_freebsd_sysarch(CPUX86State *env, int op, abi_ulong parms)
 }
 #endif
 
+#ifdef TARGET_MIPS
+static abi_long do_freebsd_sysarch(void *env, int op, abi_ulong parms)
+{
+
+    return -TARGET_EINVAL;
+}
+#endif /* TARGET_MIPS */
+
 #ifdef TARGET_SPARC
 static abi_long do_freebsd_sysarch(void *env, int op, abi_ulong parms)
 {
default-configs/mips-bsd-user.mak new file +1 -0
new file mode 100644
index 0000000..3fb129a
@@ -0,0 +1 @@
+# Default configuration for mips-bsd-user
default-configs/mips64-bsd-user.mak new file +1 -0
new file mode 100644
index 0000000..d4e72a6
@@ -0,0 +1 @@
+# Default configuration for mips64-bsd-user
default-configs/mips64el-bsd-user.mak new file +1 -0
new file mode 100644
index 0000000..b879228
@@ -0,0 +1 @@
+# Default configuration for mips64el-bsd-user
default-configs/mipsel-bsd-user.mak new file +1 -0
new file mode 100644
index 0000000..312b9d5
@@ -0,0 +1 @@
+# Default configuration for mipsel-bsd-user
target-mips/mips-defs.h +11 -2
index bf094a3..7ec9d20 100644
@@ -10,8 +10,17 @@
 
 #if defined(TARGET_MIPS64)
 #define TARGET_LONG_BITS 64
-#define TARGET_PHYS_ADDR_SPACE_BITS 36
-#define TARGET_VIRT_ADDR_SPACE_BITS 42
+#  if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
+#    define TARGET_PHYS_ADDR_SPACE_BITS 59
+#    ifdef TARGET_ABI32
+#       define TARGET_VIRT_ADDR_SPACE_BITS 32
+#    else
+#       define TARGET_VIRT_ADDR_SPACE_BITS 62
+#    endif
+#  else
+#    define TARGET_PHYS_ADDR_SPACE_BITS 36
+#    define TARGET_VIRT_ADDR_SPACE_BITS 42
+#  endif
 #else
 #define TARGET_LONG_BITS 32
 #define TARGET_PHYS_ADDR_SPACE_BITS 36
Signature · 1 line
1.7.8

Stacey Son

author
#0 lore raw

cover bsd-user: FreeBSD support for mips/mips64 and arm

Hi all,

This patch series add BSD user mode support for FreeBSD. In addition, it adds the necessary architecture dependent code for the mips, mips64, and arm targets. In its current state it can emulate most mips/mips64 and arm target binaries on a x86 host in a simple chroot environment (see https://wiki.freebsd.org/QemuUserModeHowTo for example).

To build this code it requires Ed Maste's configure/linker patches for using an alternate .text segment on FreeBSD. ie.

    https://github.com/emaste/qemu/commit/2fdae0f4172175dddbd19283a4607eae2a46587d

and the suggested change by Richard Henderson

    https://github.com/emaste/qemu/commit/ede607ad998bac1d44f2e3a79d5f5fb5e70c9f46

Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible.

I recognize and give credit to Olivier Houchard (arm dependent and other bsd-user code), Juergen Lock (FreeBSD qemu port owner), and Ed Maste (linker configuration). Also, to Andreas Tobler (initial PPC dependent code). I am sure I forgot someone and apoligize in advance.

Once this patch set has been has been reviewed and approved I can submit it as a pull request if desired.

Best Regards,

Stacey D. Son
---

Stacey Son (23):
bsd-user: initial code clean up
bsd-user: add initial support for mips/mips64
bsd-user: additional seperation of OS and architecture dependent code
bsd-user: add bsd signal emulation
bsd-user: add bsd_binprm to TaskState for core dumping emulation
bsd-user: fix thread initialization and ELF addresses for mips/mips64
bsd-user: find target executable in path when absolute path not given
bsd-user: initialize stack with signal trampolin code and canary
bsd-user: refresh FreeBSD's system call numbers
bsd-user: add shims for memory management related syscalls
bsd-user: add shims for file related system calls
bsd-user: add shims for time related system calls.
bsd-user: add shims for signal related system calls
bsd-user: add shims for process related system calls
bsd-user: add shims for socket related system calls
bsd-user: add shims for stat and file handle related syscalls
bsd-user: add shims for thread related system calls
bsd-user: add shim for the ioctl system call
bsd-user: add shims for sysarch() and sysctl() system calls
bsd-user: add shims for extended attributes system calls
bsd-user: add miscellaneous system call shims
bsd-user: add more strace formating
bsd-user: add arm cpu support

 Makefile.target                         |    5 +-
 bsd-user/Makefile.objs                  |    9 +-
 bsd-user/arm/syscall.h                  |   36 +
 bsd-user/arm/target_arch.h              |   13 +
 bsd-user/arm/target_arch_cpu.h          |  405 +++++++
 bsd-user/arm/target_arch_signal.h       |  255 ++++
 bsd-user/arm/target_arch_sigtramp.h     |   33 +
 bsd-user/arm/target_arch_sysarch.h      |   80 ++
 bsd-user/arm/target_arch_thread.h       |   40 +
 bsd-user/arm/target_arch_vmparam.h      |   49 +
 bsd-user/bsd-file.h                     | 1095 ++++++++++++++++++
 bsd-user/bsd-mem.c                      |  122 ++
 bsd-user/bsd-mem.h                      |  387 +++++++
 bsd-user/bsd-misc.c                     |  209 ++++
 bsd-user/bsd-misc.h                     |  339 ++++++
 bsd-user/bsd-mman.h                     |  121 --
 bsd-user/bsd-proc.c                     |  160 +++
 bsd-user/bsd-proc.h                     |  434 +++++++
 bsd-user/bsd-signal.h                   |  232 ++++
 bsd-user/bsd-socket.c                   |  108 ++
 bsd-user/bsd-socket.h                   |  266 +++++
 bsd-user/bsdload.c                      |  139 ++-
 bsd-user/elfload.c                      |  387 ++++---
 bsd-user/errno_defs.h                   |   13 +-
 bsd-user/freebsd/host_os.h              |   46 +
 bsd-user/freebsd/ioctl-cmds.h           |   47 +
 bsd-user/freebsd/ioctl-filio.h          |   45 +
 bsd-user/freebsd/ioctl-ioccom.h         |   54 +
 bsd-user/freebsd/ioctl-ttycom.h         |  257 ++++
 bsd-user/freebsd/ioctl-types.h          |    7 +
 bsd-user/freebsd/os-extattr.c           |  119 ++
 bsd-user/freebsd/os-extattr.h           |  644 +++++++++++
 bsd-user/freebsd/os-misc.h              |  442 +++++++
 bsd-user/freebsd/os-proc.c              |  234 ++++
 bsd-user/freebsd/os-proc.h              |  427 +++++++
 bsd-user/freebsd/os-signal.h            |   43 +
 bsd-user/freebsd/os-socket.c            |  149 +++
 bsd-user/freebsd/os-socket.h            |  548 +++++++++
 bsd-user/freebsd/os-stat.c              |  234 ++++
 bsd-user/freebsd/os-stat.h              |  437 +++++++
 bsd-user/freebsd/os-strace.h            |   29 +
 bsd-user/freebsd/os-sys.c               |  268 +++++
 bsd-user/freebsd/os-thread.c            |  802 +++++++++++++
 bsd-user/freebsd/os-thread.h            |  742 ++++++++++++
 bsd-user/freebsd/os-time.c              |  205 ++++
 bsd-user/freebsd/os-time.h              |  602 ++++++++++
 bsd-user/freebsd/qemu-os.h              |   77 ++
 bsd-user/freebsd/strace.list            |   76 ++-
 bsd-user/freebsd/syscall_nr.h           |  813 +++++++------
 bsd-user/freebsd/target_os_siginfo.h    |  100 ++
 bsd-user/freebsd/target_os_signal.h     |   79 ++
 bsd-user/freebsd/target_os_stack.h      |  124 ++
 bsd-user/freebsd/target_os_vmparam.h    |   19 +
 bsd-user/i386/syscall.h                 |   23 +
 bsd-user/i386/target_arch.h             |   11 +
 bsd-user/i386/target_arch_cpu.c         |   79 ++
 bsd-user/i386/target_arch_cpu.h         |  290 +++++
 bsd-user/i386/target_arch_signal.h      |   81 ++
 bsd-user/i386/target_arch_sigtramp.h    |   11 +
 bsd-user/i386/target_arch_sysarch.h     |   78 ++
 bsd-user/i386/target_arch_thread.h      |   30 +
 bsd-user/i386/target_arch_vmparam.h     |   26 +
 bsd-user/i386/target_signal.h           |   20 -
 bsd-user/ioctl.c                        |  447 +++++++
 bsd-user/main.c                         |  875 +++------------
 bsd-user/mips/syscall.h                 |   52 +
 bsd-user/mips/target_arch.h             |   13 +
 bsd-user/mips/target_arch_cpu.h         |  227 ++++
 bsd-user/mips/target_arch_signal.h      |  237 ++++
 bsd-user/mips/target_arch_sigtramp.h    |   23 +
 bsd-user/mips/target_arch_sysarch.h     |   69 ++
 bsd-user/mips/target_arch_thread.h      |   45 +
 bsd-user/mips/target_arch_vmparam.h     |   47 +
 bsd-user/mips64/syscall.h               |   53 +
 bsd-user/mips64/target_arch.h           |   13 +
 bsd-user/mips64/target_arch_cpu.h       |  226 ++++
 bsd-user/mips64/target_arch_signal.h    |  236 ++++
 bsd-user/mips64/target_arch_sigtramp.h  |   23 +
 bsd-user/mips64/target_arch_sysarch.h   |   69 ++
 bsd-user/mips64/target_arch_thread.h    |   45 +
 bsd-user/mips64/target_arch_vmparam.h   |   47 +
 bsd-user/mmap.c                         |  108 +--
 bsd-user/netbsd/host_os.h               |   31 +
 bsd-user/netbsd/ioctl-cmds.h            |   48 +
 bsd-user/netbsd/ioctl-filio.h           |   29 +
 bsd-user/netbsd/ioctl-ioccom.h          |   38 +
 bsd-user/netbsd/ioctl-ttycom.h          |  240 ++++
 bsd-user/netbsd/ioctl-types.h           |    7 +
 bsd-user/netbsd/os-extattr.h            |  247 ++++
 bsd-user/netbsd/os-proc.c               |   11 +
 bsd-user/netbsd/os-proc.h               |  243 ++++
 bsd-user/netbsd/os-signal.h             |   34 +
 bsd-user/netbsd/os-socket.c             |    1 +
 bsd-user/netbsd/os-socket.h             |   98 ++
 bsd-user/netbsd/os-stat.c               |    1 +
 bsd-user/netbsd/os-stat.h               |  176 +++
 bsd-user/netbsd/os-strace.h             |    1 +
 bsd-user/netbsd/os-sys.c                |   46 +
 bsd-user/netbsd/os-time.c               |    1 +
 bsd-user/netbsd/os-time.h               |  179 +++
 bsd-user/netbsd/qemu-os.h               |    1 +
 bsd-user/netbsd/strace.list             |   18 +
 bsd-user/netbsd/syscall_nr.h            |   24 +-
 bsd-user/netbsd/target_os_siginfo.h     |   82 ++
 bsd-user/netbsd/target_os_signal.h      |   70 ++
 bsd-user/netbsd/target_os_stack.h       |   31 +
 bsd-user/netbsd/target_os_vmparam.h     |   17 +
 bsd-user/openbsd/host_os.h              |   31 +
 bsd-user/openbsd/ioctl-cmds.h           |   48 +
 bsd-user/openbsd/ioctl-filio.h          |   29 +
 bsd-user/openbsd/ioctl-ioccom.h         |   38 +
 bsd-user/openbsd/ioctl-ttycom.h         |  240 ++++
 bsd-user/openbsd/ioctl-types.h          |    7 +
 bsd-user/openbsd/os-extattr.h           |  247 ++++
 bsd-user/openbsd/os-proc.c              |   11 +
 bsd-user/openbsd/os-proc.h              |  243 ++++
 bsd-user/openbsd/os-signal.h            |   34 +
 bsd-user/openbsd/os-socket.c            |    1 +
 bsd-user/openbsd/os-socket.h            |   98 ++
 bsd-user/openbsd/os-stat.c              |    1 +
 bsd-user/openbsd/os-stat.h              |  176 +++
 bsd-user/openbsd/os-strace.h            |    1 +
 bsd-user/openbsd/os-sys.c               |   46 +
 bsd-user/openbsd/os-time.c              |    1 +
 bsd-user/openbsd/os-time.h              |  179 +++
 bsd-user/openbsd/qemu-os.h              |    1 +
 bsd-user/openbsd/strace.list            |   18 +
 bsd-user/openbsd/syscall_nr.h           |   24 +-
 bsd-user/openbsd/target_os_siginfo.h    |   82 ++
 bsd-user/openbsd/target_os_signal.h     |   70 ++
 bsd-user/openbsd/target_os_stack.h      |   31 +
 bsd-user/openbsd/target_os_vmparam.h    |   17 +
 bsd-user/qemu-bsd.h                     |   79 ++
 bsd-user/qemu.h                         |  195 +++-
 bsd-user/signal.c                       |  923 +++++++++++++++-
 bsd-user/sparc/syscall.h                |   29 +-
 bsd-user/sparc/target_arch.h            |    9 +
 bsd-user/sparc/target_arch_cpu.c        |  113 ++
 bsd-user/sparc/target_arch_cpu.h        |  143 +++
 bsd-user/sparc/target_arch_signal.h     |   64 +
 bsd-user/sparc/target_arch_sigtramp.h   |   11 +
 bsd-user/sparc/target_arch_sysarch.h    |   52 +
 bsd-user/sparc/target_arch_thread.h     |   30 +
 bsd-user/sparc/target_arch_vmparam.h    |   35 +
 bsd-user/sparc/target_signal.h          |   27 -
 bsd-user/sparc64/syscall.h              |   28 +-
 bsd-user/sparc64/target_arch.h          |    9 +
 bsd-user/sparc64/target_arch_cpu.c      |  118 ++
 bsd-user/sparc64/target_arch_cpu.h      |  175 +++
 bsd-user/sparc64/target_arch_signal.h   |   81 ++
 bsd-user/sparc64/target_arch_sigtramp.h |   11 +
 bsd-user/sparc64/target_arch_sysarch.h  |   52 +
 bsd-user/sparc64/target_arch_thread.h   |   30 +
 bsd-user/sparc64/target_arch_vmparam.h  |   37 +
 bsd-user/sparc64/target_signal.h        |   27 -
 bsd-user/strace.c                       |  175 ++-
 bsd-user/syscall.c                      | 1929 ++++++++++++++++++++++++-------
 bsd-user/syscall_defs.h                 |  790 +++++++++++--
 bsd-user/uaccess.c                      |   20 +-
 bsd-user/x86_64/syscall.h               |   26 +-
 bsd-user/x86_64/target_arch.h           |   11 +
 bsd-user/x86_64/target_arch_cpu.c       |   79 ++
 bsd-user/x86_64/target_arch_cpu.h       |  312 +++++
 bsd-user/x86_64/target_arch_signal.h    |   81 ++
 bsd-user/x86_64/target_arch_sigtramp.h  |   11 +
 bsd-user/x86_64/target_arch_sysarch.h   |   76 ++
 bsd-user/x86_64/target_arch_thread.h    |   30 +
 bsd-user/x86_64/target_arch_vmparam.h   |   28 +
 bsd-user/x86_64/target_signal.h         |   19 -
 configure                               |   25 +-
 default-configs/arm-bsd-user.mak        |    3 +
 default-configs/armeb-bsd-user.mak      |    3 +
 default-configs/mips-bsd-user.mak       |    1 +
 default-configs/mips64-bsd-user.mak     |    1 +
 default-configs/mips64el-bsd-user.mak   |    1 +
 default-configs/mipsel-bsd-user.mak     |    1 +
 include/qemu/tls.h                      |    2 +-
 target-mips/mips-defs.h                 |   13 +-
 178 files changed, 23181 insertions(+), 2192 deletions(-)
 create mode 100644 bsd-user/arm/syscall.h
 create mode 100644 bsd-user/arm/target_arch.h
 create mode 100644 bsd-user/arm/target_arch_cpu.c
 create mode 100644 bsd-user/arm/target_arch_cpu.h
 create mode 100644 bsd-user/arm/target_arch_signal.h
 create mode 100644 bsd-user/arm/target_arch_sigtramp.h
 create mode 100644 bsd-user/arm/target_arch_sysarch.h
 create mode 100644 bsd-user/arm/target_arch_thread.h
 create mode 100644 bsd-user/arm/target_arch_vmparam.h
 create mode 100644 bsd-user/bsd-file.h
 create mode 100644 bsd-user/bsd-mem.c
 create mode 100644 bsd-user/bsd-mem.h
 create mode 100644 bsd-user/bsd-misc.c
 create mode 100644 bsd-user/bsd-misc.h
 delete mode 100644 bsd-user/bsd-mman.h
 create mode 100644 bsd-user/bsd-proc.c
 create mode 100644 bsd-user/bsd-proc.h
 create mode 100644 bsd-user/bsd-signal.h
 create mode 100644 bsd-user/bsd-socket.c
 create mode 100644 bsd-user/bsd-socket.h
 create mode 100644 bsd-user/freebsd/host_os.h
 create mode 100644 bsd-user/freebsd/ioctl-cmds.h
 create mode 100644 bsd-user/freebsd/ioctl-filio.h
 create mode 100644 bsd-user/freebsd/ioctl-ioccom.h
 create mode 100644 bsd-user/freebsd/ioctl-ttycom.h
 create mode 100644 bsd-user/freebsd/ioctl-types.h
 create mode 100644 bsd-user/freebsd/os-extattr.c
 create mode 100644 bsd-user/freebsd/os-extattr.h
 create mode 100644 bsd-user/freebsd/os-misc.h
 create mode 100644 bsd-user/freebsd/os-proc.c
 create mode 100644 bsd-user/freebsd/os-proc.h
 create mode 100644 bsd-user/freebsd/os-signal.h
 create mode 100644 bsd-user/freebsd/os-socket.c
 create mode 100644 bsd-user/freebsd/os-socket.h
 create mode 100644 bsd-user/freebsd/os-stat.c
 create mode 100644 bsd-user/freebsd/os-stat.h
 create mode 100644 bsd-user/freebsd/os-strace.h
 create mode 100644 bsd-user/freebsd/os-sys.c
 create mode 100644 bsd-user/freebsd/os-thread.c
 create mode 100644 bsd-user/freebsd/os-thread.h
 create mode 100644 bsd-user/freebsd/os-time.c
 create mode 100644 bsd-user/freebsd/os-time.h
 create mode 100644 bsd-user/freebsd/qemu-os.h
 create mode 100644 bsd-user/freebsd/target_os_siginfo.h
 create mode 100644 bsd-user/freebsd/target_os_signal.h
 create mode 100644 bsd-user/freebsd/target_os_stack.h
 create mode 100644 bsd-user/freebsd/target_os_vmparam.h
 create mode 100644 bsd-user/i386/target_arch.h
 create mode 100644 bsd-user/i386/target_arch_cpu.c
 create mode 100644 bsd-user/i386/target_arch_cpu.h
 create mode 100644 bsd-user/i386/target_arch_signal.h
 create mode 100644 bsd-user/i386/target_arch_sigtramp.h
 create mode 100644 bsd-user/i386/target_arch_sysarch.h
 create mode 100644 bsd-user/i386/target_arch_thread.h
 create mode 100644 bsd-user/i386/target_arch_vmparam.h
 delete mode 100644 bsd-user/i386/target_signal.h
 create mode 100644 bsd-user/ioctl.c
 create mode 100644 bsd-user/mips/syscall.h
 create mode 100644 bsd-user/mips/target_arch.h
 create mode 100644 bsd-user/mips/target_arch_cpu.c
 create mode 100644 bsd-user/mips/target_arch_cpu.h
 create mode 100644 bsd-user/mips/target_arch_signal.h
 create mode 100644 bsd-user/mips/target_arch_sigtramp.h
 create mode 100644 bsd-user/mips/target_arch_sysarch.h
 create mode 100644 bsd-user/mips/target_arch_thread.h
 create mode 100644 bsd-user/mips/target_arch_vmparam.h
 create mode 100644 bsd-user/mips64/syscall.h
 create mode 100644 bsd-user/mips64/target_arch.h
 create mode 100644 bsd-user/mips64/target_arch_cpu.c
 create mode 100644 bsd-user/mips64/target_arch_cpu.h
 create mode 100644 bsd-user/mips64/target_arch_signal.h
 create mode 100644 bsd-user/mips64/target_arch_sigtramp.h
 create mode 100644 bsd-user/mips64/target_arch_sysarch.h
 create mode 100644 bsd-user/mips64/target_arch_thread.h
 create mode 100644 bsd-user/mips64/target_arch_vmparam.h
 create mode 100644 bsd-user/mips64/touch_arch.cpu.c
 create mode 100644 bsd-user/netbsd/host_os.h
 create mode 100644 bsd-user/netbsd/ioctl-cmds.h
 create mode 100644 bsd-user/netbsd/ioctl-filio.h
 create mode 100644 bsd-user/netbsd/ioctl-ioccom.h
 create mode 100644 bsd-user/netbsd/ioctl-ttycom.h
 create mode 100644 bsd-user/netbsd/ioctl-types.h
 create mode 100644 bsd-user/netbsd/os-extattr.h
 create mode 100644 bsd-user/netbsd/os-proc.c
 create mode 100644 bsd-user/netbsd/os-proc.h
 create mode 100644 bsd-user/netbsd/os-signal.h
 create mode 100644 bsd-user/netbsd/os-socket.c
 create mode 100644 bsd-user/netbsd/os-socket.h
 create mode 100644 bsd-user/netbsd/os-stat.c
 create mode 100644 bsd-user/netbsd/os-stat.h
 create mode 100644 bsd-user/netbsd/os-strace.h
 create mode 100644 bsd-user/netbsd/os-sys.c
 create mode 100644 bsd-user/netbsd/os-time.c
 create mode 100644 bsd-user/netbsd/os-time.h
 create mode 100644 bsd-user/netbsd/qemu-os.h
 create mode 100644 bsd-user/netbsd/target_os_siginfo.h
 create mode 100644 bsd-user/netbsd/target_os_signal.h
 create mode 100644 bsd-user/netbsd/target_os_stack.h
 create mode 100644 bsd-user/netbsd/target_os_vmparam.h
 create mode 100644 bsd-user/openbsd/host_os.h
 create mode 100644 bsd-user/openbsd/ioctl-cmds.h
 create mode 100644 bsd-user/openbsd/ioctl-filio.h
 create mode 100644 bsd-user/openbsd/ioctl-ioccom.h
 create mode 100644 bsd-user/openbsd/ioctl-ttycom.h
 create mode 100644 bsd-user/openbsd/ioctl-types.h
 create mode 100644 bsd-user/openbsd/os-extattr.h
 create mode 100644 bsd-user/openbsd/os-proc.c
 create mode 100644 bsd-user/openbsd/os-proc.h
 create mode 100644 bsd-user/openbsd/os-signal.h
 create mode 100644 bsd-user/openbsd/os-socket.c
 create mode 100644 bsd-user/openbsd/os-socket.h
 create mode 100644 bsd-user/openbsd/os-stat.c
 create mode 100644 bsd-user/openbsd/os-stat.h
 create mode 100644 bsd-user/openbsd/os-strace.h
 create mode 100644 bsd-user/openbsd/os-sys.c
 create mode 100644 bsd-user/openbsd/os-time.c
 create mode 100644 bsd-user/openbsd/os-time.h
 create mode 100644 bsd-user/openbsd/qemu-os.h
 create mode 100644 bsd-user/openbsd/target_os_siginfo.h
 create mode 100644 bsd-user/openbsd/target_os_signal.h
 create mode 100644 bsd-user/openbsd/target_os_stack.h
 create mode 100644 bsd-user/openbsd/target_os_vmparam.h
 create mode 100644 bsd-user/qemu-bsd.h
 create mode 100644 bsd-user/sparc/target_arch.h
 create mode 100644 bsd-user/sparc/target_arch_cpu.c
 create mode 100644 bsd-user/sparc/target_arch_cpu.h
 create mode 100644 bsd-user/sparc/target_arch_signal.h
 create mode 100644 bsd-user/sparc/target_arch_sigtramp.h
 create mode 100644 bsd-user/sparc/target_arch_sysarch.h
 create mode 100644 bsd-user/sparc/target_arch_thread.h
 create mode 100644 bsd-user/sparc/target_arch_vmparam.h
 delete mode 100644 bsd-user/sparc/target_signal.h
 create mode 100644 bsd-user/sparc64/target_arch.h
 create mode 100644 bsd-user/sparc64/target_arch_cpu.c
 create mode 100644 bsd-user/sparc64/target_arch_cpu.h
 create mode 100644 bsd-user/sparc64/target_arch_signal.h
 create mode 100644 bsd-user/sparc64/target_arch_sigtramp.h
 create mode 100644 bsd-user/sparc64/target_arch_sysarch.h
 create mode 100644 bsd-user/sparc64/target_arch_thread.h
 create mode 100644 bsd-user/sparc64/target_arch_vmparam.h
 delete mode 100644 bsd-user/sparc64/target_signal.h
 create mode 100644 bsd-user/x86_64/target_arch.h
 create mode 100644 bsd-user/x86_64/target_arch_cpu.c
 create mode 100644 bsd-user/x86_64/target_arch_cpu.h
 create mode 100644 bsd-user/x86_64/target_arch_signal.h
 create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h
 create mode 100644 bsd-user/x86_64/target_arch_sysarch.h
 create mode 100644 bsd-user/x86_64/target_arch_thread.h
 create mode 100644 bsd-user/x86_64/target_arch_vmparam.h
 delete mode 100644 bsd-user/x86_64/target_signal.h
 create mode 100644 default-configs/arm-bsd-user.mak
 create mode 100644 default-configs/armeb-bsd-user.mak
 create mode 100644 default-configs/mips-bsd-user.mak
 create mode 100644 default-configs/mips64-bsd-user.mak
 create mode 100644 default-configs/mips64el-bsd-user.mak
 create mode 100644 default-configs/mipsel-bsd-user.mak
Signature · 1 line
1.7.8
author
#1 lore raw

PATCH 1/23 bsd-user: initial code clean up

Add license headers, #ifndef's for header files, and fix various style problem as reported by checkpatch.pl.

---
 bsd-user/bsd-mman.h              |    2 +-
 bsd-user/bsdload.c               |   21 ++++++-
 bsd-user/elfload.c               |  122 ++++++++++++++++++++++----------------
 bsd-user/errno_defs.h            |    8 ++-
 bsd-user/freebsd/strace.list     |   18 ++++++
 bsd-user/freebsd/syscall_nr.h    |   21 ++++++-
 bsd-user/i386/syscall.h          |   21 +++++++
 bsd-user/i386/target_signal.h    |   17 +++++
 bsd-user/main.c                  |   24 ++++----
 bsd-user/mmap.c                  |   24 ++++----
 bsd-user/netbsd/strace.list      |   18 ++++++
 bsd-user/netbsd/syscall_nr.h     |   24 +++++++-
 bsd-user/openbsd/strace.list     |   18 ++++++
 bsd-user/openbsd/syscall_nr.h    |   24 +++++++-
 bsd-user/qemu.h                  |   20 ++++++-
 bsd-user/sparc/syscall.h         |   22 +++++++
 bsd-user/sparc64/syscall.h       |   21 +++++++
 bsd-user/sparc64/target_signal.h |   23 ++++++-
 bsd-user/strace.c                |   17 +++++
 bsd-user/syscall.c               |   14 ++--
 bsd-user/syscall_defs.h          |    6 +-
 bsd-user/uaccess.c               |   20 ++++++-
 bsd-user/x86_64/syscall.h        |   22 +++++++
 bsd-user/x86_64/target_signal.h  |   23 ++++++-
 24 files changed, 442 insertions(+), 108 deletions(-)
bsd-user/bsd-mman.h +1 -1
index 910e8c1..2193ce7 100644
@@ -1,4 +1,4 @@
-/*-
+/*--
  * Copyright (c) 1982, 1986, 1993
  *      The Regents of the University of California.  All rights reserved.
  *
bsd-user/bsdload.c +18 -3
index 2abc713..637a217 100644
@@ -1,4 +1,19 @@
-/* Code for loading BSD executables.  Mostly linux kernel code.  */
+/*
+ *  Load BSD executables.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -34,7 +49,7 @@ static int in_group_p(gid_t g)
     gid_t       grouplist[TARGET_NGROUPS];
 
     ngroup = getgroups(TARGET_NGROUPS, grouplist);
-    for(i = 0; i < ngroup; i++) {
+    for (i = 0; i < ngroup; i++) {
         if(grouplist[i] == g) {
             return 1;
         }
@@ -46,7 +61,7 @@ static int count(char ** vec)
 {
     int         i;
 
-    for(i = 0; *vec; i++) {
+    for (i = 0; *vec; i++) {
         vec++;
     }
 
bsd-user/elfload.c +71 -51

150 lines not on this page · raw message

bsd-user/errno_defs.h +5 -3
index 1efa502..fcf95d3 100644
@@ -1,6 +1,3 @@
-/*      $OpenBSD: errno.h,v 1.20 2007/09/03 14:37:52 millert Exp $      */
-/*      $NetBSD: errno.h,v 1.10 1996/01/20 01:33:53 jtc Exp $   */
-
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
  *      The Regents of the University of California.  All rights reserved.
@@ -37,6 +34,9 @@
  *      @(#)errno.h     8.5 (Berkeley) 1/21/94
  */
 
+#ifndef _ERRNO_DEFS_H_
+#define _ERRNO_DEFS_H_
+
 #define TARGET_EPERM            1               /* Operation not permitted */
 #define TARGET_ENOENT           2               /* No such file or directory */
 #define TARGET_ESRCH            3               /* No such process */
@@ -147,3 +147,5 @@
 #define TARGET_EIDRM            89              /* Identifier removed */
 #define TARGET_ENOMSG           90              /* No message of desired type */
 #define TARGET_ELAST            90              /* Must be equal largest errno */
+
+#endif /* !  _ERRNO_DEFS_H_ */
bsd-user/freebsd/strace.list +18 -0
index 1edf412..3e793cb 100644
@@ -1,3 +1,21 @@
+/*
+ *  FreeBSD strace list
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
 { TARGET_FREEBSD_NR___getcwd, "__getcwd", NULL, NULL, NULL },
 { TARGET_FREEBSD_NR___semctl, "__semctl", NULL, NULL, NULL },
 { TARGET_FREEBSD_NR___syscall, "__syscall", NULL, NULL, NULL },
bsd-user/freebsd/syscall_nr.h +20 -1
index 36336ab..057f46c 100644
@@ -1,9 +1,26 @@
 /*
- * System call numbers.
+ *  FreeBSD System call numbers.
  *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
  * $FreeBSD: src/sys/sys/syscall.h,v 1.224 2008/08/24 21:23:08 rwatson Exp $
  * created from FreeBSD: head/sys/kern/syscalls.master 182123 2008-08-24 21:20:35Z rwatson
  */
+#ifndef _FREEBSD_SYSCALL_NR_H_
+#define _FREEBSD_SYSCALL_NR_H_
 
 #define TARGET_FREEBSD_NR_syscall     0
 #define TARGET_FREEBSD_NR_exit        1
@@ -371,3 +388,5 @@
 #define TARGET_FREEBSD_NR_symlinkat   502
 #define TARGET_FREEBSD_NR_unlinkat    503
 #define TARGET_FREEBSD_NR_posix_openpt        504
+
+#endif /* ! _FREEBSD_SYSCALL_NR_H_ */
bsd-user/i386/syscall.h +21 -0
index 9b34c61..8028fc8 100644
@@ -1,3 +1,23 @@
+/*
+ *  i386 system call definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _I386_SYSCALL_H_
+#define _I386_SYSCALL_H_
+
 /* default linux values for the selectors */
 #define __USER_CS	(0x23)
 #define __USER_DS	(0x2B)
@@ -159,3 +179,4 @@ struct target_vm86plus_struct {
 
 #define UNAME_MACHINE "i386"
 
+#endif /* ! _I386_SYSCALL_H_ */
bsd-user/i386/target_signal.h +17 -0
index 2ef36d1..806e1e2 100644
@@ -1,3 +1,20 @@
+/*
+ *  i386 dependent signal definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
 #ifndef TARGET_SIGNAL_H
 #define TARGET_SIGNAL_H
 
bsd-user/main.c +13 -11
index 572f13a..572aa14 100644
@@ -1,4 +1,4 @@
-/*
+/**
  *  qemu user main
  *
  *  Copyright (c) 2003-2008 Fabrice Bellard
@@ -174,9 +174,9 @@ void cpu_loop(CPUX86State *env)
     abi_ulong pc;
     //target_siginfo_t info;
 
-    for(;;) {
+    for (;;) {
         trapnr = cpu_x86_exec(env);
-        switch(trapnr) {
+        switch (trapnr) {
         case 0x80:
             /* syscall from int $0x80 */
             if (bsd_type == target_freebsd) {
@@ -378,8 +378,8 @@ void cpu_loop(CPUX86State *env)
 #endif
         default:
             pc = env->segs[R_CS].base + env->eip;
-            fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
-                    (long)pc, trapnr);
+            fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - "
+                    "aborting\n", (long)pc, trapnr);
             abort();
         }
         process_pending_signals(env);
@@ -418,7 +418,7 @@ static inline void save_window_offset(CPUSPARCState *env, int cwp1)
     printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n",
            sp_ptr, cwp1);
 #endif
-    for(i = 0; i < 16; i++) {
+    for (i = 0; i < 16; i++) {
         /* FIXME - what to do if put_user() fails? */
         put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
         sp_ptr += sizeof(abi_ulong);
@@ -464,7 +464,7 @@ static void restore_window(CPUSPARCState *env)
     printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n",
            sp_ptr, cwp1);
 #endif
-    for(i = 0; i < 16; i++) {
+    for (i = 0; i < 16; i++) {
         /* FIXME - what to do if get_user() fails? */
         get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
         sp_ptr += sizeof(abi_ulong);
@@ -484,7 +484,7 @@ static void flush_windows(CPUSPARCState *env)
     int offset, cwp1;
 
     offset = 1;
-    for(;;) {
+    for (;;) {
         /* if restore would invoke restore_window(), then we can stop */
         cwp1 = cpu_cwp_inc(env, env->cwp + offset);
 #ifndef TARGET_SPARC64
@@ -765,7 +765,7 @@ int main(int argc, char **argv)
 #endif
 
     optind = 1;
-    for(;;) {
+    for (;;) {
         if (optind >= argc)
             break;
         r = argv[optind];
@@ -1122,10 +1122,12 @@ int main(int argc, char **argv)
         env->pc = regs->pc;
         env->npc = regs->npc;
         env->y = regs->y;
-        for(i = 0; i < 8; i++)
+        for (i = 0; i < 8; i++) {
             env->gregs[i] = regs->u_regs[i];
-        for(i = 0; i < 8; i++)
+        }
+        for (i = 0; i < 8; i++) {
             env->regwptr[i] = regs->u_regs[i + 8];
+        }
     }
 #else
 #error unsupported target CPU
bsd-user/mmap.c +12 -12
index aae8ea1..29e0427 100644
@@ -1,4 +1,4 @@
-/*
+/**
  *  mmap support for qemu
  *
  *  Copyright (c) 2003 - 2008 Fabrice Bellard
@@ -164,11 +164,11 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
     if (start > host_start) {
         /* handle host page containing start */
         prot1 = prot;
-        for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
+        for (addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
             prot1 |= page_get_flags(addr);
         }
         if (host_end == host_start + qemu_host_page_size) {
-            for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
+            for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
                 prot1 |= page_get_flags(addr);
             }
             end = host_end;
@@ -180,7 +180,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
     }
     if (end < host_end) {
         prot1 = prot;
-        for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
+        for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
             prot1 |= page_get_flags(addr);
         }
         ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size,
@@ -218,7 +218,7 @@ static int mmap_frag(abi_ulong real_start,
 
     /* get the protection of the target pages outside the mapping */
     prot1 = 0;
-    for(addr = real_start; addr < real_end; addr++) {
+    for (addr = real_start; addr < real_end; addr++) {
         if (addr < start || addr >= end)
             prot1 |= page_get_flags(addr);
     }
@@ -300,9 +300,9 @@ static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
     if (addr == 0)
         addr = mmap_next_start;
     addr_start = addr;
-    for(;;) {
+    for (;;) {
         prot = 0;
-        for(addr1 = addr; addr1 < (addr + size); addr1 += TARGET_PAGE_SIZE) {
+        for (addr1 = addr; addr1 < (addr + size); addr1 += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr1);
         }
         if (prot == 0)
@@ -337,7 +337,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             printf("MAP_FIXED ");
         if (flags & MAP_ANON)
             printf("MAP_ANON ");
-        switch(flags & TARGET_BSD_MAP_FLAGMASK) {
+        switch (flags & TARGET_BSD_MAP_FLAGMASK) {
         case MAP_PRIVATE:
             printf("MAP_PRIVATE ");
             break;
@@ -396,7 +396,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
         end = start + len;
         real_end = HOST_PAGE_ALIGN(end);
 
-        for(addr = real_start; addr < real_end; addr += TARGET_PAGE_SIZE) {
+        for (addr = real_start; addr < real_end; addr += TARGET_PAGE_SIZE) {
             flg = page_get_flags(addr);
             if (flg & PAGE_RESERVED) {
                 errno = ENXIO;
@@ -508,11 +508,11 @@ int target_munmap(abi_ulong start, abi_ulong len)
     if (start > real_start) {
         /* handle host page containing start */
         prot = 0;
-        for(addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) {
+        for (addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr);
         }
         if (real_end == real_start + qemu_host_page_size) {
-            for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
+            for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
                 prot |= page_get_flags(addr);
             }
             end = real_end;
@@ -522,7 +522,7 @@ int target_munmap(abi_ulong start, abi_ulong len)
     }
     if (end < real_end) {
         prot = 0;
-        for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
+        for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr);
         }
         if (prot != 0)
bsd-user/netbsd/strace.list +18 -0
index 5609d70..41233cd 100644
@@ -1,3 +1,21 @@
+/*
+ *  NetBSD strace list
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
 { TARGET_NETBSD_NR___getcwd, "__getcwd", NULL, NULL, NULL },
 { TARGET_NETBSD_NR___syscall, "__syscall", NULL, NULL, NULL },
 { TARGET_NETBSD_NR___sysctl, "__sysctl", NULL, NULL, NULL },
bsd-user/netbsd/syscall_nr.h +21 -3
index 2e9ab53..b598f18 100644
@@ -1,8 +1,24 @@
-/* $NetBSD: syscall.h,v 1.215 2008/06/17 16:07:57 tsutsui Exp $ */
-
 /*
- * System call numbers.
+ *  NetBSD system call numbers
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
  *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _NETBSD_SYSCALL_NR_H_
+#define _NETBSD_SYSCALL_NR_H_
+
+/*
  * created from	NetBSD: syscalls.master,v 1.204 2008/06/17 16:05:23 tsutsui Exp
  */
 
@@ -371,3 +387,5 @@
 #define TARGET_NETBSD_NR_pset_assign 414
 #define TARGET_NETBSD_NR__pset_bind  415
 #define TARGET_NETBSD_NR___posix_fadvise50   416
+
+#endif /* ! _NETBSD_SYSCALL_NR_H_ */
bsd-user/openbsd/strace.list +18 -0
index 1f0a331..6575013 100644
@@ -1,3 +1,21 @@
+/*
+ *  OpenBSD strace list
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
 { TARGET_OPENBSD_NR___getcwd, "__getcwd", NULL, NULL, NULL },
 { TARGET_OPENBSD_NR___semctl, "__semctl", NULL, NULL, NULL },
 { TARGET_OPENBSD_NR___syscall, "__syscall", NULL, NULL, NULL },
bsd-user/openbsd/syscall_nr.h +21 -3
index dececfd..2f17f2f 100644
@@ -1,8 +1,24 @@
-/*      $OpenBSD: syscall.h,v 1.101 2008/03/16 19:43:41 otto Exp $      */
-
 /*
- * System call numbers.
+ *  OpenBSD system call numbers
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
  *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _OPENBSD_SYSCALL_NR_H_
+#define _OPENBSD_SYSCALL_NR_H_
+/*
  * created from;        OpenBSD: syscalls.master,v 1.90 2008/03/16 19:42:57 otto Exp
  */
 
@@ -223,3 +239,5 @@
  */
 #define TARGET_OPENBSD_SYSCALL_G2RFLAG 0x400   /* on success, return to %g2 rather than npc */
 #define TARGET_OPENBSD_SYSCALL_G7RFLAG 0x800   /* use %g7 as above (deprecated) */
+
+#endif /* !_OPENBSD_SYSCALL_NR_H_ */
bsd-user/qemu.h +18 -2
index a826086..1e14660 100644
@@ -1,3 +1,19 @@
+/*
+ *  qemu bsd user mode definition
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
 #ifndef QEMU_H
 #define QEMU_H
 
@@ -216,7 +232,7 @@ static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
 #define __put_user(x, hptr)\
 ({\
     int size = sizeof(*hptr);\
-    switch(size) {\
+    switch (size) {\
     case 1:\
         *(uint8_t *)(hptr) = (uint8_t)(typeof(*hptr))(x);\
         break;\
@@ -238,7 +254,7 @@ static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
 #define __get_user(x, hptr) \
 ({\
     int size = sizeof(*hptr);\
-    switch(size) {\
+    switch (size) {\
     case 1:\
         x = (typeof(*hptr))*(uint8_t *)(hptr);\
         break;\
bsd-user/sparc/syscall.h +22 -0
index 5a9bb7e..804889a 100644
@@ -1,3 +1,23 @@
+/*
+ *  sparc dependent system call definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _SPARC_SYSCALL_H_
+#define _SPARC_SYSCALL_H_
+
 struct target_pt_regs {
 	abi_ulong psr;
 	abi_ulong pc;
@@ -7,3 +27,5 @@ struct target_pt_regs {
 };
 
 #define UNAME_MACHINE "sun4"
+
+#endif /* ! _SPARC_SYSCALL_H_ */
bsd-user/sparc64/syscall.h +21 -0
index 81a816d..9f3b97e 100644
@@ -1,3 +1,22 @@
+/*
+ *  sparc64 dependent system call definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _SPARC64_SYSCALL_H_
+#define _SPARC64_SYSCALL_H_
 struct target_pt_regs {
 	abi_ulong u_regs[16];
 	abi_ulong tstate;
@@ -8,3 +27,5 @@ struct target_pt_regs {
 };
 
 #define UNAME_MACHINE "sun4u"
+
+#endif /* !_SPARC64_SYSCALL_H_ */
bsd-user/sparc64/target_signal.h +20 -3
index 5b2abba..51e44bb 100644
@@ -1,5 +1,22 @@
-#ifndef TARGET_SIGNAL_H
-#define TARGET_SIGNAL_H
+/*
+ *  sparc64 dependent signal definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _SPARC64_TARGET_SIGNAL_H_
+#define _SPARC64_TARGET_SIGNAL_H_
 
 #include "cpu.h"
 
@@ -24,4 +41,4 @@ static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state)
     return state->regwptr[UREG_FP];
 }
 
-#endif /* TARGET_SIGNAL_H */
+#endif /* !_SPARC64_TARGET_SIGNAL_H_ */
bsd-user/strace.c +17 -0
index d73bbca..7a28c96 100644
@@ -1,3 +1,20 @@
+/*
+ *  System call tracing and debugging
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
 #include <stdio.h>
 #include <errno.h>
 #include <sys/select.h>
bsd-user/syscall.c +7 -7
index a4d1583..8e8107b 100644
@@ -1,4 +1,4 @@
-/*
+/**
  *  BSD syscalls
  *
  *  Copyright (c) 2003 - 2008 Fabrice Bellard
@@ -103,7 +103,7 @@ static abi_long do_freebsd_sysarch(CPUX86State *env, int op, abi_ulong parms)
     abi_ulong val;
     int idx;
 
-    switch(op) {
+    switch (op) {
 #ifdef TARGET_ABI32
     case TARGET_FREEBSD_I386_SET_GSBASE:
     case TARGET_FREEBSD_I386_SET_FSBASE:
@@ -279,7 +279,7 @@ static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr,
     target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1);
     if (!target_vec)
         return -TARGET_EFAULT;
-    for(i = 0;i < count; i++) {
+    for (i = 0; i < count; i++) {
         base = tswapl(target_vec[i].iov_base);
         vec[i].iov_len = tswapl(target_vec[i].iov_len);
         if (vec[i].iov_len != 0) {
@@ -305,7 +305,7 @@ static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr,
     target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1);
     if (!target_vec)
         return -TARGET_EFAULT;
-    for(i = 0;i < count; i++) {
+    for (i = 0; i < count; i++) {
         if (target_vec[i].iov_base) {
             base = tswapl(target_vec[i].iov_base);
             unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
@@ -333,7 +333,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
     if(do_strace)
         print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
 
-    switch(num) {
+    switch (num) {
     case TARGET_FREEBSD_NR_exit:
 #ifdef TARGET_GPROF
         _mcleanup();
@@ -428,7 +428,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
     if(do_strace)
         print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
 
-    switch(num) {
+    switch (num) {
     case TARGET_NETBSD_NR_exit:
 #ifdef TARGET_GPROF
         _mcleanup();
@@ -500,7 +500,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
     if(do_strace)
         print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
 
-    switch(num) {
+    switch (num) {
     case TARGET_OPENBSD_NR_exit:
 #ifdef TARGET_GPROF
         _mcleanup();
bsd-user/syscall_defs.h +3 -3
index 207ddee..58dafd1 100644
@@ -1,6 +1,3 @@
-/*      $OpenBSD: signal.h,v 1.19 2006/01/08 14:20:16 millert Exp $     */
-/*      $NetBSD: signal.h,v 1.21 1996/02/09 18:25:32 christos Exp $     */
-
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
  *      The Regents of the University of California.  All rights reserved.
@@ -36,6 +33,8 @@
  *
  *      @(#)signal.h    8.2 (Berkeley) 1/21/94
  */
+#ifndef _SYSCALL_DEFS_H_
+#define _SYSCALL_DEFS_H_
 
 #define TARGET_NSIG     32              /* counting 0; could be 33 (mask is 1-32) */
 
@@ -112,3 +111,4 @@ struct target_iovec {
     abi_long iov_len;   /* Number of bytes */
 };
 
+#endif /* ! _SYSCALL_DEFS_H_ */
bsd-user/uaccess.c +18 -2
index 677f19c..09ac88e 100644
@@ -1,4 +1,20 @@
-/* User memory access */
+/*
+ *  User memory access
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
 #include <stdio.h>
 #include <string.h>
 
@@ -46,7 +62,7 @@ abi_long target_strlen(abi_ulong guest_addr1)
     int max_len, len;
 
     guest_addr = guest_addr1;
-    for(;;) {
+    for (;;) {
         max_len = TARGET_PAGE_SIZE - (guest_addr & ~TARGET_PAGE_MASK);
         ptr = lock_user(VERIFY_READ, guest_addr, max_len, 1);
         if (!ptr)
bsd-user/x86_64/syscall.h +22 -0
index 630514a..fbaeacf 100644
@@ -1,3 +1,23 @@
+/*
+ *  x86_64 system call definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _X86_64_SYSCALL_H_
+#define _X86_64_SYSCALL_H_
+
 #define __USER_CS	(0x33)
 #define __USER_DS	(0x2B)
 
@@ -114,3 +134,5 @@ struct target_msqid64_ds {
 #define TARGET_ARCH_SET_FS 0x1002
 #define TARGET_ARCH_GET_FS 0x1003
 #define TARGET_ARCH_GET_GS 0x1004
+
+#endif /* ! _X86_64_SYSCALL_H_ */
bsd-user/x86_64/target_signal.h +20 -3
index 659cd40..c33dbcc 100644
@@ -1,5 +1,22 @@
-#ifndef TARGET_SIGNAL_H
-#define TARGET_SIGNAL_H
+/*
+ *  x86_64 signal definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _X86_64_TARGET_SIGNAL_H_
+#define _X86_64_TARGET_SIGNAL_H_
 
 #include "cpu.h"
 
@@ -16,4 +33,4 @@ static inline abi_ulong get_sp_from_cpustate(CPUX86State *state)
     return state->regs[R_ESP];
 }
 
-#endif /* TARGET_SIGNAL_H */
+#endif /* !_X86_64_TARGET_SIGNAL_H_ */
Signature · 1 line
1.7.8
author
#17 lore raw

PATCH 11/23 bsd-user: add shims for file related system calls

In reply to Stacey Son

This changes adds support for file and file system related system calls that are largely BSD OS independent. Also includes some more clean up of syscall.c.

---
 bsd-user/bsd-file.h                    | 1095 ++++++++++++++++++++++++++++++++
 bsd-user/i386/target_arch_vmparam.h    |    5 +
 bsd-user/mips/target_arch_vmparam.h    |    5 +
 bsd-user/mips64/target_arch_vmparam.h  |    5 +
 bsd-user/qemu.h                        |   36 +
 bsd-user/sparc/target_arch_vmparam.h   |    5 +
 bsd-user/sparc64/target_arch_vmparam.h |    5 +
 bsd-user/syscall.c                     |  384 +++++++++---
 bsd-user/x86_64/target_arch_vmparam.h  |    5 +
 9 files changed, 1467 insertions(+), 78 deletions(-)
 create mode 100644 bsd-user/bsd-file.h
bsd-user/bsd-file.h new file +1095 -0
new file mode 100644
index 0000000..f2c0fc7
@@ -0,0 +1,1095 @@
+/*
+ *  file related system call shims and definitions
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __BSD_FILE_H_
+#define __BSD_FILE_H_
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/uio.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define target_to_host_bitmask(x, tbl) (x)
+
+#define LOCK_PATH(p, arg)  do {             \
+    (p) =  lock_user_string(arg);           \
+    if ((p) == NULL) {                      \
+        return -TARGET_EFAULT;              \
+    }                                       \
+} while (0)
+
+#define UNLOCK_PATH(p, arg)   unlock_user((p), (arg), 0)
+
+struct target_pollfd {
+    int32_t fd;         /* file descriptor */
+    int16_t events;     /* requested events */
+    int16_t revents;    /* returned events */
+};
+
+static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr,
+        int count, int copy);
+static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr,
+        int count, int copy);
+extern int __getcwd(char *path, size_t len);
+
+/* read(2) */
+static inline abi_long do_bsd_read(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    p = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(read(arg1, p, arg3));
+    unlock_user(p, arg2, ret);
+
+    return ret;
+}
+
+/* pread(2) */
+static inline abi_long do_bsd_pread(abi_long arg1, abi_long arg2, abi_long arg3,
+        abi_long arg4, abi_long arg5)
+{
+    abi_long ret;
+    void *p;
+
+    p = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(pread(arg1, p, arg3, target_offset64(arg4, arg5)));
+    unlock_user(p, arg2, ret);
+
+    return ret;
+}
+
+/* readv(2) */
+static inline abi_long do_bsd_readv(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+    abi_long ret;
+    int count = arg3;
+    struct iovec *vec;
+
+    vec = alloca(count * sizeof(struct iovec));
+    if (vec == NULL) {
+        return -TARGET_ENOMEM;
+    }
+    if (lock_iovec(VERIFY_WRITE, vec, arg2, count, 0) < 0) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(readv(arg1, vec, count));
+    unlock_iovec(vec, arg2, count, 1);
+
+    return ret;
+}
+
+/* write(2) */
+static inline abi_long do_bsd_write(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    p = lock_user(VERIFY_READ, arg2, arg3, 1);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(write(arg1, p, arg3));
+    unlock_user(p, arg2, 0);
+
+    return ret;
+}
+
+/* pwrite(2) */
+static inline abi_long do_bsd_pwrite(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    abi_long ret;
+    void *p;
+
+    p = lock_user(VERIFY_READ, arg2, arg3, 1);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(pwrite(arg1, p, arg3, target_offset64(arg4, arg5)));
+    unlock_user(p, arg2, 0);
+
+    return ret;
+}
+
+/* writev(2) */
+static inline abi_long do_bsd_writev(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    int count = arg3;
+    struct iovec *vec;
+
+    vec = alloca(count * sizeof(struct iovec));
+    if (vec == NULL) {
+        return -TARGET_ENOMEM;
+    }
+    if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(writev(arg1, vec, count));
+    unlock_iovec(vec, arg2, count, 0);
+
+    return ret;
+}
+
+/* pwritev(2) */
+static inline abi_long do_bsd_pwritev(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    abi_long ret;
+    int count = arg3;
+    struct iovec *vec;
+
+    vec = alloca(count * sizeof(struct iovec));
+    if (vec == NULL) {
+        return -TARGET_ENOMEM;
+    }
+    if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(pwritev(arg1, vec, count, target_offset64(arg4, arg5)));
+    unlock_iovec(vec, arg2, count, 0);
+
+    return ret;
+}
+
+/* open(2) */
+static inline abi_long do_bsd_open(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(open(path(p), target_to_host_bitmask(arg2, fcntl_flags_tbl),
+                arg3));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* openat(2) */
+static inline abi_long do_bsd_openat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(openat(arg1, path(p),
+                target_to_host_bitmask(arg3, fcntl_flags_tbl), arg4));
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+/* close(2) */
+static inline abi_long do_bsd_close(abi_long arg1)
+{
+
+    return get_errno(close(arg1));
+}
+
+/* closefrom(2) */
+static inline abi_long do_bsd_closefrom(abi_long arg1)
+{
+
+    closefrom(arg1);  /* returns void */
+    return get_errno(0);
+}
+
+/* revoke(2) */
+static inline abi_long do_bsd_revoke(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(revoke(p)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* creat(2) (obsolete) */
+static inline abi_long do_bsd_creat(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(open(path(p), O_CREAT | O_TRUNC | O_WRONLY, arg2));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+
+/* access(2) */
+static inline abi_long do_bsd_access(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(access(path(p), arg2));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* eaccess(2) */
+static inline abi_long do_bsd_eaccess(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(eaccess(path(p), arg2));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* faccessat(2) */
+static inline abi_long do_bsd_faccessat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(faccessat(arg1, p, arg3, arg4)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+/* chdir(2) */
+static inline abi_long do_bsd_chdir(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(chdir(p)); /* XXX  path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* fchdir(2) */
+static inline abi_long do_bsd_fchdir(abi_long arg1)
+{
+
+    return get_errno(fchdir(arg1));
+}
+
+/* rename(2) */
+static inline abi_long do_bsd_rename(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg1);
+    LOCK_PATH(p2, arg2);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        ret = get_errno(rename(p1, p2)); /* XXX path(p1), path(p2) */
+    }
+    UNLOCK_PATH(p2, arg2);
+    UNLOCK_PATH(p1, arg1);
+
+    return ret;
+}
+
+/* renameat(2) */
+static inline abi_long do_bsd_renameat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg1);
+    LOCK_PATH(p2, arg2);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        ret = get_errno(renameat(arg1, p1, arg3, p2));
+    }
+    UNLOCK_PATH(p2, arg2);
+    UNLOCK_PATH(p1, arg1);
+
+    return ret;
+}
+
+/* link(2) */
+static inline abi_long do_bsd_link(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg1);
+    LOCK_PATH(p2, arg2);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        ret = get_errno(link(p1, p2)); /* XXX path(p1), path(p2) */
+    }
+    UNLOCK_PATH(p2, arg2);
+    UNLOCK_PATH(p1, arg1);
+
+    return ret;
+}
+
+/* linkat(2) */
+static inline abi_long do_bsd_linkat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg2);
+    LOCK_PATH(p2, arg4);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        ret = get_errno(linkat(arg1, p1, arg3, p2, arg5));
+    }
+    UNLOCK_PATH(p2, arg4);
+    UNLOCK_PATH(p1, arg2);
+
+    return ret;
+}
+
+/* unlink(2) */
+static inline abi_long do_bsd_unlink(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(unlink(p)); /* XXX path(p) */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* unlinkat(2) */
+static inline abi_long do_bsd_unlinkat(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(unlinkat(arg1, p, arg3)); /* XXX path(p) */
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+/* mkdir(2) */
+static inline abi_long do_bsd_mkdir(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(mkdir(p, arg2)); /* XXX path(p) */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+
+/* mkdirat(2) */
+static inline abi_long do_bsd_mkdirat(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(mkdirat(arg1, p, arg3));
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+
+/* rmdir(2) */
+static inline abi_long do_bsd_rmdir(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(rmdir(p)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* undocumented __getcwd(char *buf, size_t len)  system call */
+static inline abi_long do_bsd___getcwd(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    p = lock_user(VERIFY_WRITE, arg1, arg2, 0);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(__getcwd(p, arg2));
+    unlock_user(p, arg1, ret);
+
+    return ret;
+}
+
+/* dup(2) */
+static inline abi_long do_bsd_dup(abi_long arg1)
+{
+
+    return get_errno(dup(arg1));
+}
+
+/* dup2(2) */
+static inline abi_long do_bsd_dup2(abi_long arg1, abi_long arg2)
+{
+
+    return get_errno(dup2(arg1, arg2));
+}
+
+/* truncate(2) */
+static inline abi_long do_bsd_truncate(void *cpu_env, abi_long arg1,
+        abi_long arg2, abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    if (regpairs_aligned(cpu_env) != 0) {
+        arg2 = arg3;
+        arg3 = arg4;
+    }
+    ret = get_errno(truncate(p, target_offset64(arg2, arg3)));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* ftruncate(2) */
+static inline abi_long do_bsd_ftruncate(void *cpu_env, abi_long arg1,
+        abi_long arg2, abi_long arg3, abi_long arg4)
+{
+
+    if (regpairs_aligned(cpu_env)) {
+        arg2 = arg3;
+        arg3 = arg4;
+    }
+    return get_errno(ftruncate(arg1, target_offset64(arg2, arg3)));
+}
+
+/* acct(2) */
+static inline abi_long do_bsd_acct(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    if (arg1 == 0) {
+        ret = get_errno(acct(NULL));
+    } else {
+        LOCK_PATH(p, arg1);
+        ret = get_errno(acct(path(p)));
+        UNLOCK_PATH(p, arg1);
+    }
+    return ret;
+}
+
+/* sync(2) */
+static inline abi_long do_bsd_sync(void)
+{
+
+    sync();
+    return 0;
+}
+
+/* mount(2) */
+static inline abi_long do_bsd_mount(abi_long arg1, abi_long arg2, abi_long arg3,
+        abi_long arg4)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg1);
+    LOCK_PATH(p2, arg2);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        /*
+         * XXX arg4 should be locked, but it isn't clear how to do that
+         * since it's it may be not be a NULL-terminated string.
+         */
+        if (arg4 == 0) {
+            ret = get_errno(mount(p1, p2, arg3, NULL)); /* XXX path(p2)? */
+        } else {
+            ret = get_errno(mount(p1, p2, arg3, g2h(arg4))); /* XXX path(p2)? */
+        }
+    }
+    UNLOCK_PATH(p2, arg2);
+    UNLOCK_PATH(p1, arg1);
+
+    return ret;
+}
+
+/* unmount(2) */
+static inline abi_long do_bsd_unmount(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(unmount(p, arg2)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* nmount(2) */
+static inline abi_long do_bsd_nmount(abi_long arg1, abi_long count,
+        abi_long flags)
+{
+    abi_long ret;
+    struct iovec *vec;
+
+    vec = alloca(count * sizeof(struct iovec));
+    if (lock_iovec(VERIFY_READ, vec, arg1, count, 1) < 0) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(nmount(vec, count, flags));
+    unlock_iovec(vec, arg1, count, 0);
+
+    return ret;
+}
+
+/* symlink(2) */
+static inline abi_long do_bsd_symlink(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg1);
+    LOCK_PATH(p2, arg2);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        ret = get_errno(symlink(p1, p2)); /* XXX path(p1), path(p2) */
+    }
+    UNLOCK_PATH(p2, arg2);
+    UNLOCK_PATH(p1, arg1);
+
+    return ret;
+}
+
+/* symlinkat(2) */
+static inline abi_long do_bsd_symlinkat(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg1);
+    LOCK_PATH(p2, arg3);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        ret = get_errno(symlinkat(p1, arg2, p2)); /* XXX path(p1), path(p2) */
+    }
+    UNLOCK_PATH(p2, arg3);
+    UNLOCK_PATH(p1, arg1);
+
+    return ret;
+}
+
+/* readlink(2) */
+static inline abi_long do_bsd_readlink(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg1);
+    p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        ret = get_errno(readlink(path(p1), p2, arg3));
+    }
+    unlock_user(p2, arg2, ret);
+    UNLOCK_PATH(p1, arg1);
+
+    return ret;
+}
+
+/* readlinkat(2) */
+static inline abi_long do_bsd_readlinkat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH(p1, arg2);
+    p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
+    if (!p1 || !p2) {
+        ret = -TARGET_EFAULT;
+    } else {
+        ret = get_errno(readlinkat(arg1, p1, p2, arg4));
+    }
+    unlock_user(p2, arg3, ret);
+    UNLOCK_PATH(p1, arg2);
+
+    return ret;
+}
+
+/* chmod(2) */
+static inline abi_long do_bsd_chmod(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(chmod(p, arg2)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* fchmod(2) */
+static inline abi_long do_bsd_fchmod(abi_long arg1, abi_long arg2)
+{
+
+    return get_errno(fchmod(arg1, arg2));
+}
+
+/* lchmod(2) */
+static inline abi_long do_bsd_lchmod(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(lchmod(p, arg2)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* fchmodat(2) */
+static inline abi_long do_bsd_fchmodat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(fchmodat(arg1, p, arg3, arg4));
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+/* mknod(2) */
+static inline abi_long do_bsd_mknod(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(mknod(p, arg2, arg3)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* mknodat(2) */
+static inline abi_long do_bsd_mknodat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(mknodat(arg1, p, arg3, arg4));
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+/* chown(2) */
+static inline abi_long do_bsd_chown(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(chown(p, arg2, arg3)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* fchown(2) */
+static inline abi_long do_bsd_fchown(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+
+    return get_errno(fchown(arg1, arg2, arg3));
+}
+
+/* lchown(2) */
+static inline abi_long do_bsd_lchown(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(lchown(p, arg2, arg3)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* fchownat(2) */
+static inline abi_long do_bsd_fchownat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(fchownat(arg1, p, arg3, arg4, arg5)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+/* chflags(2) */
+static inline abi_long do_bsd_chflags(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(chflags(p, arg2)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* lchflags(2) */
+static inline abi_long do_bsd_lchflags(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(lchflags(p, arg2)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* fchflags(2) */
+static inline abi_long do_bsd_fchflags(abi_long arg1, abi_long arg2)
+{
+
+    return get_errno(fchflags(arg1, arg2));
+}
+
+/* chroot(2) */
+static inline abi_long do_bsd_chroot(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(chroot(p)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* flock(2) */
+static abi_long do_bsd_flock(abi_long arg1, abi_long arg2)
+{
+
+    return get_errno(flock(arg1, arg2));
+}
+
+/* mkfifo(2) */
+static inline abi_long do_bsd_mkfifo(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(mkfifo(p, arg2)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* mkfifoat(2) */
+static inline abi_long do_bsd_mkfifoat(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(mkfifoat(arg1, p, arg3));
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+/* pathconf(2) */
+static inline abi_long do_bsd_pathconf(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(pathconf(p, arg2)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* lpathconf(2) */
+static inline abi_long do_bsd_lpathconf(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(lpathconf(p, arg2)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* fpathconf(2) */
+static inline abi_long do_bsd_fpathconf(abi_long arg1, abi_long arg2)
+{
+
+    return get_errno(fpathconf(arg1, arg2));
+}
+
+/* undelete(2) */
+static inline abi_long do_bsd_undelete(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(undelete(p)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* poll(2) */
+static abi_long do_bsd_poll(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+    abi_long ret;
+    nfds_t i, nfds = arg2;
+    int timeout = arg3;
+    struct pollfd *pfd;
+    struct target_pollfd *target_pfd;
+
+    target_pfd = lock_user(VERIFY_WRITE, arg1,
+            sizeof(struct target_pollfd) * nfds, 1);
+    if (!target_pfd) {
+        return -TARGET_EFAULT;
+    }
+    pfd = alloca(sizeof(struct pollfd) * nfds);
+    for (i = 0; i < nfds; i++) {
+        pfd[i].fd = tswap32(target_pfd[i].fd);
+        pfd[i].events = tswap16(target_pfd[i].events);
+    } ret = get_errno(poll(pfd, nfds, timeout));
+    if (!is_error(ret)) {
+        for (i = 0; i < nfds; i++) {
+            target_pfd[i].revents = tswap16(pfd[i].revents);
+        }
+    }
+    unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds);
+
+    return ret;
+}
+
+/*
+ * undocumented openbsd_poll(struct pollfd *fds, u_int nfds, int
+ * timeout) system call.
+ */
+static abi_long do_bsd_openbsd_poll(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+
+    qemu_log("qemu: Unsupported syscall openbsd_poll()\n");
+    return -TARGET_ENOSYS;
+}
+
+/* lseek(2) */
+static abi_long do_bsd_lseek(void *cpu_env, abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+
+#if TARGET_ABI_BITS == 32
+    /* 32-bit arch's use two 32 registers for 64 bit return value */
+    int64_t res = lseek(arg1, target_offset64(arg2, arg3), arg4);
+
+    if (res == -1) {
+        ret = get_errno(res);
+    } else {
+        ret = res & 0xFFFFFFFF;
+        set_second_rval(cpu_env, (res >> 32) & 0xFFFFFFFF);
+    }
+#else
+    ret = get_errno(lseek(arg1, arg2, arg3));
+#endif
+    return ret;
+}
+
+/* pipe(2) */
+static abi_long do_bsd_pipe(void *cpu_env, abi_long arg1)
+{
+    abi_long ret;
+    int host_pipe[2];
+    int host_ret = pipe(host_pipe);
+
+    if (host_ret != -1) {
+        set_second_rval(cpu_env, host_pipe[1]);
+        ret = host_pipe[0];
+    } else {
+        ret = get_errno(host_ret);
+    }
+    return ret;
+}
+
+/* swapon(2) */
+static abi_long do_bsd_swapon(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(swapon(path(p)));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* swapoff(2) */
+static abi_long do_bsd_swapoff(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(swapoff(path(p)));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/*
+ * undocumented freebsd6_pread(int fd, void *buf, size_t nbyte, int pad,
+ * off_t offset) system call.
+ */
+static abi_long do_bsd_freebsd6_pread(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5)
+{
+
+    qemu_log("qemu: Unsupported syscall freebsd6_pread()\n");
+    return -TARGET_ENOSYS;
+}
+
+/*
+ * undocumented freebsd6_pwrite(int fd, void *buf, size_t nbyte, int pad,
+ * off_t offset) system call.
+ */
+static abi_long do_bsd_freebsd6_pwrite(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5)
+{
+
+    qemu_log("qemu: Unsupported syscall freebsd6_pwrite()\n");
+    return -TARGET_ENOSYS;
+}
+
+/*
+ * undocumented freebsd6_lseek(int fd, int pad, off_t offset, int whence)
+ * system call.
+ */
+static abi_long do_bsd_freebsd6_lseek(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+
+    qemu_log("qemu: Unsupported syscall freebsd6_lseek()\n");
+    return -TARGET_ENOSYS;
+}
+
+/*
+ * undocumented freebsd6_truncate(char *path, int pad, off_t offset) system
+ * call.
+ */
+static abi_long do_bsd_freebsd6_truncate(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+
+    qemu_log("qemu: Unsupported syscall freebsd6_truncate()\n");
+    return -TARGET_ENOSYS;
+}
+
+/*
+ * undocumented freebsd6_ftruncate(int fd, int pad, off_t offset) system
+ * call.
+ */
+static abi_long do_bsd_freebsd6_ftruncate(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+
+    qemu_log("qemu: Unsupported syscall freebsd6_ftruncate()\n");
+    return -TARGET_ENOSYS;
+}
+
+#endif /* !__BSD_FILE_H_ */
bsd-user/i386/target_arch_vmparam.h +5 -0
index 6d3cf4f..654400a 100644
@@ -18,4 +18,9 @@ static inline abi_ulong get_sp_from_cpustate(CPUX86State *state)
     return state->regs[R_ESP];
 }
 
+static inline void set_second_rval(CPUX86State *state, abi_ulong retval2)
+{
+    state->regs[R_EDX] = retval2;
+}
+
 #endif /* !_TARGET_ARCH_VMPARAM_H_ */
bsd-user/mips/target_arch_vmparam.h +5 -0
index 8f8bc9e..f9e54ce 100644
@@ -39,4 +39,9 @@ static inline abi_ulong get_sp_from_cpustate(CPUMIPSState *state)
     return state->active_tc.gpr[29];
 }
 
+static inline void set_second_rval(CPUMIPSState *state, abi_ulong retval2)
+{
+    state->active_tc.gpr[3] = retval2;
+}
+
 #endif  /* ! _TARGET_ARCH_VMPARAM_H_ */
bsd-user/mips64/target_arch_vmparam.h +5 -0
index 0480035..1ba09e0 100644
@@ -39,4 +39,9 @@ static inline abi_ulong get_sp_from_cpustate(CPUMIPSState *state)
     return state->active_tc.gpr[29];
 }
 
+static inline void set_second_rval(CPUMIPSState *state, abi_ulong retval2)
+{
+    state->active_tc.gpr[3] = retval2;
+}
+
 #endif  /* ! _TARGET_ARCH_VMPARAM_H_ */
bsd-user/qemu.h +36 -0
index 02a05bb..da69073 100644
@@ -422,6 +422,42 @@ static inline void *lock_user_string(abi_ulong guest_addr)
 #define unlock_user_struct(host_ptr, guest_addr, copy)          \
     unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0)
 
+#if TARGET_ABI_BITS == 32
+static inline uint64_t
+target_offset64(uint32_t word0, uint32_t word1)
+{
+#ifdef TARGET_WORDS_BIGENDIAN
+    return ((uint64_t)word0 << 32) | word1;
+#else
+    return ((uint64_t)word1 << 32) | word0;
+#endif
+}
+#else /* TARGET_ABI_BITS != 32 */
+static inline uint64_t
+target_offset64(uint64_t word0, uint64_t word1)
+{
+    return word0;
+}
+#endif /* TARGET_ABI_BITS != 32 */
+
+/* ARM EABI and MIPS expect 64bit types aligned even on pairs of registers */
+#ifdef TARGET_ARM
+static inline int
+regpairs_aligned(void *cpu_env) {
+    return ((((CPUARMState *)cpu_env)->eabi) == 1);
+}
+#elif defined(TARGET_MIPS) && TARGET_ABI_BITS == 32
+static inline int regpairs_aligned(void *cpu_env)
+{
+    return 1;
+}
+#else
+static inline int regpairs_aligned(void *cpu_env)
+{
+    return 0;
+}
+#endif
+
 #if defined(CONFIG_USE_NPTL)
 #include <pthread.h>
 #endif
bsd-user/sparc/target_arch_vmparam.h +5 -0
index 4bda417..75bbeeb 100644
@@ -26,5 +26,10 @@ static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state)
     return state->regwptr[UREG_FP];
 }
 
+static inline void set_second_rval(CPUSPARCState *state, abi_ulong retval2)
+{
+    state->regwptr[1] = retval2;
+}
+
 #endif /* !_TARGET_ARCH_VMPARAM_H_ */
 
bsd-user/sparc64/target_arch_vmparam.h +5 -0
index 87548da..2c2323b 100644
@@ -28,5 +28,10 @@ static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state)
     return state->regwptr[UREG_FP];
 }
 
+static inline void set_second_rval(CPUSPARCState *state, abi_ulong retval2)
+{
+    state->regwptr[1] = retval2;
+}
+
 #endif /* !_TARGET_ARCH_VMPARAM_H_ */
 
bsd-user/syscall.c +306 -78

491 lines not on this page · raw message

bsd-user/x86_64/target_arch_vmparam.h +5 -0
index 8acf7a5..5e13076 100644
@@ -20,4 +20,9 @@ static inline abi_ulong get_sp_from_cpustate(CPUX86State *state)
     return state->regs[R_ESP];
 }
 
+static inline void set_second_rval(CPUX86State *state, abi_ulong retval2)
+{
+    state->regs[R_EDX] = retval2;
+}
+
 #endif /* !_TARGET_ARCH_VMPARAM_H_ */
Signature · 1 line
1.7.8
author
#5 lore raw

PATCH 3/23 bsd-user: additional seperation of OS and architecture dependent code

In reply to Stacey Son

This change moves more OS dependent code into *bsd directories. Also moves architecture dependent code into the various arch directories. Add to 'configure' $TARGET_OS so the path to the target OS can be include file search path in the Makefile.

---
 Makefile.target                        |    3 +-
 bsd-user/elfload.c                     |    5 +-
 bsd-user/freebsd/target_os_siginfo.h   |  100 ++++++++++++++++++++++++++++++++
 bsd-user/freebsd/target_os_signal.h    |   70 ++++++++++++++++++++++
 bsd-user/freebsd/target_os_vmparam.h   |   19 ++++++
 bsd-user/i386/target_arch_signal.h     |   23 +++++++
 bsd-user/i386/target_arch_vmparam.h    |   23 +++++++
 bsd-user/i386/target_signal.h          |   37 ------------
 bsd-user/main.c                        |   29 ++++++----
 bsd-user/mips/target_arch_signal.h     |   68 +++++++++++++++++++++
 bsd-user/mips/target_arch_vmparam.h    |   42 +++++++++++++
 bsd-user/mips/target_signal.h          |   38 ------------
 bsd-user/mips64/target_arch_signal.h   |   68 +++++++++++++++++++++
 bsd-user/mips64/target_arch_vmparam.h  |   42 +++++++++++++
 bsd-user/mips64/target_signal.h        |   38 ------------
 bsd-user/netbsd/target_os_siginfo.h    |   82 ++++++++++++++++++++++++++
 bsd-user/netbsd/target_os_signal.h     |   70 ++++++++++++++++++++++
 bsd-user/netbsd/target_os_vmparam.h    |   17 ++++++
 bsd-user/openbsd/target_os_siginfo.h   |   82 ++++++++++++++++++++++++++
 bsd-user/openbsd/target_os_signal.h    |   70 ++++++++++++++++++++++
 bsd-user/openbsd/target_os_vmparam.h   |   17 ++++++
 bsd-user/qemu.h                        |   10 +++-
 bsd-user/signal.c                      |    1 -
 bsd-user/sparc/target_arch_signal.h    |    6 ++
 bsd-user/sparc/target_arch_vmparam.h   |   30 ++++++++++
 bsd-user/sparc/target_signal.h         |   27 ---------
 bsd-user/sparc64/target_arch_signal.h  |   23 +++++++
 bsd-user/sparc64/target_arch_vmparam.h |   32 ++++++++++
 bsd-user/sparc64/target_signal.h       |   44 --------------
 bsd-user/syscall_defs.h                |   99 -------------------------------
 bsd-user/x86_64/target_arch_signal.h   |   23 +++++++
 bsd-user/x86_64/target_arch_vmparam.h  |   23 +++++++
 bsd-user/x86_64/target_signal.h        |   36 -----------
 configure                              |    7 ++
 34 files changed, 967 insertions(+), 337 deletions(-)
 create mode 100644 bsd-user/freebsd/target_os_siginfo.h
 create mode 100644 bsd-user/freebsd/target_os_signal.h
 create mode 100644 bsd-user/freebsd/target_os_vmparam.h
 create mode 100644 bsd-user/i386/target_arch_signal.h
 create mode 100644 bsd-user/i386/target_arch_vmparam.h
 delete mode 100644 bsd-user/i386/target_signal.h
 create mode 100644 bsd-user/mips/target_arch_signal.h
 create mode 100644 bsd-user/mips/target_arch_vmparam.h
 delete mode 100644 bsd-user/mips/target_signal.h
 create mode 100644 bsd-user/mips64/target_arch_signal.h
 create mode 100644 bsd-user/mips64/target_arch_vmparam.h
 delete mode 100644 bsd-user/mips64/target_signal.h
 create mode 100644 bsd-user/netbsd/target_os_siginfo.h
 create mode 100644 bsd-user/netbsd/target_os_signal.h
 create mode 100644 bsd-user/netbsd/target_os_vmparam.h
 create mode 100644 bsd-user/openbsd/target_os_siginfo.h
 create mode 100644 bsd-user/openbsd/target_os_signal.h
 create mode 100644 bsd-user/openbsd/target_os_vmparam.h
 create mode 100644 bsd-user/sparc/target_arch_signal.h
 create mode 100644 bsd-user/sparc/target_arch_vmparam.h
 delete mode 100644 bsd-user/sparc/target_signal.h
 create mode 100644 bsd-user/sparc64/target_arch_signal.h
 create mode 100644 bsd-user/sparc64/target_arch_vmparam.h
 delete mode 100644 bsd-user/sparc64/target_signal.h
 create mode 100644 bsd-user/x86_64/target_arch_signal.h
 create mode 100644 bsd-user/x86_64/target_arch_vmparam.h
 delete mode 100644 bsd-user/x86_64/target_signal.h
Makefile.target +2 -1
index 9a49852..ec00c80 100644
@@ -103,7 +103,8 @@ endif #CONFIG_LINUX_USER
 
 ifdef CONFIG_BSD_USER
 
-QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR)
+QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH) \
+			 -I$(SRC_PATH)/bsd-user/$(TARGET_OS)
 
 obj-y += bsd-user/
 obj-y += gdbstub.o user-exec.o
bsd-user/elfload.c +2 -3
index 007bcb1..035bcea 100644
@@ -688,9 +688,8 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
     /* Create enough stack to hold everything.  If we don't use
      * it for args, we'll use it for something else...
      */
-    size = x86_stack_size;
-    if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
-        size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
+    size = target_dflssiz;
+    stack_base = TARGET_USRSTACK - size;
     error = target_mmap(0,
                         size + qemu_host_page_size,
                         PROT_READ | PROT_WRITE,
bsd-user/freebsd/target_os_siginfo.h new file +100 -0

100 lines not on this page · raw message

bsd-user/freebsd/target_os_signal.h new file +70 -0

70 lines not on this page · raw message

bsd-user/freebsd/target_os_vmparam.h new file +19 -0
new file mode 100644
index 0000000..baad8a6
@@ -0,0 +1,19 @@
+#ifndef _TARGET_OS_VMPARAM_H_
+#define _TARGET_OS_VMPARAM_H_
+
+#include "target_arch_vmparam.h"
+
+#define TARGET_SPACE_USRSPACE   4096
+#define TARGET_ARG_MAX          262144
+
+/* Compare to sys/exec.h */
+struct target_ps_strings {
+    abi_ulong ps_argvstr;
+    uint32_t ps_nargvstr;
+    abi_ulong ps_envstr;
+    uint32_t ps_nenvstr;
+};
+
+#define TARGET_PS_STRINGS  (TARGET_USRSTACK - sizeof(struct target_ps_strings))
+
+#endif /* !TARGET_OS_VMPARAM_H_ */
bsd-user/i386/target_arch_signal.h new file +23 -0
new file mode 100644
index 0000000..ebd83f6
@@ -0,0 +1,23 @@
+/*
+ *  i386 dependent signal definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef TARGET_ARCH_SIGNAL_H
+#define TARGET_ARCH_SIGNAL_H
+
+#include "cpu.h"
+
+#endif /* TARGET_ARCH_SIGNAL_H */
bsd-user/i386/target_arch_vmparam.h new file +23 -0
new file mode 100644
index 0000000..6687adb
@@ -0,0 +1,23 @@
+#ifndef _TARGET_ARCH_VMPARAM_H_
+#define _TARGET_ARCH_VMPARAM_H_
+
+#include "cpu.h"
+
+/* compare to i386/include/vmparam.h */
+#define TARGET_MAXTSIZ  (128UL*1024*1024)   /* max text size */
+#define TARGET_DFLDSIZ  (128UL*1024*1024)   /* initial data size limit */
+#define TARGET_MAXDSIZ  (512UL*1024*1024)   /* max data size */
+#define TARGET_DFLSSIZ  (8UL*1024*1024)     /* initial stack size limit */
+#define TARGET_MAXSSIZ  (64UL*1024*1024)    /* max stack size */
+#define TARGET_SGROWSIZ (128UL*1024)        /* amount to grow stack */
+
+#define TARGET_USRSTACK (0xbfc00000)
+
+#define TARGET_PS_STRINGS  (TARGET_USRSTACK - sizeof(struct target_ps_strings))
+
+static inline abi_ulong get_sp_from_cpustate(CPUX86State *state)
+{
+    return state->regs[R_ESP];
+}
+
+#endif /* !_TARGET_ARCH_VMPARAM_H_ */
bsd-user/i386/target_signal.h deleted +0 -37
deleted file mode 100644
index 806e1e2..0000000
@@ -1,37 +0,0 @@
-/*
- *  i386 dependent signal definitions
- *
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef TARGET_SIGNAL_H
-#define TARGET_SIGNAL_H
-
-#include "cpu.h"
-
-/* this struct defines a stack used during syscall handling */
-
-typedef struct target_sigaltstack {
-	abi_ulong ss_sp;
-	abi_long ss_flags;
-	abi_ulong ss_size;
-} target_stack_t;
-
-
-static inline abi_ulong get_sp_from_cpustate(CPUX86State *state)
-{
-    return state->regs[R_ESP];
-}
-
-#endif /* TARGET_SIGNAL_H */
bsd-user/main.c +18 -11
index e64a3ba..2eb4a1b 100644
@@ -49,10 +49,12 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
 extern char **environ;
 enum BSDType bsd_type;
 
-/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
-   we allocate a bigger stack. Need a better solution, for example
-   by remapping the process stack directly at the right place */
-unsigned long x86_stack_size = 512 * 1024;
+unsigned long target_maxtsiz = TARGET_MAXTSIZ;   /* max text size */
+unsigned long target_dfldsiz = TARGET_DFLDSIZ;   /* initial data size limit */
+unsigned long target_maxdsiz = TARGET_MAXDSIZ;   /* max data size */
+unsigned long target_dflssiz = TARGET_DFLSSIZ;   /* initial data size limit */
+unsigned long target_maxssiz = TARGET_MAXSSIZ;   /* max stack size */
+unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount to grow stack */
 
 void gemu_log(const char *fmt, ...)
 {
@@ -876,7 +878,7 @@ static void usage(void)
            ,
            TARGET_NAME,
            interp_prefix,
-           x86_stack_size);
+           target_dflssiz);
     exit(1);
 }
 
@@ -969,13 +971,18 @@ int main(int argc, char **argv)
                 usage();
         } else if (!strcmp(r, "s")) {
             r = argv[optind++];
-            x86_stack_size = strtol(r, (char **)&r, 0);
-            if (x86_stack_size <= 0)
+            target_dflssiz = strtol(r, (char **)&r, 0);
+            if (target_dflssiz <= 0) {
                 usage();
-            if (*r == 'M')
-                x86_stack_size *= 1024 * 1024;
-            else if (*r == 'k' || *r == 'K')
-                x86_stack_size *= 1024;
+            }
+            if (*r == 'M') {
+                target_dflssiz *= 1024 * 1024;
+            } else if (*r == 'k' || *r == 'K') {
+                target_dflssiz *= 1024;
+            }
+            if (target_dflssiz > target_maxssiz) {
+                usage();
+            }
         } else if (!strcmp(r, "L")) {
             interp_prefix = argv[optind++];
         } else if (!strcmp(r, "p")) {
bsd-user/mips/target_arch_signal.h new file +68 -0

68 lines not on this page · raw message

bsd-user/mips/target_arch_vmparam.h new file +42 -0

42 lines not on this page · raw message

bsd-user/mips/target_signal.h deleted +0 -38
deleted file mode 100644
index 8ac3a2f..0000000
@@ -1,38 +0,0 @@
-/*
- *  mips signal definitions
- *
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef _MIPS_TARGET_SIGNAL_H_
-#define _MIPS_TARGET_SIGNAL_H_
-
-#include "cpu.h"
-
-#define TARGET_INSN_SIZE    4       /* mips instruction size */
-
-/* this struct defines a stack used during syscall handling */
-
-typedef struct target_sigaltstack {
-    abi_ulong ss_sp;
-    abi_long ss_flags;
-    abi_ulong ss_size;
-} target_stack_t;
-
-static inline abi_ulong get_sp_from_cpustate(CPUMIPSState *state)
-{
-    return state->active_tc.gpr[29];
-}
-
-#endif /* !_MIP64_TARGET_SIGNAL_H_ */
bsd-user/mips64/target_arch_signal.h new file +68 -0

68 lines not on this page · raw message

bsd-user/mips64/target_arch_vmparam.h new file +42 -0

42 lines not on this page · raw message

bsd-user/mips64/target_signal.h deleted +0 -38
deleted file mode 100644
index fc8674d..0000000
@@ -1,38 +0,0 @@
-/*
- *  mips64 signal definitions
- *
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef _MIPS64_TARGET_SIGNAL_H_
-#define _MIPS64_TARGET_SIGNAL_H_
-
-#include "cpu.h"
-
-#define TARGET_INSN_SIZE        4       /* mips64 instruction size */
-
-/* this struct defines a stack used during syscall handling */
-
-typedef struct target_sigaltstack {
-    abi_ulong ss_sp;
-    abi_long ss_flags;
-    abi_ulong ss_size;
-} target_stack_t;
-
-static inline abi_ulong get_sp_from_cpustate(CPUMIPSState *state)
-{
-    return state->active_tc.gpr[29];
-}
-
-#endif /* !_MIP64_TARGET_SIGNAL_H_ */
bsd-user/netbsd/target_os_siginfo.h new file +82 -0

82 lines not on this page · raw message

bsd-user/netbsd/target_os_signal.h new file +70 -0

70 lines not on this page · raw message

bsd-user/netbsd/target_os_vmparam.h new file +17 -0
new file mode 100644
index 0000000..aba1241
@@ -0,0 +1,17 @@
+#ifndef _NETBSD_TARGET_OS_VMPARAM_H_
+#define _NETBSD_TARGET_OS_VMPARAM_H_
+
+#define TARGET_SPACE_USRSPACE   4096
+#define TARGET_ARG_MAX          262144
+
+/* sys/exec.h */
+struct target_ps_strings {
+    abi_ulong ps_argvstr;
+    uint32_t ps_nargvstr;
+    abi_ulong ps_envstr;
+    uint32_t ps_nenvstr;
+};
+
+#define TARGET_PS_STRINGS  (TARGET_USRSTACK - sizeof(struct target_ps_strings))
+
+#endif /* !_NETBSD_TARGET_OS_VMPARAM_H_ */
bsd-user/openbsd/target_os_siginfo.h new file +82 -0

82 lines not on this page · raw message

bsd-user/openbsd/target_os_signal.h new file +70 -0

70 lines not on this page · raw message

bsd-user/openbsd/target_os_vmparam.h new file +17 -0
new file mode 100644
index 0000000..31313ef
@@ -0,0 +1,17 @@
+#ifndef _OPENBSD_TARGET_OS_VMPARAM_H_
+#define _OPENBSD_TARGET_OS_VMPARAM_H_
+
+#define TARGET_SPACE_USRSPACE   4096
+#define TARGET_ARG_MAX          262144
+
+/* sys/exec.h */
+struct target_ps_strings {
+    abi_ulong ps_argvstr;
+    uint32_t ps_nargvstr;
+    abi_ulong ps_envstr;
+    uint32_t ps_nenvstr;
+};
+
+#define TARGET_PS_STRINGS  (TARGET_USRSTACK - sizeof(struct target_ps_strings))
+
+#endif /* !_OPENBSD_TARGET_OS_VMPARAM_H_ */
bsd-user/qemu.h +8 -2
index 1e14660..63a3942 100644
@@ -38,7 +38,8 @@ extern enum BSDType bsd_type;
 
 #include "syscall_defs.h"
 #include "syscall.h"
-#include "target_signal.h"
+#include "target_os_signal.h"
+#include "target_os_vmparam.h"
 #include "exec/gdbstub.h"
 
 #if defined(CONFIG_USE_NPTL)
@@ -212,7 +213,12 @@ void mmap_fork_end(int child);
 #endif
 
 /* main.c */
-extern unsigned long x86_stack_size;
+extern unsigned long target_maxtsiz;
+extern unsigned long target_dfldsiz;
+extern unsigned long target_maxdsiz;
+extern unsigned long target_dflssiz;
+extern unsigned long target_maxssiz;
+extern unsigned long target_sgrowsiz;
 
 /* user access */
 
bsd-user/signal.c +0 -1
index 445f69e..e75fd0b 100644
@@ -25,7 +25,6 @@
 #include <errno.h>
 
 #include "qemu.h"
-#include "target_signal.h"
 
 //#define DEBUG_SIGNAL
 
bsd-user/sparc/target_arch_signal.h new file +6 -0
new file mode 100644
index 0000000..6bef0ad
@@ -0,0 +1,6 @@
+#ifndef TARGET_ARCH_SIGNAL_H
+#define TARGET_ARCH_SIGNAL_H
+
+#include "cpu.h"
+
+#endif /* TARGET_ARCH_SIGNAL_H */
bsd-user/sparc/target_arch_vmparam.h new file +30 -0
new file mode 100644
index 0000000..4bda417
@@ -0,0 +1,30 @@
+#ifndef _TARGET_ARCH_VMPARAM_H_
+#define _TARGET_ARCH_VMPARAM_H_
+
+#include "cpu.h"
+
+#define TARGET_MAXTSIZ  (1*1024*1024*1024)  /* max text size */
+#define TARGET_DFLDSIZ  (128*1024*1024)     /* initial data size limit */
+#define TARGET_MAXDSIZ  (1*1024*1024*1024)  /* max data size */
+#define TARGET_DFLSSIZ  (128*1024*1024)     /* initial stack size limit */
+#define TARGET_MAXSSIZ  (1*1024*1024*1024)  /* max stack size */
+#define TARGET_SGROWSIZ (128*1024)      /* amount to grow stack */
+
+/* XXX this may not be right */
+#define TARGET_VM_MAXUSER_ADDRESS   (0xc0000000 - (512 * 1024 * 1024))
+#define TARGET_USRSTACK (TARGET_VM_MAXUSER_ADDRESS - TARGET_PAGE_SIZE)
+
+#ifndef UREG_I6
+#define UREG_I6        6
+#endif
+#ifndef UREG_FP
+#define UREG_FP        UREG_I6
+#endif
+
+static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state)
+{
+    return state->regwptr[UREG_FP];
+}
+
+#endif /* !_TARGET_ARCH_VMPARAM_H_ */
+
bsd-user/sparc/target_signal.h deleted +0 -27
deleted file mode 100644
index 5b2abba..0000000
@@ -1,27 +0,0 @@
-#ifndef TARGET_SIGNAL_H
-#define TARGET_SIGNAL_H
-
-#include "cpu.h"
-
-/* this struct defines a stack used during syscall handling */
-
-typedef struct target_sigaltstack {
-	abi_ulong ss_sp;
-	abi_long ss_flags;
-	abi_ulong ss_size;
-} target_stack_t;
-
-
-#ifndef UREG_I6
-#define UREG_I6        6
-#endif
-#ifndef UREG_FP
-#define UREG_FP        UREG_I6
-#endif
-
-static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state)
-{
-    return state->regwptr[UREG_FP];
-}
-
-#endif /* TARGET_SIGNAL_H */
bsd-user/sparc64/target_arch_signal.h new file +23 -0
new file mode 100644
index 0000000..eb7ad2a
@@ -0,0 +1,23 @@
+/*
+ *  sparc64 dependent signal definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_SIGNAL_H_
+#define _TARGET_ARCH_SIGNAL_H_
+
+#include "cpu.h"
+
+#endif /* !_TARGET_ARCH_SIGNAL_H_ */
bsd-user/sparc64/target_arch_vmparam.h new file +32 -0
new file mode 100644
index 0000000..87548da
@@ -0,0 +1,32 @@
+#ifndef _TARGET_ARCH_VMPARAM_H_
+#define _TARGET_ARCH_VMPARAM_H_
+
+#include "cpu.h"
+
+/* compare to amd64/include/vmparam.h */
+#define TARGET_MAXTSIZ  (1*1024*1024*1024)  /* max text size */
+#define TARGET_DFLDSIZ  (128*1024*1024)     /* initial data size limit */
+#define TARGET_MAXDSIZ  (1*1024*1024*1024)  /* max data size */
+#define TARGET_DFLSSIZ  (128*1024*1024)     /* initial stack size limit */
+#define TARGET_MAXSSIZ  (1*1024*1024*1024)  /* max stack size */
+#define TARGET_SGROWSIZ (128*1024)      /* amount to grow stack */
+
+/* XXX */
+#define TARGET_VM_MINUSER_ADDRESS   (0x0000000000000000UL)
+#define TARGET_VM_MAXUSER_ADDRESS   (0x000007fe00000000UL)
+#define TARGET_USRSTACK (TARGET_VM_MAXUSER_ADDRESS - TARGET_PAGE_SIZE)
+
+#ifndef UREG_I6
+#define UREG_I6        6
+#endif
+#ifndef UREG_FP
+#define UREG_FP        UREG_I6
+#endif
+
+static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state)
+{
+    return state->regwptr[UREG_FP];
+}
+
+#endif /* !_TARGET_ARCH_VMPARAM_H_ */
+
bsd-user/sparc64/target_signal.h deleted +0 -44

44 lines not on this page · raw message

bsd-user/syscall_defs.h +0 -99

105 lines not on this page · raw message

bsd-user/x86_64/target_arch_signal.h new file +23 -0
new file mode 100644
index 0000000..614c11a
@@ -0,0 +1,23 @@
+/*
+ *  x86_64 signal definitions
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_SIGNAL_H_
+#define _TARGET_ARCH_SIGNAL_H_
+
+#include "cpu.h"
+
+#endif /* !TARGET_ARCH_SIGNAL_H_ */
bsd-user/x86_64/target_arch_vmparam.h new file +23 -0
new file mode 100644
index 0000000..8acf7a5
@@ -0,0 +1,23 @@
+#ifndef _TARGET_ARCH_VMPARAM_H_
+#define _TARGET_ARCH_VMPARAM_H_
+
+#include "cpu.h"
+
+/* compare to amd64/include/vmparam.h */
+#define TARGET_MAXTSIZ  (128UL*1024*1024)   /* max text size */
+#define TARGET_DFLDSIZ  (32768UL*1024*1024) /* initial data size limit */
+#define TARGET_MAXDSIZ  (32768UL*1024*1024) /* max data size */
+#define TARGET_DFLSSIZ  (8UL*1024*1024)     /* initial stack size limit */
+#define TARGET_MAXSSIZ  (512UL*1024*1024)   /* max stack size */
+#define TARGET_SGROWSIZ (128UL*1024)        /* amount to grow stack */
+
+#define TARGET_VM_MAXUSER_ADDRESS   (0x0000800000000000UL)
+
+#define TARGET_USRSTACK (TARGET_VM_MAXUSER_ADDRESS - TARGET_PAGE_SIZE)
+
+static inline abi_ulong get_sp_from_cpustate(CPUX86State *state)
+{
+    return state->regs[R_ESP];
+}
+
+#endif /* !_TARGET_ARCH_VMPARAM_H_ */
bsd-user/x86_64/target_signal.h deleted +0 -36
deleted file mode 100644
index c33dbcc..0000000
@@ -1,36 +0,0 @@
-/*
- *  x86_64 signal definitions
- *
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef _X86_64_TARGET_SIGNAL_H_
-#define _X86_64_TARGET_SIGNAL_H_
-
-#include "cpu.h"
-
-/* this struct defines a stack used during syscall handling */
-
-typedef struct target_sigaltstack {
-	abi_ulong ss_sp;
-	abi_long ss_flags;
-	abi_ulong ss_size;
-} target_stack_t;
-
-static inline abi_ulong get_sp_from_cpustate(CPUX86State *state)
-{
-    return state->regs[R_ESP];
-}
-
-#endif /* !_X86_64_TARGET_SIGNAL_H_ */
configure +7 -0
index ad32f87..749eba8 100755
@@ -432,6 +432,7 @@ if test -z "$ARCH"; then
 fi
 
 # OS specific
+TARGET_OS=""
 
 case $targetos in
 CYGWIN*)
@@ -457,6 +458,7 @@ FreeBSD)
   audio_possible_drivers="oss sdl esd pa"
   # needed for kinfo_getvmmap(3) in libutil.h
   LIBS="-lutil $LIBS"
+  TARGET_OS="freebsd"
 ;;
 DragonFly)
   bsd="yes"
@@ -470,12 +472,14 @@ NetBSD)
   audio_drv_list="oss"
   audio_possible_drivers="oss sdl esd"
   oss_lib="-lossaudio"
+  TARGET_OS="netbsd"
 ;;
 OpenBSD)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="sdl"
   audio_possible_drivers="sdl esd"
+  TARGET_OS="openbsd"
 ;;
 Darwin)
   bsd="yes"
@@ -4267,6 +4271,9 @@ upper() {
 
 target_arch_name="`upper $TARGET_ARCH`"
 echo "TARGET_$target_arch_name=y" >> $config_target_mak
+if [ "$TARGET_OS" != "" ]; then
+    echo "TARGET_OS=$TARGET_OS" >> $config_target_mak
+fi
 echo "TARGET_NAME=$target_name" >> $config_target_mak
 echo "TARGET_BASE_ARCH=$TARGET_BASE_ARCH" >> $config_target_mak
 if [ "$TARGET_ABI_DIR" = "" ]; then
Signature · 1 line
1.7.8
author
#14 lore raw

PATCH 9/23 bsd-user: refresh FreeBSD's system call numbers

In reply to Stacey Son

Update freebsd/syscall_nr.h with FreeBSD's latest system call numbers from -current (FreeBSD 10).

---
 bsd-user/freebsd/syscall_nr.h |  834 ++++++++++++++++++++++-------------------
 1 files changed, 446 insertions(+), 388 deletions(-)
bsd-user/freebsd/syscall_nr.h +446 -388
index 057f46c..d849024 100644
@@ -1,392 +1,450 @@
 /*
- *  FreeBSD System call numbers.
+ * System call numbers.
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * $FreeBSD: src/sys/sys/syscall.h,v 1.224 2008/08/24 21:23:08 rwatson Exp $
- * created from FreeBSD: head/sys/kern/syscalls.master 182123 2008-08-24 21:20:35Z rwatson
+ * created from FreeBSD: releng/9.1/sys/kern/syscalls.master 229723
+ * 2012-01-06 19:29:16Z jhb
  */
-#ifndef _FREEBSD_SYSCALL_NR_H_
-#define _FREEBSD_SYSCALL_NR_H_
-
-#define TARGET_FREEBSD_NR_syscall     0
-#define TARGET_FREEBSD_NR_exit        1
-#define TARGET_FREEBSD_NR_fork        2
-#define TARGET_FREEBSD_NR_read        3
-#define TARGET_FREEBSD_NR_write       4
-#define TARGET_FREEBSD_NR_open        5
-#define TARGET_FREEBSD_NR_close       6
-#define TARGET_FREEBSD_NR_wait4       7
-#define TARGET_FREEBSD_NR_link        9
-#define TARGET_FREEBSD_NR_unlink      10
-#define TARGET_FREEBSD_NR_chdir       12
-#define TARGET_FREEBSD_NR_fchdir      13
-#define TARGET_FREEBSD_NR_mknod       14
-#define TARGET_FREEBSD_NR_chmod       15
-#define TARGET_FREEBSD_NR_chown       16
-#define TARGET_FREEBSD_NR_break       17
-#define TARGET_FREEBSD_NR_freebsd4_getfsstat  18
-#define TARGET_FREEBSD_NR_getpid      20
-#define TARGET_FREEBSD_NR_mount       21
-#define TARGET_FREEBSD_NR_unmount     22
-#define TARGET_FREEBSD_NR_setuid      23
-#define TARGET_FREEBSD_NR_getuid      24
-#define TARGET_FREEBSD_NR_geteuid     25
-#define TARGET_FREEBSD_NR_ptrace      26
-#define TARGET_FREEBSD_NR_recvmsg     27
-#define TARGET_FREEBSD_NR_sendmsg     28
-#define TARGET_FREEBSD_NR_recvfrom    29
-#define TARGET_FREEBSD_NR_accept      30
-#define TARGET_FREEBSD_NR_getpeername 31
-#define TARGET_FREEBSD_NR_getsockname 32
-#define TARGET_FREEBSD_NR_access      33
-#define TARGET_FREEBSD_NR_chflags     34
-#define TARGET_FREEBSD_NR_fchflags    35
-#define TARGET_FREEBSD_NR_sync        36
-#define TARGET_FREEBSD_NR_kill        37
-#define TARGET_FREEBSD_NR_getppid     39
-#define TARGET_FREEBSD_NR_dup 41
-#define TARGET_FREEBSD_NR_pipe        42
-#define TARGET_FREEBSD_NR_getegid     43
-#define TARGET_FREEBSD_NR_profil      44
-#define TARGET_FREEBSD_NR_ktrace      45
-#define TARGET_FREEBSD_NR_getgid      47
-#define TARGET_FREEBSD_NR_getlogin    49
-#define TARGET_FREEBSD_NR_setlogin    50
-#define TARGET_FREEBSD_NR_acct        51
-#define TARGET_FREEBSD_NR_sigaltstack 53
-#define TARGET_FREEBSD_NR_ioctl       54
-#define TARGET_FREEBSD_NR_reboot      55
-#define TARGET_FREEBSD_NR_revoke      56
-#define TARGET_FREEBSD_NR_symlink     57
-#define TARGET_FREEBSD_NR_readlink    58
-#define TARGET_FREEBSD_NR_execve      59
-#define TARGET_FREEBSD_NR_umask       60
-#define TARGET_FREEBSD_NR_chroot      61
-#define TARGET_FREEBSD_NR_msync       65
-#define TARGET_FREEBSD_NR_vfork       66
-#define TARGET_FREEBSD_NR_sbrk        69
-#define TARGET_FREEBSD_NR_sstk        70
-#define TARGET_FREEBSD_NR_vadvise     72
-#define TARGET_FREEBSD_NR_munmap      73
-#define TARGET_FREEBSD_NR_mprotect    74
-#define TARGET_FREEBSD_NR_madvise     75
-#define TARGET_FREEBSD_NR_mincore     78
-#define TARGET_FREEBSD_NR_getgroups   79
-#define TARGET_FREEBSD_NR_setgroups   80
-#define TARGET_FREEBSD_NR_getpgrp     81
-#define TARGET_FREEBSD_NR_setpgid     82
-#define TARGET_FREEBSD_NR_setitimer   83
-#define TARGET_FREEBSD_NR_swapon      85
-#define TARGET_FREEBSD_NR_getitimer   86
-#define TARGET_FREEBSD_NR_getdtablesize       89
-#define TARGET_FREEBSD_NR_dup2        90
-#define TARGET_FREEBSD_NR_fcntl       92
-#define TARGET_FREEBSD_NR_select      93
-#define TARGET_FREEBSD_NR_fsync       95
-#define TARGET_FREEBSD_NR_setpriority 96
-#define TARGET_FREEBSD_NR_socket      97
-#define TARGET_FREEBSD_NR_connect     98
-#define TARGET_FREEBSD_NR_getpriority 100
-#define TARGET_FREEBSD_NR_bind        104
-#define TARGET_FREEBSD_NR_setsockopt  105
-#define TARGET_FREEBSD_NR_listen      106
-#define TARGET_FREEBSD_NR_gettimeofday        116
-#define TARGET_FREEBSD_NR_getrusage   117
-#define TARGET_FREEBSD_NR_getsockopt  118
-#define TARGET_FREEBSD_NR_readv       120
-#define TARGET_FREEBSD_NR_writev      121
-#define TARGET_FREEBSD_NR_settimeofday        122
-#define TARGET_FREEBSD_NR_fchown      123
-#define TARGET_FREEBSD_NR_fchmod      124
-#define TARGET_FREEBSD_NR_setreuid    126
-#define TARGET_FREEBSD_NR_setregid    127
-#define TARGET_FREEBSD_NR_rename      128
-#define TARGET_FREEBSD_NR_flock       131
-#define TARGET_FREEBSD_NR_mkfifo      132
-#define TARGET_FREEBSD_NR_sendto      133
-#define TARGET_FREEBSD_NR_shutdown    134
-#define TARGET_FREEBSD_NR_socketpair  135
-#define TARGET_FREEBSD_NR_mkdir       136
-#define TARGET_FREEBSD_NR_rmdir       137
-#define TARGET_FREEBSD_NR_utimes      138
-#define TARGET_FREEBSD_NR_adjtime     140
-#define TARGET_FREEBSD_NR_setsid      147
-#define TARGET_FREEBSD_NR_quotactl    148
-#define TARGET_FREEBSD_NR_nlm_syscall 154
-#define TARGET_FREEBSD_NR_nfssvc      155
-#define TARGET_FREEBSD_NR_freebsd4_statfs     157
-#define TARGET_FREEBSD_NR_freebsd4_fstatfs    158
-#define TARGET_FREEBSD_NR_lgetfh      160
-#define TARGET_FREEBSD_NR_getfh       161
-#define TARGET_FREEBSD_NR_getdomainname       162
-#define TARGET_FREEBSD_NR_setdomainname       163
-#define TARGET_FREEBSD_NR_uname       164
-#define TARGET_FREEBSD_NR_sysarch     165
-#define TARGET_FREEBSD_NR_rtprio      166
-#define TARGET_FREEBSD_NR_semsys      169
-#define TARGET_FREEBSD_NR_msgsys      170
-#define TARGET_FREEBSD_NR_shmsys      171
-#define TARGET_FREEBSD_NR_freebsd6_pread      173
-#define TARGET_FREEBSD_NR_freebsd6_pwrite     174
-#define TARGET_FREEBSD_NR_setfib      175
-#define TARGET_FREEBSD_NR_ntp_adjtime 176
-#define TARGET_FREEBSD_NR_setgid      181
-#define TARGET_FREEBSD_NR_setegid     182
-#define TARGET_FREEBSD_NR_seteuid     183
-#define TARGET_FREEBSD_NR_stat        188
-#define TARGET_FREEBSD_NR_fstat       189
-#define TARGET_FREEBSD_NR_lstat       190
-#define TARGET_FREEBSD_NR_pathconf    191
-#define TARGET_FREEBSD_NR_fpathconf   192
-#define TARGET_FREEBSD_NR_getrlimit   194
-#define TARGET_FREEBSD_NR_setrlimit   195
-#define TARGET_FREEBSD_NR_getdirentries       196
-#define TARGET_FREEBSD_NR_freebsd6_mmap       197
-#define TARGET_FREEBSD_NR___syscall   198
-#define TARGET_FREEBSD_NR_freebsd6_lseek      199
-#define TARGET_FREEBSD_NR_freebsd6_truncate   200
-#define TARGET_FREEBSD_NR_freebsd6_ftruncate  201
-#define TARGET_FREEBSD_NR___sysctl    202
-#define TARGET_FREEBSD_NR_mlock       203
-#define TARGET_FREEBSD_NR_munlock     204
-#define TARGET_FREEBSD_NR_undelete    205
-#define TARGET_FREEBSD_NR_futimes     206
-#define TARGET_FREEBSD_NR_getpgid     207
-#define TARGET_FREEBSD_NR_poll        209
-#define TARGET_FREEBSD_NR___semctl    220
-#define TARGET_FREEBSD_NR_semget      221
-#define TARGET_FREEBSD_NR_semop       222
-#define TARGET_FREEBSD_NR_msgctl      224
-#define TARGET_FREEBSD_NR_msgget      225
-#define TARGET_FREEBSD_NR_msgsnd      226
-#define TARGET_FREEBSD_NR_msgrcv      227
-#define TARGET_FREEBSD_NR_shmat       228
-#define TARGET_FREEBSD_NR_shmctl      229
-#define TARGET_FREEBSD_NR_shmdt       230
-#define TARGET_FREEBSD_NR_shmget      231
-#define TARGET_FREEBSD_NR_clock_gettime       232
-#define TARGET_FREEBSD_NR_clock_settime       233
-#define TARGET_FREEBSD_NR_clock_getres        234
-#define TARGET_FREEBSD_NR_ktimer_create       235
-#define TARGET_FREEBSD_NR_ktimer_delete       236
-#define TARGET_FREEBSD_NR_ktimer_settime      237
-#define TARGET_FREEBSD_NR_ktimer_gettime      238
-#define TARGET_FREEBSD_NR_ktimer_getoverrun   239
-#define TARGET_FREEBSD_NR_nanosleep   240
-#define TARGET_FREEBSD_NR_ntp_gettime 248
-#define TARGET_FREEBSD_NR_minherit    250
-#define TARGET_FREEBSD_NR_rfork       251
-#define TARGET_FREEBSD_NR_openbsd_poll        252
-#define TARGET_FREEBSD_NR_issetugid   253
-#define TARGET_FREEBSD_NR_lchown      254
-#define TARGET_FREEBSD_NR_aio_read    255
-#define TARGET_FREEBSD_NR_aio_write   256
-#define TARGET_FREEBSD_NR_lio_listio  257
-#define TARGET_FREEBSD_NR_getdents    272
-#define TARGET_FREEBSD_NR_lchmod      274
-#define TARGET_FREEBSD_NR_netbsd_lchown       275
-#define TARGET_FREEBSD_NR_lutimes     276
-#define TARGET_FREEBSD_NR_netbsd_msync        277
-#define TARGET_FREEBSD_NR_nstat       278
-#define TARGET_FREEBSD_NR_nfstat      279
-#define TARGET_FREEBSD_NR_nlstat      280
-#define TARGET_FREEBSD_NR_preadv      289
-#define TARGET_FREEBSD_NR_pwritev     290
-#define TARGET_FREEBSD_NR_freebsd4_fhstatfs   297
-#define TARGET_FREEBSD_NR_fhopen      298
-#define TARGET_FREEBSD_NR_fhstat      299
-#define TARGET_FREEBSD_NR_modnext     300
-#define TARGET_FREEBSD_NR_modstat     301
-#define TARGET_FREEBSD_NR_modfnext    302
-#define TARGET_FREEBSD_NR_modfind     303
-#define TARGET_FREEBSD_NR_kldload     304
-#define TARGET_FREEBSD_NR_kldunload   305
-#define TARGET_FREEBSD_NR_kldfind     306
-#define TARGET_FREEBSD_NR_kldnext     307
-#define TARGET_FREEBSD_NR_kldstat     308
-#define TARGET_FREEBSD_NR_kldfirstmod 309
-#define TARGET_FREEBSD_NR_getsid      310
-#define TARGET_FREEBSD_NR_setresuid   311
-#define TARGET_FREEBSD_NR_setresgid   312
-#define TARGET_FREEBSD_NR_aio_return  314
-#define TARGET_FREEBSD_NR_aio_suspend 315
-#define TARGET_FREEBSD_NR_aio_cancel  316
-#define TARGET_FREEBSD_NR_aio_error   317
-#define TARGET_FREEBSD_NR_oaio_read   318
-#define TARGET_FREEBSD_NR_oaio_write  319
-#define TARGET_FREEBSD_NR_olio_listio 320
-#define TARGET_FREEBSD_NR_yield       321
-#define TARGET_FREEBSD_NR_mlockall    324
-#define TARGET_FREEBSD_NR_munlockall  325
-#define TARGET_FREEBSD_NR___getcwd    326
-#define TARGET_FREEBSD_NR_sched_setparam      327
-#define TARGET_FREEBSD_NR_sched_getparam      328
-#define TARGET_FREEBSD_NR_sched_setscheduler  329
-#define TARGET_FREEBSD_NR_sched_getscheduler  330
-#define TARGET_FREEBSD_NR_sched_yield 331
-#define TARGET_FREEBSD_NR_sched_get_priority_max      332
-#define TARGET_FREEBSD_NR_sched_get_priority_min      333
-#define TARGET_FREEBSD_NR_sched_rr_get_interval       334
-#define TARGET_FREEBSD_NR_utrace      335
-#define TARGET_FREEBSD_NR_freebsd4_sendfile   336
-#define TARGET_FREEBSD_NR_kldsym      337
-#define TARGET_FREEBSD_NR_jail        338
-#define TARGET_FREEBSD_NR_sigprocmask 340
-#define TARGET_FREEBSD_NR_sigsuspend  341
-#define TARGET_FREEBSD_NR_freebsd4_sigaction  342
-#define TARGET_FREEBSD_NR_sigpending  343
-#define TARGET_FREEBSD_NR_freebsd4_sigreturn  344
-#define TARGET_FREEBSD_NR_sigtimedwait        345
-#define TARGET_FREEBSD_NR_sigwaitinfo 346
-#define TARGET_FREEBSD_NR___acl_get_file      347
-#define TARGET_FREEBSD_NR___acl_set_file      348
-#define TARGET_FREEBSD_NR___acl_get_fd        349
-#define TARGET_FREEBSD_NR___acl_set_fd        350
-#define TARGET_FREEBSD_NR___acl_delete_file   351
-#define TARGET_FREEBSD_NR___acl_delete_fd     352
-#define TARGET_FREEBSD_NR___acl_aclcheck_file 353
-#define TARGET_FREEBSD_NR___acl_aclcheck_fd   354
-#define TARGET_FREEBSD_NR_extattrctl  355
-#define TARGET_FREEBSD_NR_extattr_set_file    356
-#define TARGET_FREEBSD_NR_extattr_get_file    357
-#define TARGET_FREEBSD_NR_extattr_delete_file 358
-#define TARGET_FREEBSD_NR_aio_waitcomplete    359
-#define TARGET_FREEBSD_NR_getresuid   360
-#define TARGET_FREEBSD_NR_getresgid   361
-#define TARGET_FREEBSD_NR_kqueue      362
-#define TARGET_FREEBSD_NR_kevent      363
-#define TARGET_FREEBSD_NR_extattr_set_fd      371
-#define TARGET_FREEBSD_NR_extattr_get_fd      372
-#define TARGET_FREEBSD_NR_extattr_delete_fd   373
-#define TARGET_FREEBSD_NR___setugid   374
-#define TARGET_FREEBSD_NR_nfsclnt     375
-#define TARGET_FREEBSD_NR_eaccess     376
-#define TARGET_FREEBSD_NR_nmount      378
-#define TARGET_FREEBSD_NR___mac_get_proc      384
-#define TARGET_FREEBSD_NR___mac_set_proc      385
-#define TARGET_FREEBSD_NR___mac_get_fd        386
-#define TARGET_FREEBSD_NR___mac_get_file      387
-#define TARGET_FREEBSD_NR___mac_set_fd        388
-#define TARGET_FREEBSD_NR___mac_set_file      389
-#define TARGET_FREEBSD_NR_kenv        390
-#define TARGET_FREEBSD_NR_lchflags    391
-#define TARGET_FREEBSD_NR_uuidgen     392
-#define TARGET_FREEBSD_NR_sendfile    393
-#define TARGET_FREEBSD_NR_mac_syscall 394
-#define TARGET_FREEBSD_NR_getfsstat   395
-#define TARGET_FREEBSD_NR_statfs      396
-#define TARGET_FREEBSD_NR_fstatfs     397
-#define TARGET_FREEBSD_NR_fhstatfs    398
-#define TARGET_FREEBSD_NR_ksem_close  400
-#define TARGET_FREEBSD_NR_ksem_post   401
-#define TARGET_FREEBSD_NR_ksem_wait   402
-#define TARGET_FREEBSD_NR_ksem_trywait        403
-#define TARGET_FREEBSD_NR_ksem_init   404
-#define TARGET_FREEBSD_NR_ksem_open   405
-#define TARGET_FREEBSD_NR_ksem_unlink 406
-#define TARGET_FREEBSD_NR_ksem_getvalue       407
-#define TARGET_FREEBSD_NR_ksem_destroy        408
-#define TARGET_FREEBSD_NR___mac_get_pid       409
-#define TARGET_FREEBSD_NR___mac_get_link      410
-#define TARGET_FREEBSD_NR___mac_set_link      411
-#define TARGET_FREEBSD_NR_extattr_set_link    412
-#define TARGET_FREEBSD_NR_extattr_get_link    413
-#define TARGET_FREEBSD_NR_extattr_delete_link 414
-#define TARGET_FREEBSD_NR___mac_execve        415
-#define TARGET_FREEBSD_NR_sigaction   416
-#define TARGET_FREEBSD_NR_sigreturn   417
-#define TARGET_FREEBSD_NR_getcontext  421
-#define TARGET_FREEBSD_NR_setcontext  422
-#define TARGET_FREEBSD_NR_swapcontext 423
-#define TARGET_FREEBSD_NR_swapoff     424
-#define TARGET_FREEBSD_NR___acl_get_link      425
-#define TARGET_FREEBSD_NR___acl_set_link      426
-#define TARGET_FREEBSD_NR___acl_delete_link   427
-#define TARGET_FREEBSD_NR___acl_aclcheck_link 428
-#define TARGET_FREEBSD_NR_sigwait     429
-#define TARGET_FREEBSD_NR_thr_create  430
-#define TARGET_FREEBSD_NR_thr_exit    431
-#define TARGET_FREEBSD_NR_thr_self    432
-#define TARGET_FREEBSD_NR_thr_kill    433
-#define TARGET_FREEBSD_NR__umtx_lock  434
-#define TARGET_FREEBSD_NR__umtx_unlock        435
-#define TARGET_FREEBSD_NR_jail_attach 436
-#define TARGET_FREEBSD_NR_extattr_list_fd     437
-#define TARGET_FREEBSD_NR_extattr_list_file   438
-#define TARGET_FREEBSD_NR_extattr_list_link   439
-#define TARGET_FREEBSD_NR_ksem_timedwait      441
-#define TARGET_FREEBSD_NR_thr_suspend 442
-#define TARGET_FREEBSD_NR_thr_wake    443
-#define TARGET_FREEBSD_NR_kldunloadf  444
-#define TARGET_FREEBSD_NR_audit       445
-#define TARGET_FREEBSD_NR_auditon     446
-#define TARGET_FREEBSD_NR_getauid     447
-#define TARGET_FREEBSD_NR_setauid     448
-#define TARGET_FREEBSD_NR_getaudit    449
-#define TARGET_FREEBSD_NR_setaudit    450
-#define TARGET_FREEBSD_NR_getaudit_addr       451
-#define TARGET_FREEBSD_NR_setaudit_addr       452
-#define TARGET_FREEBSD_NR_auditctl    453
-#define TARGET_FREEBSD_NR__umtx_op    454
-#define TARGET_FREEBSD_NR_thr_new     455
-#define TARGET_FREEBSD_NR_sigqueue    456
-#define TARGET_FREEBSD_NR_kmq_open    457
-#define TARGET_FREEBSD_NR_kmq_setattr 458
-#define TARGET_FREEBSD_NR_kmq_timedreceive    459
-#define TARGET_FREEBSD_NR_kmq_timedsend       460
-#define TARGET_FREEBSD_NR_kmq_notify  461
-#define TARGET_FREEBSD_NR_kmq_unlink  462
-#define TARGET_FREEBSD_NR_abort2      463
-#define TARGET_FREEBSD_NR_thr_set_name        464
-#define TARGET_FREEBSD_NR_aio_fsync   465
-#define TARGET_FREEBSD_NR_rtprio_thread       466
-#define TARGET_FREEBSD_NR_sctp_peeloff        471
-#define TARGET_FREEBSD_NR_sctp_generic_sendmsg        472
-#define TARGET_FREEBSD_NR_sctp_generic_sendmsg_iov    473
-#define TARGET_FREEBSD_NR_sctp_generic_recvmsg        474
-#define TARGET_FREEBSD_NR_pread       475
-#define TARGET_FREEBSD_NR_pwrite      476
-#define TARGET_FREEBSD_NR_mmap        477
-#define TARGET_FREEBSD_NR_lseek       478
-#define TARGET_FREEBSD_NR_truncate    479
-#define TARGET_FREEBSD_NR_ftruncate   480
-#define TARGET_FREEBSD_NR_thr_kill2   481
-#define TARGET_FREEBSD_NR_shm_open    482
-#define TARGET_FREEBSD_NR_shm_unlink  483
-#define TARGET_FREEBSD_NR_cpuset      484
-#define TARGET_FREEBSD_NR_cpuset_setid        485
-#define TARGET_FREEBSD_NR_cpuset_getid        486
-#define TARGET_FREEBSD_NR_cpuset_getaffinity  487
-#define TARGET_FREEBSD_NR_cpuset_setaffinity  488
-#define TARGET_FREEBSD_NR_faccessat   489
-#define TARGET_FREEBSD_NR_fchmodat    490
-#define TARGET_FREEBSD_NR_fchownat    491
-#define TARGET_FREEBSD_NR_fexecve     492
-#define TARGET_FREEBSD_NR_fstatat     493
-#define TARGET_FREEBSD_NR_futimesat   494
-#define TARGET_FREEBSD_NR_linkat      495
-#define TARGET_FREEBSD_NR_mkdirat     496
-#define TARGET_FREEBSD_NR_mkfifoat    497
-#define TARGET_FREEBSD_NR_mknodat     498
-#define TARGET_FREEBSD_NR_openat      499
-#define TARGET_FREEBSD_NR_readlinkat  500
-#define TARGET_FREEBSD_NR_renameat    501
-#define TARGET_FREEBSD_NR_symlinkat   502
-#define TARGET_FREEBSD_NR_unlinkat    503
-#define TARGET_FREEBSD_NR_posix_openpt        504
 
-#endif /* ! _FREEBSD_SYSCALL_NR_H_ */
+#define TARGET_FREEBSD_NR_syscall   0
+#define TARGET_FREEBSD_NR_exit  1
+#define TARGET_FREEBSD_NR_fork  2
+#define TARGET_FREEBSD_NR_read  3
+#define TARGET_FREEBSD_NR_write 4
+#define TARGET_FREEBSD_NR_open  5
+#define TARGET_FREEBSD_NR_close 6
+#define TARGET_FREEBSD_NR_wait4 7
+                /* 8 is old creat */
+#define TARGET_FREEBSD_NR_link  9
+#define TARGET_FREEBSD_NR_unlink    10
+                /* 11 is obsolete execv */
+#define TARGET_FREEBSD_NR_chdir 12
+#define TARGET_FREEBSD_NR_fchdir    13
+#define TARGET_FREEBSD_NR_mknod 14
+#define TARGET_FREEBSD_NR_chmod 15
+#define TARGET_FREEBSD_NR_chown 16
+#define TARGET_FREEBSD_NR_break 17
+#define TARGET_FREEBSD_NR_freebsd4_getfsstat    18
+                /* 19 is old lseek */
+#define TARGET_FREEBSD_NR_getpid    20
+#define TARGET_FREEBSD_NR_mount 21
+#define TARGET_FREEBSD_NR_unmount   22
+#define TARGET_FREEBSD_NR_setuid    23
+#define TARGET_FREEBSD_NR_getuid    24
+#define TARGET_FREEBSD_NR_geteuid   25
+#define TARGET_FREEBSD_NR_ptrace    26
+#define TARGET_FREEBSD_NR_recvmsg   27
+#define TARGET_FREEBSD_NR_sendmsg   28
+#define TARGET_FREEBSD_NR_recvfrom  29
+#define TARGET_FREEBSD_NR_accept    30
+#define TARGET_FREEBSD_NR_getpeername   31
+#define TARGET_FREEBSD_NR_getsockname   32
+#define TARGET_FREEBSD_NR_access    33
+#define TARGET_FREEBSD_NR_chflags   34
+#define TARGET_FREEBSD_NR_fchflags  35
+#define TARGET_FREEBSD_NR_sync  36
+#define TARGET_FREEBSD_NR_kill  37
+                /* 38 is old stat */
+#define TARGET_FREEBSD_NR_getppid   39
+                /* 40 is old lstat */
+#define TARGET_FREEBSD_NR_dup   41
+#define TARGET_FREEBSD_NR_pipe  42
+#define TARGET_FREEBSD_NR_getegid   43
+#define TARGET_FREEBSD_NR_profil    44
+#define TARGET_FREEBSD_NR_ktrace    45
+                /* 46 is old sigaction */
+#define TARGET_FREEBSD_NR_getgid    47
+                /* 48 is old sigprocmask */
+#define TARGET_FREEBSD_NR_getlogin  49
+#define TARGET_FREEBSD_NR_setlogin  50
+#define TARGET_FREEBSD_NR_acct  51
+                /* 52 is old sigpending */
+#define TARGET_FREEBSD_NR_sigaltstack   53
+#define TARGET_FREEBSD_NR_ioctl 54
+#define TARGET_FREEBSD_NR_reboot    55
+#define TARGET_FREEBSD_NR_revoke    56
+#define TARGET_FREEBSD_NR_symlink   57
+#define TARGET_FREEBSD_NR_readlink  58
+#define TARGET_FREEBSD_NR_execve    59
+#define TARGET_FREEBSD_NR_umask 60
+#define TARGET_FREEBSD_NR_chroot    61
+                /* 62 is old fstat */
+                /* 63 is old getkerninfo */
+                /* 64 is old getpagesize */
+#define TARGET_FREEBSD_NR_msync 65
+#define TARGET_FREEBSD_NR_vfork 66
+                /* 67 is obsolete vread */
+                /* 68 is obsolete vwrite */
+#define TARGET_FREEBSD_NR_sbrk  69
+#define TARGET_FREEBSD_NR_sstk  70
+                /* 71 is old mmap */
+#define TARGET_FREEBSD_NR_vadvise   72
+#define TARGET_FREEBSD_NR_munmap    73
+#define TARGET_FREEBSD_NR_mprotect  74
+#define TARGET_FREEBSD_NR_madvise   75
+                /* 76 is obsolete vhangup */
+                /* 77 is obsolete vlimit */
+#define TARGET_FREEBSD_NR_mincore   78
+#define TARGET_FREEBSD_NR_getgroups 79
+#define TARGET_FREEBSD_NR_setgroups 80
+#define TARGET_FREEBSD_NR_getpgrp   81
+#define TARGET_FREEBSD_NR_setpgid   82
+#define TARGET_FREEBSD_NR_setitimer 83
+                /* 84 is old wait */
+#define TARGET_FREEBSD_NR_swapon    85
+#define TARGET_FREEBSD_NR_getitimer 86
+                /* 87 is old gethostname */
+                /* 88 is old sethostname */
+#define TARGET_FREEBSD_NR_getdtablesize 89
+#define TARGET_FREEBSD_NR_dup2  90
+#define TARGET_FREEBSD_NR_fcntl 92
+#define TARGET_FREEBSD_NR_select    93
+#define TARGET_FREEBSD_NR_fsync 95
+#define TARGET_FREEBSD_NR_setpriority   96
+#define TARGET_FREEBSD_NR_socket    97
+#define TARGET_FREEBSD_NR_connect   98
+                /* 99 is old accept */
+#define TARGET_FREEBSD_NR_getpriority   100
+                /* 101 is old send */
+                /* 102 is old recv */
+                /* 103 is old sigreturn */
+#define TARGET_FREEBSD_NR_bind  104
+#define TARGET_FREEBSD_NR_setsockopt    105
+#define TARGET_FREEBSD_NR_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 */
+#define TARGET_FREEBSD_NR_gettimeofday  116
+#define TARGET_FREEBSD_NR_getrusage 117
+#define TARGET_FREEBSD_NR_getsockopt    118
+#define TARGET_FREEBSD_NR_readv 120
+#define TARGET_FREEBSD_NR_writev    121
+#define TARGET_FREEBSD_NR_settimeofday  122
+#define TARGET_FREEBSD_NR_fchown    123
+#define TARGET_FREEBSD_NR_fchmod    124
+                /* 125 is old recvfrom */
+#define TARGET_FREEBSD_NR_setreuid  126
+#define TARGET_FREEBSD_NR_setregid  127
+#define TARGET_FREEBSD_NR_rename    128
+                /* 129 is old truncate */
+                /* 130 is old ftruncate */
+#define TARGET_FREEBSD_NR_flock 131
+#define TARGET_FREEBSD_NR_mkfifo    132
+#define TARGET_FREEBSD_NR_sendto    133
+#define TARGET_FREEBSD_NR_shutdown  134
+#define TARGET_FREEBSD_NR_socketpair    135
+#define TARGET_FREEBSD_NR_mkdir 136
+#define TARGET_FREEBSD_NR_rmdir 137
+#define TARGET_FREEBSD_NR_utimes    138
+                /* 139 is obsolete 4.2 sigreturn */
+#define TARGET_FREEBSD_NR_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 */
+#define TARGET_FREEBSD_NR_killpg    146 /* COMPAT */
+#define TARGET_FREEBSD_NR_setsid    147
+#define TARGET_FREEBSD_NR_quotactl  148
+                /* 149 is old quota */
+                /* 150 is old getsockname */
+#define TARGET_FREEBSD_NR_nlm_syscall   154
+#define TARGET_FREEBSD_NR_nfssvc    155
+                /* 156 is old getdirentries */
+#define TARGET_FREEBSD_NR_freebsd4_statfs   157
+#define TARGET_FREEBSD_NR_freebsd4_fstatfs  158
+#define TARGET_FREEBSD_NR_lgetfh    160
+#define TARGET_FREEBSD_NR_getfh 161
+#define TARGET_FREEBSD_NR_freebsd4_getdomainname    162
+#define TARGET_FREEBSD_NR_freebsd4_setdomainname    163
+#define TARGET_FREEBSD_NR_freebsd4_uname    164
+#define TARGET_FREEBSD_NR_sysarch   165
+#define TARGET_FREEBSD_NR_rtprio    166
+#define TARGET_FREEBSD_NR_semsys    169
+#define TARGET_FREEBSD_NR_msgsys    170
+#define TARGET_FREEBSD_NR_shmsys    171
+#define TARGET_FREEBSD_NR_freebsd6_pread    173
+#define TARGET_FREEBSD_NR_freebsd6_pwrite   174
+#define TARGET_FREEBSD_NR_setfib    175
+#define TARGET_FREEBSD_NR_ntp_adjtime   176
+#define TARGET_FREEBSD_NR_setgid    181
+#define TARGET_FREEBSD_NR_setegid   182
+#define TARGET_FREEBSD_NR_seteuid   183
+#define TARGET_FREEBSD_NR_stat  188
+#define TARGET_FREEBSD_NR_fstat 189
+#define TARGET_FREEBSD_NR_lstat 190
+#define TARGET_FREEBSD_NR_pathconf  191
+#define TARGET_FREEBSD_NR_fpathconf 192
+#define TARGET_FREEBSD_NR_getrlimit 194
+#define TARGET_FREEBSD_NR_setrlimit 195
+#define TARGET_FREEBSD_NR_getdirentries 196
+#define TARGET_FREEBSD_NR_freebsd6_mmap 197
+#define TARGET_FREEBSD_NR___syscall 198
+#define TARGET_FREEBSD_NR_freebsd6_lseek    199
+#define TARGET_FREEBSD_NR_freebsd6_truncate 200
+#define TARGET_FREEBSD_NR_freebsd6_ftruncate    201
+#define TARGET_FREEBSD_NR___sysctl  202
+#define TARGET_FREEBSD_NR_mlock 203
+#define TARGET_FREEBSD_NR_munlock   204
+#define TARGET_FREEBSD_NR_undelete  205
+#define TARGET_FREEBSD_NR_futimes   206
+#define TARGET_FREEBSD_NR_getpgid   207
+#define TARGET_FREEBSD_NR_poll  209
+#define TARGET_FREEBSD_NR_freebsd7___semctl 220
+#define TARGET_FREEBSD_NR_semget    221
+#define TARGET_FREEBSD_NR_semop 222
+#define TARGET_FREEBSD_NR_freebsd7_msgctl   224
+#define TARGET_FREEBSD_NR_msgget    225
+#define TARGET_FREEBSD_NR_msgsnd    226
+#define TARGET_FREEBSD_NR_msgrcv    227
+#define TARGET_FREEBSD_NR_shmat 228
+#define TARGET_FREEBSD_NR_freebsd7_shmctl   229
+#define TARGET_FREEBSD_NR_shmdt 230
+#define TARGET_FREEBSD_NR_shmget    231
+#define TARGET_FREEBSD_NR_clock_gettime 232
+#define TARGET_FREEBSD_NR_clock_settime 233
+#define TARGET_FREEBSD_NR_clock_getres  234
+#define TARGET_FREEBSD_NR_ktimer_create 235
+#define TARGET_FREEBSD_NR_ktimer_delete 236
+#define TARGET_FREEBSD_NR_ktimer_settime    237
+#define TARGET_FREEBSD_NR_ktimer_gettime    238
+#define TARGET_FREEBSD_NR_ktimer_getoverrun 239
+#define TARGET_FREEBSD_NR_nanosleep 240
+#define TARGET_FREEBSD_NR_ntp_gettime   248
+#define TARGET_FREEBSD_NR_minherit  250
+#define TARGET_FREEBSD_NR_rfork 251
+#define TARGET_FREEBSD_NR_openbsd_poll  252
+#define TARGET_FREEBSD_NR_issetugid 253
+#define TARGET_FREEBSD_NR_lchown    254
+#define TARGET_FREEBSD_NR_aio_read  255
+#define TARGET_FREEBSD_NR_aio_write 256
+#define TARGET_FREEBSD_NR_lio_listio    257
+#define TARGET_FREEBSD_NR_getdents  272
+#define TARGET_FREEBSD_NR_lchmod    274
+#define TARGET_FREEBSD_NR_netbsd_lchown 275
+#define TARGET_FREEBSD_NR_lutimes   276
+#define TARGET_FREEBSD_NR_netbsd_msync  277
+#define TARGET_FREEBSD_NR_nstat 278
+#define TARGET_FREEBSD_NR_nfstat    279
+#define TARGET_FREEBSD_NR_nlstat    280
+#define TARGET_FREEBSD_NR_preadv    289
+#define TARGET_FREEBSD_NR_pwritev   290
+#define TARGET_FREEBSD_NR_freebsd4_fhstatfs 297
+#define TARGET_FREEBSD_NR_fhopen    298
+#define TARGET_FREEBSD_NR_fhstat    299
+#define TARGET_FREEBSD_NR_modnext   300
+#define TARGET_FREEBSD_NR_modstat   301
+#define TARGET_FREEBSD_NR_modfnext  302
+#define TARGET_FREEBSD_NR_modfind   303
+#define TARGET_FREEBSD_NR_kldload   304
+#define TARGET_FREEBSD_NR_kldunload 305
+#define TARGET_FREEBSD_NR_kldfind   306
+#define TARGET_FREEBSD_NR_kldnext   307
+#define TARGET_FREEBSD_NR_kldstat   308
+#define TARGET_FREEBSD_NR_kldfirstmod   309
+#define TARGET_FREEBSD_NR_getsid    310
+#define TARGET_FREEBSD_NR_setresuid 311
+#define TARGET_FREEBSD_NR_setresgid 312
+                /* 313 is obsolete signanosleep */
+#define TARGET_FREEBSD_NR_aio_return    314
+#define TARGET_FREEBSD_NR_aio_suspend   315
+#define TARGET_FREEBSD_NR_aio_cancel    316
+#define TARGET_FREEBSD_NR_aio_error 317
+#define TARGET_FREEBSD_NR_oaio_read 318
+#define TARGET_FREEBSD_NR_oaio_write    319
+#define TARGET_FREEBSD_NR_olio_listio   320
+#define TARGET_FREEBSD_NR_yield 321
+                /* 322 is obsolete thr_sleep */
+                /* 323 is obsolete thr_wakeup */
+#define TARGET_FREEBSD_NR_mlockall  324
+#define TARGET_FREEBSD_NR_munlockall    325
+#define TARGET_FREEBSD_NR___getcwd  326
+#define TARGET_FREEBSD_NR_sched_setparam    327
+#define TARGET_FREEBSD_NR_sched_getparam    328
+#define TARGET_FREEBSD_NR_sched_setscheduler    329
+#define TARGET_FREEBSD_NR_sched_getscheduler    330
+#define TARGET_FREEBSD_NR_sched_yield   331
+#define TARGET_FREEBSD_NR_sched_get_priority_max    332
+#define TARGET_FREEBSD_NR_sched_get_priority_min    333
+#define TARGET_FREEBSD_NR_sched_rr_get_interval 334
+#define TARGET_FREEBSD_NR_utrace    335
+#define TARGET_FREEBSD_NR_freebsd4_sendfile 336
+#define TARGET_FREEBSD_NR_kldsym    337
+#define TARGET_FREEBSD_NR_jail  338
+#define TARGET_FREEBSD_NR_nnpfs_syscall 339
+#define TARGET_FREEBSD_NR_sigprocmask   340
+#define TARGET_FREEBSD_NR_sigsuspend    341
+#define TARGET_FREEBSD_NR_freebsd4_sigaction    342
+#define TARGET_FREEBSD_NR_sigpending    343
+#define TARGET_FREEBSD_NR_freebsd4_sigreturn    344
+#define TARGET_FREEBSD_NR_sigtimedwait  345
+#define TARGET_FREEBSD_NR_sigwaitinfo   346
+#define TARGET_FREEBSD_NR___acl_get_file    347
+#define TARGET_FREEBSD_NR___acl_set_file    348
+#define TARGET_FREEBSD_NR___acl_get_fd  349
+#define TARGET_FREEBSD_NR___acl_set_fd  350
+#define TARGET_FREEBSD_NR___acl_delete_file 351
+#define TARGET_FREEBSD_NR___acl_delete_fd   352
+#define TARGET_FREEBSD_NR___acl_aclcheck_file   353
+#define TARGET_FREEBSD_NR___acl_aclcheck_fd 354
+#define TARGET_FREEBSD_NR_extattrctl    355
+#define TARGET_FREEBSD_NR_extattr_set_file  356
+#define TARGET_FREEBSD_NR_extattr_get_file  357
+#define TARGET_FREEBSD_NR_extattr_delete_file   358
+#define TARGET_FREEBSD_NR_aio_waitcomplete  359
+#define TARGET_FREEBSD_NR_getresuid 360
+#define TARGET_FREEBSD_NR_getresgid 361
+#define TARGET_FREEBSD_NR_kqueue    362
+#define TARGET_FREEBSD_NR_kevent    363
+#define TARGET_FREEBSD_NR_extattr_set_fd    371
+#define TARGET_FREEBSD_NR_extattr_get_fd    372
+#define TARGET_FREEBSD_NR_extattr_delete_fd 373
+#define TARGET_FREEBSD_NR___setugid 374
+#define TARGET_FREEBSD_NR_eaccess   376
+#define TARGET_FREEBSD_NR_afs3_syscall  377
+#define TARGET_FREEBSD_NR_nmount    378
+#define TARGET_FREEBSD_NR___mac_get_proc    384
+#define TARGET_FREEBSD_NR___mac_set_proc    385
+#define TARGET_FREEBSD_NR___mac_get_fd  386
+#define TARGET_FREEBSD_NR___mac_get_file    387
+#define TARGET_FREEBSD_NR___mac_set_fd  388
+#define TARGET_FREEBSD_NR___mac_set_file    389
+#define TARGET_FREEBSD_NR_kenv  390
+#define TARGET_FREEBSD_NR_lchflags  391
+#define TARGET_FREEBSD_NR_uuidgen   392
+#define TARGET_FREEBSD_NR_sendfile  393
+#define TARGET_FREEBSD_NR_mac_syscall   394
+#define TARGET_FREEBSD_NR_getfsstat 395
+#define TARGET_FREEBSD_NR_statfs    396
+#define TARGET_FREEBSD_NR_fstatfs   397
+#define TARGET_FREEBSD_NR_fhstatfs  398
+#define TARGET_FREEBSD_NR_ksem_close    400
+#define TARGET_FREEBSD_NR_ksem_post 401
+#define TARGET_FREEBSD_NR_ksem_wait 402
+#define TARGET_FREEBSD_NR_ksem_trywait  403
+#define TARGET_FREEBSD_NR_ksem_init 404
+#define TARGET_FREEBSD_NR_ksem_open 405
+#define TARGET_FREEBSD_NR_ksem_unlink   406
+#define TARGET_FREEBSD_NR_ksem_getvalue 407
+#define TARGET_FREEBSD_NR_ksem_destroy  408
+#define TARGET_FREEBSD_NR___mac_get_pid 409
+#define TARGET_FREEBSD_NR___mac_get_link    410
+#define TARGET_FREEBSD_NR___mac_set_link    411
+#define TARGET_FREEBSD_NR_extattr_set_link  412
+#define TARGET_FREEBSD_NR_extattr_get_link  413
+#define TARGET_FREEBSD_NR_extattr_delete_link   414
+#define TARGET_FREEBSD_NR___mac_execve  415
+#define TARGET_FREEBSD_NR_sigaction 416
+#define TARGET_FREEBSD_NR_sigreturn 417
+#define TARGET_FREEBSD_NR_getcontext    421
+#define TARGET_FREEBSD_NR_setcontext    422
+#define TARGET_FREEBSD_NR_swapcontext   423
+#define TARGET_FREEBSD_NR_swapoff   424
+#define TARGET_FREEBSD_NR___acl_get_link    425
+#define TARGET_FREEBSD_NR___acl_set_link    426
+#define TARGET_FREEBSD_NR___acl_delete_link 427
+#define TARGET_FREEBSD_NR___acl_aclcheck_link   428
+#define TARGET_FREEBSD_NR_sigwait   429
+#define TARGET_FREEBSD_NR_thr_create    430
+#define TARGET_FREEBSD_NR_thr_exit  431
+#define TARGET_FREEBSD_NR_thr_self  432
+#define TARGET_FREEBSD_NR_thr_kill  433
+#define TARGET_FREEBSD_NR__umtx_lock    434
+#define TARGET_FREEBSD_NR__umtx_unlock  435
+#define TARGET_FREEBSD_NR_jail_attach   436
+#define TARGET_FREEBSD_NR_extattr_list_fd   437
+#define TARGET_FREEBSD_NR_extattr_list_file 438
+#define TARGET_FREEBSD_NR_extattr_list_link 439
+#define TARGET_FREEBSD_NR_ksem_timedwait    441
+#define TARGET_FREEBSD_NR_thr_suspend   442
+#define TARGET_FREEBSD_NR_thr_wake  443
+#define TARGET_FREEBSD_NR_kldunloadf    444
+#define TARGET_FREEBSD_NR_audit 445
+#define TARGET_FREEBSD_NR_auditon   446
+#define TARGET_FREEBSD_NR_getauid   447
+#define TARGET_FREEBSD_NR_setauid   448
+#define TARGET_FREEBSD_NR_getaudit  449
+#define TARGET_FREEBSD_NR_setaudit  450
+#define TARGET_FREEBSD_NR_getaudit_addr 451
+#define TARGET_FREEBSD_NR_setaudit_addr 452
+#define TARGET_FREEBSD_NR_auditctl  453
+#define TARGET_FREEBSD_NR__umtx_op  454
+#define TARGET_FREEBSD_NR_thr_new   455
+#define TARGET_FREEBSD_NR_sigqueue  456
+#define TARGET_FREEBSD_NR_kmq_open  457
+#define TARGET_FREEBSD_NR_kmq_setattr   458
+#define TARGET_FREEBSD_NR_kmq_timedreceive  459
+#define TARGET_FREEBSD_NR_kmq_timedsend 460
+#define TARGET_FREEBSD_NR_kmq_notify    461
+#define TARGET_FREEBSD_NR_kmq_unlink    462
+#define TARGET_FREEBSD_NR_abort2    463
+#define TARGET_FREEBSD_NR_thr_set_name  464
+#define TARGET_FREEBSD_NR_aio_fsync 465
+#define TARGET_FREEBSD_NR_rtprio_thread 466
+#define TARGET_FREEBSD_NR_sctp_peeloff  471
+#define TARGET_FREEBSD_NR_sctp_generic_sendmsg  472
+#define TARGET_FREEBSD_NR_sctp_generic_sendmsg_iov  473
+#define TARGET_FREEBSD_NR_sctp_generic_recvmsg  474
+#define TARGET_FREEBSD_NR_pread 475
+#define TARGET_FREEBSD_NR_pwrite    476
+#define TARGET_FREEBSD_NR_mmap  477
+#define TARGET_FREEBSD_NR_lseek 478
+#define TARGET_FREEBSD_NR_truncate  479
+#define TARGET_FREEBSD_NR_ftruncate 480
+#define TARGET_FREEBSD_NR_thr_kill2 481
+#define TARGET_FREEBSD_NR_shm_open  482
+#define TARGET_FREEBSD_NR_shm_unlink    483
+#define TARGET_FREEBSD_NR_cpuset    484
+#define TARGET_FREEBSD_NR_cpuset_setid  485
+#define TARGET_FREEBSD_NR_cpuset_getid  486
+#define TARGET_FREEBSD_NR_cpuset_getaffinity    487
+#define TARGET_FREEBSD_NR_cpuset_setaffinity    488
+#define TARGET_FREEBSD_NR_faccessat 489
+#define TARGET_FREEBSD_NR_fchmodat  490
+#define TARGET_FREEBSD_NR_fchownat  491
+#define TARGET_FREEBSD_NR_fexecve   492
+#define TARGET_FREEBSD_NR_fstatat   493
+#define TARGET_FREEBSD_NR_futimesat 494
+#define TARGET_FREEBSD_NR_linkat    495
+#define TARGET_FREEBSD_NR_mkdirat   496
+#define TARGET_FREEBSD_NR_mkfifoat  497
+#define TARGET_FREEBSD_NR_mknodat   498
+#define TARGET_FREEBSD_NR_openat    499
+#define TARGET_FREEBSD_NR_readlinkat    500
+#define TARGET_FREEBSD_NR_renameat  501
+#define TARGET_FREEBSD_NR_symlinkat 502
+#define TARGET_FREEBSD_NR_unlinkat  503
+#define TARGET_FREEBSD_NR_posix_openpt  504
+#define TARGET_FREEBSD_NR_gssd_syscall  505
+#define TARGET_FREEBSD_NR_jail_get  506
+#define TARGET_FREEBSD_NR_jail_set  507
+#define TARGET_FREEBSD_NR_jail_remove   508
+#define TARGET_FREEBSD_NR_closefrom 509
+#define TARGET_FREEBSD_NR___semctl  510
+#define TARGET_FREEBSD_NR_msgctl    511
+#define TARGET_FREEBSD_NR_shmctl    512
+#define TARGET_FREEBSD_NR_lpathconf 513
+#define TARGET_FREEBSD_NR_cap_new   514
+#define TARGET_FREEBSD_NR_cap_getrights 515
+#define TARGET_FREEBSD_NR_cap_enter 516
+#define TARGET_FREEBSD_NR_cap_getmode   517
+#define TARGET_FREEBSD_NR_pdfork    518
+#define TARGET_FREEBSD_NR_pdkill    519
+#define TARGET_FREEBSD_NR_pdgetpid  520
+#define TARGET_FREEBSD_NR_pselect   522
+#define TARGET_FREEBSD_NR_getloginclass 523
+#define TARGET_FREEBSD_NR_setloginclass 524
+#define TARGET_FREEBSD_NR_rctl_get_racct    525
+#define TARGET_FREEBSD_NR_rctl_get_rules    526
+#define TARGET_FREEBSD_NR_rctl_get_limits   527
+#define TARGET_FREEBSD_NR_rctl_add_rule 528
+#define TARGET_FREEBSD_NR_rctl_remove_rule  529
+#define TARGET_FREEBSD_NR_posix_fallocate   530
+#define TARGET_FREEBSD_NR_posix_fadvise 531
+#define TARGET_FREEBSD_NR_MAXSYSCALL    532
Signature · 1 line
1.7.8
author
#15 lore raw

PATCH 10/23 bsd-user: add shims for memory management related syscalls

In reply to Stacey Son

This change adds support for bsd memory management system calls including mmap(2), munmap(2), mprotect(2), msync(2), etc. Also, it adds shared memory management system calls. In addition, cleans up syscall.c a bit and fixes checkpatch.pl warnings and errors.

---
 bsd-user/Makefile.objs  |    2 +-
 bsd-user/bsd-errno.h    |   41 +++++
 bsd-user/bsd-mem.c      |  122 +++++++++++++++
 bsd-user/bsd-mem.h      |  387 +++++++++++++++++++++++++++++++++++++++++++++++
 bsd-user/bsd-mman.h     |  121 ---------------
 bsd-user/mmap.c         |   84 +++--------
 bsd-user/qemu-bsd.h     |   34 ++++
 bsd-user/qemu.h         |    1 +
 bsd-user/syscall.c      |  185 +++++++++++++----------
 bsd-user/syscall_defs.h |   71 +++++++++
 10 files changed, 782 insertions(+), 266 deletions(-)
 create mode 100644 bsd-user/bsd-errno.h
 create mode 100644 bsd-user/bsd-mem.c
 create mode 100644 bsd-user/bsd-mem.h
 delete mode 100644 bsd-user/bsd-mman.h
 create mode 100644 bsd-user/qemu-bsd.h
bsd-user/Makefile.objs +1 -1
index 5e77f57..d0cea36 100644
@@ -1,2 +1,2 @@
 obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
-	        uaccess.o
+	        uaccess.o bsd-mem.o
bsd-user/bsd-errno.h new file +41 -0

41 lines not on this page · raw message

bsd-user/bsd-mem.c new file +122 -0

122 lines not on this page · raw message

bsd-user/bsd-mem.h new file +387 -0

387 lines not on this page · raw message

bsd-user/bsd-mman.h deleted +0 -121

121 lines not on this page · raw message

bsd-user/mmap.c +19 -65

118 lines not on this page · raw message

bsd-user/qemu-bsd.h new file +34 -0
new file mode 100644
index 0000000..0add0b3
@@ -0,0 +1,34 @@
+/*
+ *  BSD conversion extern declarations
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _QEMU_BSD_H_
+#define _QEMU_BSD_H_
+
+/* bsd-mem.c */
+abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
+        abi_ulong target_addr);
+abi_long host_to_target_ipc_perm(abi_ulong target_addr,
+        struct ipc_perm *host_ip);
+abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
+        abi_ulong target_addr);
+abi_long host_to_target_shmid_ds(abi_ulong target_addr,
+        struct shmid_ds *host_sd);
+
+
+#endif /* !_QEMU_BSD_H_ */
bsd-user/qemu.h +1 -0
index 1e2abd5..02a05bb 100644
@@ -217,6 +217,7 @@ int target_msync(abi_ulong start, abi_ulong len, int flags);
 extern unsigned long last_brk;
 void mmap_lock(void);
 void mmap_unlock(void);
+abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size);
 void cpu_list_lock(void);
 void cpu_list_unlock(void);
 #if defined(CONFIG_USE_NPTL)
bsd-user/syscall.c +106 -79

251 lines not on this page · raw message

bsd-user/syscall_defs.h +71 -0

75 lines not on this page · raw message

Signature · 1 line
1.7.8
author
#18 lore raw

PATCH 12/23 bsd-user: add shims for time related system calls.

In reply to Stacey Son

This change adds support for time related system calls that are largely FreeBSD dependent because time_t is inconsistly defined for the various *BSD's. On FreeBSD time_t is mostly defined as a 64-bit value. On some architectures like PPC32 it is defined as a 32-bit value, however. On NetBSD it is always defined as an int64_t. On OpenBSD it is defined as an int. This change also defines system call shim stubs for NetBSD/OpenBSD in case some whats to add code to emulate FreeBSD binaries on one of the other *BSD's.

---
 bsd-user/Makefile.objs     |    2 +-
 bsd-user/freebsd/os-time.c |  205 +++++++++++++++
 bsd-user/freebsd/os-time.h |  602 ++++++++++++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/qemu-os.h |   41 +++
 bsd-user/netbsd/os-time.c  |    1 +
 bsd-user/netbsd/os-time.h  |  179 +++++++++++++
 bsd-user/netbsd/qemu-os.h  |    1 +
 bsd-user/openbsd/os-time.c |    1 +
 bsd-user/openbsd/os-time.h |  179 +++++++++++++
 bsd-user/openbsd/qemu-os.h |    1 +
 bsd-user/syscall.c         |   96 +++++++
 bsd-user/syscall_defs.h    |   76 ++++++
 12 files changed, 1383 insertions(+), 1 deletions(-)
 create mode 100644 bsd-user/freebsd/os-time.c
 create mode 100644 bsd-user/freebsd/os-time.h
 create mode 100644 bsd-user/freebsd/qemu-os.h
 create mode 100644 bsd-user/netbsd/os-time.c
 create mode 100644 bsd-user/netbsd/os-time.h
 create mode 100644 bsd-user/netbsd/qemu-os.h
 create mode 100644 bsd-user/openbsd/os-time.c
 create mode 100644 bsd-user/openbsd/os-time.h
 create mode 100644 bsd-user/openbsd/qemu-os.h
bsd-user/Makefile.objs +1 -1
index d0cea36..4c6acb0 100644
@@ -1,2 +1,2 @@
 obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
-	        uaccess.o bsd-mem.o
+	        uaccess.o bsd-mem.o $(TARGET_OS)/os-time.o
bsd-user/freebsd/os-time.c new file +205 -0

205 lines not on this page · raw message

bsd-user/freebsd/os-time.h new file +602 -0

602 lines not on this page · raw message

bsd-user/freebsd/qemu-os.h new file +41 -0

41 lines not on this page · raw message

bsd-user/netbsd/os-time.c new file +1 -0
new file mode 100644
index 0000000..ee2c7a0
@@ -0,0 +1 @@
+/* XXX NetBSD time related helpers */
bsd-user/netbsd/os-time.h new file +179 -0

179 lines not on this page · raw message

bsd-user/netbsd/qemu-os.h new file +1 -0
new file mode 100644
index 0000000..016618b
@@ -0,0 +1 @@
+/* NetBSD conversion extern declarations */
bsd-user/openbsd/os-time.c new file +1 -0
new file mode 100644
index 0000000..accd886
@@ -0,0 +1 @@
+/* XXX OpenBSD time related helpers */
bsd-user/openbsd/os-time.h new file +179 -0

179 lines not on this page · raw message

bsd-user/openbsd/qemu-os.h new file +1 -0
new file mode 100644
index 0000000..f4ad3be
@@ -0,0 +1 @@
+/* OpenBSD conversion extern declarations */
bsd-user/syscall.c +96 -0

114 lines not on this page · raw message

bsd-user/syscall_defs.h +76 -0

80 lines not on this page · raw message

Signature · 1 line
1.7.8
author
#9 lore raw

PATCH 4/23 bsd-user: add bsd signal emulation

In reply to Stacey Son

Add bsd-user signal emulation code, fix name space confict with sigqueue, add arch dependent code for mips/mips64, and OS dependent definitions for FreeBSD.

---
 bsd-user/freebsd/target_os_signal.h   |    9 +
 bsd-user/i386/target_arch_signal.h    |   39 ++
 bsd-user/i386/target_arch_vmparam.h   |    2 -
 bsd-user/mips/target_arch_signal.h    |  160 ++++++
 bsd-user/mips/target_arch_vmparam.h   |    6 +-
 bsd-user/mips64/target_arch_signal.h  |  159 ++++++
 bsd-user/qemu.h                       |   33 +-
 bsd-user/signal.c                     |  922 +++++++++++++++++++++++++++++++++
 bsd-user/sparc/target_arch_signal.h   |   39 ++
 bsd-user/sparc64/target_arch_signal.h |   39 ++
 bsd-user/x86_64/target_arch_signal.h  |   39 ++
 11 files changed, 1429 insertions(+), 18 deletions(-)
bsd-user/freebsd/target_os_signal.h +9 -0
index 3421a4e..d7004c8 100644
@@ -52,6 +52,15 @@
 #define TARGET_SIG_IGN      ((abi_long)1)   /* ignore signal */
 #define TARGET_SIG_ERR      ((abi_long)-1)  /* error return from signal */
 
+#define TARGET_SA_ONSTACK   0x0001  /* take signal on signal stack */
+#define TARGET_SA_RESTART   0x0002  /* restart system on signal return */
+#define TARGET_SA_RESETHAND 0x0004  /* reset to SIG_DFL when taking signal */
+#define TARGET_SA_NODEFER   0x0010  /* don't mask the signal we're delivering */
+#define TARGET_SA_NOCLDWAIT 0x0020  /* don't create zombies (assign to pid 1) */
+#define TARGET_SA_USERTRAMP 0x0100  /* do not bounce off kernel's sigtramp */
+#define TARGET_SA_NOCLDSTOP 0x0008  /* do not generate SIGCHLD on child stop */
+#define TARGET_SA_SIGINFO   0x0040  /* generate siginfo_t */
+
 /*
  * Flags for sigprocmask:
  */
bsd-user/i386/target_arch_signal.h +39 -0
index ebd83f6..2e89529 100644
@@ -20,4 +20,43 @@
 
 #include "cpu.h"
 
+/* Size of the signal trampolin code placed on the stack. */
+/* #define TARGET_SZSIGCODE    (0) */      /* XXX to be added. */
+
+/* compare to  x86/include/_limits.h */
+#define TARGET_MINSIGSTKSZ  (512 * 4)               /* min sig stack size */
+#define TARGET_SIGSTKSZ     (MINSIGSTKSZ + 32768)   /* recommended size */
+
+struct target_sigcontext {
+    /* to be added */
+};
+
+typedef struct target_mcontext {
+} target_mcontext_t;
+
+typedef struct target_ucontext {
+    target_sigset_t   uc_sigmask;
+    target_mcontext_t uc_mcontext;
+    abi_ulong         uc_link;
+    target_stack_t    uc_stack;
+    int32_t           uc_flags;
+    int32_t         __spare__[4];
+} target_ucontext_t;
+
+struct target_sigframe {
+    abi_ulong   sf_signum;
+    abi_ulong   sf_siginfo;    /* code or pointer to sf_si */
+    abi_ulong   sf_ucontext;   /* points to sf_uc */
+    abi_ulong   sf_addr;       /* undocumented 4th arg */
+    target_ucontext_t   sf_uc; /* = *sf_uncontext */
+    target_siginfo_t    sf_si; /* = *sf_siginfo (SA_SIGINFO case)*/
+    uint32_t    __spare__[2];
+};
+
+static inline abi_long set_mcontext(CPUX86State *regs,
+        target_mcontext_t *mcp, int srflag)
+{
+    return -TARGET_EOPNOTSUPP;
+}
+
 #endif /* TARGET_ARCH_SIGNAL_H */
bsd-user/i386/target_arch_vmparam.h +0 -2
index 6687adb..6d3cf4f 100644
@@ -13,8 +13,6 @@
 
 #define TARGET_USRSTACK (0xbfc00000)
 
-#define TARGET_PS_STRINGS  (TARGET_USRSTACK - sizeof(struct target_ps_strings))
-
 static inline abi_ulong get_sp_from_cpustate(CPUX86State *state)
 {
     return state->regs[R_ESP];
bsd-user/mips/target_arch_signal.h +160 -0

170 lines not on this page · raw message

bsd-user/mips/target_arch_vmparam.h +3 -3
index 0480035..8f8bc9e 100644
@@ -1,5 +1,5 @@
 /*
- *  mips64 VM parameters definitions
+ *  mips VM parameters definitions
  *
  *  Copyright (c) 2013 Stacey D. Son
  *
@@ -29,8 +29,8 @@
 #define TARGET_MAXSSIZ      (64UL*1024*1024)    /* max stack size */
 #define TARGET_SGROWSIZ     (128UL*1024)        /* amount to grow stack */
 
-#define TARGET_VM_MINUSER_ADDRESS   (0x0000000000000000UL)
-#define TARGET_VM_MAXUSER_ADDRESS   (0x0000008000000000UL)
+#define TARGET_VM_MINUSER_ADDRESS   (0x00000000)
+#define TARGET_VM_MAXUSER_ADDRESS   (0x80000000)
 
 #define TARGET_USRSTACK (TARGET_VM_MAXUSER_ADDRESS - TARGET_PAGE_SIZE)
 
bsd-user/mips64/target_arch_signal.h +159 -0

169 lines not on this page · raw message

bsd-user/qemu.h +20 -13
index 63a3942..c0cdfcd 100644
@@ -38,8 +38,8 @@ extern enum BSDType bsd_type;
 
 #include "syscall_defs.h"
 #include "syscall.h"
-#include "target_os_signal.h"
 #include "target_os_vmparam.h"
+#include "target_os_signal.h"
 #include "exec/gdbstub.h"
 
 #if defined(CONFIG_USE_NPTL)
@@ -72,16 +72,16 @@ struct image_info {
 
 #define MAX_SIGQUEUE_SIZE 1024
 
-struct sigqueue {
-    struct sigqueue *next;
-    //target_siginfo_t info;
+struct qemu_sigqueue {
+    struct qemu_sigqueue *next;
+    target_siginfo_t info;
 };
 
 struct emulated_sigtable {
     int pending; /* true if signal is pending */
-    struct sigqueue *first;
-    struct sigqueue info; /* in order to always have memory for the
-                             first signal, we put it here */
+    struct qemu_sigqueue *first;
+    struct qemu_sigqueue info; /* in order to always have memory for the
+                                  first signal, we put it here */
 };
 
 /* NOTE: we force a big alignment so that the stack stored after is
@@ -92,8 +92,8 @@ typedef struct TaskState {
     struct image_info *info;
 
     struct emulated_sigtable sigtab[TARGET_NSIG];
-    struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */
-    struct sigqueue *first_free; /* first free siginfo queue entry */
+    struct qemu_sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */
+    struct qemu_sigqueue *first_free; /* first free siginfo queue entry */
     int signal_pending; /* non zero if a signal may be pending */
 
     uint8_t stack[0];
@@ -186,12 +186,19 @@ extern int do_strace;
 /* signal.c */
 void process_pending_signals(CPUArchState *cpu_env);
 void signal_init(void);
-//int queue_signal(CPUArchState *env, int sig, target_siginfo_t *info);
-//void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
-//void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
-long do_sigreturn(CPUArchState *env);
+int queue_signal(CPUArchState *env, int sig, target_siginfo_t *info);
+void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
+void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
+int target_to_host_signal(int sig);
+int host_to_target_signal(int sig);
+void host_to_target_sigset(target_sigset_t *d, const sigset_t *s);
+void target_to_host_sigset(sigset_t *d, const target_sigset_t *s);
+long do_sigreturn(CPUArchState *env, abi_ulong addr);
 long do_rt_sigreturn(CPUArchState *env);
 abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp);
+int do_sigaction(int sig, const struct target_sigaction *act,
+                struct target_sigaction *oact);
+void QEMU_NORETURN force_sig(int target_sig);
 
 /* mmap.c */
 int target_mprotect(abi_ulong start, abi_ulong len, int prot);
bsd-user/signal.c +922 -0

943 lines not on this page · raw message

bsd-user/sparc/target_arch_signal.h +39 -0
index 6bef0ad..275d1ef 100644
@@ -3,4 +3,43 @@
 
 #include "cpu.h"
 
+/* Size of the signal trampolin code placed on the stack. */
+/* #define TARGET_SZSIGCODE   (0) */       /* XXX to be added. */
+
+/* compare to  sparc64/include/_limits.h */
+#define TARGET_MINSIGSTKSZ  (1024 * 4)              /* min sig stack size */
+#define TARGET_SIGSTKSZ     (MINSIGSTKSZ + 32768)   /* recommended size */
+
+struct target_sigcontext {
+    /* to be added */
+};
+
+typedef struct target_mcontext {
+} target_mcontext_t;
+
+typedef struct target_ucontext {
+    target_sigset_t   uc_sigmask;
+    target_mcontext_t uc_mcontext;
+    abi_ulong         uc_link;
+    target_stack_t    uc_stack;
+    int32_t           uc_flags;
+    int32_t         __spare__[4];
+} target_ucontext_t;
+
+struct target_sigframe {
+    abi_ulong   sf_signum;
+    abi_ulong   sf_siginfo;    /* code or pointer to sf_si */
+    abi_ulong   sf_ucontext;   /* points to sf_uc */
+    abi_ulong   sf_addr;       /* undocumented 4th arg */
+    target_ucontext_t   sf_uc; /* = *sf_uncontext */
+    target_siginfo_t    sf_si; /* = *sf_siginfo (SA_SIGINFO case)*/
+    uint32_t    __spare__[2];
+};
+
+static inline abi_long set_mcontext(CPUSPARCState *regs,
+        target_mcontext_t *mcp, int srflag)
+{
+    return -TARGET_EOPNOTSUPP;
+}
+
 #endif /* TARGET_ARCH_SIGNAL_H */
bsd-user/sparc64/target_arch_signal.h +39 -0
index eb7ad2a..8126383 100644
@@ -20,4 +20,43 @@
 
 #include "cpu.h"
 
+/* Size of the signal trampolin code placed on the stack. */
+/* #define TARGET_SZSIGCODE    (0) */      /* XXX to be added. */
+
+/* compare to  sparc64/include/_limits.h */
+#define TARGET_MINSIGSTKSZ  (1024 * 4)              /* min sig stack size */
+#define TARGET_SIGSTKSZ     (MINSIGSTKSZ + 32768)   /* recommended size */
+
+struct target_sigcontext {
+    /* to be added */
+};
+
+typedef struct target_mcontext {
+} target_mcontext_t;
+
+typedef struct target_ucontext {
+    target_sigset_t   uc_sigmask;
+    target_mcontext_t uc_mcontext;
+    abi_ulong         uc_link;
+    target_stack_t    uc_stack;
+    int32_t           uc_flags;
+    int32_t         __spare__[4];
+} target_ucontext_t;
+
+struct target_sigframe {
+    abi_ulong   sf_signum;
+    abi_ulong   sf_siginfo;    /* code or pointer to sf_si */
+    abi_ulong   sf_ucontext;   /* points to sf_uc */
+    abi_ulong   sf_addr;       /* undocumented 4th arg */
+    target_ucontext_t   sf_uc; /* = *sf_uncontext */
+    target_siginfo_t    sf_si; /* = *sf_siginfo (SA_SIGINFO case)*/
+    uint32_t    __spare__[2];
+};
+
+static inline abi_long set_mcontext(CPUSPARCState *regs,
+        target_mcontext_t *mcp, int srflag)
+{
+    return -TARGET_EOPNOTSUPP;
+}
+
 #endif /* !_TARGET_ARCH_SIGNAL_H_ */
bsd-user/x86_64/target_arch_signal.h +39 -0
index 614c11a..d43f5f0 100644
@@ -20,4 +20,43 @@
 
 #include "cpu.h"
 
+/* Size of the signal trampolin code placed on the stack. */
+/* #define TARGET_SZSIGCODE    (0) */   /* XXX to be added */
+
+/* compare to  x86/include/_limits.h */
+#define TARGET_MINSIGSTKSZ  (512 * 4)               /* min sig stack size */
+#define TARGET_SIGSTKSZ     (MINSIGSTKSZ + 32768)   /* recommended size */
+
+struct target_sigcontext {
+    /* to be added */
+};
+
+typedef struct target_mcontext {
+} target_mcontext_t;
+
+typedef struct target_ucontext {
+    target_sigset_t   uc_sigmask;
+    target_mcontext_t uc_mcontext;
+    abi_ulong         uc_link;
+    target_stack_t    uc_stack;
+    int32_t           uc_flags;
+    int32_t         __spare__[4];
+} target_ucontext_t;
+
+struct target_sigframe {
+    abi_ulong   sf_signum;
+    abi_ulong   sf_siginfo;    /* code or pointer to sf_si */
+    abi_ulong   sf_ucontext;   /* points to sf_uc */
+    abi_ulong   sf_addr;       /* undocumented 4th arg */
+    target_ucontext_t   sf_uc; /* = *sf_uncontext */
+    target_siginfo_t    sf_si; /* = *sf_siginfo (SA_SIGINFO case)*/
+    uint32_t    __spare__[2];
+};
+
+static inline abi_long set_mcontext(CPUX86State *regs,
+        target_mcontext_t *mcp, int srflag)
+{
+    return -TARGET_EOPNOTSUPP;
+}
+
 #endif /* !TARGET_ARCH_SIGNAL_H_ */
Signature · 1 line
1.7.8
author
#30 lore raw

PATCH 22/23 bsd-user: add more strace formating

In reply to Stacey Son

This change add more strace formating for popular system calls. It also separates out *BSD and architecture dependent code. In addition, it changes TARGET_OS in configure (and in the associated makefiles) to what it should really be: HOST_OS.

---
 Makefile.target                        |    4 +-
 bsd-user/Makefile.objs                 |   10 +-
 bsd-user/freebsd/os-strace.h           |   29 ++++++
 bsd-user/freebsd/strace.list           |   58 ++++++++++--
 bsd-user/i386/target_arch_sysarch.h    |   11 ++-
 bsd-user/mips/target_arch_sysarch.h    |   21 ++++-
 bsd-user/mips64/target_arch_sysarch.h  |   19 ++++
 bsd-user/netbsd/os-strace.h            |    1 +
 bsd-user/openbsd/os-strace.h           |    1 +
 bsd-user/qemu.h                        |   10 ++
 bsd-user/sparc/target_arch_sysarch.h   |   11 ++-
 bsd-user/sparc64/target_arch_sysarch.h |   11 ++-
 bsd-user/strace.c                      |  158 ++++++++++++++++++++------------
 bsd-user/x86_64/target_arch_sysarch.h  |   11 ++-
 configure                              |   18 ++--
 15 files changed, 290 insertions(+), 83 deletions(-)
 create mode 100644 bsd-user/freebsd/os-strace.h
 create mode 100644 bsd-user/netbsd/os-strace.h
 create mode 100644 bsd-user/openbsd/os-strace.h
Makefile.target +2 -2
index e67e2bd..ef52ee4 100644
@@ -103,8 +103,8 @@ endif #CONFIG_LINUX_USER
 
 ifdef CONFIG_BSD_USER
 
-QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH) \
-			 -I$(SRC_PATH)/bsd-user/$(TARGET_OS)
+QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) \
+			 -I$(SRC_PATH)/bsd-user/$(HOST_ABI_DIR)
 
 obj-y += bsd-user/
 obj-y += gdbstub.o thunk.o user-exec.o
bsd-user/Makefile.objs +6 -4
index 5308e29..06a3026 100644
@@ -1,5 +1,7 @@
 obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \
-	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
-			$(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \
-			$(TARGET_OS)/os-stat.o $(TARGET_OS)/os-sys.o \
-			$(TARGET_OS)/os-thread.o $(TARGET_OS)/os-extattr.o bsd-misc.o
+	        uaccess.o bsd-mem.o bsd-misc.o bsd-proc.o bsd-socket.o \
+			$(HOST_ABI_DIR)/os-extattr.o $(HOST_ABI_DIR)/os-proc.o \
+			$(HOST_ABI_DIR)/os-socket.o $(HOST_ABI_DIR)/os-stat.o \
+			$(HOST_ABI_DIR)/os-sys.o $(HOST_ABI_DIR)/os-thread.o  \
+			$(HOST_ABI_DIR)/os-time.o
+
bsd-user/freebsd/os-strace.h new file +29 -0
new file mode 100644
index 0000000..a222f09
@@ -0,0 +1,29 @@
+/*
+ *  FreeBSD dependent strace print functions
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "target_arch_sysarch.h"    /* architecture dependent functions */
+
+
+static inline void do_os_print_sysarch(const struct syscallname *name,
+        abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4,
+        abi_long arg5, abi_long arg6)
+{
+    /* This is arch dependent */
+    do_freebsd_arch_print_sysarch(name, arg1, arg2, arg3, arg4, arg5, arg6);
+}
bsd-user/freebsd/strace.list +51 -7

132 lines not on this page · raw message

bsd-user/i386/target_arch_sysarch.h +10 -1
index 373c838..4fa6698 100644
@@ -22,7 +22,7 @@
 
 #include "syscall.h"
 
-static abi_long do_freebsd_arch_sysarch(CPUX86State *env, int op,
+static inline abi_long do_freebsd_arch_sysarch(CPUX86State *env, int op,
         abi_ulong parms)
 {
     abi_long ret = 0;
@@ -65,5 +65,14 @@ static abi_long do_freebsd_arch_sysarch(CPUX86State *env, int op,
     return ret;
 }
 
+static inline void do_freebsd_arch_print_sysarch(
+        const struct syscallname *name, abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
+{
+
+    gemu_log("%s(%d, " TARGET_ABI_FMT_lx ", " TARGET_ABI_FMT_lx ", "
+        TARGET_ABI_FMT_lx ")", name->name, (int)arg1, arg2, arg3, arg4);
+}
+
 #endif /* !__ARCH_SYSARCH_H_ */
 
bsd-user/mips/target_arch_sysarch.h +20 -1
index 22fa53a..842b29a 100644
@@ -22,7 +22,7 @@
 
 #include "syscall.h"
 
-static abi_long do_freebsd_arch_sysarch(CPUMIPSState *env, int op,
+static inline abi_long do_freebsd_arch_sysarch(CPUMIPSState *env, int op,
         abi_ulong parms)
 {
     int ret = 0;
@@ -47,4 +47,23 @@ static abi_long do_freebsd_arch_sysarch(CPUMIPSState *env, int op,
     return ret;
 }
 
+static inline void do_freebsd_arch_print_sysarch(
+        const struct syscallname *name, abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
+{
+
+    switch (arg1) {
+    case TARGET_MIPS_SET_TLS:
+        gemu_log("%s(SET_TLS, 0x" TARGET_ABI_FMT_lx ")", name->name, arg2);
+        break;
+
+    case TARGET_MIPS_GET_TLS:
+        gemu_log("%s(GET_TLS, 0x" TARGET_ABI_FMT_lx ")", name->name, arg2);
+        break;
+
+    default:
+        gemu_log("UNKNOWN OP: %d, " TARGET_ABI_FMT_lx ")", (int)arg1, arg2);
+    }
+}
+
 #endif /*!__ARCH_SYSARCH_H_ */
bsd-user/mips64/target_arch_sysarch.h +19 -0
index 503bc90..6210366 100644
@@ -47,4 +47,23 @@ static inline abi_long do_freebsd_arch_sysarch(CPUMIPSState *env, int op,
     return ret;
 }
 
+static inline void do_freebsd_arch_print_sysarch(
+        const struct syscallname *name, abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
+{
+
+    switch (arg1) {
+    case TARGET_MIPS_SET_TLS:
+        gemu_log("%s(SET_TLS, 0x" TARGET_ABI_FMT_lx ")", name->name, arg2);
+        break;
+
+    case TARGET_MIPS_GET_TLS:
+        gemu_log("%s(GET_TLS, 0x" TARGET_ABI_FMT_lx ")", name->name, arg2);
+        break;
+
+    default:
+        gemu_log("UNKNOWN OP: %d, " TARGET_ABI_FMT_lx ")", (int)arg1, arg2);
+    }
+}
+
 #endif /*!__ARCH_SYSARCH_H_ */
bsd-user/netbsd/os-strace.h new file +1 -0
new file mode 100644
index 0000000..70cf51d
@@ -0,0 +1 @@
+/* XXX NetBSD dependent strace print functions */
bsd-user/openbsd/os-strace.h new file +1 -0
new file mode 100644
index 0000000..9161390
@@ -0,0 +1 @@
+/* XXX OpenBSD dependent strace print functions */
bsd-user/qemu.h +10 -0
index 2ddf244..3967e22 100644
@@ -173,6 +173,16 @@ void fork_end(int child);
 #include "qemu/log.h"
 
 /* strace.c */
+struct syscallname {
+    int nr;
+    const char *name;
+    const char *format;
+    void (*call)(const struct syscallname *,
+                 abi_long, abi_long, abi_long,
+                 abi_long, abi_long, abi_long);
+    void (*result)(const struct syscallname *, abi_long);
+};
+
 void
 print_freebsd_syscall(int num,
                       abi_long arg1, abi_long arg2, abi_long arg3,
bsd-user/sparc/target_arch_sysarch.h +10 -1
index e523798..454c084 100644
@@ -22,7 +22,8 @@
 
 #include "syscall.h"
 
-static abi_long do_freebsd_arch_sysarch(void *env, int op, abi_ulong parms)
+static inline abi_long do_freebsd_arch_sysarch(void *env, int op,
+        abi_ulong parms)
 {
     int ret = 0;
 
@@ -39,5 +40,13 @@ static abi_long do_freebsd_arch_sysarch(void *env, int op, abi_ulong parms)
     return ret;
 }
 
+static inline void do_freebsd_arch_print_sysarch(
+        const struct syscallname *name, abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
+{
+
+    gemu_log("%s(%d, " TARGET_ABI_FMT_lx ", " TARGET_ABI_FMT_lx ", "
+        TARGET_ABI_FMT_lx ")", name->name, (int)arg1, arg2, arg3, arg4);
+}
 
 #endif /*!__ARCH_SYSARCH_H_ */
bsd-user/sparc64/target_arch_sysarch.h +10 -1
index c18f699..84e1339 100644
@@ -22,7 +22,8 @@
 
 #include "syscall.h"
 
-static abi_long do_freebsd_arch_sysarch(void *env, int op, abi_ulong parms)
+static inline abi_long do_freebsd_arch_sysarch(void *env, int op,
+        abi_ulong parms)
 {
     int ret = 0;
 
@@ -39,5 +40,13 @@ static abi_long do_freebsd_arch_sysarch(void *env, int op, abi_ulong parms)
     return ret;
 }
 
+static inline void do_freebsd_arch_print_sysarch(
+        const struct syscallname *name, abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
+{
+
+    gemu_log("%s(%d, " TARGET_ABI_FMT_lx ", " TARGET_ABI_FMT_lx ", "
+        TARGET_ABI_FMT_lx ")", name->name, (int)arg1, arg2, arg3, arg4);
+}
 
 #endif /*!__ARCH_SYSARCH_H_ */
bsd-user/strace.c +101 -57

268 lines not on this page · raw message

bsd-user/x86_64/target_arch_sysarch.h +10 -1
index 52a1d18..6d09d50 100644
@@ -21,7 +21,7 @@
 
 #include "syscall.h"
 
-static abi_long do_freebsd_arch_sysarch(CPUX86State *env, int op,
+static inline abi_long do_freebsd_arch_sysarch(CPUX86State *env, int op,
         abi_ulong parms)
 {
     abi_long ret = 0;
@@ -64,4 +64,13 @@ static abi_long do_freebsd_arch_sysarch(CPUX86State *env, int op,
     return ret;
 }
 
+static inline void do_freebsd_arch_print_sysarch(
+        const struct syscallname *name, abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
+{
+
+    gemu_log("%s(%d, " TARGET_ABI_FMT_lx ", " TARGET_ABI_FMT_lx ", "
+        TARGET_ABI_FMT_lx ")", name->name, (int)arg1, arg2, arg3, arg4);
+}
+
 #endif /*! __ARCH_SYSARCH_H_ */
configure +10 -8
index 812ea3f..90167f8 100755
@@ -432,7 +432,9 @@ if test -z "$ARCH"; then
 fi
 
 # OS specific
-TARGET_OS=""
+
+# host *BSD for user mode
+HOST_ABI_DIR=""
 
 case $targetos in
 CYGWIN*)
@@ -456,10 +458,10 @@ FreeBSD)
   make="${MAKE-gmake}"
   audio_drv_list="oss"
   audio_possible_drivers="oss sdl esd pa"
-  # needed for kinfo_getvmmap(3) in libutil.h
+  # -lutil needed for kinfo_getvmmap(3) in libutil.h
   # -lprocstat needed for procstat_*(3) in bsd-user/main.c
   LIBS="-lprocstat -lutil $LIBS"
-  TARGET_OS="freebsd"
+  HOST_ABI_DIR="freebsd"
 ;;
 DragonFly)
   bsd="yes"
@@ -473,14 +475,14 @@ NetBSD)
   audio_drv_list="oss"
   audio_possible_drivers="oss sdl esd"
   oss_lib="-lossaudio"
-  TARGET_OS="netbsd"
+  HOST_ABI_DIR="netbsd"
 ;;
 OpenBSD)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="sdl"
   audio_possible_drivers="sdl esd"
-  TARGET_OS="openbsd"
+  HOST_ABI_DIR="openbsd"
 ;;
 Darwin)
   bsd="yes"
@@ -4283,15 +4285,15 @@ upper() {
 
 target_arch_name="`upper $TARGET_ARCH`"
 echo "TARGET_$target_arch_name=y" >> $config_target_mak
-if [ "$TARGET_OS" != "" ]; then
-    echo "TARGET_OS=$TARGET_OS" >> $config_target_mak
-fi
 echo "TARGET_NAME=$target_name" >> $config_target_mak
 echo "TARGET_BASE_ARCH=$TARGET_BASE_ARCH" >> $config_target_mak
 if [ "$TARGET_ABI_DIR" = "" ]; then
   TARGET_ABI_DIR=$TARGET_ARCH
 fi
 echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_target_mak
+if [ "$HOST_ABI_DIR" != "" ]; then
+    echo "HOST_ABI_DIR=$HOST_ABI_DIR" >> $config_target_mak
+fi
 case "$target_name" in
   i386|x86_64)
     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
Signature · 1 line
1.7.8
author
#28 lore raw

PATCH 20/23 bsd-user: add shims for extended attributes system calls

In reply to Stacey Son

This change adds support for the extended attribute and access control list system calls. While NetBSD has the same extended attribute system calls it is unclear if OpenBSD does. Therefore, this calls were added as FreeBSD-only.

---
 bsd-user/Makefile.objs        |    2 +-
 bsd-user/freebsd/os-extattr.c |  119 ++++++++
 bsd-user/freebsd/os-extattr.h |  644 +++++++++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/qemu-os.h    |    7 +
 bsd-user/netbsd/os-extattr.h  |  247 ++++++++++++++++
 bsd-user/openbsd/os-extattr.h |  247 ++++++++++++++++
 bsd-user/syscall.c            |  105 +++++++
 bsd-user/syscall_defs.h       |   27 ++
 8 files changed, 1397 insertions(+), 1 deletions(-)
 create mode 100644 bsd-user/freebsd/os-extattr.c
 create mode 100644 bsd-user/freebsd/os-extattr.h
 create mode 100644 bsd-user/netbsd/os-extattr.h
 create mode 100644 bsd-user/openbsd/os-extattr.h
bsd-user/Makefile.objs +1 -1
index e392760..3dddc00 100644
@@ -2,4 +2,4 @@ obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \
 	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
 			$(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \
 			$(TARGET_OS)/os-stat.o $(TARGET_OS)/os-sys.o \
-			$(TARGET_OS)/os-thread.o
+			$(TARGET_OS)/os-thread.o $(TARGET_OS)/os-extattr.o
bsd-user/freebsd/os-extattr.c new file +119 -0

119 lines not on this page · raw message

bsd-user/freebsd/os-extattr.h new file +644 -0

644 lines not on this page · raw message

bsd-user/freebsd/qemu-os.h +7 -0
index eac9085..26ad751 100644
@@ -21,6 +21,7 @@
 #define _QEMU_OS_H_
 
 #include <sys/types.h>
+#include <sys/acl.h>
 #include <sys/mount.h>
 #include <sys/timex.h>
 #include <sys/rtprio.h>
@@ -67,4 +68,10 @@ abi_long target_to_host_fcntl_cmd(int cmd);
 abi_long t2h_freebsd_rtprio(struct rtprio *host_rtp, abi_ulong target_addr);
 abi_long h2t_freebsd_rtprio(abi_ulong target_addr, struct rtprio *host_rtp);
 
+/* os-extattr.c */
+struct acl;
+abi_long t2h_freebsd_acl(struct acl *host_acl, abi_ulong target_addr);
+abi_long h2t_freebsd_acl(abi_ulong target_addr, struct acl *host_acl);
+abi_long t2h_freebsd_acl_type(acl_type_t *host_type, abi_long target_type);
+
 #endif /* !_QEMU_OS_H_ */
bsd-user/netbsd/os-extattr.h new file +247 -0

247 lines not on this page · raw message

bsd-user/openbsd/os-extattr.h new file +247 -0

247 lines not on this page · raw message

bsd-user/syscall.c +105 -0

117 lines not on this page · raw message

bsd-user/syscall_defs.h +27 -0
index b4e0739..ff329f7 100644
@@ -589,4 +589,31 @@ typedef struct {
 #define TARGET_URWLOCK_MAX_READERS      0x1fffffffU
 #define TARGET_URWLOCK_READER_COUNT(c)  ((c) & TARGET_URWLOCK_MAX_READERS)
 
+/*
+ * sys/acl.h
+ */
+#define TARGET_FREEBSD_ACL_MAX_ENTRIES          254
+
+/* vaild acl_type_t arguments */
+#define TARGET_FREEBSD_ACL_TYPE_ACCESS_OLD      0x00000000
+#define TARGET_FREEBSD_ACL_TYPE_DEFAULT_OLD     0x00000001
+#define TARGET_FREEBSD_ACL_TYPE_ACCESS          0x00000002
+#define TARGET_FREEBSD_ACL_TYPE_DEFAULT         0x00000003
+#define TARGET_FREEBSD_ACL_TYPE_NFS4            0x00000004
+
+struct target_freebsd_acl_entry {
+    int32_t     ae_tag;
+    uint32_t    ae_id;
+    uint16_t    ae_perm;
+    uint16_t    ae_entry_type;
+    uint16_t    ae_flags;
+};
+
+struct target_freebsd_acl {
+    uint32_t            acl_maxcnt;
+    uint32_t            acl_cnt;
+    int32_t             acl_space[4];
+    struct target_freebsd_acl_entry  acl_entry[TARGET_FREEBSD_ACL_MAX_ENTRIES];
+};
+
 #endif /* ! _SYSCALL_DEFS_H_ */
Signature · 1 line
1.7.8
author
#26 lore raw

PATCH 18/23 bsd-user: add shim for the ioctl system call

In reply to Stacey Son

This change adds support for the ioctl(2) system call emulation. In addtion, it adds definitions and support for the FreeBSD tty(4) and file io ioctl's.

---
 Makefile.target                 |    2 +-
 bsd-user/Makefile.objs          |    2 +-
 bsd-user/freebsd/ioctl-cmds.h   |   47 ++++
 bsd-user/freebsd/ioctl-filio.h  |   45 ++++
 bsd-user/freebsd/ioctl-ioccom.h |   54 +++++
 bsd-user/freebsd/ioctl-ttycom.h |  257 ++++++++++++++++++++++
 bsd-user/freebsd/ioctl-types.h  |    7 +
 bsd-user/ioctl.c                |  447 +++++++++++++++++++++++++++++++++++++++
 bsd-user/netbsd/ioctl-cmds.h    |   48 +++++
 bsd-user/netbsd/ioctl-filio.h   |   29 +++
 bsd-user/netbsd/ioctl-ioccom.h  |   38 ++++
 bsd-user/netbsd/ioctl-ttycom.h  |  240 +++++++++++++++++++++
 bsd-user/netbsd/ioctl-types.h   |    7 +
 bsd-user/openbsd/ioctl-cmds.h   |   48 +++++
 bsd-user/openbsd/ioctl-filio.h  |   29 +++
 bsd-user/openbsd/ioctl-ioccom.h |   38 ++++
 bsd-user/openbsd/ioctl-ttycom.h |  240 +++++++++++++++++++++
 bsd-user/openbsd/ioctl-types.h  |    7 +
 bsd-user/qemu.h                 |    5 +
 bsd-user/syscall.c              |    9 +
 20 files changed, 1597 insertions(+), 2 deletions(-)
 create mode 100644 bsd-user/freebsd/ioctl-cmds.h
 create mode 100644 bsd-user/freebsd/ioctl-filio.h
 create mode 100644 bsd-user/freebsd/ioctl-ioccom.h
 create mode 100644 bsd-user/freebsd/ioctl-ttycom.h
 create mode 100644 bsd-user/freebsd/ioctl-types.h
 create mode 100644 bsd-user/ioctl.c
 create mode 100644 bsd-user/netbsd/ioctl-cmds.h
 create mode 100644 bsd-user/netbsd/ioctl-filio.h
 create mode 100644 bsd-user/netbsd/ioctl-ioccom.h
 create mode 100644 bsd-user/netbsd/ioctl-ttycom.h
 create mode 100644 bsd-user/netbsd/ioctl-types.h
 create mode 100644 bsd-user/openbsd/ioctl-cmds.h
 create mode 100644 bsd-user/openbsd/ioctl-filio.h
 create mode 100644 bsd-user/openbsd/ioctl-ioccom.h
 create mode 100644 bsd-user/openbsd/ioctl-ttycom.h
 create mode 100644 bsd-user/openbsd/ioctl-types.h
Makefile.target +1 -1
index ec00c80..e67e2bd 100644
@@ -107,7 +107,7 @@ QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH) \
 			 -I$(SRC_PATH)/bsd-user/$(TARGET_OS)
 
 obj-y += bsd-user/
-obj-y += gdbstub.o user-exec.o
+obj-y += gdbstub.o thunk.o user-exec.o
 
 endif #CONFIG_BSD_USER
 
bsd-user/Makefile.objs +1 -1
index 2608337..fbb3e56 100644
@@ -1,4 +1,4 @@
-obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
+obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \
 	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
 			$(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \
 			$(TARGET_OS)/os-stat.o $(TARGET_OS)/os-thread.o
bsd-user/freebsd/ioctl-cmds.h new file +47 -0

47 lines not on this page · raw message

bsd-user/freebsd/ioctl-filio.h new file +45 -0

45 lines not on this page · raw message

bsd-user/freebsd/ioctl-ioccom.h new file +54 -0

54 lines not on this page · raw message

bsd-user/freebsd/ioctl-ttycom.h new file +257 -0

257 lines not on this page · raw message

bsd-user/freebsd/ioctl-types.h new file +7 -0
new file mode 100644
index 0000000..60b9288
@@ -0,0 +1,7 @@
+
+STRUCT_SPECIAL(termios)
+
+STRUCT(winsize, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT)
+
+STRUCT(fiodgname_arg, TYPE_INT, TYPE_PTRVOID)
+
bsd-user/ioctl.c new file +447 -0

447 lines not on this page · raw message

bsd-user/netbsd/ioctl-cmds.h new file +48 -0

48 lines not on this page · raw message

bsd-user/netbsd/ioctl-filio.h new file +29 -0
new file mode 100644
index 0000000..24b63ae
@@ -0,0 +1,29 @@
+#ifndef _IOCTL_FILIO_H_
+#define _IOCTL_FILIO_H_
+
+/* XXX needs to be fixed for NetBSD dependencies */
+
+/* see sys/filio.h */
+#define TARGET_FIOCLEX      TARGET_IO('f', 1)
+#define TARGET_FIONCLEX     TARGET_IO('f', 2)
+#define TARGET_FIONREAD     TARGET_IOR('f', 127, int)
+#define TARGET_FIONBIO      TARGET_IOW('f', 126, int)
+#define TARGET_FIOASYNC     TARGET_IOW('f', 125, int)
+#define TARGET_FIOSETOWN    TARGET_IOW('f', 124, int)
+#define TARGET_FIOGETOWN    TARGET_IOR('f', 123, int)
+#define TARGET_FIODTYPE     TARGET_IOR('f', 122, int)
+#define TARGET_FIOGETLBA    TARGET_IOR('f', 121, int)
+
+struct target_fiodgname_arg {
+    int32_t     len;
+    abi_ulong   buf;
+};
+
+#define TARGET_FIODGNAME    TARGET_IOW('f', 120,    \
+                struct target_fiodgname_arg)
+#define TARGET_FIONWRITE    TARGET_IOR('f', 119, int)
+#define TARGET_FIONSPACE    TARGET_IOR('f', 118, int)
+#define TARGET_FIOSEEKDATA  TARGET_IOWR('f', 97, off_t)
+#define TARGET_FIOSEEKHOLE  TARGET_IOWR('f', 98, off_t)
+
+#endif /* !_IOCTL_FILIO_H_ */
bsd-user/netbsd/ioctl-ioccom.h new file +38 -0
new file mode 100644
index 0000000..e193a16
@@ -0,0 +1,38 @@
+#ifndef _IOCTL_IOCCOM_H_
+#define _IOCTL_IOCCOM_H_
+
+/* XXX needs to be fixed for NetBSD dependencies */
+
+/*
+ * Ioctl's have the command encoded in the lower word, and the size of
+ * any in or out parameters in the upper word.  The high 3 bits of the
+ * upper word are used to encode the in/out status of the parameter.
+ */
+/* number of bits for ioctl size */
+#define TARGET_IOCPARM_SHIFT    13
+
+/* parameter length mask */
+#define TARGET_IOCPARM_MASK ((1 << TARGET_IOCPARM_SHIFT) - 1)
+
+#define TARGET_IOCPARM_LEN(x)   (((x) >> 16) & TARGET_IOCPARM_MASK)
+#define TARGET_IOCBASECMD(x)    ((x) & ~(TARGET_IOCPARM_MASK << 16))
+#define TARGET_IOCGROUP(x)  (((x) >> 8) & 0xff)
+
+#define TARGET_IOCPARM_MAX  (1 << TARGET_IOCPARM_SHIFT) /* max size of ioctl */
+#define TARGET_IOC_VOID     0x20000000  /* no parameters */
+#define TARGET_IOC_OUT      0x40000000  /* copy out parameters */
+#define TARGET_IOC_IN       0x80000000  /* copy in parameters */
+#define TARGET_IOC_INOUT    (TARGET_IOC_IN|TARGET_IOC_OUT)
+#define TARGET_IOC_DIRMASK  (TARGET_IOC_VOID|TARGET_IOC_OUT|TARGET_IOC_IN)
+
+#define TARGET_IOC(inout, group, num, len) ((abi_ulong) \
+    ((inout) | (((len) & TARGET_IOCPARM_MASK) << 16) | ((group) << 8) \
+     | (num)))
+#define TARGET_IO(g, n)      TARGET_IOC(IOC_VOID,    (g), (n), 0)
+#define TARGET_IOWINT(g, n)  TARGET_IOC(IOC_VOID,    (g), (n), sizeof(int))
+#define TARGET_IOR(g, n, t)   TARGET_IOC(IOC_OUT, (g), (n), sizeof(t))
+#define TARGET_IOW(g, n, t)   TARGET_IOC(IOC_IN,  (g), (n), sizeof(t))
+/* this should be _IORW, but stdio got there first */
+#define TARGET_IOWR(g, n, t)  TARGET_IOC(IOC_INOUT,   (g), (n), sizeof(t))
+
+#endif /* !_IOCTL_IOCCOM_H_ */
bsd-user/netbsd/ioctl-ttycom.h new file +240 -0

240 lines not on this page · raw message

bsd-user/netbsd/ioctl-types.h new file +7 -0
new file mode 100644
index 0000000..e761c20
@@ -0,0 +1,7 @@
+/* XXX should be fixed for NetBSD types and structs */
+STRUCT_SPECIAL(termios)
+
+STRUCT(winsize, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT)
+
+STRUCT(fiodgname_arg, TYPE_INT, TYPE_PTRVOID)
+
bsd-user/openbsd/ioctl-cmds.h new file +48 -0

48 lines not on this page · raw message

bsd-user/openbsd/ioctl-filio.h new file +29 -0
new file mode 100644
index 0000000..e3f7474
@@ -0,0 +1,29 @@
+#ifndef _IOCTL_FILIO_H_
+#define _IOCTL_FILIO_H_
+
+/* XXX needs to be fixed for OpenBSD dependencies */
+
+/* see sys/filio.h */
+#define TARGET_FIOCLEX      TARGET_IO('f', 1)
+#define TARGET_FIONCLEX     TARGET_IO('f', 2)
+#define TARGET_FIONREAD     TARGET_IOR('f', 127, int)
+#define TARGET_FIONBIO      TARGET_IOW('f', 126, int)
+#define TARGET_FIOASYNC     TARGET_IOW('f', 125, int)
+#define TARGET_FIOSETOWN    TARGET_IOW('f', 124, int)
+#define TARGET_FIOGETOWN    TARGET_IOR('f', 123, int)
+#define TARGET_FIODTYPE     TARGET_IOR('f', 122, int)
+#define TARGET_FIOGETLBA    TARGET_IOR('f', 121, int)
+
+struct target_fiodgname_arg {
+    int32_t     len;
+    abi_ulong   buf;
+};
+
+#define TARGET_FIODGNAME    TARGET_IOW('f', 120,    \
+                struct target_fiodgname_arg)
+#define TARGET_FIONWRITE    TARGET_IOR('f', 119, int)
+#define TARGET_FIONSPACE    TARGET_IOR('f', 118, int)
+#define TARGET_FIOSEEKDATA  TARGET_IOWR('f', 97, off_t)
+#define TARGET_FIOSEEKHOLE  TARGET_IOWR('f', 98, off_t)
+
+#endif /* !_IOCTL_FILIO_H_ */
bsd-user/openbsd/ioctl-ioccom.h new file +38 -0
new file mode 100644
index 0000000..fa1c6b4
@@ -0,0 +1,38 @@
+#ifndef _IOCTL_IOCCOM_H_
+#define _IOCTL_IOCCOM_H_
+
+/* XXX needs to be fixed for OpenBSD dependencies */
+
+/*
+ * Ioctl's have the command encoded in the lower word, and the size of
+ * any in or out parameters in the upper word.  The high 3 bits of the
+ * upper word are used to encode the in/out status of the parameter.
+ */
+/* number of bits for ioctl size */
+#define TARGET_IOCPARM_SHIFT    13
+
+/* parameter length mask */
+#define TARGET_IOCPARM_MASK ((1 << TARGET_IOCPARM_SHIFT) - 1)
+
+#define TARGET_IOCPARM_LEN(x)   (((x) >> 16) & TARGET_IOCPARM_MASK)
+#define TARGET_IOCBASECMD(x)    ((x) & ~(TARGET_IOCPARM_MASK << 16))
+#define TARGET_IOCGROUP(x)  (((x) >> 8) & 0xff)
+
+#define TARGET_IOCPARM_MAX  (1 << TARGET_IOCPARM_SHIFT) /* max size of ioctl */
+#define TARGET_IOC_VOID     0x20000000  /* no parameters */
+#define TARGET_IOC_OUT      0x40000000  /* copy out parameters */
+#define TARGET_IOC_IN       0x80000000  /* copy in parameters */
+#define TARGET_IOC_INOUT    (TARGET_IOC_IN|TARGET_IOC_OUT)
+#define TARGET_IOC_DIRMASK  (TARGET_IOC_VOID|TARGET_IOC_OUT|TARGET_IOC_IN)
+
+#define TARGET_IOC(inout, group, num, len) ((abi_ulong) \
+    ((inout) | (((len) & TARGET_IOCPARM_MASK) << 16) | ((group) << 8) \
+     | (num)))
+#define TARGET_IO(g, n)       TARGET_IOC(IOC_VOID,    (g), (n), 0)
+#define TARGET_IOWINT(g, n)   TARGET_IOC(IOC_VOID,    (g), (n), sizeof(int))
+#define TARGET_IOR(g, n, t)   TARGET_IOC(IOC_OUT, (g), (n), sizeof(t))
+#define TARGET_IOW(g, n, t)   TARGET_IOC(IOC_IN,  (g), (n), sizeof(t))
+/* this should be _IORW, but stdio got there first */
+#define TARGET_IOWR(g, n, t)  TARGET_IOC(IOC_INOUT,   (g), (n), sizeof(t))
+
+#endif /* !_IOCTL_IOCCOM_H_ */
bsd-user/openbsd/ioctl-ttycom.h new file +240 -0

240 lines not on this page · raw message

bsd-user/openbsd/ioctl-types.h new file +7 -0
new file mode 100644
index 0000000..6f8b97b
@@ -0,0 +1,7 @@
+/* XXX should be fixed for OpenBSD types and structs */
+STRUCT_SPECIAL(termios)
+
+STRUCT(winsize, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT)
+
+STRUCT(fiodgname_arg, TYPE_INT, TYPE_PTRVOID)
+
bsd-user/qemu.h +5 -0
index f063974..ec194d2 100644
@@ -36,6 +36,7 @@ enum BSDType {
 };
 extern enum BSDType bsd_type;
 
+#include "exec/user/thunk.h"
 #include "syscall_defs.h"
 #include "syscall.h"
 #include "target_os_vmparam.h"
@@ -235,6 +236,10 @@ extern unsigned long target_maxssiz;
 extern unsigned long target_sgrowsiz;
 extern char qemu_proc_pathname[];
 
+/* ioctl.c */
+abi_long do_bsd_ioctl(int fd, abi_long cmd, abi_long arg);
+void ioctl_init(void);
+
 /* syscall.c */
 abi_long get_errno(abi_long ret);
 int is_error(abi_long ret);
bsd-user/syscall.c +9 -0
index 86aa471..3407894 100644
@@ -1341,6 +1341,13 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_freebsd__umtx_op(arg1, arg2, arg3, arg4, arg5);
         break;
 
+        /*
+         * ioctl(2)
+         */
+    case TARGET_FREEBSD_NR_ioctl: /* ioctl(2) */
+        ret = do_bsd_ioctl(arg1, arg2, arg3);
+        break;
+
 
     case TARGET_FREEBSD_NR_break:
         ret = do_obreak(arg1);
@@ -1472,4 +1479,6 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
 
 void syscall_init(void)
 {
+
+    ioctl_init();
 }
Signature · 1 line
1.7.8
author
#22 lore raw

PATCH 16/23 bsd-user: add shims for stat and file handle related syscalls

In reply to Stacey Son

This change adds support for status, file handle, and fcntl related system calls including stat(), statfs(), fhstatfs(), fcntl() and the many variants.

---
 bsd-user/Makefile.objs     |    3 +-
 bsd-user/freebsd/os-stat.c |  234 +++++++++++++++++++++++
 bsd-user/freebsd/os-stat.h |  437 ++++++++++++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/qemu-os.h |   10 +
 bsd-user/netbsd/os-stat.c  |    1 +
 bsd-user/netbsd/os-stat.h  |  176 ++++++++++++++++++
 bsd-user/openbsd/os-stat.c |    1 +
 bsd-user/openbsd/os-stat.h |  176 ++++++++++++++++++
 bsd-user/syscall.c         |   76 ++++++++
 bsd-user/syscall_defs.h    |  155 ++++++++++++++++
 10 files changed, 1268 insertions(+), 1 deletions(-)
 create mode 100644 bsd-user/freebsd/os-stat.c
 create mode 100644 bsd-user/freebsd/os-stat.h
 create mode 100644 bsd-user/netbsd/os-stat.c
 create mode 100644 bsd-user/netbsd/os-stat.h
 create mode 100644 bsd-user/openbsd/os-stat.c
 create mode 100644 bsd-user/openbsd/os-stat.h
bsd-user/Makefile.objs +2 -1
index 01f315e..cc7a82b 100644
@@ -1,3 +1,4 @@
 obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
 	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
-		    $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o
+		    $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \
+			$(TARGET_OS)/os-stat.o
bsd-user/freebsd/os-stat.c new file +234 -0

234 lines not on this page · raw message

bsd-user/freebsd/os-stat.h new file +437 -0

437 lines not on this page · raw message

bsd-user/freebsd/qemu-os.h +10 -0
index ff3a2c2..0dd65f5 100644
@@ -21,9 +21,11 @@
 #define _QEMU_OS_H_
 
 #include <sys/types.h>
+#include <sys/mount.h>
 #include <sys/timex.h>
 #include <sys/select.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <netinet/in.h>
 
 #include <time.h>
@@ -52,4 +54,12 @@ abi_long t2h_freebsd_cmsg(struct msghdr *msgh,
 abi_long h2t_freebsd_cmsg(struct target_msghdr *target_msgh,
                 struct msghdr *msgh);
 
+/* os-stat.c */
+abi_long h2t_freebsd_stat(abi_ulong target_addr, struct stat *host_st);
+abi_long h2t_freebsd_nstat(abi_ulong target_addr, struct stat *host_st);
+abi_long t2h_freebsd_fhandle(fhandle_t *host_fh, abi_ulong target_addr);
+abi_long h2t_freebsd_fhandle(abi_ulong target_addr, fhandle_t *host_fh);
+abi_long h2t_freebsd_statfs(abi_ulong target_addr, struct statfs *host_statfs);
+abi_long target_to_host_fcntl_cmd(int cmd);
+
 #endif /* !_QEMU_OS_H_ */
bsd-user/netbsd/os-stat.c new file +1 -0
new file mode 100644
index 0000000..11ea122
@@ -0,0 +1 @@
+/* XXX NetBSD stat related helpers */
bsd-user/netbsd/os-stat.h new file +176 -0

176 lines not on this page · raw message

bsd-user/openbsd/os-stat.c new file +1 -0
new file mode 100644
index 0000000..de4e3f5
@@ -0,0 +1 @@
+/* XXX OpenBSD stat related helpers */
bsd-user/openbsd/os-stat.h new file +176 -0

176 lines not on this page · raw message

bsd-user/syscall.c +76 -0

88 lines not on this page · raw message

bsd-user/syscall_defs.h +155 -0

159 lines not on this page · raw message

Signature · 1 line
1.7.8
author
#21 lore raw

PATCH 15/23 bsd-user: add shims for socket related system calls

In reply to Stacey Son

This change adds support for socket related system calls including socket, bind, accept, getsockopt, setsocketopt, etc. Like the other changes to add shims for system calls some are FreeBSD dependent. These shims are defined in freebsd/os-socket.h. Stubs to emulate these on other *BSDs are included in *bsd/os-socket.h.

---
 bsd-user/Makefile.objs       |    2 +-
 bsd-user/bsd-socket.c        |  108 +++++++++
 bsd-user/bsd-socket.h        |  266 ++++++++++++++++++++
 bsd-user/freebsd/os-socket.c |  149 ++++++++++++
 bsd-user/freebsd/os-socket.h |  548 ++++++++++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/qemu-os.h   |   14 +
 bsd-user/netbsd/os-socket.c  |    1 +
 bsd-user/netbsd/os-socket.h  |   98 ++++++++
 bsd-user/openbsd/os-socket.c |    1 +
 bsd-user/openbsd/os-socket.h |   98 ++++++++
 bsd-user/qemu-bsd.h          |   11 +
 bsd-user/syscall.c           |   98 ++++++++-
 bsd-user/syscall_defs.h      |  134 ++++++++++
 13 files changed, 1524 insertions(+), 4 deletions(-)
 create mode 100644 bsd-user/bsd-socket.c
 create mode 100644 bsd-user/bsd-socket.h
 create mode 100644 bsd-user/freebsd/os-socket.c
 create mode 100644 bsd-user/freebsd/os-socket.h
 create mode 100644 bsd-user/netbsd/os-socket.c
 create mode 100644 bsd-user/netbsd/os-socket.h
 create mode 100644 bsd-user/openbsd/os-socket.c
 create mode 100644 bsd-user/openbsd/os-socket.h
bsd-user/Makefile.objs +1 -1
index d21ddfa..01f315e 100644
@@ -1,3 +1,3 @@
 obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
 	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
-			$(TARGET_OS)/os-proc.o
+		    $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o
bsd-user/bsd-socket.c new file +108 -0

108 lines not on this page · raw message

bsd-user/bsd-socket.h new file +266 -0

266 lines not on this page · raw message

bsd-user/freebsd/os-socket.c new file +149 -0

149 lines not on this page · raw message

bsd-user/freebsd/os-socket.h new file +548 -0

548 lines not on this page · raw message

bsd-user/freebsd/qemu-os.h +14 -0
index 7a1ed9c..ff3a2c2 100644
@@ -20,6 +20,14 @@
 #ifndef _QEMU_OS_H_
 #define _QEMU_OS_H_
 
+#include <sys/types.h>
+#include <sys/timex.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <time.h>
+
 /* os-time.c */
 abi_long t2h_freebsd_timeval(struct timeval *tv, abi_ulong target_tv_addr);
 abi_long h2t_freebsd_timeval(struct timeval *tv, abi_ulong target_tv_addr);
@@ -38,4 +46,10 @@ abi_ulong copy_from_user_fdset_ptr(fd_set *fds, fd_set **fds_ptr,
 abi_long copy_to_user_fdset(abi_ulong target_fds_addr, const fd_set *fds,
         int n);
 
+/* os-socket.c */
+abi_long t2h_freebsd_cmsg(struct msghdr *msgh,
+                struct target_msghdr *target_msgh);
+abi_long h2t_freebsd_cmsg(struct target_msghdr *target_msgh,
+                struct msghdr *msgh);
+
 #endif /* !_QEMU_OS_H_ */
bsd-user/netbsd/os-socket.c new file +1 -0
new file mode 100644
index 0000000..d983c34
@@ -0,0 +1 @@
+/* XXX NetBSD socket related helpers */
bsd-user/netbsd/os-socket.h new file +98 -0

98 lines not on this page · raw message

bsd-user/openbsd/os-socket.c new file +1 -0
new file mode 100644
index 0000000..183002d
@@ -0,0 +1 @@
+/* XXX OpenBSD socket related helpers */
bsd-user/openbsd/os-socket.h new file +98 -0

98 lines not on this page · raw message

bsd-user/qemu-bsd.h +11 -0
index 893a475..c7c39c6 100644
@@ -24,7 +24,10 @@
 #include <sys/ipc.h>
 #include <sys/resource.h>
 #include <sys/shm.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 #include <sys/wait.h>
+#include <netinet/in.h>
 
 /* bsd-mem.c */
 abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
@@ -44,4 +47,12 @@ abi_long host_to_target_rusage(abi_ulong target_addr,
         const struct rusage *rusage);
 int host_to_target_waitstatus(int status);
 
+/* bsd-socket.c */
+abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_addr,
+        socklen_t len);
+abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *addr,
+        socklen_t len);
+abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, abi_ulong target_addr,
+        socklen_t len);
+
 #endif /* !_QEMU_BSD_H_ */
bsd-user/syscall.c +95 -3

120 lines not on this page · raw message

bsd-user/syscall_defs.h +134 -0

138 lines not on this page · raw message

Signature · 1 line
1.7.8
author
#20 lore raw

PATCH 14/23 bsd-user: add shims for process related system calls

In reply to Stacey Son

This change adds support for process related system calls including fork calls, execve calls, wait4(2), getuid(2), etc. It also adds a feature to check the target binary before exec'ing to see if it should run native or under emulation. This can be useful when there is not kernel support for something like binfmt_misc as in Linux. libprocstat is added to the libraries in configure to support this.

---
 bsd-user/Makefile.objs     |    3 +-
 bsd-user/bsd-errno.h       |   41 ----
 bsd-user/bsd-proc.c        |  160 ++++++++++++++++
 bsd-user/bsd-proc.h        |  434 ++++++++++++++++++++++++++++++++++++++++++++
 bsd-user/elfload.c         |   37 ++++
 bsd-user/freebsd/os-proc.c |  234 ++++++++++++++++++++++++
 bsd-user/freebsd/os-proc.h |  427 +++++++++++++++++++++++++++++++++++++++++++
 bsd-user/main.c            |   29 +++
 bsd-user/netbsd/os-proc.c  |   11 +
 bsd-user/netbsd/os-proc.h  |  243 +++++++++++++++++++++++++
 bsd-user/openbsd/os-proc.c |   11 +
 bsd-user/openbsd/os-proc.h |  243 +++++++++++++++++++++++++
 bsd-user/qemu-bsd.h        |   13 ++
 bsd-user/qemu.h            |   10 +
 bsd-user/syscall.c         |  303 ++++++++++++++++++++++++++++---
 bsd-user/syscall_defs.h    |   50 +++++
 configure                  |    3 +-
 17 files changed, 2186 insertions(+), 66 deletions(-)
 delete mode 100644 bsd-user/bsd-errno.h
 create mode 100644 bsd-user/bsd-proc.c
 create mode 100644 bsd-user/bsd-proc.h
 create mode 100644 bsd-user/freebsd/os-proc.c
 create mode 100644 bsd-user/freebsd/os-proc.h
 create mode 100644 bsd-user/netbsd/os-proc.c
 create mode 100644 bsd-user/netbsd/os-proc.h
 create mode 100644 bsd-user/openbsd/os-proc.c
 create mode 100644 bsd-user/openbsd/os-proc.h
bsd-user/Makefile.objs +2 -1
index 4c6acb0..d21ddfa 100644
@@ -1,2 +1,3 @@
 obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
-	        uaccess.o bsd-mem.o $(TARGET_OS)/os-time.o
+	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
+			$(TARGET_OS)/os-proc.o
bsd-user/bsd-errno.h deleted +0 -41

41 lines not on this page · raw message

bsd-user/bsd-proc.c new file +160 -0

160 lines not on this page · raw message

bsd-user/bsd-proc.h new file +434 -0

434 lines not on this page · raw message

bsd-user/elfload.c +37 -0
index 0cd5fc4..78a8d98 100644
@@ -111,6 +111,7 @@ enum {
 
 #ifdef TARGET_I386
 
+#ifndef __FreeBSD__
 #define ELF_PLATFORM get_elf_platform()
 
 static const char *get_elf_platform(void)
@@ -130,6 +131,7 @@ static uint32_t get_elf_hwcap(void)
 {
     return thread_env->features[FEAT_1_EDX];
 }
+#endif /* ! __FreeBSD__ */
 
 #ifdef TARGET_X86_64
 #define ELF_START_MMAP 0x2aaaaab000ULL
@@ -211,6 +213,9 @@ static inline void init_thread(struct target_pt_regs *regs,
       regs->ARM_cpsr |= CPSR_T;
     regs->ARM_pc = infop->entry & 0xfffffffe;
     regs->ARM_sp = infop->start_stack;
+    if (bsd_type == target_freebsd) {
+        regs->ARM_lr = infop->entry & 0xfffffffe;
+    }
     /* FIXME - what to for failure of get_user()? */
     get_user_ual(regs->ARM_r2, stack + 8); /* envp */
     get_user_ual(regs->ARM_r1, stack + 4); /* envp */
@@ -803,11 +808,14 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
 {
         abi_ulong sp;
         int size;
+#ifndef __FreeBSD__
         abi_ulong u_platform;
         const char *k_platform;
+#endif
         const int n = sizeof(elf_addr_t);
 
         sp = p;
+#ifndef __FreeBSD__
         u_platform = 0;
         k_platform = ELF_PLATFORM;
         if (k_platform) {
@@ -817,16 +825,19 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
             /* FIXME - check return value of memcpy_to_target() for failure */
             memcpy_to_target(sp, k_platform, len);
         }
+#endif /* !__FreeBSD__ */
         /*
          * Force 16 byte _final_ alignment here for generality.
          */
         sp = sp &~ (abi_ulong)15;
         size = (DLINFO_ITEMS + 1) * 2;
+#ifndef __FreeBSD__
         if (k_platform)
           size += 2;
 #ifdef DLINFO_ARCH_ITEMS
         size += DLINFO_ARCH_ITEMS * 2;
 #endif
+#endif /* ! __FreeBSD__ */
         size += envc + argc + 2;
         size += (!ibcs ? 3 : 1);        /* argc itself */
         size *= n;
@@ -855,10 +866,12 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
         NEW_AUX_ENT(AT_EUID, (abi_ulong) geteuid());
         NEW_AUX_ENT(AT_GID, (abi_ulong) getgid());
         NEW_AUX_ENT(AT_EGID, (abi_ulong) getegid());
+#ifndef __FreeBSD__
         NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP);
         NEW_AUX_ENT(AT_CLKTCK, (abi_ulong) sysconf(_SC_CLK_TCK));
         if (k_platform)
             NEW_AUX_ENT(AT_PLATFORM, u_platform);
+#endif
 #ifdef ARCH_DLINFO
         /*
          * ARCH_DLINFO must come last so platform specific code can enforce
@@ -1173,6 +1186,30 @@ static void load_symbols(struct elfhdr *hdr, int fd)
     syminfos = s;
 }
 
+/* Check the elf header and see if this a target elf binary. */
+int is_target_elf_binary(int fd)
+{
+    uint8_t buf[128];
+    struct elfhdr elf_ex;
+
+    if (lseek(fd, 0L, SEEK_SET) < 0) {
+        return 0;
+    }
+    if (read(fd, buf, sizeof(buf)) < 0) {
+        return 0;
+    }
+
+    elf_ex = *((struct elfhdr *)buf);
+    bswap_ehdr(&elf_ex);
+
+    if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
+        (!elf_check_arch(elf_ex.e_machine))) {
+        return 0;
+    } else {
+        return 1;
+    }
+}
+
 int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
                     struct image_info *info)
 {
bsd-user/freebsd/os-proc.c new file +234 -0

234 lines not on this page · raw message

bsd-user/freebsd/os-proc.h new file +427 -0

427 lines not on this page · raw message

bsd-user/main.c +29 -0
index 0442dbe..1fa5e7f 100644
@@ -27,6 +27,7 @@
 #include <sys/syscall.h>
 #include <sys/types.h>
 #include <sys/mman.h>
+#include <sys/sysctl.h>
 
 #include "qemu.h"
 #include "qemu-common.h"
@@ -56,6 +57,32 @@ unsigned long target_dflssiz = TARGET_DFLSSIZ;   /* initial data size limit */
 unsigned long target_maxssiz = TARGET_MAXSSIZ;   /* max stack size */
 unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount to grow stack */
 
+#ifdef __FreeBSD__
+char qemu_proc_pathname[PATH_MAX];
+
+static void save_proc_pathname(void)
+{
+    int mib[4];
+    size_t len;
+
+    mib[0] = CTL_KERN;
+    mib[1] = KERN_PROC;
+    mib[2] = KERN_PROC_PATHNAME;
+    mib[3] = -1;
+
+    len = sizeof(qemu_proc_pathname);
+    if (sysctl(mib, 4, qemu_proc_pathname, &len, NULL, 0)) {
+        perror("sysctl");
+    }
+}
+
+#else
+
+static void save_prov_pathname(void)
+{
+}
+#endif /* !__FreeBSD__ */
+
 void gemu_log(const char *fmt, ...)
 {
     va_list ap;
@@ -931,6 +958,8 @@ int main(int argc, char **argv)
     if (argc <= 1)
         usage();
 
+    save_proc_pathname();
+
     module_call_init(MODULE_INIT_QOM);
 
     if ((envlist = envlist_create()) == NULL) {
bsd-user/netbsd/os-proc.c new file +11 -0
new file mode 100644
index 0000000..bc11d29
@@ -0,0 +1,11 @@
+/*
+ * XXX To support FreeBSD binaries on NetBSD the following will need to be
+ * emulated.
+ */
+abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp,
+        abi_ulong guest_envp, int do_fexec)
+{
+
+    qemu_log("qemu: Unsupported %s\n", __func__);
+    return -TARGET_ENOSYS;
+}
bsd-user/netbsd/os-proc.h new file +243 -0

243 lines not on this page · raw message

bsd-user/openbsd/os-proc.c new file +11 -0
new file mode 100644
index 0000000..bc11d29
@@ -0,0 +1,11 @@
+/*
+ * XXX To support FreeBSD binaries on NetBSD the following will need to be
+ * emulated.
+ */
+abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp,
+        abi_ulong guest_envp, int do_fexec)
+{
+
+    qemu_log("qemu: Unsupported %s\n", __func__);
+    return -TARGET_ENOSYS;
+}
bsd-user/openbsd/os-proc.h new file +243 -0

243 lines not on this page · raw message

bsd-user/qemu-bsd.h +13 -0
index 0add0b3..893a475 100644
@@ -20,6 +20,12 @@
 #ifndef _QEMU_BSD_H_
 #define _QEMU_BSD_H_
 
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/resource.h>
+#include <sys/shm.h>
+#include <sys/wait.h>
+
 /* bsd-mem.c */
 abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
         abi_ulong target_addr);
@@ -30,5 +36,12 @@ abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
 abi_long host_to_target_shmid_ds(abi_ulong target_addr,
         struct shmid_ds *host_sd);
 
+/* bsd-proc.c */
+int target_to_host_resource(int code);
+rlim_t target_to_host_rlim(abi_ulong target_rlim);
+abi_ulong host_to_target_rlim(rlim_t rlim);
+abi_long host_to_target_rusage(abi_ulong target_addr,
+        const struct rusage *rusage);
+int host_to_target_waitstatus(int status);
 
 #endif /* !_QEMU_BSD_H_ */
bsd-user/qemu.h +10 -0
index da69073..7ded869 100644
@@ -144,6 +144,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
                     struct image_info *info);
 int load_flt_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
                     struct image_info *info);
+int is_target_elf_binary(int fd);
 
 abi_long memcpy_to_target(abi_ulong dest, const void *src,
                           unsigned long len);
@@ -232,6 +233,15 @@ extern unsigned long target_maxdsiz;
 extern unsigned long target_dflssiz;
 extern unsigned long target_maxssiz;
 extern unsigned long target_sgrowsiz;
+extern char qemu_proc_pathname[];
+
+/* syscall.c */
+abi_long get_errno(abi_long ret);
+int is_error(abi_long ret);
+
+/* os-proc.c */
+abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp,
+        abi_ulong guest_envp, int do_fexec);
 
 /* user access */
 
bsd-user/syscall.c +280 -23

346 lines not on this page · raw message

bsd-user/syscall_defs.h +50 -0

54 lines not on this page · raw message

configure +2 -1
index 749eba8..ba90975 100755
@@ -457,7 +457,8 @@ FreeBSD)
   audio_drv_list="oss"
   audio_possible_drivers="oss sdl esd pa"
   # needed for kinfo_getvmmap(3) in libutil.h
-  LIBS="-lutil $LIBS"
+  # -lprocstat needed for procstat_*(3) in bsd-user/main.c
+  LIBS="-lprocstat -lutil $LIBS"
   TARGET_OS="freebsd"
 ;;
 DragonFly)
Signature · 1 line
1.7.8
author
#29 lore raw

PATCH 21/23 bsd-user: add miscellaneous system call shims

In reply to Stacey Son

This change add System V semaphores/messages, uuid, FreeBSD cpu scheduling/affinity management, and other miscellaneous system call shims. A lot of these other system call shims are stubs for maybe future work.

---
 bsd-user/Makefile.objs     |    2 +-
 bsd-user/bsd-misc.c        |  209 +++++++++++++++++++++
 bsd-user/bsd-misc.h        |  339 +++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-misc.h |  442 ++++++++++++++++++++++++++++++++++++++++++++
 bsd-user/qemu-bsd.h        |   21 ++
 bsd-user/syscall.c         |  224 ++++++++++++++++++++++
 bsd-user/syscall_defs.h    |   81 ++++++++
 7 files changed, 1317 insertions(+), 1 deletions(-)
 create mode 100644 bsd-user/bsd-misc.c
 create mode 100644 bsd-user/bsd-misc.h
 create mode 100644 bsd-user/freebsd/os-misc.h
bsd-user/Makefile.objs +1 -1
index 3dddc00..5308e29 100644
@@ -2,4 +2,4 @@ obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \
 	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
 			$(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \
 			$(TARGET_OS)/os-stat.o $(TARGET_OS)/os-sys.o \
-			$(TARGET_OS)/os-thread.o $(TARGET_OS)/os-extattr.o
+			$(TARGET_OS)/os-thread.o $(TARGET_OS)/os-extattr.o bsd-misc.o
bsd-user/bsd-misc.c new file +209 -0

209 lines not on this page · raw message

bsd-user/bsd-misc.h new file +339 -0

339 lines not on this page · raw message

bsd-user/freebsd/os-misc.h new file +442 -0

442 lines not on this page · raw message

bsd-user/qemu-bsd.h +21 -0
index c7c39c6..771245d 100644
@@ -22,10 +22,13 @@
 
 #include <sys/types.h>
 #include <sys/ipc.h>
+#include <sys/msg.h>
 #include <sys/resource.h>
+#include <sys/sem.h>
 #include <sys/shm.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <sys/uuid.h>
 #include <sys/wait.h>
 #include <netinet/in.h>
 
@@ -55,4 +58,22 @@ abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *addr,
 abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, abi_ulong target_addr,
         socklen_t len);
 
+/* bsd-misc.c */
+abi_long host_to_target_uuid(abi_ulong target_addr, struct uuid *host_uuid);
+
+abi_long target_to_host_semarray(int semid, unsigned short **host_array,
+        abi_ulong target_addr);
+abi_long host_to_target_semarray(int semid, abi_ulong target_addr,
+        unsigned short **host_array);
+
+abi_long target_to_host_semid_ds(struct semid_ds *host_sd,
+        abi_ulong target_addr);
+abi_long host_to_target_semid_ds(abi_ulong target_addr,
+        struct semid_ds *host_sd);
+
+abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
+        abi_ulong target_addr);
+abi_long host_to_target_msqid_ds(abi_ulong target_addr,
+        struct msqid_ds *host_md);
+
 #endif /* !_QEMU_BSD_H_ */
bsd-user/syscall.c +224 -0

242 lines not on this page · raw message

bsd-user/syscall_defs.h +81 -0

97 lines not on this page · raw message

Signature · 1 line
1.7.8
author
#23 lore raw

PATCH 17/23 bsd-user: add shims for thread related system calls

In reply to Stacey Son

This change adds support for thread and user mutex related system call shims. Much of this change is FreeBSD dependent. Also, the thread start up code is architecture dependent and is only included for mips/mips64 for now. Stubs were added for the other architectures.

---
 bsd-user/Makefile.objs                |    4 +-
 bsd-user/freebsd/os-thread.c          |  802 +++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-thread.h          |  742 ++++++++++++++++++++++++++++++
 bsd-user/freebsd/qemu-os.h            |    5 +
 bsd-user/i386/target_arch_signal.h    |   12 +
 bsd-user/i386/target_arch_thread.h    |   30 ++
 bsd-user/main.c                       |  225 +++++++++-
 bsd-user/mips/target_arch_signal.h    |    8 +-
 bsd-user/mips/target_arch_thread.h    |   45 ++
 bsd-user/mips64/target_arch_signal.h  |    8 +-
 bsd-user/mips64/target_arch_thread.h  |   45 ++
 bsd-user/qemu.h                       |   35 ++
 bsd-user/sparc/target_arch_signal.h   |   12 +
 bsd-user/sparc/target_arch_thread.h   |   30 ++
 bsd-user/sparc64/target_arch_signal.h |   12 +
 bsd-user/sparc64/target_arch_thread.h |   30 ++
 bsd-user/syscall.c                    |   70 +++
 bsd-user/syscall_defs.h               |   91 ++++
 bsd-user/x86_64/target_arch_signal.h  |   12 +
 bsd-user/x86_64/target_arch_thread.h  |   30 ++
 configure                             |   11 +
 include/qemu/tls.h                    |    2 +-
 22 files changed, 2232 insertions(+), 29 deletions(-)
 create mode 100644 bsd-user/freebsd/os-thread.c
 create mode 100644 bsd-user/freebsd/os-thread.h
 create mode 100644 bsd-user/i386/target_arch_thread.h
 create mode 100644 bsd-user/mips/target_arch_thread.h
 create mode 100644 bsd-user/mips64/target_arch_thread.h
 create mode 100644 bsd-user/sparc/target_arch_thread.h
 create mode 100644 bsd-user/sparc64/target_arch_thread.h
 create mode 100644 bsd-user/x86_64/target_arch_thread.h
bsd-user/Makefile.objs +2 -2
index cc7a82b..2608337 100644
@@ -1,4 +1,4 @@
 obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
 	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
-		    $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \
-			$(TARGET_OS)/os-stat.o
+			$(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \
+			$(TARGET_OS)/os-stat.o $(TARGET_OS)/os-thread.o
bsd-user/freebsd/os-thread.c new file +802 -0

802 lines not on this page · raw message

bsd-user/freebsd/os-thread.h new file +742 -0

742 lines not on this page · raw message

bsd-user/freebsd/qemu-os.h +5 -0
index 0dd65f5..eac9085 100644
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 #include <sys/mount.h>
 #include <sys/timex.h>
+#include <sys/rtprio.h>
 #include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
@@ -62,4 +63,8 @@ abi_long h2t_freebsd_fhandle(abi_ulong target_addr, fhandle_t *host_fh);
 abi_long h2t_freebsd_statfs(abi_ulong target_addr, struct statfs *host_statfs);
 abi_long target_to_host_fcntl_cmd(int cmd);
 
+/* os-thread.c */
+abi_long t2h_freebsd_rtprio(struct rtprio *host_rtp, abi_ulong target_addr);
+abi_long h2t_freebsd_rtprio(abi_ulong target_addr, struct rtprio *host_rtp);
+
 #endif /* !_QEMU_OS_H_ */
bsd-user/i386/target_arch_signal.h +12 -0
index 2e89529..7fd1399 100644
@@ -27,6 +27,8 @@
 #define TARGET_MINSIGSTKSZ  (512 * 4)               /* min sig stack size */
 #define TARGET_SIGSTKSZ     (MINSIGSTKSZ + 32768)   /* recommended size */
 
+#define TARGET_MC_GET_CLEAR_RET 0x0001
+
 struct target_sigcontext {
     /* to be added */
 };
@@ -53,9 +55,19 @@ struct target_sigframe {
     uint32_t    __spare__[2];
 };
 
+/* Compare to i386/i386/machdep.c get_mcontext() */
+static inline abi_long get_mcontext(CPUX86State *regs,
+        target_mcontext_t *mcp, int flags)
+{
+    /* XXX */
+    return -TARGET_EOPNOTSUPP;
+}
+
+/* Compare to i386/i386/machdep.c set_mcontext() */
 static inline abi_long set_mcontext(CPUX86State *regs,
         target_mcontext_t *mcp, int srflag)
 {
+    /* XXX */
     return -TARGET_EOPNOTSUPP;
 }
 
bsd-user/i386/target_arch_thread.h new file +30 -0
new file mode 100644
index 0000000..8307dce
@@ -0,0 +1,30 @@
+/*
+ *  i386 thread support
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_THREAD_H_
+#define _TARGET_ARCH_THREAD_H_
+
+/* Compare to vm_machdep.c cpu_set_upcall_kse() */
+static inline void
+thread_set_upcall(CPUX86State *regs, abi_ulong entry,
+    abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
+{
+    /* XXX */
+}
+
+#endif /* !_TARGET_ARCH_THREAD_H_ */
bsd-user/main.c +207 -18

301 lines not on this page · raw message

bsd-user/mips/target_arch_signal.h +4 -4
index f68034f..6be34c6 100644
@@ -124,8 +124,8 @@ set_sigtramp_args(CPUMIPSState *regs, int sig, struct target_sigframe *frame,
  * Compare to mips/mips/pm_machdep.c get_mcontext()
  * Assumes that the memory is locked if mcp points to user memory.
  */
-static inline abi_long
-get_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp, int flags)
+static inline abi_long get_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp,
+        int flags)
 {
     int i, err = 0;
 
@@ -180,8 +180,8 @@ get_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp, int flags)
 }
 
 /* Compare to mips/mips/pm_machdep.c set_mcontext() */
-static inline abi_long set_mcontext(CPUMIPSState *regs,
-        target_mcontext_t *mcp, int srflag)
+static inline abi_long set_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp,
+        int srflag)
 {
     int i, err = 0;
 
bsd-user/mips/target_arch_thread.h new file +45 -0

45 lines not on this page · raw message

bsd-user/mips64/target_arch_signal.h +4 -4
index 5edcc3a..ab84e0f 100644
@@ -123,8 +123,8 @@ set_sigtramp_args(CPUMIPSState *regs, int sig, struct target_sigframe *frame,
  * Compare to mips/mips/pm_machdep.c get_mcontext()
  * Assumes that the memory is locked if mcp points to user memory.
  */
-static inline abi_long
-get_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp, int flags)
+static inline abi_long get_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp,
+        int flags)
 {
     int i, err = 0;
 
@@ -179,8 +179,8 @@ get_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp, int flags)
 }
 
 /* Compare to mips/mips/pm_machdep.c set_mcontext() */
-static inline abi_long set_mcontext(CPUMIPSState *regs,
-        target_mcontext_t *mcp, int srflag)
+static inline abi_long set_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp,
+        int srflag)
 {
     int i, err = 0;
 
bsd-user/mips64/target_arch_thread.h new file +45 -0

45 lines not on this page · raw message

bsd-user/qemu.h +35 -0
index 7ded869..f063974 100644
@@ -243,6 +243,41 @@ int is_error(abi_long ret);
 abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp,
         abi_ulong guest_envp, int do_fexec);
 
+/* os-thread.c */
+extern pthread_mutex_t *new_freebsd_thread_lock_ptr;
+void *new_freebsd_thread_start(void *arg);
+abi_long freebsd_lock_umtx(abi_ulong target_addr, abi_long tid,
+        struct timespec *timeout);
+abi_long freebsd_unlock_umtx(abi_ulong target_addr, abi_long id);
+abi_long freebsd_umtx_wait(abi_ulong targ_addr, abi_ulong id,
+        struct timespec *ts);
+abi_long freebsd_umtx_wake(abi_ulong target_addr, uint32_t n_wake);
+abi_long freebsd_umtx_mutex_wake(abi_ulong target_addr, abi_long val);
+abi_long freebsd_umtx_wait_uint(abi_ulong obj, uint32_t val,
+                struct timespec *timeout);
+abi_long freebsd_umtx_wait_uint_private(abi_ulong obj, uint32_t val,
+                struct timespec *timeout);
+abi_long freebsd_umtx_wake_private(abi_ulong obj, uint32_t val);
+#if defined(__FreeBSD_version) && __FreeBSD_version > 900000
+abi_long freebsd_umtx_nwake_private(abi_ulong obj, uint32_t val);
+abi_long freebsd_umtx_mutex_wake2(abi_ulong obj, uint32_t val);
+abi_long freebsd_umtx_sem_wait(abi_ulong obj, struct timespec *timeout);
+abi_long freebsd_umtx_sem_wake(abi_ulong obj, uint32_t val);
+#endif
+abi_long freebsd_lock_umutex(abi_ulong target_addr, uint32_t id,
+        struct timespec *ts, int mode);
+abi_long freebsd_unlock_umutex(abi_ulong target_addr, uint32_t id);
+abi_long freebsd_cv_wait(abi_ulong target_ucond_addr,
+                abi_ulong target_umtx_addr, struct timespec *ts, int wflags);
+abi_long freebsd_cv_signal(abi_ulong target_ucond_addr);
+abi_long freebsd_cv_broadcast(abi_ulong target_ucond_addr);
+abi_long freebsd_rw_rdlock(abi_ulong target_addr, long fflag,
+        struct timespec *ts);
+abi_long freebsd_rw_wrlock(abi_ulong target_addr, long fflag,
+        struct timespec *ts);
+abi_long freebsd_rw_unlock(abi_ulong target_addr);
+
+
 /* user access */
 
 #define VERIFY_READ 0
bsd-user/sparc/target_arch_signal.h +12 -0
index 275d1ef..70b89b9 100644
@@ -10,6 +10,8 @@
 #define TARGET_MINSIGSTKSZ  (1024 * 4)              /* min sig stack size */
 #define TARGET_SIGSTKSZ     (MINSIGSTKSZ + 32768)   /* recommended size */
 
+#define TARGET_MC_GET_CLEAR_RET 0x0001
+
 struct target_sigcontext {
     /* to be added */
 };
@@ -36,9 +38,19 @@ struct target_sigframe {
     uint32_t    __spare__[2];
 };
 
+/* Compare to sparc64/sparc64/machdep.c get_mcontext() */
+static inline abi_long get_mcontext(CPUSPARCState *regs,
+        target_mcontext_t *mcp, int flags)
+{
+    /* XXX */
+    return -TARGET_EOPNOTSUPP;
+}
+
+/* Compare to sparc64/space64/machdep.c set_mcontext() */
 static inline abi_long set_mcontext(CPUSPARCState *regs,
         target_mcontext_t *mcp, int srflag)
 {
+    /* XXX */
     return -TARGET_EOPNOTSUPP;
 }
 
bsd-user/sparc/target_arch_thread.h new file +30 -0
new file mode 100644
index 0000000..ddfbbe2
@@ -0,0 +1,30 @@
+/*
+ *  sparc thread support
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_THREAD_H_
+#define _TARGET_ARCH_THREAD_H_
+
+/* Compare to vm_machdep.c cpu_set_upcall_kse() */
+static inline void
+thread_set_upcall(CPUSPARCState *regs, abi_ulong entry,
+    abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
+{
+    /* XXX */
+}
+
+#endif /* !_TARGET_ARCH_THREAD_H_ */
bsd-user/sparc64/target_arch_signal.h +12 -0
index 8126383..cc075ed 100644
@@ -27,6 +27,8 @@
 #define TARGET_MINSIGSTKSZ  (1024 * 4)              /* min sig stack size */
 #define TARGET_SIGSTKSZ     (MINSIGSTKSZ + 32768)   /* recommended size */
 
+#define TARGET_MC_GET_CLEAR_RET 0x0001
+
 struct target_sigcontext {
     /* to be added */
 };
@@ -53,9 +55,19 @@ struct target_sigframe {
     uint32_t    __spare__[2];
 };
 
+/* Compare to sparc64/sparc64/machdep.c get_mcontext() */
+static inline abi_long get_mcontext(CPUSPARCState *regs,
+        target_mcontext_t *mcp, int flags)
+{
+    /* XXX */
+    return -TARGET_EOPNOTSUPP;
+}
+
+/* Compare to sparc64/space64/machdep.c set_mcontext() */
 static inline abi_long set_mcontext(CPUSPARCState *regs,
         target_mcontext_t *mcp, int srflag)
 {
+    /* XXX */
     return -TARGET_EOPNOTSUPP;
 }
 
bsd-user/sparc64/target_arch_thread.h new file +30 -0
new file mode 100644
index 0000000..0f06d14
@@ -0,0 +1,30 @@
+/*
+ *  sparc64 thread support
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_THREAD_H_
+#define _TARGET_ARCH_THREAD_H_
+
+/* Compare to vm_machdep.c cpu_set_upcall_kse() */
+static inline void
+thread_set_upcall(CPUSPARCState *regs, abi_ulong entry,
+    abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
+{
+    /* XXX */
+}
+
+#endif /* !_TARGET_ARCH_THREAD_H_ */
bsd-user/syscall.c +70 -0

93 lines not on this page · raw message

bsd-user/syscall_defs.h +91 -0

95 lines not on this page · raw message

bsd-user/x86_64/target_arch_signal.h +12 -0
index d43f5f0..7525a56 100644
@@ -27,6 +27,8 @@
 #define TARGET_MINSIGSTKSZ  (512 * 4)               /* min sig stack size */
 #define TARGET_SIGSTKSZ     (MINSIGSTKSZ + 32768)   /* recommended size */
 
+#define TARGET_MC_GET_CLEAR_RET 0x0001
+
 struct target_sigcontext {
     /* to be added */
 };
@@ -53,9 +55,19 @@ struct target_sigframe {
     uint32_t    __spare__[2];
 };
 
+/* Compare to amd64/amd64/machdep.c get_mcontext() */
+static inline abi_long get_mcontext(CPUX86State *regs,
+                target_mcontext_t *mcp, int flags)
+{
+        /* XXX */
+        return -TARGET_EOPNOTSUPP;
+}
+
+/* Compare to amd64/amd64/machdep.c set_mcontext() */
 static inline abi_long set_mcontext(CPUX86State *regs,
         target_mcontext_t *mcp, int srflag)
 {
+    /* XXX */
     return -TARGET_EOPNOTSUPP;
 }
 
bsd-user/x86_64/target_arch_thread.h new file +30 -0
new file mode 100644
index 0000000..32a833f
@@ -0,0 +1,30 @@
+/*
+ *  x86_64 thread support
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_THREAD_H_
+#define _TARGET_ARCH_THREAD_H_
+
+/* Compare to vm_machdep.c cpu_set_upcall_kse() */
+static inline void
+thread_set_upcall(CPUX86State *regs, abi_ulong entry,
+    abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
+{
+    /* XXX */
+}
+
+#endif /* !_TARGET_ARCH_THREAD_H_ */
configure +11 -0
index ba90975..812ea3f 100755
@@ -1438,6 +1438,15 @@ fi
 
 if test "$nptl" != "no" ; then
   cat > $TMPC <<EOF
+#ifdef __FreeBSD__
+#include <sys/thr.h>
+int main(void) {
+#if !defined(THR_SUSPENDED)
+#error bork
+#endif
+  return 0;
+}
+#else
 #include <sched.h>
 #include <linux/futex.h>
 int main(void) {
@@ -1446,6 +1455,7 @@ int main(void) {
 #endif
   return 0;
 }
+#endif
 EOF
 
   if compile_object ; then
@@ -4202,6 +4212,7 @@ case "$target_name" in
     TARGET_ARCH=mips64
     TARGET_BASE_ARCH=mips
     echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
+    target_nptl="yes"
   ;;
   moxie)
   ;;
include/qemu/tls.h +1 -1
index b92ea9d..ae7d79d 100644
@@ -38,7 +38,7 @@
  * TODO: proper implementations via Win32 .tls sections and
  * POSIX pthread_getspecific.
  */
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
 #define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x)
 #define DEFINE_TLS(type, x)  __thread __typeof__(type) tls__##x
 #define tls_var(x)           tls__##x
Signature · 1 line
1.7.8
author
#27 lore raw

PATCH 19/23 bsd-user: add shims for sysarch() and sysctl() system calls

In reply to Stacey Son

This change adds support for sysarch() and sysctl() system call emulation. sysarch() is both architecture and OS dependent. Therefore this change adds a handler for each architecture. sysctl() has a lot special cases that have to each decoded and handled individually.

---
 bsd-user/Makefile.objs                 |    3 +-
 bsd-user/freebsd/os-sys.c              |  268 ++++++++++++++++++++++++++++++++
 bsd-user/i386/syscall.h                |    2 +
 bsd-user/i386/target_arch_sysarch.h    |   69 ++++++++
 bsd-user/mips/syscall.h                |   12 ++-
 bsd-user/mips/target_arch_sysarch.h    |   50 ++++++
 bsd-user/mips64/syscall.h              |   11 ++
 bsd-user/mips64/target_arch_sysarch.h  |   50 ++++++
 bsd-user/netbsd/os-sys.c               |   46 ++++++
 bsd-user/openbsd/os-sys.c              |   46 ++++++
 bsd-user/qemu.h                        |    5 +
 bsd-user/sparc/syscall.h               |    7 +-
 bsd-user/sparc/target_arch_sysarch.h   |   43 +++++
 bsd-user/sparc64/syscall.h             |    7 +-
 bsd-user/sparc64/target_arch_sysarch.h |   43 +++++
 bsd-user/syscall.c                     |  209 +++----------------------
 bsd-user/x86_64/syscall.h              |    4 +-
 bsd-user/x86_64/target_arch_sysarch.h  |   67 ++++++++
 18 files changed, 747 insertions(+), 195 deletions(-)
 create mode 100644 bsd-user/freebsd/os-sys.c
 create mode 100644 bsd-user/i386/target_arch_sysarch.h
 create mode 100644 bsd-user/mips/target_arch_sysarch.h
 create mode 100644 bsd-user/mips64/target_arch_sysarch.h
 create mode 100644 bsd-user/netbsd/os-sys.c
 create mode 100644 bsd-user/openbsd/os-sys.c
 create mode 100644 bsd-user/sparc/target_arch_sysarch.h
 create mode 100644 bsd-user/sparc64/target_arch_sysarch.h
 create mode 100644 bsd-user/x86_64/target_arch_sysarch.h
bsd-user/Makefile.objs +2 -1
index fbb3e56..e392760 100644
@@ -1,4 +1,5 @@
 obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \
 	        uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \
 			$(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \
-			$(TARGET_OS)/os-stat.o $(TARGET_OS)/os-thread.o
+			$(TARGET_OS)/os-stat.o $(TARGET_OS)/os-sys.o \
+			$(TARGET_OS)/os-thread.o
bsd-user/freebsd/os-sys.c new file +268 -0

268 lines not on this page · raw message

bsd-user/i386/syscall.h +2 -0
index 8028fc8..52de302 100644
@@ -178,5 +178,7 @@ struct target_vm86plus_struct {
 
 
 #define UNAME_MACHINE "i386"
+#define TARGET_HW_MACHINE UNAME_MACHINE
+#define TARGET_HW_MACHINE_ARCH UNAME_MACHINE
 
 #endif /* ! _I386_SYSCALL_H_ */
bsd-user/i386/target_arch_sysarch.h new file +69 -0

69 lines not on this page · raw message

bsd-user/mips/syscall.h +11 -1
index 149970a..49e2833 100644
@@ -36,7 +36,17 @@ struct target_pt_regs {
     abi_ulong cp0_epc;
 };
 
-
+#if defined(TARGET_WORDS_BIG_ENDIAN)
 #define UNAME_MACHINE "mips"
+#else
+#define UNAME_MACHINE "mipsel"
+#endif
+
+#define TARGET_HW_MACHINE       "mips"
+#define TARGET_HW_MACHINE_ARCH   UNAME_MACHINE
+
+/* sysarch() commands */
+#define TARGET_MIPS_SET_TLS     1
+#define TARGET_MIPS_GET_TLS     2
 
 #endif /* !_MIPS_SYSCALL_H_ */
bsd-user/mips/target_arch_sysarch.h new file +50 -0

50 lines not on this page · raw message

bsd-user/mips64/syscall.h +11 -0
index 300ed9b..b068fa1 100644
@@ -37,6 +37,17 @@ struct target_pt_regs {
 };
 
 
+#if defined(TARGET_WORDS_BIG_ENDIAN)
 #define UNAME_MACHINE "mips64"
+#else
+#define UNAME_MACHINE "mips64el"
+#endif
+
+#define TARGET_HW_MACHINE       "mips"
+#define TARGET_HW_MACHINE_ARCH  UNAME_MACHINE
+
+/* sysarch() commands */
+#define TARGET_MIPS_SET_TLS     1
+#define TARGET_MIPS_GET_TLS     2
 
 #endif /* !_MIPS64_SYSCALL_H_ */
bsd-user/mips64/target_arch_sysarch.h new file +50 -0

50 lines not on this page · raw message

bsd-user/netbsd/os-sys.c new file +46 -0

46 lines not on this page · raw message

bsd-user/openbsd/os-sys.c new file +46 -0

46 lines not on this page · raw message

bsd-user/qemu.h +5 -0
index ec194d2..2ddf244 100644
@@ -248,6 +248,11 @@ int is_error(abi_long ret);
 abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp,
         abi_ulong guest_envp, int do_fexec);
 
+/* os-sys.c */
+abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen,
+        abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen);
+abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2);
+
 /* os-thread.c */
 extern pthread_mutex_t *new_freebsd_thread_lock_ptr;
 void *new_freebsd_thread_start(void *arg);
bsd-user/sparc/syscall.h +6 -1
index 804889a..3a5b1e2 100644
@@ -26,6 +26,11 @@ struct target_pt_regs {
 	abi_ulong u_regs[16];
 };
 
-#define UNAME_MACHINE "sun4"
+#define UNAME_MACHINE           "sun4"
+#define TARGET_HW_MACHINE       "sparc"
+#define TARGET_HW_MACHINE_ARCH  "sparc"
+
+#define TARGET_SPARC_UTRAP_INSTALL      1
+#define TARGET_SPARC_SIGTRAMP_INSTALL   2
 
 #endif /* ! _SPARC_SYSCALL_H_ */
bsd-user/sparc/target_arch_sysarch.h new file +43 -0

43 lines not on this page · raw message

bsd-user/sparc64/syscall.h +6 -1
index 9f3b97e..58cc38d 100644
@@ -26,6 +26,11 @@ struct target_pt_regs {
 	abi_ulong fprs;
 };
 
-#define UNAME_MACHINE "sun4u"
+#define UNAME_MACHINE           "sun4u"
+#define TARGET_HW_MACHINE       "sparc"
+#define TARGET_HW_MACHINE_ARCH  "sparc64"
+
+#define TARGET_SPARC_UTRAP_INSTALL      1
+#define TARGET_SPARC_SIGTRAMP_INSTALL   2
 
 #endif /* !_SPARC64_SYSCALL_H_ */
bsd-user/sparc64/target_arch_sysarch.h new file +43 -0

43 lines not on this page · raw message

bsd-user/syscall.c +19 -190

226 lines not on this page · raw message

bsd-user/x86_64/syscall.h +3 -1
index fbaeacf..4fff6a5 100644
@@ -128,7 +128,9 @@ struct target_msqid64_ds {
 #define TARGET_FREEBSD_AMD64_SET_GSBASE	131
 
 
-#define UNAME_MACHINE "x86_64"
+#define UNAME_MACHINE           "x86_64"
+#define TARGET_HW_MACHINE       "amd64"
+#define TARGET_HW_MACHINE_ARCH  "amd64"
 
 #define TARGET_ARCH_SET_GS 0x1001
 #define TARGET_ARCH_SET_FS 0x1002
bsd-user/x86_64/target_arch_sysarch.h new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
1.7.8
author
#33 lore raw

PATCH 23/23 bsd-user: add arm cpu support

In reply to Stacey Son

This change adds support for the arm cpu target. In addition, it moves the cpu dependent code out of main.c into the individual architecture directories and cleans up main.c in general. Credit for much of this code: Olivier Houchard.

---
 bsd-user/Makefile.objs                |    2 +-
 bsd-user/arm/syscall.h                |   36 ++
 bsd-user/arm/target_arch.h            |   13 +
 bsd-user/arm/target_arch_cpu.h        |  405 +++++++++++++
 bsd-user/arm/target_arch_signal.h     |  255 ++++++++
 bsd-user/arm/target_arch_sigtramp.h   |   33 +
 bsd-user/arm/target_arch_sysarch.h    |   80 +++
 bsd-user/arm/target_arch_thread.h     |   40 ++
 bsd-user/arm/target_arch_vmparam.h    |   49 ++
 bsd-user/freebsd/host_os.h            |   46 ++
 bsd-user/i386/target_arch.h           |   11 +
 bsd-user/i386/target_arch_cpu.c       |   79 +++
 bsd-user/i386/target_arch_cpu.h       |  290 +++++++++
 bsd-user/i386/target_arch_signal.h    |    7 +
 bsd-user/main.c                       | 1062 ++-------------------------------
 bsd-user/mips/target_arch.h           |   13 +
 bsd-user/mips/target_arch_cpu.h       |  227 +++++++
 bsd-user/mips/target_arch_signal.h    |    9 +
 bsd-user/mips64/target_arch.h         |   13 +
 bsd-user/mips64/target_arch_cpu.h     |  226 +++++++
 bsd-user/mips64/target_arch_signal.h  |    9 +
 bsd-user/netbsd/host_os.h             |   31 +
 bsd-user/openbsd/host_os.h            |   31 +
 bsd-user/qemu.h                       |   11 +
 bsd-user/signal.c                     |   20 +-
 bsd-user/sparc/target_arch.h          |    9 +
 bsd-user/sparc/target_arch_cpu.c      |  113 ++++
 bsd-user/sparc/target_arch_cpu.h      |  143 +++++
 bsd-user/sparc/target_arch_signal.h   |    7 +
 bsd-user/sparc64/target_arch.h        |    9 +
 bsd-user/sparc64/target_arch_cpu.c    |  118 ++++
 bsd-user/sparc64/target_arch_cpu.h    |  175 ++++++
 bsd-user/sparc64/target_arch_signal.h |    7 +
 bsd-user/syscall.c                    |    7 +
 bsd-user/x86_64/target_arch.h         |   11 +
 bsd-user/x86_64/target_arch_cpu.c     |   79 +++
 bsd-user/x86_64/target_arch_cpu.h     |  312 ++++++++++
 bsd-user/x86_64/target_arch_signal.h  |   11 +-
 default-configs/arm-bsd-user.mak      |    3 +
 default-configs/armeb-bsd-user.mak    |    3 +
 40 files changed, 2971 insertions(+), 1034 deletions(-)
 create mode 100644 bsd-user/arm/syscall.h
 create mode 100644 bsd-user/arm/target_arch.h
 create mode 100644 bsd-user/arm/target_arch_cpu.c
 create mode 100644 bsd-user/arm/target_arch_cpu.h
 create mode 100644 bsd-user/arm/target_arch_signal.h
 create mode 100644 bsd-user/arm/target_arch_sigtramp.h
 create mode 100644 bsd-user/arm/target_arch_sysarch.h
 create mode 100644 bsd-user/arm/target_arch_thread.h
 create mode 100644 bsd-user/arm/target_arch_vmparam.h
 create mode 100644 bsd-user/freebsd/host_os.h
 create mode 100644 bsd-user/i386/target_arch.h
 create mode 100644 bsd-user/i386/target_arch_cpu.c
 create mode 100644 bsd-user/i386/target_arch_cpu.h
 create mode 100644 bsd-user/mips/target_arch.h
 create mode 100644 bsd-user/mips/target_arch_cpu.c
 create mode 100644 bsd-user/mips/target_arch_cpu.h
 create mode 100644 bsd-user/mips64/target_arch.h
 create mode 100644 bsd-user/mips64/target_arch_cpu.c
 create mode 100644 bsd-user/mips64/target_arch_cpu.h
 create mode 100644 bsd-user/mips64/touch_arch.cpu.c
 create mode 100644 bsd-user/netbsd/host_os.h
 create mode 100644 bsd-user/openbsd/host_os.h
 create mode 100644 bsd-user/sparc/target_arch.h
 create mode 100644 bsd-user/sparc/target_arch_cpu.c
 create mode 100644 bsd-user/sparc/target_arch_cpu.h
 create mode 100644 bsd-user/sparc64/target_arch.h
 create mode 100644 bsd-user/sparc64/target_arch_cpu.c
 create mode 100644 bsd-user/sparc64/target_arch_cpu.h
 create mode 100644 bsd-user/x86_64/target_arch.h
 create mode 100644 bsd-user/x86_64/target_arch_cpu.c
 create mode 100644 bsd-user/x86_64/target_arch_cpu.h
 create mode 100644 default-configs/arm-bsd-user.mak
 create mode 100644 default-configs/armeb-bsd-user.mak
bsd-user/Makefile.objs +1 -1
index 06a3026..ddc91ff 100644
@@ -3,5 +3,5 @@ obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \
 			$(HOST_ABI_DIR)/os-extattr.o $(HOST_ABI_DIR)/os-proc.o \
 			$(HOST_ABI_DIR)/os-socket.o $(HOST_ABI_DIR)/os-stat.o \
 			$(HOST_ABI_DIR)/os-sys.o $(HOST_ABI_DIR)/os-thread.o  \
-			$(HOST_ABI_DIR)/os-time.o
+			$(HOST_ABI_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o
 
bsd-user/arm/syscall.h new file +36 -0
new file mode 100644
index 0000000..bc3d6e6
@@ -0,0 +1,36 @@
+#ifndef __ARCH_SYSCALL_H_
+#define __ARCH_SYSCALL_H_
+
+struct target_pt_regs {
+    abi_long uregs[17];
+};
+
+#define ARM_cpsr    uregs[16]
+#define ARM_pc      uregs[15]
+#define ARM_lr      uregs[14]
+#define ARM_sp      uregs[13]
+#define ARM_ip      uregs[12]
+#define ARM_fp      uregs[11]
+#define ARM_r10     uregs[10]
+#define ARM_r9      uregs[9]
+#define ARM_r8      uregs[8]
+#define ARM_r7      uregs[7]
+#define ARM_r6      uregs[6]
+#define ARM_r5      uregs[5]
+#define ARM_r4      uregs[4]
+#define ARM_r3      uregs[3]
+#define ARM_r2      uregs[2]
+#define ARM_r1      uregs[1]
+#define ARM_r0      uregs[0]
+
+#define ARM_SYSCALL_BASE    0 /* XXX: FreeBSD only */
+
+#define TARGET_FREEBSD_ARM_SYNC_ICACHE      0
+#define TARGET_FREEBSD_ARM_DRAIN_WRITEBUF   1
+#define TARGET_FREEBSD_ARM_SET_TP       2
+#define TARGET_FREEBSD_ARM_GET_TP       3
+
+#define TARGET_HW_MACHINE       "arm"
+#define TARGET_HW_MACHINE_ARCH  "armv6"
+
+#endif /* !__ARCH_SYSCALL_H_ */
bsd-user/arm/target_arch.h new file +13 -0
new file mode 100644
index 0000000..f186986
@@ -0,0 +1,13 @@
+
+#ifndef _TARGET_ARCH_H_
+#define _TARGET_ARCH_H_
+
+#include "cpu.h"
+
+/* main.c */
+static inline void start_exclusive(void);
+static inline void end_exclusive(void);
+static inline void cpu_exec_start(CPUState *env);
+static inline void cpu_exec_end(CPUState *env);
+
+#endif /* !_TARGET_ARCH_H_ */
bsd-user/arm/target_arch_cpu.c new file +0 -0
new file mode 100644
index 0000000..e69de29
bsd-user/arm/target_arch_cpu.h new file +405 -0

405 lines not on this page · raw message

bsd-user/arm/target_arch_signal.h new file +255 -0

255 lines not on this page · raw message

bsd-user/arm/target_arch_sigtramp.h new file +33 -0
new file mode 100644
index 0000000..98dc313
@@ -0,0 +1,33 @@
+
+#ifndef _TARGET_ARCH_SIGTRAMP_H_
+#define _TARGET_ARCH_SIGTRAMP_H_
+
+/* Compare to arm/arm/locore.S ENTRY_NP(sigcode) */
+static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
+        unsigned sys_sigreturn)
+{
+    int i;
+    uint32_t sys_exit = TARGET_FREEBSD_NR_exit;
+    /*
+     * The code has to load r7 manually rather than using
+     * "ldr r7, =SYS_return to make sure the size of the
+     * code is correct.
+     */
+    uint32_t sigtramp_code[] = {
+    /* 1 */ 0xE1A0000D,         /* mov r0, sp */
+    /* 2 */ 0xE59F700C,         /* ldr r7, [pc, #12] */
+    /* 3 */ 0xEF000000 + sys_sigreturn, /* swi (SYS_sigreturn) */
+    /* 4 */ 0xE59F7008,         /* ldr r7, [pc, #8] */
+    /* 5 */ 0xEF000000 + sys_exit,      /* swi (SYS_exit)*/
+    /* 6 */ 0xEAFFFFFA,         /* b . -16 */
+    /* 7 */ sys_sigreturn,
+    /* 8 */ sys_exit
+    };
+
+    for (i = 0; i < 8; i++) {
+        tswap32s(&sigtramp_code[i]);
+    }
+
+    return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE);
+}
+#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
bsd-user/arm/target_arch_sysarch.h new file +80 -0

80 lines not on this page · raw message

bsd-user/arm/target_arch_thread.h new file +40 -0
new file mode 100644
index 0000000..7090cd5
@@ -0,0 +1,40 @@
+/*
+ *  arm thread support
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_THREAD_H_
+#define _TARGET_ARCH_THREAD_H_
+
+/* Compare to arm/arm/vm_machdep.c cpu_set_upcall_kse() */
+static inline void
+thread_set_upcall(CPUARMState *regs, abi_ulong entry,
+    abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
+{
+    abi_ulong sp;
+
+    sp = ((stack_base + stack_size) & (8 - 1)) -
+        sizeof(struct target_trapframe);
+
+    /* fp = sp = stack base */
+    regs->regs[11] = regs->regs[13] = sp;
+    /* pc = start function entry */
+    regs->regs[15] = regs->regs[14] = entry & 0xfffffffe;
+    /* r0 = arg */
+    regs->regs[0] = arg;
+}
+
+#endif /* !_TARGET_ARCH_THREAD_H_ */
bsd-user/arm/target_arch_vmparam.h new file +49 -0

49 lines not on this page · raw message

bsd-user/freebsd/host_os.h new file +46 -0

46 lines not on this page · raw message

bsd-user/i386/target_arch.h new file +11 -0
new file mode 100644
index 0000000..5f14ee7
@@ -0,0 +1,11 @@
+
+#ifndef _TARGET_ARCH_H_
+#define _TARGET_ARCH_H_
+
+/* target_arch_cpu.c */
+void bsd_i386_write_dt(void *ptr, unsigned long addr, unsigned long limit,
+                int flags);
+void bsd_i386_set_idt(int n, unsigned int dpl);
+void bsd_i386_set_idt_base(uint64_t base);
+
+#endif /* ! _TARGET_ARCH_H_ */
bsd-user/i386/target_arch_cpu.c new file +79 -0

79 lines not on this page · raw message

bsd-user/i386/target_arch_cpu.h new file +290 -0

290 lines not on this page · raw message

bsd-user/i386/target_arch_signal.h +7 -0
index 7fd1399..d4f219e 100644
@@ -71,4 +71,11 @@ static inline abi_long set_mcontext(CPUX86State *regs,
     return -TARGET_EOPNOTSUPP;
 }
 
+static inline abi_long get_ucontext_sigreturn(CPUX86State *regs,
+                        abi_ulong target_sf, abi_ulong *target_uc)
+{
+    /* XXX */
+    return -TARGET_EOPNOTSUPP;
+}
+
 #endif /* TARGET_ARCH_SIGNAL_H */
bsd-user/main.c +38 -1024

1,199 lines not on this page · raw message

bsd-user/mips/target_arch.h new file +13 -0
new file mode 100644
index 0000000..f186986
@@ -0,0 +1,13 @@
+
+#ifndef _TARGET_ARCH_H_
+#define _TARGET_ARCH_H_
+
+#include "cpu.h"
+
+/* main.c */
+static inline void start_exclusive(void);
+static inline void end_exclusive(void);
+static inline void cpu_exec_start(CPUState *env);
+static inline void cpu_exec_end(CPUState *env);
+
+#endif /* !_TARGET_ARCH_H_ */
bsd-user/mips/target_arch_cpu.c new file +0 -0
new file mode 100644
index 0000000..e69de29
bsd-user/mips/target_arch_cpu.h new file +227 -0

227 lines not on this page · raw message

bsd-user/mips/target_arch_signal.h +9 -0
index 6be34c6..8d20e85 100644
@@ -225,4 +225,13 @@ static inline abi_long set_mcontext(CPUMIPSState *regs, target_mcontext_t *mcp,
     return err;
 }
 
+static inline abi_long get_ucontext_sigreturn(CPUMIPSState *regs,
+                abi_ulong target_sf, abi_ulong *target_uc)
+{
+
+    *target_uc = target_sf;
+    return 0;
+}
+
+
 #endif /* !_TARGET_ARCH_SIGNAL_H_ */
bsd-user/mips64/target_arch.h new file +13 -0
new file mode 100644
index 0000000..f186986
@@ -0,0 +1,13 @@
+
+#ifndef _TARGET_ARCH_H_
+#define _TARGET_ARCH_H_
+
+#include "cpu.h"
+
+/* main.c */
+static inline void start_exclusive(void);
+static inline void end_exclusive(void);
+static inline void cpu_exec_start(CPUState *env);
+static inline void cpu_exec_end(CPUState *env);
+
+#endif /* !_TARGET_ARCH_H_ */
bsd-user/mips64/target_arch_cpu.c new file +0 -0
new file mode 100644
index 0000000..e69de29
bsd-user/mips64/target_arch_cpu.h new file +226 -0

181 lines not on this page · raw message

bsd-user/mips64/target_arch_signal.h +9 -0
index ab84e0f..7f531c8 100644

Lines of this file are not shown. View the raw message.

bsd-user/mips64/touch_arch.cpu.c new file +0 -0
new file mode 100644
index 0000000..e69de29
bsd-user/netbsd/host_os.h new file +31 -0
new file mode 100644
index 0000000..5c492e3

Lines of this file are not shown. View the raw message.

bsd-user/openbsd/host_os.h new file +31 -0
new file mode 100644
index 0000000..162ce58

Lines of this file are not shown. View the raw message.

bsd-user/qemu.h +11 -0
index 3967e22..edc21d8 100644

Lines of this file are not shown. View the raw message.

bsd-user/signal.c +13 -7
index 4ee97af..b1c6743 100644

Lines of this file are not shown. View the raw message.

bsd-user/sparc/target_arch.h new file +9 -0
new file mode 100644
index 0000000..878bbc4

Lines of this file are not shown. View the raw message.

bsd-user/sparc/target_arch_cpu.c new file +113 -0

113 lines not on this page · raw message

bsd-user/sparc/target_arch_cpu.h new file +143 -0

143 lines not on this page · raw message

bsd-user/sparc/target_arch_signal.h +7 -0
index 70b89b9..5c54c78 100644

Lines of this file are not shown. View the raw message.

bsd-user/sparc64/target_arch.h new file +9 -0
new file mode 100644
index 0000000..06021ec

Lines of this file are not shown. View the raw message.

bsd-user/sparc64/target_arch_cpu.c new file +118 -0

118 lines not on this page · raw message

bsd-user/sparc64/target_arch_cpu.h new file +175 -0

175 lines not on this page · raw message

bsd-user/sparc64/target_arch_signal.h +7 -0
index cc075ed..4204807 100644

Lines of this file are not shown. View the raw message.

bsd-user/syscall.c +7 -0
index 0e639fe..84c3c63 100644

Lines of this file are not shown. View the raw message.

bsd-user/x86_64/target_arch.h new file +11 -0
new file mode 100644
index 0000000..a200af5

Lines of this file are not shown. View the raw message.

bsd-user/x86_64/target_arch_cpu.c new file +79 -0

79 lines not on this page · raw message

bsd-user/x86_64/target_arch_cpu.h new file +312 -0

312 lines not on this page · raw message

bsd-user/x86_64/target_arch_signal.h +9 -2
index 7525a56..9752684 100644

Lines of this file are not shown. View the raw message.

default-configs/arm-bsd-user.mak new file +3 -0
new file mode 100644
index 0000000..46d4aa2

Lines of this file are not shown. View the raw message.

default-configs/armeb-bsd-user.mak new file +3 -0
new file mode 100644
index 0000000..46d4aa2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.8

Part of the diff is not shown here. View the raw message.

#3 lore raw

Re: [Qemu-devel] [PATCH 02/23] bsd-user: add initial support for mips/mips64

In reply to Stacey Son
Quoted 22 lines · Stacey Son

Add the main cpu loop, cpu_loop(), for mips and mips64 architecture. Set the cpu model. Add some stubs for future code.

bsd-user/main.c +2 -0
@@ -2,6 +2,7 @@
  *  qemu user main
  *
  *  Copyright (c) 2003-2008 Fabrice Bellard
+ *  Copyright (c) 2013 Stacey Son
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -23,6 +24,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <machine/trap.h>
+#include <sys/syscall.h>
 #include <sys/types.h>
 #include <sys/mman.h>
 

bsd-user/main.c void cpu_loop(CPUX86State *env) · line 396

Quoted 8 lines
bsd-user/main.c +5 -0
@@ -387,6 +389,172 @@ void cpu_loop(CPUX86State *env)
 }
 #endif
 
+#if defined(TARGET_MIPS)
+
+/* Compare to sys/mips/mips/trap.c */
+
+void cpu_loop(CPUMIPSState *env)

I suspect you'd do better in the long term to restructure to pull cpu_loop out into a per-architecture source file and avoid the ifdefs. (This is something I'd like to do to the linux-user/ code, which is currently even more ifdef-ridden than bsd-user/.)

Quoted 12 lines
target-mips/mips-defs.h +4 -2
@@ -10,8 +10,17 @@
 
 #if defined(TARGET_MIPS64)
 #define TARGET_LONG_BITS 64
-#define TARGET_PHYS_ADDR_SPACE_BITS 36
-#define TARGET_VIRT_ADDR_SPACE_BITS 42
+#  if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
+#    define TARGET_PHYS_ADDR_SPACE_BITS 59
+#    ifdef TARGET_ABI32
+#       define TARGET_VIRT_ADDR_SPACE_BITS 32

target-mips/mips-defs.h line 26

Quoted 10 lines
target-mips/mips-defs.h +7 -0
+#    else
+#       define TARGET_VIRT_ADDR_SPACE_BITS 62
+#    endif
+#  else
+#    define TARGET_PHYS_ADDR_SPACE_BITS 36
+#    define TARGET_VIRT_ADDR_SPACE_BITS 42
+#  endif
 #else
 #define TARGET_LONG_BITS 32
 #define TARGET_PHYS_ADDR_SPACE_BITS 36

This looks a little fishy -- could you give some rationale? Why does only BSD need to do this? Why do you need to change the TARGET_PHYS_ADDR_SPACE_BITS for a -user target? Where do the numbers come from?

thanks
-- PMM

#34 lore raw

Re: [Qemu-devel] [PATCH 23/23] bsd-user: add arm cpu support

In reply to Stacey Son
Quoted 3 lines · Stacey Son

This change adds support for the arm cpu target. In addition, it moves the cpu dependent code out of main.c into the individual architecture directories and cleans up main.c in general. Credit for much of this code: Olivier Houchard.

Rule of thumb: if your commit message says "also" or "in addition" it's a sign it should probably be more than one patch.

Quoted 13 lines
 bsd-user/Makefile.objs                |    2 +-
 bsd-user/arm/syscall.h                |   36 ++
 bsd-user/arm/target_arch.h            |   13 +
 bsd-user/arm/target_arch_cpu.h        |  405 +++++++++++++
 bsd-user/arm/target_arch_signal.h     |  255 ++++++++
 bsd-user/arm/target_arch_sigtramp.h   |   33 +
 bsd-user/arm/target_arch_sysarch.h    |   80 +++
 bsd-user/arm/target_arch_thread.h     |   40 ++
 bsd-user/arm/target_arch_vmparam.h    |   49 ++
 bsd-user/freebsd/host_os.h            |   46 ++
 bsd-user/i386/target_arch.h           |   11 +
 bsd-user/i386/target_arch_cpu.c       |   79 +++
 bsd-user/i386/target_arch_cpu.h       |  290 +++++++++
Quoted 8 lines
 bsd-user/i386/target_arch_signal.h    |    7 +
 bsd-user/main.c                       | 1062 ++-------------------------------
 bsd-user/mips/target_arch.h           |   13 +
 bsd-user/mips/target_arch_cpu.h       |  227 +++++++
 bsd-user/mips/target_arch_signal.h    |    9 +
 bsd-user/mips64/target_arch.h         |   13 +
 bsd-user/mips64/target_arch_cpu.h     |  226 +++++++
 bsd-user/mips64/target_arch_signal.h  |    9 +

...in particular an "add ARM support" patch shouldn't be touching i386, mips, sparc, etc code.

thanks
-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH 03/23] bsd-user: additional seperation of OS and architecture dependent code

In reply to Stacey Son
Quoted 11 lines · Stacey Son

This change moves more OS dependent code into *bsd directories. Also moves architecture dependent code into the various arch directories. Add to 'configure' $TARGET_OS so the path to the target OS can be include file search path in the Makefile.

 bsd-user/mips/target_arch_signal.h     |   68 +++++++++++++++++++++
 bsd-user/mips/target_arch_vmparam.h    |   42 +++++++++++++
 bsd-user/mips/target_signal.h          |   38 ------------
 bsd-user/mips64/target_arch_signal.h   |   68 +++++++++++++++++++++
 bsd-user/mips64/target_arch_vmparam.h  |   42 +++++++++++++
 bsd-user/mips64/target_signal.h        |   38 ------------

You just added these files in patch 2, right? You need to reorder
things: get the structure right first, then just add the new code for MIPS in the right place.

thanks
-- PMM

#7 lore raw

Re: [Qemu-devel] [PATCH 03/23] bsd-user: additional seperation of OS and architecture dependent code

In reply to Stacey Son
Quoted 36 lines · Stacey Son
configure +4 -0
index ad32f87..749eba8 100755
@@ -432,6 +432,7 @@ if test -z "$ARCH"; then
 fi
 
 # OS specific
+TARGET_OS=""
 
 case $targetos in
 CYGWIN*)
@@ -457,6 +458,7 @@ FreeBSD)
   audio_possible_drivers="oss sdl esd pa"
   # needed for kinfo_getvmmap(3) in libutil.h
   LIBS="-lutil $LIBS"
+  TARGET_OS="freebsd"
 ;;
 DragonFly)
   bsd="yes"
@@ -470,12 +472,14 @@ NetBSD)
   audio_drv_list="oss"
   audio_possible_drivers="oss sdl esd"
   oss_lib="-lossaudio"
+  TARGET_OS="netbsd"
 ;;
 OpenBSD)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="sdl"
   audio_possible_drivers="sdl esd"
+  TARGET_OS="openbsd"
 ;;
 Darwin)
   bsd="yes"

configure upper() { · line 4279

Quoted 9 lines
configure +3 -0
@@ -4267,6 +4271,9 @@ upper() {
 
 target_arch_name="`upper $TARGET_ARCH`"
 echo "TARGET_$target_arch_name=y" >> $config_target_mak
+if [ "$TARGET_OS" != "" ]; then
+    echo "TARGET_OS=$TARGET_OS" >> $config_target_mak
+fi
 echo "TARGET_NAME=$target_name" >> $config_target_mak
 echo "TARGET_BASE_ARCH=$TARGET_BASE_ARCH" >> $config_target_mak
 if [ "$TARGET_ABI_DIR" = "" ]; then

This looks kind of fishy. What do you need this for that you can't do just by checking for relevant preprocessor defines like __OpenBSD__ directly in the bsd-user code?

thanks
-- PMM

#16 lore raw

Re: [Qemu-devel] [PATCH 10/23] bsd-user: add shims for memory management related syscalls

In reply to Stacey Son
Quoted 4 lines · Stacey Son

This change adds support for bsd memory management system calls including mmap(2), munmap(2), mprotect(2), msync(2), etc. Also, it adds shared memory management system calls. In addition, cleans up syscall.c a bit and fixes checkpatch.pl warnings and errors.

"Also" in a commit message again -- would be better split.

thanks
-- PMM

#24 lore raw

Re: [Qemu-devel] [PATCH 17/23] bsd-user: add shims for thread related system calls

In reply to Stacey Son
Quoted 29 lines · Stacey Son
configure +10 -0
index ba90975..812ea3f 100755
@@ -1438,6 +1438,15 @@ fi
 
 if test "$nptl" != "no" ; then
   cat > $TMPC <<EOF
+#ifdef __FreeBSD__
+#include <sys/thr.h>
+int main(void) {
+#if !defined(THR_SUSPENDED)
+#error bork
+#endif
+  return 0;
+}
+#else
 #include <sched.h>
 #include <linux/futex.h>
 int main(void) {
@@ -1446,6 +1455,7 @@ int main(void) {
 #endif
   return 0;
 }
+#endif
 EOF
 
   if compile_object ; then

configure case "$target_name" in · line 4218

Quoted 7 lines
configure +1 -0
@@ -4202,6 +4212,7 @@ case "$target_name" in
     TARGET_ARCH=mips64
     TARGET_BASE_ARCH=mips
     echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
+    target_nptl="yes"
   ;;
   moxie)
   ;;

I think this is the wrong way to do this. target_nptl should be a linux-user specific define (and we really ought to try to get rid of it altogether there at some point).

For bsd-user, the ideal would be if you could just support guest threads always, ie no #defines or configure checks needed. If you do need a configure check, then it should be its own, totally separate from CONFIG_NPTL. In any case, definitely do not make the Linux mistake of having "do we support threads?" be target specific if you can avoid it. (You might not be able to avoid it, though -- not sure :-( )

(I suspect these other MIPS targets should actually have target_nptl set as your patch fragment does, but that should be done as a linux-user bugfix patch, not buried in the bsd-user support patchset.)

include/qemu/tls.h line 44

Quoted 13 lines
include/qemu/tls.h +1 -1
index b92ea9d..ae7d79d 100644
@@ -38,7 +38,7 @@
  * TODO: proper implementations via Win32 .tls sections and
  * POSIX pthread_getspecific.
  */
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
 #define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x)
 #define DEFINE_TLS(type, x)  __thread __typeof__(type) tls__##x
 #define tls_var(x)           tls__##x

This should be its own patch (especially as it affects the system emulation code on FreeBSD hosts).

thanks
-- PMM

#31 lore raw

Re: [Qemu-devel] [PATCH 22/23] bsd-user: add more strace formating

In reply to Stacey Son
Quoted 4 lines · Stacey Son

This change add more strace formating for popular system calls. It also separates out *BSD and architecture dependent code. In addition, it changes TARGET_OS in configure (and in the associated makefiles) to what it should really be: HOST_OS.

You introduced TARGET_OS in the first place. Please don't put code in in one patch and then change it in a later one; rearrange your patchset to avoid this.

This patch is also doing too many things at once.

configure upper() { · line 4296

Quoted 3 lines
configure +3 -0
+if [ "$HOST_ABI_DIR" != "" ]; then
+    echo "HOST_ABI_DIR=$HOST_ABI_DIR" >> $config_target_mak
+fi

Host specific definitions in the target config? Doesn't look right.

-- PMM

#35 lore raw
In reply to Stacey Son
Quoted 14 lines · Stacey Son

This patch series add BSD user mode support for FreeBSD. In addition, it adds the necessary architecture dependent code for the mips, mips64, and arm targets. In its current state it can emulate most mips/mips64 and arm target binaries on a x86 host in a simple chroot environment (see https://wiki.freebsd.org/QemuUserModeHowTo for example).

Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible.

Quoted 1 line
 178 files changed, 23181 insertions(+), 2192 deletions(-)

This is an awful lot of code to ask people to review. Your patchset here is doing a lot of things:
* restructuring to put cpu dependent code into subdirs
* adding ARM support
* adding MIPS support
* adding support for lots of extra system calls
and it's also doing them all jumbled up together, and includes individual patches which do more than one thing at once.

I'm not the bsd-user maintainer, but my suggestion would be that you'll find it much easier to get your code submitted if you try to get these various new features added one at a time rather than all at once.

PS: for future bsd-user patch submissions you should cc Blue Swirl <[email protected]> who is the bsd-user maintainer (see the MAINTAINERS file).

thanks
-- PMM

#37 lore raw
In reply to Stacey Son
Quoted 234 lines · Stacey Son

Hi all,

This patch series add BSD user mode support for FreeBSD. In addition, it adds the necessary architecture dependent code for the mips, mips64, and arm targets. In its current state it can emulate most mips/mips64 and arm target binaries on a x86 host in a simple chroot environment (see https://wiki.freebsd.org/QemuUserModeHowTo for example).

To build this code it requires Ed Maste's configure/linker patches for using an alternate .text segment on FreeBSD. ie.

    https://github.com/emaste/qemu/commit/2fdae0f4172175dddbd19283a4607eae2a46587d

and the suggested change by Richard Henderson

    https://github.com/emaste/qemu/commit/ede607ad998bac1d44f2e3a79d5f5fb5e70c9f46

Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible.

I recognize and give credit to Olivier Houchard (arm dependent and other bsd-user code), Juergen Lock (FreeBSD qemu port owner), and Ed Maste (linker configuration). Also, to Andreas Tobler (initial PPC dependent code). I am sure I forgot someone and apoligize in advance.

Once this patch set has been has been reviewed and approved I can submit it as a pull request if desired.

Best Regards,

Stacey D. Son
---

Stacey Son (23):
bsd-user: initial code clean up
bsd-user: add initial support for mips/mips64
bsd-user: additional seperation of OS and architecture dependent code
bsd-user: add bsd signal emulation
bsd-user: add bsd_binprm to TaskState for core dumping emulation
bsd-user: fix thread initialization and ELF addresses for mips/mips64
bsd-user: find target executable in path when absolute path not given
bsd-user: initialize stack with signal trampolin code and canary
bsd-user: refresh FreeBSD's system call numbers
bsd-user: add shims for memory management related syscalls
bsd-user: add shims for file related system calls
bsd-user: add shims for time related system calls.
bsd-user: add shims for signal related system calls
bsd-user: add shims for process related system calls
bsd-user: add shims for socket related system calls
bsd-user: add shims for stat and file handle related syscalls
bsd-user: add shims for thread related system calls
bsd-user: add shim for the ioctl system call
bsd-user: add shims for sysarch() and sysctl() system calls
bsd-user: add shims for extended attributes system calls
bsd-user: add miscellaneous system call shims
bsd-user: add more strace formating
bsd-user: add arm cpu support

 Makefile.target                         |    5 +-
 bsd-user/Makefile.objs                  |    9 +-
 bsd-user/arm/syscall.h                  |   36 +
 bsd-user/arm/target_arch.h              |   13 +
 bsd-user/arm/target_arch_cpu.h          |  405 +++++++
 bsd-user/arm/target_arch_signal.h       |  255 ++++
 bsd-user/arm/target_arch_sigtramp.h     |   33 +
 bsd-user/arm/target_arch_sysarch.h      |   80 ++
 bsd-user/arm/target_arch_thread.h       |   40 +
 bsd-user/arm/target_arch_vmparam.h      |   49 +
 bsd-user/bsd-file.h                     | 1095 ++++++++++++++++++
 bsd-user/bsd-mem.c                      |  122 ++
 bsd-user/bsd-mem.h                      |  387 +++++++
 bsd-user/bsd-misc.c                     |  209 ++++
 bsd-user/bsd-misc.h                     |  339 ++++++
 bsd-user/bsd-mman.h                     |  121 --
 bsd-user/bsd-proc.c                     |  160 +++
 bsd-user/bsd-proc.h                     |  434 +++++++
 bsd-user/bsd-signal.h                   |  232 ++++
 bsd-user/bsd-socket.c                   |  108 ++
 bsd-user/bsd-socket.h                   |  266 +++++
 bsd-user/bsdload.c                      |  139 ++-
 bsd-user/elfload.c                      |  387 ++++---
 bsd-user/errno_defs.h                   |   13 +-
 bsd-user/freebsd/host_os.h              |   46 +
 bsd-user/freebsd/ioctl-cmds.h           |   47 +
 bsd-user/freebsd/ioctl-filio.h          |   45 +
 bsd-user/freebsd/ioctl-ioccom.h         |   54 +
 bsd-user/freebsd/ioctl-ttycom.h         |  257 ++++
 bsd-user/freebsd/ioctl-types.h          |    7 +
 bsd-user/freebsd/os-extattr.c           |  119 ++
 bsd-user/freebsd/os-extattr.h           |  644 +++++++++++
 bsd-user/freebsd/os-misc.h              |  442 +++++++
 bsd-user/freebsd/os-proc.c              |  234 ++++
 bsd-user/freebsd/os-proc.h              |  427 +++++++
 bsd-user/freebsd/os-signal.h            |   43 +
 bsd-user/freebsd/os-socket.c            |  149 +++
 bsd-user/freebsd/os-socket.h            |  548 +++++++++
 bsd-user/freebsd/os-stat.c              |  234 ++++
 bsd-user/freebsd/os-stat.h              |  437 +++++++
 bsd-user/freebsd/os-strace.h            |   29 +
 bsd-user/freebsd/os-sys.c               |  268 +++++
 bsd-user/freebsd/os-thread.c            |  802 +++++++++++++
 bsd-user/freebsd/os-thread.h            |  742 ++++++++++++
 bsd-user/freebsd/os-time.c              |  205 ++++
 bsd-user/freebsd/os-time.h              |  602 ++++++++++
 bsd-user/freebsd/qemu-os.h              |   77 ++
 bsd-user/freebsd/strace.list            |   76 ++-
 bsd-user/freebsd/syscall_nr.h           |  813 +++++++------
 bsd-user/freebsd/target_os_siginfo.h    |  100 ++
 bsd-user/freebsd/target_os_signal.h     |   79 ++
 bsd-user/freebsd/target_os_stack.h      |  124 ++
 bsd-user/freebsd/target_os_vmparam.h    |   19 +
 bsd-user/i386/syscall.h                 |   23 +
 bsd-user/i386/target_arch.h             |   11 +
 bsd-user/i386/target_arch_cpu.c         |   79 ++
 bsd-user/i386/target_arch_cpu.h         |  290 +++++
 bsd-user/i386/target_arch_signal.h      |   81 ++
 bsd-user/i386/target_arch_sigtramp.h    |   11 +
 bsd-user/i386/target_arch_sysarch.h     |   78 ++
 bsd-user/i386/target_arch_thread.h      |   30 +
 bsd-user/i386/target_arch_vmparam.h     |   26 +
 bsd-user/i386/target_signal.h           |   20 -
 bsd-user/ioctl.c                        |  447 +++++++
 bsd-user/main.c                         |  875 +++------------
 bsd-user/mips/syscall.h                 |   52 +
 bsd-user/mips/target_arch.h             |   13 +
 bsd-user/mips/target_arch_cpu.h         |  227 ++++
 bsd-user/mips/target_arch_signal.h      |  237 ++++
 bsd-user/mips/target_arch_sigtramp.h    |   23 +
 bsd-user/mips/target_arch_sysarch.h     |   69 ++
 bsd-user/mips/target_arch_thread.h      |   45 +
 bsd-user/mips/target_arch_vmparam.h     |   47 +
 bsd-user/mips64/syscall.h               |   53 +
 bsd-user/mips64/target_arch.h           |   13 +
 bsd-user/mips64/target_arch_cpu.h       |  226 ++++
 bsd-user/mips64/target_arch_signal.h    |  236 ++++
 bsd-user/mips64/target_arch_sigtramp.h  |   23 +
 bsd-user/mips64/target_arch_sysarch.h   |   69 ++
 bsd-user/mips64/target_arch_thread.h    |   45 +
 bsd-user/mips64/target_arch_vmparam.h   |   47 +
 bsd-user/mmap.c                         |  108 +--
 bsd-user/netbsd/host_os.h               |   31 +
 bsd-user/netbsd/ioctl-cmds.h            |   48 +
 bsd-user/netbsd/ioctl-filio.h           |   29 +
 bsd-user/netbsd/ioctl-ioccom.h          |   38 +
 bsd-user/netbsd/ioctl-ttycom.h          |  240 ++++
 bsd-user/netbsd/ioctl-types.h           |    7 +
 bsd-user/netbsd/os-extattr.h            |  247 ++++
 bsd-user/netbsd/os-proc.c               |   11 +
 bsd-user/netbsd/os-proc.h               |  243 ++++
 bsd-user/netbsd/os-signal.h             |   34 +
 bsd-user/netbsd/os-socket.c             |    1 +
 bsd-user/netbsd/os-socket.h             |   98 ++
 bsd-user/netbsd/os-stat.c               |    1 +
 bsd-user/netbsd/os-stat.h               |  176 +++
 bsd-user/netbsd/os-strace.h             |    1 +
 bsd-user/netbsd/os-sys.c                |   46 +
 bsd-user/netbsd/os-time.c               |    1 +
 bsd-user/netbsd/os-time.h               |  179 +++
 bsd-user/netbsd/qemu-os.h               |    1 +
 bsd-user/netbsd/strace.list             |   18 +
 bsd-user/netbsd/syscall_nr.h            |   24 +-
 bsd-user/netbsd/target_os_siginfo.h     |   82 ++
 bsd-user/netbsd/target_os_signal.h      |   70 ++
 bsd-user/netbsd/target_os_stack.h       |   31 +
 bsd-user/netbsd/target_os_vmparam.h     |   17 +
 bsd-user/openbsd/host_os.h              |   31 +
 bsd-user/openbsd/ioctl-cmds.h           |   48 +
 bsd-user/openbsd/ioctl-filio.h          |   29 +
 bsd-user/openbsd/ioctl-ioccom.h         |   38 +
 bsd-user/openbsd/ioctl-ttycom.h         |  240 ++++
 bsd-user/openbsd/ioctl-types.h          |    7 +
 bsd-user/openbsd/os-extattr.h           |  247 ++++
 bsd-user/openbsd/os-proc.c              |   11 +
 bsd-user/openbsd/os-proc.h              |  243 ++++
 bsd-user/openbsd/os-signal.h            |   34 +
 bsd-user/openbsd/os-socket.c            |    1 +
 bsd-user/openbsd/os-socket.h            |   98 ++
 bsd-user/openbsd/os-stat.c              |    1 +
 bsd-user/openbsd/os-stat.h              |  176 +++
 bsd-user/openbsd/os-strace.h            |    1 +
 bsd-user/openbsd/os-sys.c               |   46 +
 bsd-user/openbsd/os-time.c              |    1 +
 bsd-user/openbsd/os-time.h              |  179 +++
 bsd-user/openbsd/qemu-os.h              |    1 +
 bsd-user/openbsd/strace.list            |   18 +
 bsd-user/openbsd/syscall_nr.h           |   24 +-
 bsd-user/openbsd/target_os_siginfo.h    |   82 ++
 bsd-user/openbsd/target_os_signal.h     |   70 ++
 bsd-user/openbsd/target_os_stack.h      |   31 +
 bsd-user/openbsd/target_os_vmparam.h    |   17 +
 bsd-user/qemu-bsd.h                     |   79 ++
 bsd-user/qemu.h                         |  195 +++-
 bsd-user/signal.c                       |  923 +++++++++++++++-
 bsd-user/sparc/syscall.h                |   29 +-
 bsd-user/sparc/target_arch.h            |    9 +
 bsd-user/sparc/target_arch_cpu.c        |  113 ++
 bsd-user/sparc/target_arch_cpu.h        |  143 +++
 bsd-user/sparc/target_arch_signal.h     |   64 +
 bsd-user/sparc/target_arch_sigtramp.h   |   11 +
 bsd-user/sparc/target_arch_sysarch.h    |   52 +
 bsd-user/sparc/target_arch_thread.h     |   30 +
 bsd-user/sparc/target_arch_vmparam.h    |   35 +
 bsd-user/sparc/target_signal.h          |   27 -
 bsd-user/sparc64/syscall.h              |   28 +-
 bsd-user/sparc64/target_arch.h          |    9 +
 bsd-user/sparc64/target_arch_cpu.c      |  118 ++
 bsd-user/sparc64/target_arch_cpu.h      |  175 +++
 bsd-user/sparc64/target_arch_signal.h   |   81 ++
 bsd-user/sparc64/target_arch_sigtramp.h |   11 +
 bsd-user/sparc64/target_arch_sysarch.h  |   52 +
 bsd-user/sparc64/target_arch_thread.h   |   30 +
 bsd-user/sparc64/target_arch_vmparam.h  |   37 +
 bsd-user/sparc64/target_signal.h        |   27 -
 bsd-user/strace.c                       |  175 ++-
 bsd-user/syscall.c                      | 1929 ++++++++++++++++++++++++-------
 bsd-user/syscall_defs.h                 |  790 +++++++++++--
 bsd-user/uaccess.c                      |   20 +-
 bsd-user/x86_64/syscall.h               |   26 +-
 bsd-user/x86_64/target_arch.h           |   11 +
 bsd-user/x86_64/target_arch_cpu.c       |   79 ++
 bsd-user/x86_64/target_arch_cpu.h       |  312 +++++
 bsd-user/x86_64/target_arch_signal.h    |   81 ++
 bsd-user/x86_64/target_arch_sigtramp.h  |   11 +
 bsd-user/x86_64/target_arch_sysarch.h   |   76 ++
 bsd-user/x86_64/target_arch_thread.h    |   30 +
 bsd-user/x86_64/target_arch_vmparam.h   |   28 +
 bsd-user/x86_64/target_signal.h         |   19 -
 configure                               |   25 +-
 default-configs/arm-bsd-user.mak        |    3 +
Quoted 8 lines
 default-configs/armeb-bsd-user.mak      |    3 +
 default-configs/mips-bsd-user.mak       |    1 +
 default-configs/mips64-bsd-user.mak     |    1 +
 default-configs/mips64el-bsd-user.mak   |    1 +
 default-configs/mipsel-bsd-user.mak     |    1 +
 include/qemu/tls.h                      |    2 +-
 target-mips/mips-defs.h                 |   13 +-
 178 files changed, 23181 insertions(+), 2192 deletions(-)

There is no humanly way 23k LOC can be reviewed in a single series.

Has this been maintained out of tree for some time? Is it largely copy/paste from linux-user?

Regards,

Anthony Liguori

Quoted 159 lines
 create mode 100644 bsd-user/arm/syscall.h
 create mode 100644 bsd-user/arm/target_arch.h
 create mode 100644 bsd-user/arm/target_arch_cpu.c
 create mode 100644 bsd-user/arm/target_arch_cpu.h
 create mode 100644 bsd-user/arm/target_arch_signal.h
 create mode 100644 bsd-user/arm/target_arch_sigtramp.h
 create mode 100644 bsd-user/arm/target_arch_sysarch.h
 create mode 100644 bsd-user/arm/target_arch_thread.h
 create mode 100644 bsd-user/arm/target_arch_vmparam.h
 create mode 100644 bsd-user/bsd-file.h
 create mode 100644 bsd-user/bsd-mem.c
 create mode 100644 bsd-user/bsd-mem.h
 create mode 100644 bsd-user/bsd-misc.c
 create mode 100644 bsd-user/bsd-misc.h
 delete mode 100644 bsd-user/bsd-mman.h
 create mode 100644 bsd-user/bsd-proc.c
 create mode 100644 bsd-user/bsd-proc.h
 create mode 100644 bsd-user/bsd-signal.h
 create mode 100644 bsd-user/bsd-socket.c
 create mode 100644 bsd-user/bsd-socket.h
 create mode 100644 bsd-user/freebsd/host_os.h
 create mode 100644 bsd-user/freebsd/ioctl-cmds.h
 create mode 100644 bsd-user/freebsd/ioctl-filio.h
 create mode 100644 bsd-user/freebsd/ioctl-ioccom.h
 create mode 100644 bsd-user/freebsd/ioctl-ttycom.h
 create mode 100644 bsd-user/freebsd/ioctl-types.h
 create mode 100644 bsd-user/freebsd/os-extattr.c
 create mode 100644 bsd-user/freebsd/os-extattr.h
 create mode 100644 bsd-user/freebsd/os-misc.h
 create mode 100644 bsd-user/freebsd/os-proc.c
 create mode 100644 bsd-user/freebsd/os-proc.h
 create mode 100644 bsd-user/freebsd/os-signal.h
 create mode 100644 bsd-user/freebsd/os-socket.c
 create mode 100644 bsd-user/freebsd/os-socket.h
 create mode 100644 bsd-user/freebsd/os-stat.c
 create mode 100644 bsd-user/freebsd/os-stat.h
 create mode 100644 bsd-user/freebsd/os-strace.h
 create mode 100644 bsd-user/freebsd/os-sys.c
 create mode 100644 bsd-user/freebsd/os-thread.c
 create mode 100644 bsd-user/freebsd/os-thread.h
 create mode 100644 bsd-user/freebsd/os-time.c
 create mode 100644 bsd-user/freebsd/os-time.h
 create mode 100644 bsd-user/freebsd/qemu-os.h
 create mode 100644 bsd-user/freebsd/target_os_siginfo.h
 create mode 100644 bsd-user/freebsd/target_os_signal.h
 create mode 100644 bsd-user/freebsd/target_os_stack.h
 create mode 100644 bsd-user/freebsd/target_os_vmparam.h
 create mode 100644 bsd-user/i386/target_arch.h
 create mode 100644 bsd-user/i386/target_arch_cpu.c
 create mode 100644 bsd-user/i386/target_arch_cpu.h
 create mode 100644 bsd-user/i386/target_arch_signal.h
 create mode 100644 bsd-user/i386/target_arch_sigtramp.h
 create mode 100644 bsd-user/i386/target_arch_sysarch.h
 create mode 100644 bsd-user/i386/target_arch_thread.h
 create mode 100644 bsd-user/i386/target_arch_vmparam.h
 delete mode 100644 bsd-user/i386/target_signal.h
 create mode 100644 bsd-user/ioctl.c
 create mode 100644 bsd-user/mips/syscall.h
 create mode 100644 bsd-user/mips/target_arch.h
 create mode 100644 bsd-user/mips/target_arch_cpu.c
 create mode 100644 bsd-user/mips/target_arch_cpu.h
 create mode 100644 bsd-user/mips/target_arch_signal.h
 create mode 100644 bsd-user/mips/target_arch_sigtramp.h
 create mode 100644 bsd-user/mips/target_arch_sysarch.h
 create mode 100644 bsd-user/mips/target_arch_thread.h
 create mode 100644 bsd-user/mips/target_arch_vmparam.h
 create mode 100644 bsd-user/mips64/syscall.h
 create mode 100644 bsd-user/mips64/target_arch.h
 create mode 100644 bsd-user/mips64/target_arch_cpu.c
 create mode 100644 bsd-user/mips64/target_arch_cpu.h
 create mode 100644 bsd-user/mips64/target_arch_signal.h
 create mode 100644 bsd-user/mips64/target_arch_sigtramp.h
 create mode 100644 bsd-user/mips64/target_arch_sysarch.h
 create mode 100644 bsd-user/mips64/target_arch_thread.h
 create mode 100644 bsd-user/mips64/target_arch_vmparam.h
 create mode 100644 bsd-user/mips64/touch_arch.cpu.c
 create mode 100644 bsd-user/netbsd/host_os.h
 create mode 100644 bsd-user/netbsd/ioctl-cmds.h
 create mode 100644 bsd-user/netbsd/ioctl-filio.h
 create mode 100644 bsd-user/netbsd/ioctl-ioccom.h
 create mode 100644 bsd-user/netbsd/ioctl-ttycom.h
 create mode 100644 bsd-user/netbsd/ioctl-types.h
 create mode 100644 bsd-user/netbsd/os-extattr.h
 create mode 100644 bsd-user/netbsd/os-proc.c
 create mode 100644 bsd-user/netbsd/os-proc.h
 create mode 100644 bsd-user/netbsd/os-signal.h
 create mode 100644 bsd-user/netbsd/os-socket.c
 create mode 100644 bsd-user/netbsd/os-socket.h
 create mode 100644 bsd-user/netbsd/os-stat.c
 create mode 100644 bsd-user/netbsd/os-stat.h
 create mode 100644 bsd-user/netbsd/os-strace.h
 create mode 100644 bsd-user/netbsd/os-sys.c
 create mode 100644 bsd-user/netbsd/os-time.c
 create mode 100644 bsd-user/netbsd/os-time.h
 create mode 100644 bsd-user/netbsd/qemu-os.h
 create mode 100644 bsd-user/netbsd/target_os_siginfo.h
 create mode 100644 bsd-user/netbsd/target_os_signal.h
 create mode 100644 bsd-user/netbsd/target_os_stack.h
 create mode 100644 bsd-user/netbsd/target_os_vmparam.h
 create mode 100644 bsd-user/openbsd/host_os.h
 create mode 100644 bsd-user/openbsd/ioctl-cmds.h
 create mode 100644 bsd-user/openbsd/ioctl-filio.h
 create mode 100644 bsd-user/openbsd/ioctl-ioccom.h
 create mode 100644 bsd-user/openbsd/ioctl-ttycom.h
 create mode 100644 bsd-user/openbsd/ioctl-types.h
 create mode 100644 bsd-user/openbsd/os-extattr.h
 create mode 100644 bsd-user/openbsd/os-proc.c
 create mode 100644 bsd-user/openbsd/os-proc.h
 create mode 100644 bsd-user/openbsd/os-signal.h
 create mode 100644 bsd-user/openbsd/os-socket.c
 create mode 100644 bsd-user/openbsd/os-socket.h
 create mode 100644 bsd-user/openbsd/os-stat.c
 create mode 100644 bsd-user/openbsd/os-stat.h
 create mode 100644 bsd-user/openbsd/os-strace.h
 create mode 100644 bsd-user/openbsd/os-sys.c
 create mode 100644 bsd-user/openbsd/os-time.c
 create mode 100644 bsd-user/openbsd/os-time.h
 create mode 100644 bsd-user/openbsd/qemu-os.h
 create mode 100644 bsd-user/openbsd/target_os_siginfo.h
 create mode 100644 bsd-user/openbsd/target_os_signal.h
 create mode 100644 bsd-user/openbsd/target_os_stack.h
 create mode 100644 bsd-user/openbsd/target_os_vmparam.h
 create mode 100644 bsd-user/qemu-bsd.h
 create mode 100644 bsd-user/sparc/target_arch.h
 create mode 100644 bsd-user/sparc/target_arch_cpu.c
 create mode 100644 bsd-user/sparc/target_arch_cpu.h
 create mode 100644 bsd-user/sparc/target_arch_signal.h
 create mode 100644 bsd-user/sparc/target_arch_sigtramp.h
 create mode 100644 bsd-user/sparc/target_arch_sysarch.h
 create mode 100644 bsd-user/sparc/target_arch_thread.h
 create mode 100644 bsd-user/sparc/target_arch_vmparam.h
 delete mode 100644 bsd-user/sparc/target_signal.h
 create mode 100644 bsd-user/sparc64/target_arch.h
 create mode 100644 bsd-user/sparc64/target_arch_cpu.c
 create mode 100644 bsd-user/sparc64/target_arch_cpu.h
 create mode 100644 bsd-user/sparc64/target_arch_signal.h
 create mode 100644 bsd-user/sparc64/target_arch_sigtramp.h
 create mode 100644 bsd-user/sparc64/target_arch_sysarch.h
 create mode 100644 bsd-user/sparc64/target_arch_thread.h
 create mode 100644 bsd-user/sparc64/target_arch_vmparam.h
 delete mode 100644 bsd-user/sparc64/target_signal.h
 create mode 100644 bsd-user/x86_64/target_arch.h
 create mode 100644 bsd-user/x86_64/target_arch_cpu.c
 create mode 100644 bsd-user/x86_64/target_arch_cpu.h
 create mode 100644 bsd-user/x86_64/target_arch_signal.h
 create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h
 create mode 100644 bsd-user/x86_64/target_arch_sysarch.h
 create mode 100644 bsd-user/x86_64/target_arch_thread.h
 create mode 100644 bsd-user/x86_64/target_arch_vmparam.h
 delete mode 100644 bsd-user/x86_64/target_signal.h
 create mode 100644 default-configs/arm-bsd-user.mak
 create mode 100644 default-configs/armeb-bsd-user.mak
 create mode 100644 default-configs/mips-bsd-user.mak
 create mode 100644 default-configs/mips64-bsd-user.mak
 create mode 100644 default-configs/mips64el-bsd-user.mak
 create mode 100644 default-configs/mipsel-bsd-user.mak
Signature · 1 line
1.7.8
author
#36 lore raw
In reply to Peter Maydell
Quoted 17 lines · Peter Maydell
Quoted 14 lines · Stacey Son

This patch series add BSD user mode support for FreeBSD. In addition, it adds the necessary architecture dependent code for the mips, mips64, and arm targets. In its current state it can emulate most mips/mips64 and arm target binaries on a x86 host in a simple chroot environment (see https://wiki.freebsd.org/QemuUserModeHowTo for example).

Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible.

Quoted 1 line
178 files changed, 23181 insertions(+), 2192 deletions(-)
Quoted 8 lines

This is an awful lot of code to ask people to review. Your patchset here is doing a lot of things:
* restructuring to put cpu dependent code into subdirs
* adding ARM support
* adding MIPS support
* adding support for lots of extra system calls
and it's also doing them all jumbled up together, and includes individual patches which do more than one thing at once.

Sorry about that. Yes, this patch set is adding a lot of code. It has been maintained as a huge set patches in the FreeBSD qemu-devel port for some time but I finally cleaned it up and checkpatch.pl it all.

Quoted 4 lines

I'm not the bsd-user maintainer, but my suggestion would be that you'll find it much easier to get your code submitted if you try to get these various new features added one at a time rather than all at once.

Such as one system call shim at a time? That would be a lot of emails to this list. :)

The patch set does break down the individual features into individual patches such as groups of system call shims. Of course, those patches are indeed still quite large. I do apologize for that.

Quoted 3 lines

PS: for future bsd-user patch submissions you should cc Blue Swirl <[email protected]> who is the bsd-user maintainer (see the MAINTAINERS file).

Done.

Thanks,

-stacey.

author
#38 lore raw
In reply to Anthony Liguori
Quoted 1 line · Anthony Liguori

There is no humanly way 23k LOC can be reviewed in a single series.

Yes, indeed, it is a lot of code.

Quoted 1 line

Has this been maintained out of tree for some time?

Yes, it has been a large, ugly patch set in the FreeBSD qemu-devel port for some time.

Quoted 2 lines

Is it largely
copy/paste from linux-user?

A good amount of the initial code came from linux-user but then diverged when the code was restructured to put cpu and *BSD dependent code into its own subdirs which I believe was the original thought on how the code was to be structured.

Regards,

-stacey.

#39 lore raw
Quoted 10 lines · Stacey Son
Quoted 1 line · Anthony Liguori

There is no humanly way 23k LOC can be reviewed in a single series.

Yes, indeed, it is a lot of code.

Quoted 1 line

Has this been maintained out of tree for some time?

Yes, it has been a large, ugly patch set in the FreeBSD qemu-devel port for some time.

Okay, I assume there were many collaborators then? You may want to consider collecting some additional Signed-off-bys then from the original authors. I don't like the idea merging a very large patch series without preserving authorship info.

Quoted 8 lines
Quoted 3 lines

Is it largely
copy/paste from linux-user?

A good amount of the initial code came from linux-user but then diverged when the code was restructured to put cpu and *BSD dependent code into its own subdirs which I believe was the original thought on how the code was to be structured.

I think Peter made some suggestions about how to split things up...

Regards,

Anthony Liguori

Quoted 3 lines

Regards,
-stacey.

author
#4 lore raw

Re: [Qemu-devel] [PATCH 02/23] bsd-user: add initial support for mips/mips64

In reply to Peter Maydell
Quoted 12 lines · Peter Maydell

bsd-user/main.c void cpu_loop(CPUX86State *env) · line 396

Quoted 6 lines
bsd-user/main.c +5 -0
+#if defined(TARGET_MIPS)
+
+/* Compare to sys/mips/mips/trap.c */
+
+void cpu_loop(CPUMIPSState *env)

I suspect you'd do better in the long term to restructure to pull cpu_loop out into a per-architecture source file and avoid the ifdefs. (This is something I'd like to do to the linux-user/ code, which is currently even more ifdef-ridden than bsd-user/.)

Yes, the cpu_loop()'s and the cpu initialization code is actually separated out in the arm arch patch for all the arch's.

Quoted 20 lines
Quoted 20 lines
target-mips/mips-defs.h +11 -2
@@ -10,8 +10,17 @@
 
 #if defined(TARGET_MIPS64)
 #define TARGET_LONG_BITS 64
-#define TARGET_PHYS_ADDR_SPACE_BITS 36
-#define TARGET_VIRT_ADDR_SPACE_BITS 42
+#  if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
+#    define TARGET_PHYS_ADDR_SPACE_BITS 59
+#    ifdef TARGET_ABI32
+#       define TARGET_VIRT_ADDR_SPACE_BITS 32
+#    else
+#       define TARGET_VIRT_ADDR_SPACE_BITS 62
+#    endif
+#  else
+#    define TARGET_PHYS_ADDR_SPACE_BITS 36
+#    define TARGET_VIRT_ADDR_SPACE_BITS 42
+#  endif
Quoted 8 lines

target-mips/mips-defs.h line 26

Quoted 3 lines
target-mips/mips-defs.h +0 -0
 #else
 #define TARGET_LONG_BITS 32
 #define TARGET_PHYS_ADDR_SPACE_BITS 36

This looks a little fishy -- could you give some rationale? Why does only BSD need to do this? Why do you need to change the TARGET_PHYS_ADDR_SPACE_BITS for a -user target? Where do the numbers come from?

If I remember correctly these:

Quoted 7 lines

target-mips/mips-defs.h line 19

Quoted 7 lines
target-mips/mips-defs.h +7 -0
+#  if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
+#    define TARGET_PHYS_ADDR_SPACE_BITS 59
+#    ifdef TARGET_ABI32
+#       define TARGET_VIRT_ADDR_SPACE_BITS 32
+#    else
+#       define TARGET_VIRT_ADDR_SPACE_BITS 62
+#    endif

come from the See Mips Run book.

The reason they were changed for the bsd-user is FreeBSD puts the text segment in something like 0x12000000 (plus or minus a zero) and the stack at 0x8000000000 (- minus a page or two) for mips64 which didn't work as defined originally.

-stacey.

author
#8 lore raw

Re: [Qemu-devel] [PATCH 03/23] bsd-user: additional seperation of OS and architecture dependent code

In reply to Peter Maydell
Quoted 38 lines · Peter Maydell
Quoted 37 lines · Stacey Son
configure +0 -0
index ad32f87..749eba8 100755
@@ -432,6 +432,7 @@ if test -z "$ARCH"; then

fi

# OS specific
+TARGET_OS=""

case $targetos in
CYGWIN*)

configure +3 -0
@@ -457,6 +458,7 @@ FreeBSD)
  audio_possible_drivers="oss sdl esd pa"
  # needed for kinfo_getvmmap(3) in libutil.h
  LIBS="-lutil $LIBS"
+  TARGET_OS="freebsd"
 ;;
 DragonFly)
  bsd="yes"
@@ -470,12 +472,14 @@ NetBSD)
  audio_drv_list="oss"
  audio_possible_drivers="oss sdl esd"
  oss_lib="-lossaudio"
+  TARGET_OS="netbsd"
 ;;
 OpenBSD)
  bsd="yes"
  make="${MAKE-gmake}"
  audio_drv_list="sdl"
  audio_possible_drivers="sdl esd"
+  TARGET_OS="openbsd"
 ;;
 Darwin)
  bsd="yes"
@@ -4267,6 +4271,9 @@ upper() {
 
Quoted 12 lines
Quoted 8 lines

target_arch_name="upper $TARGET_ARCH"
echo "TARGET_$target_arch_name=y" >> $config_target_mak

configure +3 -0
+if [ "$TARGET_OS" != "" ]; then
+    echo "TARGET_OS=$TARGET_OS" >> $config_target_mak
+fi

echo "TARGET_NAME=$target_name" >> $config_target_mak echo "TARGET_BASE_ARCH=$TARGET_BASE_ARCH" >> $config_target_mak if [ "$TARGET_ABI_DIR" = "" ]; then

This looks kind of fishy. What do you need this for that you can't do just by checking for relevant preprocessor defines like __OpenBSD__ directly in the bsd-user code?

Note that the OS dependent directories are "freebsd", "netbsd", and "openbsd". This is used in the Makefiles to use the correct OS dependent (which eliminates much of the "#if defined(__OpenBSD__)" in the code files themselves).

Regards,

-stacey.

author
#40 lore raw
In reply to Anthony Liguori
Quoted 10 lines · Anthony Liguori
Quoted 8 lines · Stacey Son
Quoted 1 line · Anthony Liguori

There is no humanly way 23k LOC can be reviewed in a single series.

Yes, indeed, it is a lot of code.

Quoted 1 line

Has this been maintained out of tree for some time?

Quoted 7 lines
Quoted 2 lines

Yes, it has been a large, ugly patch set in the FreeBSD qemu-devel port for some time.

Okay, I assume there were many collaborators then? You may want to consider collecting some additional Signed-off-bys then from the original authors. I don't like the idea merging a very large patch series without preserving authorship info.

No, not a lot of collaborators and most of the code comes from me. The exceptions are:

(1) A lot of the arm dependent code comes from Olivier Houchard. He also added some some system call shims. I noted this in the cover letter but, yes, I should add signed-off-bys and you pointed out.

(2) Some of the system call shims comes from the linux-user code.

(3) I have some initial ppc dependent from Andreas Tobler. Of course, none of that code is included (yet).

(4) Juergen Lock, who maintains the FreeBSD port, has given me build patches for older (and supported) FreeBSD versions.

Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

Is it largely
copy/paste from linux-user?

A good amount of the initial code came from linux-user but then diverged when the code was restructured to put cpu and *BSD dependent code into its own subdirs which I believe was the original thought on how the code was to be structured.

I think Peter made some suggestions about how to split things up...

Yes, Peter has made some good suggestions and I'll work on splitting things up a bit more.

Thanks,

-stacey.

author
#25 lore raw

Re: [Qemu-devel] [PATCH 17/23] bsd-user: add shims for thread related system calls

In reply to Peter Maydell
Quoted 42 lines · Peter Maydell
Quoted 29 lines · Stacey Son
configure +0 -0
index ba90975..812ea3f 100755
@@ -1438,6 +1438,15 @@ fi
 

if test "$nptl" != "no" ; then
cat > $TMPC <<EOF

configure +9 -0
+#ifdef __FreeBSD__
+#include <sys/thr.h>
+int main(void) {
+#if !defined(THR_SUSPENDED)
+#error bork
+#endif
+  return 0;
+}
+#else

#include <sched.h>
#include <linux/futex.h>
int main(void) {

configure +1 -0
@@ -1446,6 +1455,7 @@ int main(void) {
 #endif
  return 0;
 }
+#endif

EOF

if compile_object ; then

configure case "$target_name" in · line 4218

Quoted 7 lines
configure +1 -0
@@ -4202,6 +4212,7 @@ case "$target_name" in
    TARGET_ARCH=mips64
    TARGET_BASE_ARCH=mips
    echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
+    target_nptl="yes"
  ;;
  moxie)
  ;;

I think this is the wrong way to do this. target_nptl should be a linux-user specific define (and we really ought to try to get rid of it altogether there at some point).

Quoted 7 lines

For bsd-user, the ideal would be if you could just support guest threads always, ie no #defines or configure checks needed. If you do need a configure check, then it should be its own, totally separate from CONFIG_NPTL. In any case, definitely do not make the Linux mistake of having "do we support threads?" be target specific if you can avoid it. (You might not be able to avoid it, though -- not sure :-( )

Yes, my plan is to get rid of the NPTL flag at some point for bsd-user once the FreeBSD thread emulation code proves to be stable. (Yes, I was lazy and didn't create a new thread flag for FreeBSD in configure.) It seems to fairly stable now but it is nice to turn off thread emulation now and then to eliminate the possibility of threads being a problem. I suspect that we can just turn threads up for good and be all right, however.

Quoted 5 lines

(I suspect these other MIPS targets should actually have target_nptl set as your patch fragment does, but that should be done as a linux-user bugfix patch, not buried in the bsd-user support patchset.)

Quoted 16 lines

include/qemu/tls.h line 44

Quoted 13 lines
include/qemu/tls.h +1 -1
index b92ea9d..ae7d79d 100644
@@ -38,7 +38,7 @@
 * TODO: proper implementations via Win32 .tls sections and
 * POSIX pthread_getspecific.
 */
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
 #define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x)
 #define DEFINE_TLS(type, x)  __thread __typeof__(type) tls__##x
 #define tls_var(x)           tls__##x

This should be its own patch (especially as it affects the system emulation code on FreeBSD hosts).

Yes, that is a good point. I separate into its own patch so it can be reviewed and tested individually.

-stacey.

author
#32 lore raw

Re: [Qemu-devel] [PATCH 22/23] bsd-user: add more strace formating

In reply to Peter Maydell
Quoted 10 lines · Peter Maydell
Quoted 4 lines · Stacey Son

This change add more strace formating for popular system calls. It also separates out *BSD and architecture dependent code. In addition, it changes TARGET_OS in configure (and in the associated makefiles) to what it should really be: HOST_OS.

You introduced TARGET_OS in the first place. Please don't put code in in one patch and then change it in a later one; rearrange your patchset to avoid this.

Quoted 7 lines

This patch is also doing too many things at once.

configure upper() { · line 4296

Quoted 3 lines
configure +3 -0
+if [ "$HOST_ABI_DIR" != "" ]; then
+    echo "HOST_ABI_DIR=$HOST_ABI_DIR" >> $config_target_mak
+fi

Host specific definitions in the target config? Doesn't look right.

You're right. I originally used TARGET_OS but later decided that it was not the target but really the host os that was being defined. Then after rebasing I noticed that there was a change defining TARGET_ABI_DIR so I changed HOST_OS to HOST_ABI_DIR to be consistent with that change. I really need to may this change back when TARGET_OS is first introduced.

-stacey.