-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathminimal_main.c
78 lines (60 loc) · 1.67 KB
/
minimal_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dlfcn.h>
#include "errmacros.h"
#include "foo.h"
struct libc_collfs_api {
void * fxstat64;
void * xstat64;
void * open;
void * close;
void * read;
void * lseek;
void * mmap;
void * munmap;
};
extern struct libc_collfs_api _dl_collfs_api;
typedef int (*collfs_open_fp)(const char *pathname, int flags, mode_t mode);
int minimal_open(const char *pathname, int flags, mode_t mode)
{
printf("Intercepted open call to: %s\n", pathname);
return open(pathname, flags, mode);
}
int run_tests(const char *soname, const char *path)
{
void *handle;
int err;
int (*func)(void);
handle = dlopen(soname,RTLD_GLOBAL | RTLD_LAZY);
if (!handle) ERR("failed to dlopen(\"%s\",RTLD_GLOBAL | RTLD_LAZY) due to: %s", soname, dlerror());
func = dlsym(handle,"thefunc");
if (!func) ERR("dlsym could not find symbol \"thefunc\" due to: %s", dlerror());
err = (*func)();CHK(err);
err = dlclose(handle);
if (err) ERR("dlclose failed due to: %s", dlerror());
return 0;
}
int main(int argc, char *argv[])
{
int err;
collfs_open_fp _open_fp;
char path[MAXPATHLEN];
typedef void (*vfptr)(void);
MPI_Init(&argc,&argv);
_dl_collfs_api.open = (vfptr) minimal_open;
_open_fp = (collfs_open_fp) _dl_collfs_api.open;
int fid = _open_fp("test_open.txt",O_RDONLY,0);
close(fid);
if (!getcwd(path,sizeof path)) ERR("getcwd failed");
strcat(path,"/libminimal_thefunc.so");
err = run_tests(path, path);CHK(err);
MPI_Finalize();
return 0;
}