Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/rump/librump/rumpkern Implement kobj_renamespace() for r...



details:   https://anonhg.NetBSD.org/src/rev/e92714a1e722
branches:  trunk
changeset: 754297:e92714a1e722
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Apr 26 23:17:13 2010 +0000

description:
Implement kobj_renamespace() for rump.  Support for a few archs is
missing, but that doesn't really matter, since they are living in
their own "everything is a macro" happyland and don't support the
native kernel ABI anyway.

diffstat:

 sys/rump/librump/rumpkern/Makefile.rumpkern |    6 +-
 sys/rump/librump/rumpkern/kobj_rename.c     |  128 ++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 3 deletions(-)

diffs (152 lines):

diff -r f8a4022482ad -r e92714a1e722 sys/rump/librump/rumpkern/Makefile.rumpkern
--- a/sys/rump/librump/rumpkern/Makefile.rumpkern       Mon Apr 26 23:01:53 2010 +0000
+++ b/sys/rump/librump/rumpkern/Makefile.rumpkern       Mon Apr 26 23:17:13 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.rumpkern,v 1.80 2010/04/21 16:29:08 pooka Exp $
+#      $NetBSD: Makefile.rumpkern,v 1.81 2010/04/26 23:17:13 pooka Exp $
 #
 
 .include "${RUMPTOP}/Makefile.rump"
@@ -15,8 +15,8 @@
 #
 # Source modules, first the ones specifically implemented for librump.
 # 
-SRCS=  rump.c rumpcopy.c emul.c intr.c locks.c ltsleep.c       \
-       memalloc.c scheduler.c signals.c sleepq.c               \
+SRCS=  rump.c rumpcopy.c emul.c intr.c kobj_rename.c locks.c   \
+       ltsleep.c memalloc.c scheduler.c signals.c sleepq.c     \
        sysproxy_socket.c threads.c vm.c
 
 vers.c: ${RUMPTOP}/../conf/newvers.sh ${RUMPTOP}/../conf/osrelease.sh
diff -r f8a4022482ad -r e92714a1e722 sys/rump/librump/rumpkern/kobj_rename.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/librump/rumpkern/kobj_rename.c   Mon Apr 26 23:17:13 2010 +0000
@@ -0,0 +1,128 @@
+/*     $NetBSD: kobj_rename.c,v 1.1 2010/04/26 23:17:13 pooka Exp $    */
+
+/*-
+ * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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: kobj_rename.c,v 1.1 2010/04/26 23:17:13 pooka Exp $");
+
+#define ELFSIZE ARCH_ELFSIZE
+
+#include <sys/param.h>
+#include <sys/exec_elf.h>
+#include <sys/kmem.h>
+#include <sys/kobj.h>
+#include <sys/systm.h>
+
+/*
+ * Mangle symbols into rump kernel namespace.  This means
+ * putting "rumpns" in front of select symbols.
+ * See src/sys/rump/Makefile.rump for more details on the rump kernel
+ * namespace.
+ */
+const char *norentab[] = {
+       "RUMP",
+       "rump",
+       "__",
+       "_GLOBAL_OFFSET_TABLE",
+};
+static int
+norename(const char *name)
+{
+       unsigned i;
+
+       for (i = 0; i < __arraycount(norentab); i++) {
+               if (strncmp(norentab[i], name, strlen(norentab[i])) == 0)
+                       return 1;
+       }
+       return 0;
+}
+
+#define RUMPNS "rumpns_"
+int
+kobj_renamespace(Elf_Sym *symtab, size_t symcount,
+       char **strtab, size_t *strtabsz)
+{
+       Elf_Sym *sym;
+       char *worktab, *newtab;
+       size_t worktabsz, worktabidx;
+       unsigned i;
+       const size_t prefixlen = strlen(RUMPNS);
+
+#ifndef _RUMP_NATIVE_ABI
+       static int warned;
+
+       if (!warned) {
+               printf("warning: kernel ABI not supported on this arch\n");
+               warned = 1;
+       }
+#endif
+
+       /* allocate space for worst-case stringtab */
+       worktabsz = *strtabsz + symcount * prefixlen;
+       worktab = kmem_alloc(worktabsz, KM_SLEEP);
+
+       /* now, adjust stringtab into temporary space */
+#define WORKTABP (worktab + worktabidx)
+       for (i = 0, worktabidx = 0; i < symcount; i++) {
+               const char *fromname;
+
+               sym = &symtab[i];
+               if (sym->st_name == 0) {
+                       continue;
+               }
+
+               fromname = *strtab + sym->st_name;
+               sym->st_name = worktabidx;
+
+               if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL ||
+                   norename(fromname)) {
+                       strcpy(WORKTABP, fromname);
+                       worktabidx += strlen(fromname) + 1;
+               } else {
+                       strcpy(WORKTABP, RUMPNS);
+                       worktabidx += prefixlen;
+                       strcpy(WORKTABP, fromname);
+                       worktabidx += strlen(fromname) + 1;
+               }
+               KASSERT(worktabidx <= worktabsz);
+       }
+#undef WORKTABP
+
+       /*
+        * Finally, free old strtab, allocate new one, and copy contents.
+        */
+       kmem_free(*strtab, *strtabsz);
+       *strtab = NULL; /* marvin the paradroid 999 */
+       newtab = kmem_alloc(worktabidx, KM_SLEEP);
+       memcpy(newtab, worktab, worktabidx);
+
+       kmem_free(worktab, worktabsz);
+
+       *strtab = newtab;
+       *strtabsz = worktabidx;
+
+       return 0;
+}



Home | Main Index | Thread Index | Old Index