From a4d3d010ca24a2a8e63c5cfff245f54128043abf Mon Sep 17 00:00:00 2001 From: Tejas Garrepally Date: Sun, 28 Jul 2024 12:51:16 +0800 Subject: [PATCH] feat: add hooks for malloc and mmap --- include/loom/hooks.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/loom/hooks.hpp b/include/loom/hooks.hpp index ea24061..f029271 100644 --- a/include/loom/hooks.hpp +++ b/include/loom/hooks.hpp @@ -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); +} } \ No newline at end of file