< prev index next >

src/java.base/unix/native/libjava/io_util_md.c

Print this page
rev 16220 : 8168628: (fc) SIGBUS when extending file size to map it
Summary: Synchronize file extension and subsequent map0(); on Linux use fallocate64() instead of ftruncate64().
Reviewed-by: rehn, simonis, alanb

*** 1,7 **** /* ! * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 213,222 **** --- 213,236 ---- jint handleSetLength(FD fd, jlong length) { int result; + #if defined(__linux__) + /* + * On Linux, if the file size is being increased, then ftruncate64() + * will modify the metadata value of the size without actually allocating + * any blocks which can cause a SIGBUS error if the file is subsequently + * memory-mapped. + */ + struct stat64 sb; + + if (fstat64(fd, &sb) == 0 && length > sb.st_blocks*512) { + RESTARTABLE(fallocate64(fd, 0, 0, length), result); + return result; + } + #endif RESTARTABLE(ftruncate64(fd, length), result); return result; } jlong
< prev index next >