Add malloc_open() / malloc_close() reentrancy safe helpers

This commit is contained in:
Nathan Slingerland 2024-09-10 13:29:35 -07:00 committed by Qi Wang
parent 60f472f367
commit 8c2e15d1a5
2 changed files with 32 additions and 50 deletions

View file

@ -134,4 +134,25 @@ malloc_read_fd(int fd, void *buf, size_t count) {
return bytes_read;
}
static inline int malloc_open(const char *path, int flags) {
int fd;
#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_open)
fd = (int)syscall(SYS_open, path, flags);
#elif defined(JEMALLOC_USE_SYSCALL) && defined(SYS_openat)
fd = (int)syscall(SYS_openat, AT_FDCWD, path, flags);
#else
fd = open(path, flags);
#endif
return fd;
}
static inline int malloc_close(int fd) {
#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_close)
return (int)syscall(SYS_close, fd);
#else
return close(fd);
#endif
}
#endif /* JEMALLOC_INTERNAL_MALLOC_IO_H */