< prev index next >
src/solaris/native/java/io/io_util_md.c
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -21,10 +21,14 @@
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+#if defined(__linux__)
+#define _FILE_OFFSET_BITS 64
+#endif
+
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "io_util.h"
#include "io_util_md.h"
@@ -206,10 +210,29 @@
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(posix_fallocate(fd, 0, length), result);
+ // Return on success or if errno is neither EOPNOTSUPP nor ENOSYS
+ if (result == 0) {
+ return 0;
+ } else if (errno != EOPNOTSUPP && errno != ENOSYS) {
+ return result;
+ }
+ }
+#endif
RESTARTABLE(ftruncate64(fd, length), result);
return result;
}
size_t
< prev index next >