Skip to content

Commit

Permalink
feat: add hooks for malloc and mmap
Browse files Browse the repository at this point in the history
  • Loading branch information
g-tejas committed Jul 28, 2024
1 parent ac9b302 commit a4d3d01
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/loom/hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,25 @@ void hook_libc() {
}
$HOOK_DECLARE(read, ssize_t, int fd, void *buf, size_t count);
$HOOK_DECLARE(write, ssize_t, int fd, const void *buf, size_t count);
$HOOK_DECLARE(malloc, void *, size_t size);
$HOOK_DECLARE(mmap, void *, void *addr, size_t length, int prot, int flags, int fd,
off_t offset);

ssize_t write(int fd, const void *buf, size_t count) {
HOOK_CHECK(write);
printf("Write hook called\n");
return original_write(fd, buf, count);
}
void *malloc(size_t size) {
HOOK_CHECK(malloc);
printf("Malloc hook called\n");
return original_malloc(size);
}

void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
HOOK_CHECK(mmap);
// PRint out details about mmap
printf("Size: %zu\n", length);
return original_mmap(addr, length, prot, flags, fd, offset);
}
}

0 comments on commit a4d3d01

Please sign in to comment.