| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: intercept.h |
|---|
| 5 | // Purpose: Syscall interception code for unit tests |
|---|
| 6 | // Created: 2006/11/29 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef INTERCEPT_H |
|---|
| 11 | #define INTERCEPT_H |
|---|
| 12 | #ifndef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE |
|---|
| 13 | |
|---|
| 14 | #include <dirent.h> |
|---|
| 15 | |
|---|
| 16 | #include <sys/types.h> |
|---|
| 17 | #include <sys/stat.h> |
|---|
| 18 | |
|---|
| 19 | extern "C" |
|---|
| 20 | { |
|---|
| 21 | typedef DIR *(opendir_t) (const char *name); |
|---|
| 22 | typedef struct dirent *(readdir_t) (DIR *dir); |
|---|
| 23 | typedef struct dirent *(readdir_t) (DIR *dir); |
|---|
| 24 | typedef int (closedir_t)(DIR *dir); |
|---|
| 25 | #if defined __GNUC__ && __GNUC__ >= 2 |
|---|
| 26 | #define LINUX_WEIRD_LSTAT |
|---|
| 27 | #define STAT_STRUCT struct stat /* should be stat64 */ |
|---|
| 28 | typedef int (lstat_t) (int ver, const char *file_name, |
|---|
| 29 | STAT_STRUCT *buf); |
|---|
| 30 | #else |
|---|
| 31 | #define STAT_STRUCT struct stat |
|---|
| 32 | typedef int (lstat_t) (const char *file_name, |
|---|
| 33 | STAT_STRUCT *buf); |
|---|
| 34 | #endif |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | typedef int (lstat_post_hook_t) (int old_ret, const char *file_name, |
|---|
| 38 | struct stat *buf); |
|---|
| 39 | |
|---|
| 40 | void intercept_setup_error(const char *filename, unsigned int errorafter, |
|---|
| 41 | int errortoreturn, int syscalltoerror); |
|---|
| 42 | void intercept_setup_delay(const char *filename, unsigned int delay_after, |
|---|
| 43 | int delay_ms, int syscall_to_delay, int num_delays); |
|---|
| 44 | bool intercept_triggered(); |
|---|
| 45 | |
|---|
| 46 | void intercept_setup_readdir_hook(const char *dirname, readdir_t hookfn); |
|---|
| 47 | void intercept_setup_lstat_hook (const char *filename, lstat_t hookfn); |
|---|
| 48 | void intercept_setup_lstat_post_hook(lstat_post_hook_t hookfn); |
|---|
| 49 | void intercept_setup_stat_post_hook (lstat_post_hook_t hookfn); |
|---|
| 50 | |
|---|
| 51 | void intercept_clear_setup(); |
|---|
| 52 | |
|---|
| 53 | #endif // !PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE |
|---|
| 54 | #endif // !INTERCEPT_H |
|---|