Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzihengya authored and Officeyutong committed Aug 16, 2024
1 parent 47cd523 commit 4b51e88
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ endif()
execute_process(COMMAND mkdir -p $ENV{HOME}/.bpftime/event_source/devices/uprobe/format)
execute_process(COMMAND touch $ENV{HOME}/.bpftime/event_source/devices/uprobe/type)
execute_process(COMMAND touch $ENV{HOME}/.bpftime/event_source/devices/uprobe/format/retprobe)
execute_process(COMMAND bash -c "echo '1' > $ENV{HOME}/.bpftime/event_source/devices/uprobe/type")
execute_process(COMMAND bash -c "echo '9' > $ENV{HOME}/.bpftime/event_source/devices/uprobe/type")
execute_process(COMMAND bash -c "echo 'config:0' > $ENV{HOME}/.bpftime/event_source/devices/uprobe/format/retprobe")

# install frida
Expand Down
6 changes: 4 additions & 2 deletions runtime/syscall-server/syscall_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ FILE* syscall_context::handle_fopen(const char * filename, const char * modes)
return orig_fopen_fn(filename, modes);
}
try_startup();
const char * new_filename = bpftime_checkfile(filename);
return orig_fopen_fn(new_filename, modes);
printf("2:%s\n",file);
const char * new_file = bpftime_checkfile(file);
printf("3:%s\n",new_file);
return orig_openat_fn(fd, new_file, oflag, mode);
}

int syscall_context::handle_open(const char *file, int oflag, unsigned short mode)
Expand Down
10 changes: 5 additions & 5 deletions runtime/syscall-server/syscall_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class syscall_context {
using epoll_ctl_fn = int (*)(int, int, int, struct epoll_event *);
using epoll_wait_fn = int (*)(int, struct epoll_event *, int, int);
using munmap_fn = int (*)(void *, size_t);
using fopen_fn = FILE *(*)(const char *,const char *);
using openat_fn = int (*)(int, const char *, int, ...);
using open_fn = int (*)(const char *, int, ...);
close_fn orig_close_fn = nullptr;
mmap64_fn orig_mmap64_fn = nullptr;
Expand All @@ -39,7 +39,7 @@ class syscall_context {
epoll_ctl_fn orig_epoll_ctl_fn = nullptr;
epoll_wait_fn orig_epoll_wait_fn = nullptr;
munmap_fn orig_munmap_fn = nullptr;
fopen_fn orig_fopen_fn = nullptr;
openat_fn orig_openat_fn = nullptr;
open_fn orig_open_fn = nullptr;
mmap_fn orig_mmap_fn = nullptr;

Expand All @@ -58,7 +58,7 @@ class syscall_context {
orig_munmap_fn = (munmap_fn)dlsym(RTLD_NEXT, "munmap");
orig_mmap64_fn = orig_mmap_fn =
(mmap_fn)dlsym(RTLD_NEXT, "mmap");
orig_fopen_fn = (fopen_fn)dlsym(RTLD_NEXT, "fopen");
orig_openat_fn = (openat_fn)dlsym(RTLD_NEXT, "openat");
orig_open_fn = (open_fn)dlsym(RTLD_NEXT, "open");
// To avoid polluting other child processes,
// unset the LD_PRELOAD env var after syscall context being initialized
Expand All @@ -71,7 +71,7 @@ class syscall_context {
(uintptr_t)orig_ioctl_fn, (uintptr_t)orig_syscall_fn,
(uintptr_t)orig_mmap64_fn, (uintptr_t)orig_close_fn,
(uintptr_t)orig_munmap_fn, (uintptr_t)orig_mmap_fn,
(uintptr_t)orig_fopen_fn, (uintptr_t)orig_open_fn);
(uintptr_t)orig_openat_fn, (uintptr_t)orig_open_fn);
}

int create_kernel_bpf_map(int fd);
Expand Down Expand Up @@ -117,7 +117,7 @@ class syscall_context {
int handle_epoll_wait(int epfd, epoll_event *evt, int maxevents,
int timeout);
int handle_munmap(void *addr, size_t size);
FILE* handle_fopen(const char * filename, const char * modes);
int handle_openat(int fd, const char *file, int oflag, unsigned short mode);
int handle_open(const char *file, int oflag, unsigned short mode);
};

Expand Down
12 changes: 9 additions & 3 deletions runtime/syscall-server/syscall_server_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ extern "C" int close(int fd)
SPDLOG_DEBUG("Closing fd {}", fd);
return handle_exceptions([&]() { return context.handle_close(fd); });
}
extern "C" FILE* fopen(const char * filename, const char * modes)

extern "C" int openat(int fd, const char *file, int oflag, ...)
{
SPDLOG_DEBUG("fopen {:x} {:x}", (uintptr_t)filename, (uintptr_t)modes);
return context.handle_fopen(filename, modes);
va_list args;
va_start(args, oflag);
long arg4 = va_arg(args, long);
va_end(args);
SPDLOG_DEBUG("openat {} {:x} {} {}", fd, (uintptr_t)file, oflag, arg4);
unsigned short mode = (unsigned short)arg4;
return context.handle_openat(fd, file, oflag, mode);
}
extern "C" int open(const char *file, int oflag, ...)
{
Expand Down

0 comments on commit 4b51e88

Please sign in to comment.