Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/compat Implement mach_sys_load_shared_file. This are not...
details: https://anonhg.NetBSD.org/src/rev/b5c86936ff02
branches: trunk
changeset: 539432:b5c86936ff02
user: manu <manu%NetBSD.org@localhost>
date: Sun Nov 17 02:46:24 2002 +0000
description:
Implement mach_sys_load_shared_file. This are not complete yet, especially
wrt to the flags, but at least it does relocations.
diffstat:
sys/compat/darwin/darwin_mman.c | 227 +++++++++++++++++++++++++++++++++
sys/compat/darwin/darwin_syscall.h | 7 +-
sys/compat/darwin/darwin_syscallargs.h | 15 +-
sys/compat/darwin/darwin_syscalls.c | 11 +-
sys/compat/darwin/darwin_sysent.c | 13 +-
sys/compat/darwin/files.darwin | 4 +-
sys/compat/darwin/syscalls.master | 13 +-
sys/compat/mach/mach_vm.h | 16 ++-
8 files changed, 289 insertions(+), 17 deletions(-)
diffs (truncated from 460 to 300 lines):
diff -r 2d557b4bbea5 -r b5c86936ff02 sys/compat/darwin/darwin_mman.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/darwin/darwin_mman.c Sun Nov 17 02:46:24 2002 +0000
@@ -0,0 +1,227 @@
+/* $NetBSD: darwin_mman.c,v 1.1 2002/11/17 02:47:04 manu Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/signal.h>
+#include <sys/mount.h>
+#include <sys/proc.h>
+#include <sys/fcntl.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/vnode.h>
+#include <sys/exec.h>
+
+#include <sys/syscallargs.h>
+
+#include <compat/mach/mach_types.h>
+#include <compat/mach/mach_vm.h>
+
+#include <compat/freebsd/freebsd_syscallargs.h>
+
+#include <compat/darwin/darwin_syscallargs.h>
+
+int
+darwin_sys_load_shared_file(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct darwin_sys_load_shared_file_args /* {
+ syscallarg(char *) filename;
+ syscallarg(caddr_t) addr;
+ syscallarg(u_long) len;
+ syscallarg(caddr_t *) base;
+ syscallarg(int) count:
+ syscallarg(mach_sf_mapping_t *) mappings;
+ syscallarg(int *) flags;
+ } */ *uap = v;
+ struct file *fp;
+ struct filedesc *fdp;
+ struct vnode *vp;
+ vaddr_t base;
+ int flags;
+ char filename[MAXPATHLEN + 1];
+ mach_sf_mapping_t *mapp;
+ size_t maplen;
+ struct freebsd_sys_open_args open_cup;
+ struct sys_close_args close_cup;
+ int fd;
+ int i;
+ int error;
+ vaddr_t max_addr, addr;
+ size_t len;
+ vaddr_t uaddr;
+ int need_relocation;
+ struct exec_vmcmd evc;
+
+ if ((error = copyin(SCARG(uap, filename), &filename, MAXPATHLEN)) != 0)
+ return error;
+
+ if ((error = copyin(SCARG(uap, base), &base, sizeof(base))) != 0)
+ return error;
+
+ if ((error = copyin(SCARG(uap, flags), &flags, sizeof(base))) != 0)
+ return error;
+
+ DPRINTF(("mach_sys_load_shared_file: filename = %p ",
+ SCARG(uap, filename)));
+ DPRINTF(("addr = %p len = 0x%08lx base = %p ",
+ SCARG(uap, addr), SCARG(uap, len), SCARG(uap, base)));
+ DPRINTF(("count = %d mappings = %p flags = %p ",
+ SCARG(uap, count), SCARG(uap, mappings), SCARG(uap, flags)));
+ DPRINTF(("*base = 0x%08lx *flags = %d filename=`%s'\n",
+ base, flags, filename));
+
+ SCARG(&open_cup, path) = SCARG(uap, filename);
+ SCARG(&open_cup, flags) = O_RDONLY;
+ SCARG(&open_cup, mode) = 0;
+ if ((error = freebsd_sys_open(p, &open_cup, &fd)) != 0)
+ return error;
+
+ fdp = p->p_fd;
+ fp = fd_getfile(fdp, fd);
+ if (fp == NULL) {
+ error = EBADF;
+ goto out2;
+ }
+ FILE_USE(fp);
+ vp = (struct vnode *)fp->f_data;
+
+ /* XXX maximum count ? */
+ maplen = sizeof(*mapp) * SCARG(uap, count);
+ if (maplen > PAGE_SIZE) {
+ error = ENOMEM;
+ goto out2;
+ }
+ mapp = malloc(sizeof(*mapp) * SCARG(uap, count), M_TEMP, M_WAITOK);
+
+ if ((error = copyin(SCARG(uap, mappings), mapp, maplen)) != 0)
+ goto out2;
+
+#ifdef DEBUG_DARWIN
+ for (i = 0; i < SCARG(uap, count); i++) {
+ DPRINTF(("mapp[%d].mapping_offset = 0x%08lx\n",
+ i, mapp[i].mapping_offset));
+ DPRINTF(("mapp[%d].size = 0x%08x\n", i, mapp[i].size));
+ DPRINTF(("mapp[%d].file_offset = 0x%08lx\n",
+ i, mapp[i].file_offset));
+ DPRINTF(("mapp[%d].protection = %d\n",
+ i, mapp[i].protection));
+ DPRINTF(("mapp[%d].cksum = %ld\n", i, mapp[i].cksum));
+ }
+#endif
+
+ /* Check if we can load at the default addresses */
+ need_relocation = 0;
+ for (i = 0; i < SCARG(uap, count); i++)
+ if ((uvm_map_findspace(&p->p_vmspace->vm_map,
+ base + mapp[i].mapping_offset, mapp[i].size,
+ &uaddr, NULL, 0, 0, UVM_FLAG_FIXED)) == NULL)
+ need_relocation = 1;
+
+ /* If we cannot, we need a relocation */
+ if (need_relocation) {
+ DPRINTF(("Relocating\n"));
+ /* Compute the length of the region enclosing all sections */
+ max_addr = 0;
+ for (i = 0; i < SCARG(uap, count); i++) {
+ addr = (vaddr_t)(mapp[i].mapping_offset
+ + base + mapp[i].size);
+ if (addr > max_addr)
+ max_addr = addr;
+ }
+ len = max_addr - base;
+ DPRINTF(("base = 0x%08lx max_addr = 0x%08lx len = 0x%08x\n",
+ base, max_addr, len));
+
+ /* Find some place to map this region */
+ if ((uvm_map_findspace(&p->p_vmspace->vm_map, base,
+ len, &uaddr, NULL, 0, PAGE_SIZE, 0)) == NULL) {
+ DPRINTF(("Impossible to find some space\n"));
+ error = ENOMEM;
+ goto out;
+ }
+
+ /* Update the base address */
+ base = uaddr;
+ DPRINTF(("New base address: base = 0x%08lx\n", base));
+ }
+
+ /* Do the actual mapping */
+ for (i = 0; i < SCARG(uap, count); i++) {
+ bzero(&evc, sizeof(evc));
+ evc.ev_addr = base + mapp[i].mapping_offset;
+ evc.ev_len = mapp[i].size;
+ evc.ev_prot = mapp[i].protection & VM_PROT_ALL;
+ evc.ev_flags = 0;
+ evc.ev_proc = vmcmd_map_readvn;
+ evc.ev_offset = mapp[i].file_offset;
+ evc.ev_vp = vp;
+
+ DPRINTF(("map section %d: start = 0x%08lx, len = 0x%08lx\n",
+ i, evc.ev_addr, evc.ev_len));
+
+ if ((error = (*evc.ev_proc)(p, &evc)) != 0) {
+ DPRINTF(("Failed\n"));
+ goto out;
+ }
+ DPRINTF(("Success\n"));
+ }
+out:
+ free(mapp, M_TEMP);
+
+out2:
+ FILE_UNUSE(fp, p);
+ SCARG(&close_cup, fd) = fd;
+ if ((error = sys_close(p, &close_cup, retval)) != 0)
+ return error;
+
+ if ((error = copyout(&base, SCARG(uap, base), sizeof(base))) != 0)
+ return error;
+
+ if ((error = copyout(&flags, SCARG(uap, flags), sizeof(base))) != 0)
+ return error;
+
+ return error;
+}
diff -r 2d557b4bbea5 -r b5c86936ff02 sys/compat/darwin/darwin_syscall.h
--- a/sys/compat/darwin/darwin_syscall.h Sun Nov 17 02:22:11 2002 +0000
+++ b/sys/compat/darwin/darwin_syscall.h Sun Nov 17 02:46:24 2002 +0000
@@ -1,10 +1,10 @@
-/* $NetBSD: darwin_syscall.h,v 1.5 2002/11/16 19:59:19 manu Exp $ */
+/* $NetBSD: darwin_syscall.h,v 1.6 2002/11/17 02:46:25 manu Exp $ */
/*
* System call numbers.
*
* DO NOT EDIT-- this file is automatically generated.
- * created from NetBSD: syscalls.master,v 1.2 2002/11/14 21:47:15 manu Exp
+ * created from NetBSD: syscalls.master,v 1.3 2002/11/16 19:59:20 manu Exp
*/
/* syscall: "syscall" ret: "int" args: "int" "..." */
@@ -498,5 +498,8 @@
/* syscall: "undelete" ret: "int" args: "const char *" */
#define DARWIN_SYS_undelete 205
+/* syscall: "load_shared_file" ret: "int" args: "char *" "caddr_t" "u_long" "caddr_t *" "int" "mach_sf_mapping_t *" "int *" */
+#define DARWIN_SYS_load_shared_file 296
+
#define DARWIN_SYS_MAXSYSCALL 350
#define DARWIN_SYS_NSYSENT 512
diff -r 2d557b4bbea5 -r b5c86936ff02 sys/compat/darwin/darwin_syscallargs.h
--- a/sys/compat/darwin/darwin_syscallargs.h Sun Nov 17 02:22:11 2002 +0000
+++ b/sys/compat/darwin/darwin_syscallargs.h Sun Nov 17 02:46:24 2002 +0000
@@ -1,10 +1,10 @@
-/* $NetBSD: darwin_syscallargs.h,v 1.5 2002/11/16 19:59:19 manu Exp $ */
+/* $NetBSD: darwin_syscallargs.h,v 1.6 2002/11/17 02:46:25 manu Exp $ */
/*
* System call argument lists.
*
* DO NOT EDIT-- this file is automatically generated.
- * created from NetBSD: syscalls.master,v 1.2 2002/11/14 21:47:15 manu Exp
+ * created from NetBSD: syscalls.master,v 1.3 2002/11/16 19:59:20 manu Exp
*/
#ifndef _DARWIN_SYS__SYSCALLARGS_H_
@@ -27,6 +27,16 @@
} be; \
}
+struct darwin_sys_load_shared_file_args {
+ syscallarg(char *) filename;
+ syscallarg(caddr_t) addr;
+ syscallarg(u_long) len;
+ syscallarg(caddr_t *) base;
+ syscallarg(int) count;
+ syscallarg(mach_sf_mapping_t *) mappings;
+ syscallarg(int *) flags;
+};
+
/*
* System call prototypes.
*/
@@ -213,4 +223,5 @@
int sys_mlock(struct proc *, void *, register_t *);
int sys_munlock(struct proc *, void *, register_t *);
int sys_undelete(struct proc *, void *, register_t *);
+int darwin_sys_load_shared_file(struct proc *, void *, register_t *);
#endif /* _DARWIN_SYS__SYSCALLARGS_H_ */
diff -r 2d557b4bbea5 -r b5c86936ff02 sys/compat/darwin/darwin_syscalls.c
--- a/sys/compat/darwin/darwin_syscalls.c Sun Nov 17 02:22:11 2002 +0000
+++ b/sys/compat/darwin/darwin_syscalls.c Sun Nov 17 02:46:24 2002 +0000
@@ -1,14 +1,14 @@
-/* $NetBSD: darwin_syscalls.c,v 1.5 2002/11/16 19:59:19 manu Exp $ */
Home |
Main Index |
Thread Index |
Old Index