From 285ceb9ee51e064687da6fc3fbed984e34cf02e6 Mon Sep 17 00:00:00 2001 From: Vladimir Petko Date: Tue, 20 Aug 2024 15:51:40 +0000 Subject: [PATCH] 8336529: (fs) UnixFileAttributeViews setTimes() failing on armhf, Ubuntu noble Reviewed-by: bpb, alanb --- .../native/libnio/fs/UnixNativeDispatcher.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c index b7afaf4cdce..13fe39c6551 100644 --- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c +++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c @@ -254,6 +254,23 @@ static int statx_wrapper(int dirfd, const char *restrict pathname, int flags, } #endif +#if defined(__linux__) && defined(__arm__) +/** + * Lookup functions with time_t parameter. Try to use 64 bit symbol + * if sizeof(time_t) exceeds 32 bit. + */ +static void* lookup_time_t_function(const char* symbol, const char* symbol64) { + void *func_ptr = NULL; + if (sizeof(time_t) > 4) { + func_ptr = dlsym(RTLD_DEFAULT, symbol64); + } + if (func_ptr == NULL) { + return dlsym(RTLD_DEFAULT, symbol); + } + return func_ptr; +} +#endif + /** * Call this to throw an internal UnixException when a system/library * call fails @@ -351,11 +368,20 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this) #endif my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat"); my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat"); +#if defined(__linux__) && defined(__arm__) + my_futimesat_func = (futimesat_func*) lookup_time_t_function("futimesat", + "__futimesat64"); + my_lutimes_func = (lutimes_func*) lookup_time_t_function("lutimes", + "__lutimes64"); + my_futimens_func = (futimens_func*) lookup_time_t_function("futimens", + "__futimens64"); +#else #ifndef _ALLBSD_SOURCE my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat"); my_lutimes_func = (lutimes_func*) dlsym(RTLD_DEFAULT, "lutimes"); #endif my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens"); +#endif #if defined(_AIX) // Make sure we link to the 64-bit version of the function my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64");