Skip to content

Commit 9ff49cc

Browse files
committed
Syscall intercept integration
1 parent 3e5d922 commit 9ff49cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+12792
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ results/
44
dependencies/jdk-8u221-linux-x64.tar.gz
55
dependencies/cmake-3.15.2/
66
dependencies/jdk1.8.0_221/
7+
dependencies/sysint_install/
78
kernel/kbuild/*
89
*.o
910
tpcc-sqlite/database/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "dependencies/syscall_intercept"]
2+
path = dependencies/syscall_intercept
3+
url = https://github.com/pmem/syscall_intercept.git

dependencies/splitfs_deps.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
#!/bin/bash
22

33
# install boost
4-
sudo apt-get install libboost-dev
4+
sudo apt-get install libboost-dev libcapstone-dev cmake pandoc clang
5+
6+
# install syscall_intercept
7+
git submodule init
8+
git submodule update
9+
syscall_dir=$PWD/syscall_intercept
10+
install_dir=$PWD/sysint_install
11+
12+
mkdir $install_dir
13+
cd $install_dir
14+
cmake $syscall_dir -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang
15+
if [ "$?" -ne 0 ]; then
16+
echo "Failed to build syscall_intercept"
17+
exit 1
18+
fi
19+
20+
make
21+
if [ "$?" -ne 0 ]; then
22+
echo "Failed to build syscall_intercept"
23+
exit 1
24+
fi
25+
26+
sudo make install
27+
rm -rf $install_dir

dependencies/syscall_intercept

Submodule syscall_intercept added at 3044045
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Object files
2+
*.o
3+
*.ko
4+
*.obj
5+
*.elf
6+
7+
# Precompiled Headers
8+
*.gch
9+
*.pch
10+
11+
# Libraries
12+
*.lib
13+
#*.a
14+
*.la
15+
*.lo
16+
17+
# Shared objects (inc. Windows DLLs)
18+
*.dll
19+
*.so
20+
*.so.*
21+
*.dylib
22+
23+
# Executables
24+
*.exe
25+
*.out
26+
*.app
27+
*.i*86
28+
*.x86_64
29+
*.hex
30+
31+
# Others
32+
*~
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SplitFS implementation using syscall intercept Library
2+
[syscall_intercept](https://google.com) is a library that can be used to intercept the system calls. This works by rewriting the machine code in text area of the loaded program.
3+
The prior implementation intercepts the `libc` calls.
4+
This implementation does not make any changes to the logic of SplitFS itself.
5+
6+
###Currently supported applications
7+
1. PJD Test Suite (Tests run successfully)
8+
9+
###How to use?
10+
All paths (not starting with `/`) are relative to root of repository
11+
1. `cd splitfs_syscall_intercept/src`
12+
2. `make clean && make`
13+
3. A file called `libnvp.so` will be created at `splitfs_syscall_intercept/src` -- this is the library file that needs to be used with `LD_PRELOAD`.
14+
4. Run the application that you want using `LD_PRELOAD=splitfs_syscall_intercept/src/libnvp.so` \<application cmd\>
15+
16+
###How to run the PJD test suite?
17+
All paths (not starting with `/`) are relative to root of repository
18+
1. Set up the pmem file mount at `/mnt/pmem_emul`
19+
2. Make sure the mount point has `write` and `execute` permissions so that all users can delete files. (This is required since some tests use `setuid` to switch to a different user. This user will then not have permission to delete the staging files during exit cleanup)
20+
3. `cd tests`
21+
4. `make all_sysint`
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#ifndef __DEBUG_INCLUDED
2+
#define __DEBUG_INCLUDED
3+
4+
#include "boost/preprocessor/list/for_each.hpp"
5+
6+
// Turns on debugging messages
7+
#ifndef SHOW_DEBUG
8+
#define SHOW_DEBUG 0
9+
#endif
10+
11+
#ifndef PRINT_DEBUG_FILE
12+
#define PRINT_DEBUG_FILE 0
13+
#endif
14+
15+
#ifndef SPIN_ON_ERROR
16+
#define SPIN_ON_ERROR 0
17+
#endif
18+
19+
//#define ENV_GDB_VEC "NVP_GDB_VEC"
20+
/*
21+
#define fopen fopen_orig
22+
#undef fopen
23+
*/
24+
#include <pthread.h>
25+
#include <stdio.h>
26+
#include <sys/types.h>
27+
#include <unistd.h>
28+
29+
extern FILE* _nvp_print_fd;
30+
31+
// use stderr, until we dup it
32+
#define NVP_PRINT_FD ((_nvp_print_fd)?_nvp_print_fd:stderr)
33+
34+
typedef char* charptr;
35+
void xil_printf(FILE* f, const charptr c, ...);
36+
//static inline void _nvp_debug_handoff(void)
37+
38+
/*
39+
#define _nvp_debug_handoff(x) \
40+
{ \
41+
xil_printf(stderr, "Stopping thread and waiting for gdb...\ngdb --pid=%i\n", getpid()); \
42+
fflush(stderr); \
43+
sleep(1); \
44+
volatile int asdf = 1; \
45+
sleep(1); \
46+
while(asdf) {}; \
47+
}
48+
*/
49+
50+
#define _nvp_debug_handoff(x) \
51+
{ \
52+
sleep(1); \
53+
volatile int asdf = 1; \
54+
sleep(1); \
55+
while(asdf) {}; \
56+
}
57+
58+
59+
//void outbyte(char c);
60+
61+
//#define ERROR_NAMES (EPERM) (ENOENT) (ESRCH) (EINTR) (EIO) (ENXIO) (E2BIG) (ENOEXEC) (EBADF) (ECHILD) (EAGAIN) (ENOMEM) (EACCES) (EFAULT) (ENOTBLK) (EBUSY) (EEXIST) (EXDEV) (ENODEV) (ENOTDIR) (EISDIR) (EINVAL) (ENFILE) (EMFILE) (ENOTTY) (ETXTBSY) (EFBIG) (ENOSPC) (ESPIPE) (EROFS) (EMLINK) (EPIPE) (EDOM) (ERANGE) (EDEADLK)
62+
#define ERROR_NAMES_LIST (EPERM, (ENOENT, (ESRCH, (EINTR, (EIO, (ENXIO, (E2BIG, (ENOEXEC, (EBADF, (ECHILD, (EAGAIN, (ENOMEM, (EACCES, (EFAULT, (ENOTBLK, (EBUSY, (EEXIST, (EXDEV, (ENODEV, (ENOTDIR, (EISDIR, (EINVAL, (ENFILE, (EMFILE, (ENOTTY, (ETXTBSY, (EFBIG, (ENOSPC, (ESPIPE, (EROFS, (EMLINK, (EPIPE, (EDOM, (ERANGE, (EDEADLK, BOOST_PP_NIL)))))))))))))))))))))))))))))))))))
63+
64+
#define ERROR_IF_PRINT(r, data, elem) if(data == elem) { DEBUG("errno == %s (%i): %s\n", MK_STR(elem), elem, strerror(elem)); }
65+
66+
// also used in fileops_wrap
67+
//#define PRINTFUNC fprintf
68+
#define PRINTFUNC xil_printf
69+
70+
71+
#if DISABLE_MSG
72+
#define MSG(format, ...) do{}while(0)
73+
#else
74+
#define MSG(format, ...) do{PRINTFUNC(NVP_PRINT_FD, "MSG: "); PRINTFUNC (NVP_PRINT_FD, format, ##__VA_ARGS__); fflush(NVP_PRINT_FD); }while(0)
75+
#endif
76+
#define LOG(format, ...) do{PRINTFUNC(NVP_PRINT_FD, "MSG: "); PRINTFUNC (NVP_PRINT_FD, format, ##__VA_ARGS__); fflush(NVP_PRINT_FD); }while(0)
77+
#define ERROR(format, ...) do{PRINTFUNC(NVP_PRINT_FD, "\033[01;33mNVP_ERROR\e[m (pid %i): " format, getpid(), ##__VA_ARGS__); PRINTFUNC(NVP_PRINT_FD, "ROHAN HERE\n"); if(SPIN_ON_ERROR){ _nvp_debug_handoff(); } }while(0)
78+
79+
extern FILE *debug_fd;
80+
#define DEBUG_FD debug_fd
81+
82+
#if PRINT_DEBUG_FILE
83+
#define DEBUG_FILE(format, ...) do {PRINTFUNC(DEBUG_FD, "\033[01;33mNVP_DEBUG\
84+
\e[m (pid %i): " format, getpid(), ##__VA_ARGS__); }while(0)
85+
#else
86+
#define DEBUG_FILE(format, ...) do{}while(0)
87+
#endif
88+
89+
#if SHOW_DEBUG
90+
#define DEBUG(format, ...) do{char loc; PRINTFUNC(NVP_PRINT_FD, "NVP_DEBUG (PID %i SP %p): " format, getpid(), &loc, ##__VA_ARGS__); fflush(NVP_PRINT_FD); } while(0)
91+
#define WARNING(format, ...) do{PRINTFUNC(NVP_PRINT_FD, "NVP_WARNING (PID %i): " format, getpid(), ##__VA_ARGS__); } while(0)
92+
#define DEBUG_P(format, ...) do{PRINTFUNC(NVP_PRINT_FD, format, ##__VA_ARGS__); } while(0)
93+
#else
94+
#define DEBUG(format, ...) do{}while(0)
95+
#define WARNING(format, ...) do{}while(0)
96+
#define DEBUG_P(format, ...) do{}while(0)
97+
#endif
98+
99+
#define FAIL \
100+
"FFFFFFFFFFFFFFFFFFFFFF AAA IIIIIIIIII LLLLLLLLLLL \n"\
101+
"F::::::::::::::::::::F A:::A I::::::::I L:::::::::L \n"\
102+
"F::::::::::::::::::::F A:::::A I::::::::I L:::::::::L \n"\
103+
"FF::::::FFFFFFFFF::::F A:::::::A II::::::II LL:::::::LL \n"\
104+
" F:::::F FFFFFF A:::::::::A I::::I L:::::L \n"\
105+
" F:::::F A:::::A:::::A I::::I L:::::L \n"\
106+
" F::::::FFFFFFFFFF A:::::A A:::::A I::::I L:::::L \n"\
107+
" F:::::::::::::::F A:::::A A:::::A I::::I L:::::L \n"\
108+
" F:::::::::::::::F A:::::A A:::::A I::::I L:::::L \n"\
109+
" F::::::FFFFFFFFFFA:::::AAAAAAAAA:::::A I::::I L:::::L \n"\
110+
" F:::::F A:::::::::::::::::::::A I::::I L:::::L \n"\
111+
" F:::::F A:::::AAAAAAAAAAAAA:::::A I::::I L:::::L LLLLLL\n"\
112+
"FF:::::::FF A:::::A A:::::A II::::::II LL:::::::LLLLLLLLL:::::L\n"\
113+
"F::::::::FF A:::::A A:::::A I::::::::I L::::::::::::::::::::::L\n"\
114+
"F::::::::FF A:::::A A:::::A I::::::::I L::::::::::::::::::::::L\n"\
115+
"FFFFFFFFFFF AAAAAAA AAAAAAAIIIIIIIIII LLLLLLLLLLLLLLLLLLLLLLLL\n"
116+
117+
#endif
118+
119+
//#define PRINT_ERROR_NAME(errnoin) BOOST_PP_SEQ_FOR_EACH(ERROR_IF_PRINT, errnoin, ERROR_NAMES) // can't use BOOST_PP_SEQ_FOR_EACH within another BOOST_PP_SEQ_FOR_EACH
120+
#define PRINT_ERROR_NAME(errnoin) _nvp_print_error_name(errnoin);
121+
void _nvp_print_error_name(int errnoin);
122+
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// Header file shared by nvmfileops.c, fileops_compareharness.c
2+
#define _GNU_SOURCE
3+
4+
#ifndef __NV_COMMON_H_
5+
#define __NV_COMMON_H_
6+
7+
#ifndef __cplusplus
8+
#endif
9+
10+
#define _GNU_SOURCE
11+
12+
#include <sys/types.h>
13+
#include <sys/stat.h>
14+
#include <sys/socket.h>
15+
#include <linux/kernel.h>
16+
#include <sys/syscall.h>
17+
#include <stdint.h>
18+
#include <stdlib.h>
19+
#include <sys/stat.h>
20+
#include <unistd.h>
21+
#include <fcntl.h>
22+
#include <string.h>
23+
#include <stdio.h>
24+
#include <sched.h>
25+
#include <sys/mman.h>
26+
#include <errno.h>
27+
#include <stdarg.h>
28+
#include <stddef.h>
29+
#include <sys/uio.h>
30+
#include <dlfcn.h>
31+
#include <limits.h>
32+
#include <stdint.h>
33+
#include <sched.h>
34+
#include <ctype.h>
35+
#include <signal.h>
36+
#include <pthread.h>
37+
#include "debug.h"
38+
#include "boost/preprocessor/seq/for_each.hpp"
39+
40+
#define MIN(X,Y) (((X)<(Y))?(X):(Y))
41+
#define MAX(X,Y) (((X)>(Y))?(X):(Y))
42+
43+
// tell the compiler a branch is/is not likely to be followed
44+
#define LIKELY(x) __builtin_expect((x),1)
45+
#define UNLIKELY(x) __builtin_expect((x),0)
46+
47+
#define assert(x) if(UNLIKELY(!(x))) { printf("ASSERT FAILED ROHAN\n"); fflush(NULL); ERROR("NVP_ASSERT("#x") failed!\n"); exit(100); }
48+
49+
// ----------------- Syscall Intercept Stuff ----------------
50+
#define INTF_SYSCALL long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result
51+
#define RETT_SYSCALL_INTERCEPT int
52+
53+
// Pass thru call to kernel
54+
#define RETT_PASS_KERN 1
55+
56+
// Took over call. Don't pass to kernel.
57+
#define RETT_NO_PASS_KERN 0
58+
// ----------------------------------------------------------
59+
60+
#define DO_ALIGNMENT_CHECKS 0
61+
62+
// places quotation marks around arg (eg, MK_STR(stuff) becomes "stuff")
63+
#define MK_STR(arg) #arg
64+
#define MK_STR2(x) MK_STR(x)
65+
#define MK_STR3(x) MK_STR2(x)
66+
67+
#define MACRO_WRAP(a) a
68+
#define MACRO_CAT(a, b) MACRO_WRAP(a##b)
69+
70+
#ifndef __cplusplus
71+
typedef int bool;
72+
#define false 0
73+
#define true 1
74+
#endif
75+
76+
77+
#define BG_CLOSING 0
78+
#define SEQ_LIST 0
79+
#define RAND_LIST 1
80+
81+
// maximum number of file operations to support simultaneously
82+
#define MAX_FILEOPS 32
83+
#define BUF_SIZE 40
84+
85+
// Every time a function is used, determine whether the module's functions have been resolved.
86+
#include <unistd.h>
87+
#include <fcntl.h>
88+
#include <string.h>
89+
#include <errno.h>
90+
#include <time.h>
91+
92+
extern int OPEN_MAX;
93+
94+
#define NOSANITYCHECK 1
95+
#if NOSANITYCHECK
96+
#define SANITYCHECK(x)
97+
#else
98+
#define SANITYCHECK(x) if(UNLIKELY(!(x))) { ERROR("NVP_SANITY("#x") failed!\n"); exit(101); }
99+
#endif
100+
101+
#define ASYNC_CLOSING async_close_enable
102+
volatile int async_close_enable;
103+
104+
// Used to determine contents of flags passed to OPEN
105+
#define FLAGS_INCLUDE(flags, x) ((flags&x)||(x==0))
106+
#define DUMP_FLAGS(flags, x) do{ if(FLAGS_INCLUDE(flags, x)) { DEBUG_P("%s(0x%X) ",#x,x); } }while(0)
107+
108+
109+
#define NVP_CHECK_NVF_VALID(nvf) do{ \
110+
if(UNLIKELY(!nvf->valid)) { \
111+
DEBUG("Invalid file descriptor: %i\n", file); \
112+
errno = 0; \
113+
return -1; \
114+
} \
115+
else \
116+
{ \
117+
DEBUG("this function is operating on node %p\n", nvf->node); \
118+
} \
119+
} while(0)
120+
121+
#define NVP_CHECK_NVF_VALID_WR(nvf) do{ \
122+
if(UNLIKELY(!nvf->valid)) { \
123+
DEBUG("Invalid file descriptor: %i\n", file); \
124+
errno = 0; \
125+
return -1; \
126+
} \
127+
else { \
128+
DEBUG("this function is operating on node %p\n", nvf->node); \
129+
} \
130+
} while(0)
131+
132+
#define IS_ERR(x) ((unsigned long)(x) >= (unsigned long)-4095)
133+
134+
// modifications to support different FSYNC policies
135+
#define NVMM_PATH "/mnt/pmem_emul/"
136+
137+
#define SANITYCHECKNVF(nvf) \
138+
SANITYCHECK(nvf->valid); \
139+
SANITYCHECK(nvf->node != NULL); \
140+
SANITYCHECK(nvf->fd >= 0); \
141+
SANITYCHECK(nvf->fd < OPEN_MAX); \
142+
SANITYCHECK(nvf->offset != NULL); \
143+
SANITYCHECK(*nvf->offset >= 0); \
144+
SANITYCHECK(nvf->node->length >=0); \
145+
SANITYCHECK(nvf->node->maplength >= nvf->node->length); \
146+
SANITYCHECK(nvf->node->data != NULL)
147+
148+
149+
#define SFS_OPS (CLOSE) (DUP) (DUP2) (EXECVE) (FSYNC) (LINK) (MKDIR) (MKDIRAT) (MKNOD) (MKNODAT) (OPEN) (READ) \
150+
(RENAME) (RMDIR) (SEEK) (SYMLINK) (SYMLINKAT) (UNLINK) (UNLINKAT) (WRITE)
151+
#define DECLARE_SFS_FUNCS(FUNCT, prefix) \
152+
RETT_SYSCALL_INTERCEPT prefix##FUNCT(INTF_SYSCALL);
153+
#define DECLARE_SFS_FUNCS_IWRAP(r, data, elem) DECLARE_SFS_FUNCS(elem, data)
154+
155+
BOOST_PP_SEQ_FOR_EACH(DECLARE_SFS_FUNCS_IWRAP, _sfs_, SFS_OPS)
156+
157+
#endif

0 commit comments

Comments
 (0)