From f440e51aaed3200d43d84ee14f6f1c0c479e1a57 Mon Sep 17 00:00:00 2001 From: Christian Despres Date: Mon, 7 Oct 2024 13:09:09 -0400 Subject: [PATCH] Use fallocate instead of ftruncate Even if the ftruncate() system call succeeds, this does not guarantee that the underlying filesystem has enough free blocks to support whatever increase in file size that was requested. This can cause SIGBUS errors if writes are attempted in the file. The fallocate() call does guarantee that there is enough space available. Signed-off-by: Christian Despres --- port/linux/omrvmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/port/linux/omrvmem.c b/port/linux/omrvmem.c index b96fad2207..8245da6ebb 100644 --- a/port/linux/omrvmem.c +++ b/port/linux/omrvmem.c @@ -1164,8 +1164,8 @@ reserve_memory_with_mmap(struct OMRPortLibrary *portLibrary, void *address, uint fd = mkostemp(filename, 0); if (OMRPORT_INVALID_FD != fd) { unlink(filename); - /* Set the file size with ftruncate. */ - if (OMRPORT_INVALID_FD == ftruncate(fd, byteAmount)) { + /* Set the file size with fallocate . */ + if (OMRPORT_INVALID_FD == fallocate(fd, 0, 0, byteAmount)) { close(fd); fd = OMRPORT_INVALID_FD; }