Skip to content

Commit 4466781

Browse files
committed
Syscall intercept
1 parent 3e5d922 commit 4466781

File tree

216 files changed

+22506
-0
lines changed

Some content is hidden

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

216 files changed

+22506
-0
lines changed
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1. cd src
2+
2. make clean && make
3+
3. LD_PRELOAD=./libnvp.so <program> -- relative to src directory
4+
5+
To run pjd test on this:
6+
Run these as root user
7+
1. cd <repo>/tests
8+
2. make pjd.posix_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+

0 commit comments

Comments
 (0)