Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librumphijack Put the dlsym-from-this-object trampoline ...
details: https://anonhg.NetBSD.org/src/rev/f937e68217a7
branches: trunk
changeset: 762583:f937e68217a7
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Feb 23 15:23:15 2011 +0000
description:
Put the dlsym-from-this-object trampoline into a separate source
module which is compiled -fno-optimize-sibling-calls instead of
trying to fool the optimizer in various ways in the trampoline.
thanks to yamt for the tip
diffstat:
lib/librumphijack/Makefile | 5 ++-
lib/librumphijack/hijack.c | 32 ++++-----------------------
lib/librumphijack/hijackdlsym.c | 47 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 29 deletions(-)
diffs (143 lines):
diff -r 504124915225 -r f937e68217a7 lib/librumphijack/Makefile
--- a/lib/librumphijack/Makefile Wed Feb 23 13:03:32 2011 +0000
+++ b/lib/librumphijack/Makefile Wed Feb 23 15:23:15 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.6 2011/01/27 18:12:19 pooka Exp $
+# $NetBSD: Makefile,v 1.7 2011/02/23 15:23:15 pooka Exp $
#
LIB= rumphijack
@@ -8,7 +8,7 @@
rumpclient ${.CURDIR}/../librumpclient
MAN= rumphijack.3
-SRCS= hijack.c
+SRCS= hijack.c hijackdlsym.c
CPPFLAGS+= -D_DIAGNOSTIC -D_REENTRANT
@@ -16,5 +16,6 @@
#DBG=-g
#NOGCCERROR=1
+COPTS.hijackdlsym.c+= -fno-optimize-sibling-calls
.include <bsd.lib.mk>
diff -r 504124915225 -r f937e68217a7 lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c Wed Feb 23 13:03:32 2011 +0000
+++ b/lib/librumphijack/hijack.c Wed Feb 23 15:23:15 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hijack.c,v 1.63 2011/02/21 20:11:56 pooka Exp $ */
+/* $NetBSD: hijack.c,v 1.64 2011/02/23 15:23:15 pooka Exp $ */
/*-
* Copyright (c) 2011 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.63 2011/02/21 20:11:56 pooka Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.64 2011/02/23 15:23:15 pooka Exp $");
#define __ssp_weak_name(fun) _hijack_ ## fun
@@ -59,6 +59,8 @@
#include <time.h>
#include <unistd.h>
+#include "hijack.h"
+
enum dualcall {
DUALCALL_WRITE, DUALCALL_WRITEV, DUALCALL_PWRITE, DUALCALL_PWRITEV,
DUALCALL_IOCTL, DUALCALL_FCNTL,
@@ -294,30 +296,6 @@
}
/*
- * This is called from librumpclient in case of LD_PRELOAD.
- * It ensures correct RTLD_NEXT.
- *
- * ... except, it's apparently extremely difficult to force
- * at least gcc to generate an actual stack frame here. So
- * sprinkle some volatile foobar and baz to throw the optimizer
- * off the scent and generate a variable assignment with the
- * return value. The posterboy for this meltdown is amd64
- * with -O2. At least with gcc 4.1.3 i386 works regardless of
- * optimization.
- */
-volatile int rumphijack_unrope; /* there, unhang yourself */
-static void *
-hijackdlsym(void *handle, const char *symbol)
-{
- void *rv;
-
- rv = dlsym(handle, symbol);
- rumphijack_unrope = *(volatile int *)rv;
-
- return (void *)rv;
-}
-
-/*
* This tracks if our process is in a subdirectory of /rump.
* It's preserved over exec.
*/
@@ -452,7 +430,7 @@
extern void *(*rumpclient_dlsym)(void *, const char *);
unsigned i, j;
- rumpclient_dlsym = hijackdlsym;
+ rumpclient_dlsym = rumphijack_dlsym;
host_fork = dlsym(RTLD_NEXT, "fork");
host_daemon = dlsym(RTLD_NEXT, "daemon");
host_execve = dlsym(RTLD_NEXT, "execve");
diff -r 504124915225 -r f937e68217a7 lib/librumphijack/hijackdlsym.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librumphijack/hijackdlsym.c Wed Feb 23 15:23:15 2011 +0000
@@ -0,0 +1,47 @@
+/* $NetBSD: hijackdlsym.c,v 1.1 2011/02/23 15:23:15 pooka Exp $ */
+
+/*-
+ * Copyright (c) 2011 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>
+__RCSID("$NetBSD: hijackdlsym.c,v 1.1 2011/02/23 15:23:15 pooka Exp $");
+
+#include <dlfcn.h>
+
+#include "hijack.h"
+
+/*
+ * This is called from librumpclient in case of LD_PRELOAD.
+ * It ensures correct RTLD_NEXT.
+ *
+ * (note, this module is compiled with -fno-optimize-sibling-calls
+ * to make sure this function is not treated as a tailcall)
+ */
+void *
+rumphijack_dlsym(void *handle, const char *symbol)
+{
+
+ return dlsym(handle, symbol);
+}
Home |
Main Index |
Thread Index |
Old Index