Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib Make librumphijack compile and work on Linux. Do not tr...
details: https://anonhg.NetBSD.org/src/rev/6fde16fa65ec
branches: trunk
changeset: 781190:6fde16fa65ec
user: pooka <pooka%NetBSD.org@localhost>
date: Sat Aug 25 18:00:06 2012 +0000
description:
Make librumphijack compile and work on Linux. Do not try to hijack
calls which are not supported on Linux and therefore cannot be
handled by the rump kernel side syscall emulation (not that they'd
be present in the calling binaries anyway).
diffstat:
lib/librumphijack/Makefile | 4 +-
lib/librumphijack/hijack.c | 196 ++++++++++++++++++++++++++++++++-------
lib/librumphijack/hijackdlsym.c | 6 +-
lib/librumpuser/rumpuser.c | 21 +---
lib/librumpuser/rumpuser_port.h | 64 ++++++++++++-
5 files changed, 230 insertions(+), 61 deletions(-)
diffs (truncated from 711 to 300 lines):
diff -r 88cdd0fef8bd -r 6fde16fa65ec lib/librumphijack/Makefile
--- a/lib/librumphijack/Makefile Sat Aug 25 15:39:05 2012 +0000
+++ b/lib/librumphijack/Makefile Sat Aug 25 18:00:06 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2012/03/21 05:37:44 matt Exp $
+# $NetBSD: Makefile,v 1.10 2012/08/25 18:00:06 pooka Exp $
#
LIB= rumphijack
@@ -10,7 +10,7 @@
SRCS= hijack.c hijackdlsym.c
-CPPFLAGS+= -D_DIAGNOSTIC -D_REENTRANT
+CPPFLAGS+= -D_DIAGNOSTIC -D_REENTRANT -I${.CURDIR}/../librumpuser
WARNS?= 5
diff -r 88cdd0fef8bd -r 6fde16fa65ec lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c Sat Aug 25 15:39:05 2012 +0000
+++ b/lib/librumphijack/hijack.c Sat Aug 25 18:00:06 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hijack.c,v 1.95 2012/08/04 03:56:47 riastradh Exp $ */
+/* $NetBSD: hijack.c,v 1.96 2012/08/25 18:00:06 pooka Exp $ */
/*-
* Copyright (c) 2011 Antti Kantee. All Rights Reserved.
@@ -28,22 +28,29 @@
/* Disable namespace mangling, Fortification is useless here anyway. */
#undef _FORTIFY_SOURCE
+#include "rumpuser_port.h"
+
#include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.95 2012/08/04 03:56:47 riastradh Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.96 2012/08/25 18:00:06 pooka Exp $");
#include <sys/param.h>
#include <sys/types.h>
-#include <sys/event.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/poll.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/statvfs.h>
-#include <sys/quotactl.h>
+#include <sys/time.h>
-#include <rump/rumpclient.h>
-#include <rump/rump_syscalls.h>
+#ifdef PLATFORM_HAS_KQUEUE
+#include <sys/event.h>
+#endif
+
+#ifdef PLATFORM_HAS_NBQUOTA
+#include <sys/quotactl.h>
+#endif
#include <assert.h>
#include <dlfcn.h>
@@ -55,14 +62,23 @@
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <rump/rumpclient.h>
+#include <rump/rump_syscalls.h>
+
#include "hijack.h"
+/*
+ * XXX: Consider autogenerating this, syscnames[] and syscalls[] with
+ * a DSL where the tool also checks the symbols exported by this library
+ * to make sure all relevant calls are accounted for.
+ */
enum dualcall {
DUALCALL_WRITE, DUALCALL_WRITEV, DUALCALL_PWRITE, DUALCALL_PWRITEV,
DUALCALL_IOCTL, DUALCALL_FCNTL,
@@ -81,7 +97,6 @@
DUALCALL_CHMOD, DUALCALL_LCHMOD, DUALCALL_FCHMOD,
DUALCALL_CHOWN, DUALCALL_LCHOWN, DUALCALL_FCHOWN,
DUALCALL_OPEN,
- DUALCALL_STATVFS1, DUALCALL_FSTATVFS1,
DUALCALL_CHDIR, DUALCALL_FCHDIR,
DUALCALL_LSEEK,
DUALCALL_GETDENTS,
@@ -90,16 +105,37 @@
DUALCALL_MKDIR, DUALCALL_RMDIR,
DUALCALL_UTIMES, DUALCALL_LUTIMES, DUALCALL_FUTIMES,
DUALCALL_TRUNCATE, DUALCALL_FTRUNCATE,
- DUALCALL_FSYNC, DUALCALL_FSYNC_RANGE,
- DUALCALL_MOUNT, DUALCALL_UNMOUNT,
+ DUALCALL_FSYNC,
DUALCALL___GETCWD,
- DUALCALL_CHFLAGS, DUALCALL_LCHFLAGS, DUALCALL_FCHFLAGS,
DUALCALL_ACCESS,
DUALCALL_MKNOD,
+ DUALCALL_GETFH, DUALCALL_FHOPEN, DUALCALL_FHSTAT, DUALCALL_FHSTATVFS1,
+
+#ifdef PLATFORM_HAS_NBSYSCTL
DUALCALL___SYSCTL,
- DUALCALL_GETVFSSTAT, DUALCALL_NFSSVC,
- DUALCALL_GETFH, DUALCALL_FHOPEN, DUALCALL_FHSTAT, DUALCALL_FHSTATVFS1,
-#if __NetBSD_Prereq__(5,99,48)
+#endif
+
+#ifdef PLATFORM_HAS_NFSSVC
+ DUALCALL_NFSSVC,
+#endif
+
+#ifdef PLATFORM_HAS_NBVFSSTAT
+ DUALCALL_STATVFS1, DUALCALL_FSTATVFS1, DUALCALL_GETVFSSTAT,
+#endif
+
+#ifdef PLATFORM_HAS_NBMOUNT
+ DUALCALL_MOUNT, DUALCALL_UNMOUNT,
+#endif
+
+#ifdef PLATFORM_HAS_FSYNC_RANGE
+ DUALCALL_FSYNC_RANGE,
+#endif
+
+#ifdef PLATFORM_HAS_CHFLAGS
+ DUALCALL_CHFLAGS, DUALCALL_LCHFLAGS, DUALCALL_FCHFLAGS,
+#endif
+
+#ifdef PLATFORM_HAS_NBQUOTA
DUALCALL_QUOTACTL,
#endif
DUALCALL__NUM
@@ -112,6 +148,7 @@
* Would be nice to get this automatically in sync with libc.
* Also, this does not work for compat-using binaries!
*/
+#ifdef __NetBSD__
#if !__NetBSD_Prereq__(5,99,7)
#define REALSELECT select
#define REALPOLLTS pollts
@@ -124,7 +161,7 @@
#define REALFUTIMES futimes
#define REALMKNOD mknod
#define REALFHSTAT __fhstat40
-#else
+#else /* >= 5.99.7 */
#define REALSELECT _sys___select50
#define REALPOLLTS _sys___pollts50
#define REALKEVENT _sys___kevent50
@@ -136,7 +173,7 @@
#define REALFUTIMES __futimes50
#define REALMKNOD __mknod50
#define REALFHSTAT __fhstat50
-#endif
+#endif /* < 5.99.7 */
#define REALREAD _sys_read
#define REALPREAD _sys_pread
#define REALPWRITE _sys_pwrite
@@ -146,6 +183,30 @@
#define REALFHOPEN __fhopen40
#define REALFHSTATVFS1 __fhstatvfs140
#define OLDREALQUOTACTL __quotactl50 /* 5.99.48-62 only */
+#define REALSOCKET __socket30
+
+#define LSEEK_ALIAS _lseek
+#define VFORK __vfork14
+
+#else /* !NetBSD */
+
+#define REALREAD read
+#define REALPREAD pread
+#define REALPWRITE pwrite
+#define REALGETDENTS getdents
+#define REALSELECT select
+#define REALPOLLTS ppoll
+#define REALSTAT stat
+#define REALLSTAT lstat
+#define REALFSTAT fstat
+#define REALUTIMES utimes
+#define REALLUTIMES lutimes
+#define REALFUTIMES futimes
+#define REALMKNOD mknod
+#define REALFHSTAT fhstat
+#define REALSOCKET socket
+
+#endif /* NetBSD */
int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *);
int REALPOLLTS(struct pollfd *, nfds_t,
@@ -169,7 +230,11 @@
int REALFHOPEN(const void *, size_t, int);
int REALFHSTAT(const void *, size_t, struct stat *);
int REALFHSTATVFS1(const void *, size_t, struct statvfs *, int);
+int REALSOCKET(int, int, int);
+
+#ifdef PLATFORM_HAS_NBQUOTA
int OLDREALQUOTACTL(const char *, struct plistref *);
+#endif
#define S(a) __STRING(a)
struct sysnames {
@@ -177,7 +242,7 @@
const char *scm_hostname;
const char *scm_rumpname;
} syscnames[] = {
- { DUALCALL_SOCKET, "__socket30", RSYS_NAME(SOCKET) },
+ { DUALCALL_SOCKET, S(REALSOCKET), RSYS_NAME(SOCKET) },
{ DUALCALL_ACCEPT, "accept", RSYS_NAME(ACCEPT) },
{ DUALCALL_BIND, "bind", RSYS_NAME(BIND) },
{ DUALCALL_CONNECT, "connect", RSYS_NAME(CONNECT) },
@@ -218,8 +283,6 @@
{ DUALCALL_LUTIMES, S(REALLUTIMES), RSYS_NAME(LUTIMES) },
{ DUALCALL_FUTIMES, S(REALFUTIMES), RSYS_NAME(FUTIMES) },
{ DUALCALL_OPEN, "open", RSYS_NAME(OPEN) },
- { DUALCALL_STATVFS1, "statvfs1", RSYS_NAME(STATVFS1) },
- { DUALCALL_FSTATVFS1, "fstatvfs1", RSYS_NAME(FSTATVFS1) },
{ DUALCALL_CHDIR, "chdir", RSYS_NAME(CHDIR) },
{ DUALCALL_FCHDIR, "fchdir", RSYS_NAME(FCHDIR) },
{ DUALCALL_LSEEK, "lseek", RSYS_NAME(LSEEK) },
@@ -234,27 +297,51 @@
{ DUALCALL_TRUNCATE, "truncate", RSYS_NAME(TRUNCATE) },
{ DUALCALL_FTRUNCATE, "ftruncate", RSYS_NAME(FTRUNCATE) },
{ DUALCALL_FSYNC, "fsync", RSYS_NAME(FSYNC) },
- { DUALCALL_FSYNC_RANGE, "fsync_range", RSYS_NAME(FSYNC_RANGE) },
- { DUALCALL_MOUNT, S(REALMOUNT), RSYS_NAME(MOUNT) },
- { DUALCALL_UNMOUNT, "unmount", RSYS_NAME(UNMOUNT) },
{ DUALCALL___GETCWD, "__getcwd", RSYS_NAME(__GETCWD) },
- { DUALCALL_CHFLAGS, "chflags", RSYS_NAME(CHFLAGS) },
- { DUALCALL_LCHFLAGS, "lchflags", RSYS_NAME(LCHFLAGS) },
- { DUALCALL_FCHFLAGS, "fchflags", RSYS_NAME(FCHFLAGS) },
{ DUALCALL_ACCESS, "access", RSYS_NAME(ACCESS) },
{ DUALCALL_MKNOD, S(REALMKNOD), RSYS_NAME(MKNOD) },
- { DUALCALL___SYSCTL, "__sysctl", RSYS_NAME(__SYSCTL) },
- { DUALCALL_GETVFSSTAT, "getvfsstat", RSYS_NAME(GETVFSSTAT) },
- { DUALCALL_NFSSVC, "nfssvc", RSYS_NAME(NFSSVC) },
{ DUALCALL_GETFH, S(REALGETFH), RSYS_NAME(GETFH) },
{ DUALCALL_FHOPEN, S(REALFHOPEN),RSYS_NAME(FHOPEN) },
{ DUALCALL_FHSTAT, S(REALFHSTAT),RSYS_NAME(FHSTAT) },
{ DUALCALL_FHSTATVFS1, S(REALFHSTATVFS1),RSYS_NAME(FHSTATVFS1) },
+
+#ifdef PLATFORM_HAS_NBSYSCTL
+ { DUALCALL___SYSCTL, "__sysctl", RSYS_NAME(__SYSCTL) },
+#endif
+
+#ifdef PLATFORM_HAS_NFSSVC
+ { DUALCALL_NFSSVC, "nfssvc", RSYS_NAME(NFSSVC) },
+#endif
+
+#ifdef PLATFORM_HAS_NBVFSSTAT
+ { DUALCALL_STATVFS1, "statvfs1", RSYS_NAME(STATVFS1) },
+ { DUALCALL_FSTATVFS1, "fstatvfs1", RSYS_NAME(FSTATVFS1) },
+ { DUALCALL_GETVFSSTAT, "getvfsstat", RSYS_NAME(GETVFSSTAT) },
+#endif
+
+#ifdef PLATFORM_HAS_NBMOUNT
+ { DUALCALL_MOUNT, S(REALMOUNT), RSYS_NAME(MOUNT) },
+ { DUALCALL_UNMOUNT, "unmount", RSYS_NAME(UNMOUNT) },
+#endif
+
+#ifdef PLATFORM_HAS_FSYNC_RANGE
+ { DUALCALL_FSYNC_RANGE, "fsync_range", RSYS_NAME(FSYNC_RANGE) },
+#endif
+
+#ifdef PLATFORM_HAS_CHFLAGS
+ { DUALCALL_CHFLAGS, "chflags", RSYS_NAME(CHFLAGS) },
+ { DUALCALL_LCHFLAGS, "lchflags", RSYS_NAME(LCHFLAGS) },
+ { DUALCALL_FCHFLAGS, "fchflags", RSYS_NAME(FCHFLAGS) },
+#endif /* PLATFORM_HAS_CHFLAGS */
+
+#ifdef PLATFORM_HAS_NBQUOTA
#if __NetBSD_Prereq__(5,99,63)
{ DUALCALL_QUOTACTL, "__quotactl", RSYS_NAME(__QUOTACTL) },
#elif __NetBSD_Prereq__(5,99,48)
{ DUALCALL_QUOTACTL, S(OLDREALQUOTACTL),RSYS_NAME(QUOTACTL) },
#endif
+#endif /* PLATFORM_HAS_NBQUOTA */
+
};
#undef S
@@ -469,7 +556,9 @@
} socketmap[] = {
{ PF_LOCAL, "local" },
{ PF_INET, "inet" },
+#ifdef PF_LINK
{ PF_LINK, "link" },
+#endif
#ifdef PF_OROUTE
{ PF_OROUTE, "oroute" },
#endif
@@ -484,7 +573,7 @@
static void
sockparser(char *buf)
{
Home |
Main Index |
Thread Index |
Old Index