Created
July 14, 2013 09:07
-
-
Save justincormack/5993698 to your computer and use it in GitHub Desktop.
rump kernel ioctl issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dlfcn.h> | |
#include <stdio.h> | |
#include <sys/types.h> | |
#include <inttypes.h> | |
#include <rump/rump.h> | |
#include <rump/rump_syscalls.h> | |
#include <rump/netconfig.h> | |
typedef uint32_t _netbsd_mode_t; | |
struct ptyfs_args { | |
int version; | |
gid_t gid; | |
_netbsd_mode_t mode; | |
int flags; | |
}; | |
struct ptmget { | |
int cfd; | |
int sfd; | |
char cn[16]; | |
char sn[16]; | |
}; | |
int main() { | |
int (*init)(void); | |
int (*mkdir)(const char *, _netbsd_mode_t); | |
int (*mount)(const char *, const char *, int, void *, size_t); | |
int (*open)(const char *, int, _netbsd_mode_t); | |
int (*ioctl)(int, unsigned long, ...); | |
void *rumpuser = dlopen("librumpuser.so", RTLD_GLOBAL|RTLD_LAZY); | |
void *rump = dlopen("librump.so", RTLD_GLOBAL|RTLD_LAZY); | |
void *net = dlopen("librumpvfs.so", RTLD_GLOBAL|RTLD_LAZY); | |
void *netnet = dlopen("librumpkern_tty.so", RTLD_GLOBAL|RTLD_LAZY); | |
void *netinet = dlopen("librumpfs_ptyfs.so", RTLD_GLOBAL|RTLD_LAZY); | |
int fd; | |
int TIOCPTSNAME = 1076393032; | |
struct ptyfs_args pta = {2, 0, 0666, 0}; | |
struct ptmget pm; | |
if (! rump) { | |
fprintf(stderr, "rump null\n"); | |
return 1; | |
} | |
init = dlsym(rump, "rump_init"); | |
if (! init) { | |
fprintf(stderr, "init null\n"); | |
return 1; | |
} | |
init(); | |
mkdir = dlsym(rump, "rump___sysimpl_mkdir"); | |
mount = dlsym(rump, "rump___sysimpl_mount50"); | |
open = dlsym(rump, "rump___sysimpl_open"); | |
ioctl = dlsym(rump, "rump___sysimpl_ioctl"); | |
if (! (mount && mkdir && open && ioctl)) { | |
fprintf(stderr, "syscall null\n"); | |
return 1; | |
} | |
if (mkdir("/dev/pts", 0555) == -1) { | |
fprintf(stderr, "mkdir\n"); | |
return 1; | |
} | |
if (mount("ptyfs", "/dev/pts", 0, (void *)&pta, sizeof(pta)) == -1) { | |
fprintf(stderr, "mount\n"); | |
return 1; | |
} | |
fd = open("/dev/ptmx", 0x8002, 0); /* RDWR|NOCTTY */ | |
if (fd == -1) { | |
fprintf(stderr, "open\n"); | |
return 1; | |
} | |
if (ioctl(fd, TIOCPTSNAME, &pm) == -1) { | |
fprintf(stderr, "ioctl\n"); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment