Module Name: src
Committed By: pooka
Date: Mon Apr 26 23:17:13 UTC 2010
Modified Files:
src/sys/rump/librump/rumpkern: Makefile.rumpkern
Added Files:
src/sys/rump/librump/rumpkern: kobj_rename.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/rump/librump/rumpkern/Makefile.rumpkern
cvs rdiff -u -r0 -r1.1 src/sys/rump/librump/rumpkern/kobj_rename.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/rump/librump/rumpkern/Makefile.rumpkern
diff -u src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.80 src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.81
--- src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.80 Wed Apr 21 16:29:08 2010
+++ src/sys/rump/librump/rumpkern/Makefile.rumpkern Mon Apr 26 23:17:13 2010
@@ -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
Added files:
Index: src/sys/rump/librump/rumpkern/kobj_rename.c
diff -u /dev/null src/sys/rump/librump/rumpkern/kobj_rename.c:1.1
--- /dev/null Mon Apr 26 23:17:13 2010
+++ src/sys/rump/librump/rumpkern/kobj_rename.c Mon Apr 26 23:17:13 2010
@@ -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;
+}