Commit ad8dbb81 authored by Julius Plenz's avatar Julius Plenz

handle dup(), too

parent 8c589dd5
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
int (*_original_open)(const char *pathname, int flags, mode_t mode); int (*_original_open)(const char *pathname, int flags, mode_t mode);
int (*_original_creat)(const char *pathname, int flags, mode_t mode); int (*_original_creat)(const char *pathname, int flags, mode_t mode);
int (*_original_openat)(int dirfd, const char *pathname, int flags, mode_t mode); int (*_original_openat)(int dirfd, const char *pathname, int flags, mode_t mode);
int (*_original_dup)(int fd);
int (*_original_close)(int fd); int (*_original_close)(int fd);
void init(void) __attribute__((constructor)); void init(void) __attribute__((constructor));
...@@ -28,6 +29,7 @@ int openat64(int dirfd, const char *pathname, int flags, mode_t mode) ...@@ -28,6 +29,7 @@ int openat64(int dirfd, const char *pathname, int flags, mode_t mode)
__attribute__ ((alias ("openat"))); __attribute__ ((alias ("openat")));
int __openat_2(int dirfd, const char *pathname, int flags, mode_t mode) int __openat_2(int dirfd, const char *pathname, int flags, mode_t mode)
__attribute__ ((alias ("openat"))); __attribute__ ((alias ("openat")));
int dup(int oldfd);
int close(int fd); int close(int fd);
static void store_pageinfo(int fd); static void store_pageinfo(int fd);
...@@ -58,6 +60,7 @@ void init(void) ...@@ -58,6 +60,7 @@ void init(void)
dlsym(RTLD_NEXT, "creat"); dlsym(RTLD_NEXT, "creat");
_original_openat = (int (*)(int, const char *, int, mode_t)) _original_openat = (int (*)(int, const char *, int, mode_t))
dlsym(RTLD_NEXT, "openat"); dlsym(RTLD_NEXT, "openat");
_original_dup = (int (*)(int)) dlsym(RTLD_NEXT, "dup");
_original_close = (int (*)(int)) dlsym(RTLD_NEXT, "close"); _original_close = (int (*)(int)) dlsym(RTLD_NEXT, "close");
PAGESIZE = getpagesize(); PAGESIZE = getpagesize();
for(i = 0; i < _MAX_FDS; i++) for(i = 0; i < _MAX_FDS; i++)
...@@ -99,6 +102,16 @@ int openat(int dirfd, const char *pathname, int flags, mode_t mode) ...@@ -99,6 +102,16 @@ int openat(int dirfd, const char *pathname, int flags, mode_t mode)
return fd; return fd;
} }
int dup(int oldfd)
{
int fd;
if((fd = _original_dup(oldfd)) != -1) {
fprintf(stderr, "dup()! old=%d, new=%d\n", oldfd, fd);
store_pageinfo(fd);
}
return fd;
}
int close(int fd) int close(int fd)
{ {
free_unclaimed_pages(fd); free_unclaimed_pages(fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment