changeset 4539:a66317d3a7fe

Allow compilation against system calls (COMPILE_AGAINST_SYSCALLS)
author andrew
date Wed, 24 Aug 2011 18:04:16 +0100
parents 3cb9c8dc1cdc
children 6e4576191cff
files make/java/nio/Makefile src/solaris/native/common/deps/syscalls_fp.c src/solaris/native/common/deps/syscalls_fp.h src/solaris/native/sun/nio/ch/EPollArrayWrapper.c src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c
diffstat 6 files changed, 329 insertions(+), 140 deletions(-) [+]
line wrap: on
line diff
--- a/make/java/nio/Makefile	Wed Aug 24 06:43:33 2011 +0100
+++ b/make/java/nio/Makefile	Wed Aug 24 18:04:16 2011 +0100
@@ -246,6 +246,11 @@
 	gio_fp.c
 endif
 
+ifndef COMPILE_AGAINST_SYSCALLS
+FILES_c += \
+	syscalls_fp.c
+endif
+
 FILES_export += \
 	sun/nio/ch/EPoll.java \
         sun/nio/ch/EPollArrayWrapper.java \
@@ -276,6 +281,10 @@
   vpath %.c	$(PLATFORM_SRC)/native/common/deps/glib2
 endif
 
+ifndef COMPILE_AGAINST_SYSCALLS
+  vpath %.c	$(PLATFORM_SRC)/native/common/deps
+endif
+
 #
 # Various variables
 #
@@ -316,6 +325,12 @@
 		-L$(LIBDIR)/$(LIBARCH) -ljava -lnet
 endif # PLATFORM
 
+ifdef COMPILE_AGAINST_SYSCALLS
+  OTHER_INCLUDES += -DCOMPILE_AGAINST_SYSCALLS
+else
+  OTHER_INCLUDES += -I$(PLATFORM_SRC)/native/common/deps
+endif
+
 #
 # Rules
 #
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/native/common/deps/syscalls_fp.c	Wed Aug 24 18:04:16 2011 +0100
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2008, 2009, 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+#include <syscalls_fp.h>
+
+#include <dlfcn.h>
+#include <jni_util.h>
+
+openat64_func* my_openat64_func = NULL;
+fstatat64_func* my_fstatat64_func = NULL;
+unlinkat_func* my_unlinkat_func = NULL;
+renameat_func* my_renameat_func = NULL;
+futimesat_func* my_futimesat_func = NULL;
+fdopendir_func* my_fdopendir_func = NULL;
+fgetxattr_func* my_fgetxattr_func = NULL;
+fsetxattr_func* my_fsetxattr_func = NULL;
+fremovexattr_func* my_fremovexattr_func = NULL;
+flistxattr_func* my_flistxattr_func = NULL;
+epoll_create_t epoll_create_func = NULL;
+epoll_ctl_t    epoll_ctl_func = NULL;
+epoll_wait_t   epoll_wait_func = NULL;
+
+void syscalls_init()
+{
+    my_fgetxattr_func = (fgetxattr_func*)dlsym(RTLD_DEFAULT, "fgetxattr");
+    my_fsetxattr_func = (fsetxattr_func*)dlsym(RTLD_DEFAULT, "fsetxattr");
+    my_fremovexattr_func = (fremovexattr_func*)dlsym(RTLD_DEFAULT, "fremovexattr");
+    my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr");
+}
+
+int atsyscalls_init()
+{
+    /* system calls that might not be available at run time */
+
+#if defined(__solaris__) && defined(_LP64)
+    /* Solaris 64-bit does not have openat64/fstatat64 */
+    my_openat64_func = (openat64_func*)dlsym(RTLD_DEFAULT, "openat");
+    my_fstatat64_func = (fstatat64_func*)dlsym(RTLD_DEFAULT, "fstatat");
+#else
+    my_openat64_func = (openat64_func*) dlsym(RTLD_DEFAULT, "openat64");
+    my_fstatat64_func = (fstatat64_func*) dlsym(RTLD_DEFAULT, "fstatat64");
+#endif
+    my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat");
+    my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
+    my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat");
+    my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
+
+#if defined(_ATFILE_SOURCE)
+    /* fstatat64 from glibc requires a define */
+    if (my_fstatat64_func == NULL)
+        my_fstatat64_func = (fstatat64_func*)&fstatat64;
+#endif
+
+    if (my_openat64_func != NULL &&  my_fstatat64_func != NULL &&
+        my_unlinkat_func != NULL && my_renameat_func != NULL &&
+        my_futimesat_func != NULL && my_fdopendir_func != NULL)
+    {
+        return 0;
+    }
+
+    return -1;
+}
+
+int epollcalls_init()
+{
+    epoll_create_func = (epoll_create_t) dlsym(RTLD_DEFAULT, "epoll_create");
+    epoll_ctl_func    = (epoll_ctl_t)    dlsym(RTLD_DEFAULT, "epoll_ctl");
+    epoll_wait_func   = (epoll_wait_t)   dlsym(RTLD_DEFAULT, "epoll_wait");
+
+    if ((epoll_create_func == NULL) || (epoll_ctl_func == NULL) ||
+        (epoll_wait_func == NULL)) {
+        return -1;
+    }
+    return 0;
+}
+
+size_t fgetxattr_dl(int fd, const char* name, void* value, size_t size)
+{
+    if (my_fgetxattr_func == NULL) {
+        errno = ENOTSUP;
+	return -1;
+    }
+    /* EINTR not documented */
+    return (*my_fgetxattr_func)(fd, name, value, size);
+}
+
+int fsetxattr_dl(int fd, const char* name, void* value, size_t size, int flags)
+{
+    if (my_fsetxattr_func == NULL) {
+        errno = ENOTSUP;
+	return -1;
+    }
+    /* EINTR not documented */
+    return (*my_fsetxattr_func)(fd, name, value, size, flags);
+}
+
+int fremovexattr_dl(int fd, const char* name)
+{
+    if (my_fremovexattr_func == NULL) {
+        errno = ENOTSUP;
+	return -1;
+    }
+    /* EINTR not documented */
+    return (*my_fremovexattr_func)(fd, name);
+}
+
+int flistxattr_dl(int fd, char* list, size_t size)
+{
+    if (my_flistxattr_func == NULL) {
+        errno = ENOTSUP;
+	return -1;
+    }
+    /* EINTR not documented */
+    return (*my_flistxattr_func)(fd, list, size);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/native/common/deps/syscalls_fp.h	Wed Aug 24 18:04:16 2011 +0100
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2008, 2009, 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+#ifndef __SYSCALLS_FP_H__
+#define __SYSCALLS_FP_H__
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+/* epoll_wait(2) man page */
+
+typedef union epoll_data {
+    void *ptr;
+    int fd;
+    __uint32_t u32;
+    __uint64_t u64;
+} epoll_data_t;
+
+/* x86-64 has same alignment as 32-bit */
+#ifdef __x86_64__
+#define EPOLL_PACKED __attribute__((packed))
+#else
+#define EPOLL_PACKED
+#endif
+
+struct epoll_event {
+    __uint32_t events;  /* Epoll events */
+    epoll_data_t data;  /* User data variable */
+} EPOLL_PACKED;
+
+#ifdef  __cplusplus
+}
+#endif
+
+/**
+ * System calls that may not be available at run time.
+ */
+typedef size_t fgetxattr_func(int fd, const char* name, void* value, size_t size);
+typedef int fsetxattr_func(int fd, const char* name, void* value, size_t size, int flags);
+typedef int fremovexattr_func(int fd, const char* name);
+typedef int flistxattr_func(int fd, char* list, size_t size);
+typedef int openat64_func(int, const char *, int, ...);
+typedef int fstatat64_func(int, const char *, struct stat64 *, int);
+typedef int unlinkat_func(int, const char*, int);
+typedef int renameat_func(int, const char*, int, const char*);
+typedef int futimesat_func(int, const char *, const struct timeval *);
+typedef DIR* fdopendir_func(int);
+
+/*
+ * epoll event notification is new in 2.6 kernel. As the offical build
+ * platform for the JDK is on a 2.4-based distribution then we must
+ * obtain the addresses of the epoll functions dynamically.
+ */
+typedef int (*epoll_create_t)(int size);
+typedef int (*epoll_ctl_t)   (int epfd, int op, int fd, struct epoll_event *event);
+typedef int (*epoll_wait_t)  (int epfd, struct epoll_event *events, int maxevents, int timeout);
+
+extern openat64_func* my_openat64_func;
+extern fstatat64_func* my_fstatat64_func;
+extern unlinkat_func* my_unlinkat_func;
+extern renameat_func* my_renameat_func;
+extern futimesat_func* my_futimesat_func;
+extern fdopendir_func* my_fdopendir_func;
+extern fgetxattr_func* my_fgetxattr_func;
+extern fsetxattr_func* my_fsetxattr_func;
+extern fremovexattr_func* my_fremovexattr_func;
+extern flistxattr_func* my_flistxattr_func;
+extern epoll_create_t epoll_create_func;
+extern epoll_ctl_t    epoll_ctl_func;
+extern epoll_wait_t   epoll_wait_func;
+
+void syscalls_init();
+int atsyscalls_init();
+int epollcalls_init();
+size_t fgetxattr_dl(int fd, const char* name, void* value, size_t size);
+int fsetxattr_dl(int fd, const char* name, void* value, size_t size, int flags);
+int fremovexattr_dl(int fd, const char* name);
+int flistxattr_dl(int fd, char* list, size_t size);
+
+#define openat64 (*my_openat64_func)
+#define fstatat64 (*my_fstatat64_func)
+#define unlinkat (*my_unlinkat_func)
+#define renameat (*my_renameat_func)
+#define futimesat (*my_futimesat_func)
+#define fdopendir (*my_fdopendir_func)
+#define fgetxattr fgetxattr_dl
+#define fsetxattr fsetxattr_dl
+#define fremovexattr fremovexattr_dl
+#define flistxattr flistxattr_dl
+#define epoll_create (*epoll_create_func)
+#define epoll_ctl (*epoll_ctl_func)
+#define epoll_wait (*epoll_wait_func) 
+#endif
--- a/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c	Wed Aug 24 06:43:33 2011 +0100
+++ b/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c	Wed Aug 24 18:04:16 2011 +0100
@@ -30,39 +30,14 @@
 
 #include "sun_nio_ch_EPollArrayWrapper.h"
 
-#include <dlfcn.h>
 #include <unistd.h>
 #include <sys/resource.h>
 #include <sys/time.h>
 
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-/* epoll_wait(2) man page */
-
-typedef union epoll_data {
-    void *ptr;
-    int fd;
-    __uint32_t u32;
-    __uint64_t u64;
-} epoll_data_t;
-
-
-/* x86-64 has same alignment as 32-bit */
-#ifdef __x86_64__
-#define EPOLL_PACKED __attribute__((packed))
+#ifdef COMPILE_AGAINST_SYSCALLS
+#include <sys/epoll.h>
 #else
-#define EPOLL_PACKED
-#endif
-
-struct epoll_event {
-    __uint32_t events;  /* Epoll events */
-    epoll_data_t data;  /* User data variable */
-} EPOLL_PACKED;
-
-#ifdef  __cplusplus
-}
+#include <syscalls_fp.h>
 #endif
 
 #define RESTARTABLE(_cmd, _result) do { \
@@ -71,19 +46,6 @@
   } while((_result == -1) && (errno == EINTR)); \
 } while(0)
 
-/*
- * epoll event notification is new in 2.6 kernel. As the offical build
- * platform for the JDK is on a 2.4-based distribution then we must
- * obtain the addresses of the epoll functions dynamically.
- */
-typedef int (*epoll_create_t)(int size);
-typedef int (*epoll_ctl_t)   (int epfd, int op, int fd, struct epoll_event *event);
-typedef int (*epoll_wait_t)  (int epfd, struct epoll_event *events, int maxevents, int timeout);
-
-static epoll_create_t epoll_create_func;
-static epoll_ctl_t    epoll_ctl_func;
-static epoll_wait_t   epoll_wait_func;
-
 static int
 iepoll(int epfd, struct epoll_event *events, int numfds, jlong timeout)
 {
@@ -96,7 +58,7 @@
     start = t.tv_sec * 1000 + t.tv_usec / 1000;
 
     for (;;) {
-        int res = (*epoll_wait_func)(epfd, events, numfds, timeout);
+        int res = epoll_wait (epfd, events, numfds, timeout);
         if (res < 0 && errno == EINTR) {
             if (remaining >= 0) {
                 gettimeofday(&t, NULL);
@@ -117,14 +79,10 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_EPollArrayWrapper_init(JNIEnv *env, jclass this)
 {
-    epoll_create_func = (epoll_create_t) dlsym(RTLD_DEFAULT, "epoll_create");
-    epoll_ctl_func    = (epoll_ctl_t)    dlsym(RTLD_DEFAULT, "epoll_ctl");
-    epoll_wait_func   = (epoll_wait_t)   dlsym(RTLD_DEFAULT, "epoll_wait");
-
-    if ((epoll_create_func == NULL) || (epoll_ctl_func == NULL) ||
-        (epoll_wait_func == NULL)) {
+#ifndef COMPILE_AGAINST_SYSCALLS
+    if (epollcalls_init() < 0)
         JNU_ThrowInternalError(env, "unable to get address of epoll functions, pre-2.6 kernel?");
-    }
+#endif
 }
 
 JNIEXPORT jint JNICALL
@@ -134,7 +92,7 @@
      * epoll_create expects a size as a hint to the kernel about how to
      * dimension internal structures. We can't predict the size in advance.
      */
-    int epfd = (*epoll_create_func)(256);
+    int epfd = epoll_create (256);
     if (epfd < 0) {
        JNU_ThrowIOExceptionWithLastError(env, "epoll_create failed");
     }
@@ -173,7 +131,7 @@
     event.events = events;
     event.data.fd = fd;
 
-    RESTARTABLE((*epoll_ctl_func)(epfd, (int)opcode, (int)fd, &event), res);
+    RESTARTABLE(epoll_ctl (epfd, (int)opcode, (int)fd, &event), res);
 
     /*
      * A channel may be registered with several Selectors. When each Selector
@@ -199,7 +157,7 @@
     int res;
 
     if (timeout <= 0) {           /* Indefinite or no wait */
-        RESTARTABLE((*epoll_wait_func)(epfd, events, numfds, timeout), res);
+        RESTARTABLE(epoll_wait (epfd, events, numfds, timeout), res);
     } else {                      /* Bounded wait; bounded restarts */
         res = iepoll(epfd, events, numfds, timeout);
     }
--- a/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c	Wed Aug 24 06:43:33 2011 +0100
+++ b/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c	Wed Aug 24 18:04:16 2011 +0100
@@ -35,15 +35,12 @@
 
 #include "sun_nio_fs_LinuxNativeDispatcher.h"
 
-typedef size_t fgetxattr_func(int fd, const char* name, void* value, size_t size);
-typedef int fsetxattr_func(int fd, const char* name, void* value, size_t size, int flags);
-typedef int fremovexattr_func(int fd, const char* name);
-typedef int flistxattr_func(int fd, char* list, size_t size);
-
-fgetxattr_func* my_fgetxattr_func = NULL;
-fsetxattr_func* my_fsetxattr_func = NULL;
-fremovexattr_func* my_fremovexattr_func = NULL;
-flistxattr_func* my_flistxattr_func = NULL;
+#ifdef COMPILE_AGAINST_SYSCALLS
+#include <sys/types.h>
+#include <attr/xattr.h>
+#else
+#include <syscalls_fp.h>
+#endif
 
 static void throwUnixException(JNIEnv* env, int errnum) {
     jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
@@ -56,10 +53,9 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_fs_LinuxNativeDispatcher_init(JNIEnv *env, jclass clazz)
 {
-    my_fgetxattr_func = (fgetxattr_func*)dlsym(RTLD_DEFAULT, "fgetxattr");
-    my_fsetxattr_func = (fsetxattr_func*)dlsym(RTLD_DEFAULT, "fsetxattr");
-    my_fremovexattr_func = (fremovexattr_func*)dlsym(RTLD_DEFAULT, "fremovexattr");
-    my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr");
+#ifndef COMPILE_AGAINST_SYSCALLS
+    syscalls_init();
+#endif
 }
 
 JNIEXPORT jint JNICALL
@@ -70,12 +66,7 @@
     const char* name = jlong_to_ptr(nameAddress);
     void* value = jlong_to_ptr(valueAddress);
 
-    if (my_fgetxattr_func == NULL) {
-        errno = ENOTSUP;
-    } else {
-        /* EINTR not documented */
-        res = (*my_fgetxattr_func)(fd, name, value, valueLen);
-    }
+    res = fgetxattr (fd, name, value, valueLen);
     if (res == (size_t)-1)
         throwUnixException(env, errno);
     return (jint)res;
@@ -89,12 +80,7 @@
     const char* name = jlong_to_ptr(nameAddress);
     void* value = jlong_to_ptr(valueAddress);
 
-    if (my_fsetxattr_func == NULL) {
-        errno = ENOTSUP;
-    } else {
-        /* EINTR not documented */
-        res = (*my_fsetxattr_func)(fd, name, value, valueLen, 0);
-    }
+    res = fsetxattr (fd, name, value, valueLen, 0);
     if (res == -1)
         throwUnixException(env, errno);
 }
@@ -106,12 +92,7 @@
     int res = -1;
     const char* name = jlong_to_ptr(nameAddress);
 
-    if (my_fremovexattr_func == NULL) {
-        errno = ENOTSUP;
-    } else {
-        /* EINTR not documented */
-        res = (*my_fremovexattr_func)(fd, name);
-    }
+    res = fremovexattr (fd, name);
     if (res == -1)
         throwUnixException(env, errno);
 }
@@ -123,12 +104,7 @@
     size_t res = -1;
     char* list = jlong_to_ptr(listAddress);
 
-    if (my_flistxattr_func == NULL) {
-        errno = ENOTSUP;
-    } else {
-        /* EINTR not documented */
-        res = (*my_flistxattr_func)(fd, list, (size_t)size);
-    }
+    res = flistxattr (fd, list, (size_t)size);
     if (res == (size_t)-1)
         throwUnixException(env, errno);
     return (jint)res;
--- a/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c	Wed Aug 24 06:43:33 2011 +0100
+++ b/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c	Wed Aug 24 18:04:16 2011 +0100
@@ -62,6 +62,10 @@
 
 #include "sun_nio_fs_UnixNativeDispatcher.h"
 
+#ifndef COMPILE_AGAINST_SYSCALLS
+#include <syscalls_fp.h>
+#endif
+
 /**
  * Size of password or group entry when not available via sysconf
  */
@@ -103,23 +107,6 @@
 static jfieldID entry_dev;
 
 /**
- * System calls that may not be available at run time.
- */
-typedef int openat64_func(int, const char *, int, ...);
-typedef int fstatat64_func(int, const char *, struct stat64 *, int);
-typedef int unlinkat_func(int, const char*, int);
-typedef int renameat_func(int, const char*, int, const char*);
-typedef int futimesat_func(int, const char *, const struct timeval *);
-typedef DIR* fdopendir_func(int);
-
-static openat64_func* my_openat64_func = NULL;
-static fstatat64_func* my_fstatat64_func = NULL;
-static unlinkat_func* my_unlinkat_func = NULL;
-static renameat_func* my_renameat_func = NULL;
-static futimesat_func* my_futimesat_func = NULL;
-static fdopendir_func* my_fdopendir_func = NULL;
-
-/**
  * Call this to throw an internal UnixException when a system/library
  * call fails
  */
@@ -137,8 +124,9 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
 {
+    jclass clazz;
     jint flags = 0;
-    jclass clazz;
+    int ret;
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileAttributes");
     if (clazz == NULL) {
@@ -175,33 +163,14 @@
     entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
     entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
 
-    /* system calls that might not be available at run time */
-
-#if defined(__solaris__) && defined(_LP64)
-    /* Solaris 64-bit does not have openat64/fstatat64 */
-    my_openat64_func = (openat64_func*)dlsym(RTLD_DEFAULT, "openat");
-    my_fstatat64_func = (fstatat64_func*)dlsym(RTLD_DEFAULT, "fstatat");
+#ifdef COMPILE_AGAINST_SYSCALLS
+    ret = 0;
 #else
-    my_openat64_func = (openat64_func*) dlsym(RTLD_DEFAULT, "openat64");
-    my_fstatat64_func = (fstatat64_func*) dlsym(RTLD_DEFAULT, "fstatat64");
-#endif
-    my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat");
-    my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
-    my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat");
-    my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
-
-#if defined(_ATFILE_SOURCE)
-    /* fstatat64 from glibc requires a define */
-    if (my_fstatat64_func == NULL)
-        my_fstatat64_func = (fstatat64_func*)&fstatat64;
+    ret = atsyscalls_init();
 #endif
 
-    if (my_openat64_func != NULL &&  my_fstatat64_func != NULL &&
-        my_unlinkat_func != NULL && my_renameat_func != NULL &&
-        my_futimesat_func != NULL && my_fdopendir_func != NULL)
-    {
+    if (ret == 0)
         flags |= sun_nio_fs_UnixNativeDispatcher_HAS_AT_SYSCALLS;
-    }
 
     return flags;
 }
@@ -307,12 +276,14 @@
     jint fd;
     const char* path = (const char*)jlong_to_ptr(pathAddress);
 
+#ifndef COMPILE_AGAINST_SYSCALLS
     if (my_openat64_func == NULL) {
         JNU_ThrowInternalError(env, "should not reach here");
         return -1;
     }
+#endif
 
-    RESTARTABLE((*my_openat64_func)(dfd, path, (int)oflags, (mode_t)mode), fd);
+    RESTARTABLE(openat64 (dfd, path, (int)oflags, (mode_t)mode), fd);
     if (fd == -1) {
         throwUnixException(env, errno);
     }
@@ -424,11 +395,13 @@
     struct stat64 buf;
     const char* path = (const char*)jlong_to_ptr(pathAddress);
 
+#ifndef COMPILE_AGAINST_SYSCALLS
     if (my_fstatat64_func == NULL) {
         JNU_ThrowInternalError(env, "should not reach here");
         return;
     }
-    RESTARTABLE((*my_fstatat64_func)((int)dfd, path, &buf, (int)flag), err);
+#endif
+    RESTARTABLE(fstatat64 ((int)dfd, path, &buf, (int)flag), err);
     if (err == -1) {
         throwUnixException(env, errno);
     } else {
@@ -531,12 +504,11 @@
     times[1].tv_sec = modificationTime / 1000000;
     times[1].tv_usec = modificationTime % 1000000;
 
-    if (my_futimesat_func != NULL) {
-        RESTARTABLE((*my_futimesat_func)(filedes, NULL, &times[0]), err);
-        if (err == -1) {
-            throwUnixException(env, errno);
-        }
+    RESTARTABLE(futimesat (filedes, NULL, &times[0]), err);
+    if (err == -1) {
+        throwUnixException(env, errno);
     }
+
 }
 
 JNIEXPORT jlong JNICALL
@@ -558,13 +530,15 @@
 Java_sun_nio_fs_UnixNativeDispatcher_fdopendir(JNIEnv* env, jclass this, int dfd) {
     DIR* dir;
 
+#ifndef COMPILE_AGAINST_SYSCALLS
     if (my_fdopendir_func == NULL) {
         JNU_ThrowInternalError(env, "should not reach here");
         return (jlong)-1;
     }
+#endif
 
     /* EINTR not listed as a possible error */
-    dir = (*my_fdopendir_func)((int)dfd);
+    dir = fdopendir ((int)dfd);
     if (dir == NULL) {
         throwUnixException(env, errno);
     }
@@ -667,13 +641,15 @@
 {
     const char* path = (const char*)jlong_to_ptr(pathAddress);
 
+#ifndef COMPILE_AGAINST_SYSCALLS
     if (my_unlinkat_func == NULL) {
         JNU_ThrowInternalError(env, "should not reach here");
         return;
     }
+#endif
 
     /* EINTR not listed as a possible error */
-    if ((*my_unlinkat_func)((int)dfd, path, (int)flags) == -1) {
+    if (unlinkat ((int)dfd, path, (int)flags) == -1) {
         throwUnixException(env, errno);
     }
 }
@@ -698,13 +674,15 @@
     const char* from = (const char*)jlong_to_ptr(fromAddress);
     const char* to = (const char*)jlong_to_ptr(toAddress);
 
+#ifndef COMPILE_AGAINST_SYSCALLS
     if (my_renameat_func == NULL) {
         JNU_ThrowInternalError(env, "should not reach here");
         return;
     }
+#endif
 
     /* EINTR not listed as a possible error */
-    if ((*my_renameat_func)((int)fromfd, from, (int)tofd, to) == -1) {
+    if (renameat ((int)fromfd, from, (int)tofd, to) == -1) {
         throwUnixException(env, errno);
     }
 }