posix.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // posix.h -- Helper functions for POSIX-flavored OSs.
  2. /* Copyright (C) 2000, 2002, 2003, 2006, 2010, 2012 Free Software Foundation
  3. This file is part of libgcj.
  4. This software is copyrighted work licensed under the terms of the
  5. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. details. */
  7. #ifndef __JV_POSIX_H__
  8. #define __JV_POSIX_H__
  9. #include <time.h>
  10. #include <sys/types.h>
  11. #ifdef HAVE_SYS_TIME_H
  12. #include <sys/time.h>
  13. #endif
  14. #ifdef HAVE_SYS_SELECT_H
  15. #include <sys/select.h>
  16. #endif
  17. #ifdef HAVE_SYS_SOCKET_H
  18. #include <sys/socket.h>
  19. #endif
  20. #ifdef HAVE_UNISTD_H
  21. #include <unistd.h>
  22. #endif
  23. #include <fcntl.h>
  24. /* The header file <sys/rw_lock.h> needs to be included before javaprims.h
  25. on HP-UX 11 to avoid a compilation error. */
  26. #ifdef HAVE_SYS_RW_LOCK_H
  27. #include <sys/rw_lock.h>
  28. #endif
  29. #include <gcj/cni.h>
  30. #include <java/util/Properties.h>
  31. // Prefix and suffix for shared libraries.
  32. #define _Jv_platform_solib_prefix "lib"
  33. #if defined(__APPLE__) && defined(__MACH__)
  34. #define _Jv_platform_solib_suffix ".dylib"
  35. #elif defined(HPUX) && defined(HP_PA)
  36. #define _Jv_platform_solib_suffix ".sl"
  37. #else
  38. #define _Jv_platform_solib_suffix ".so"
  39. #endif
  40. #if __MACH__ && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060)
  41. # undef _Unwind_FindEnclosingFunction
  42. # define _Unwind_FindEnclosingFunction(PC) _darwin10_Unwind_FindEnclosingFunction(PC)
  43. #endif
  44. // Some POSIX systems don't have O_SYNC and O_DYSNC so we define them here.
  45. // Needed in java/io/natFileDescriptorPosix.cc.
  46. #if !defined (O_SYNC) && defined (O_FSYNC)
  47. #define O_SYNC O_FSYNC
  48. #endif
  49. #if !defined (O_DSYNC) && defined (O_FSYNC)
  50. #define O_DSYNC O_FSYNC
  51. #endif
  52. // If O_DSYNC is still not defined, use O_SYNC (needed for newlib)
  53. #if !defined (O_DSYNC)
  54. #define O_DSYNC O_SYNC
  55. #endif
  56. // Name of the Process implementation.
  57. #ifdef ECOS
  58. #define _Jv_platform_process ::java::lang::EcosProcess
  59. #else
  60. #define _Jv_platform_process ::java::lang::PosixProcess
  61. #endif
  62. // Separator for file name components.
  63. #define _Jv_platform_file_separator ((jchar) '/')
  64. // Separator for path components.
  65. #define _Jv_platform_path_separator ((jchar) ':')
  66. // List of names for `JNI_OnLoad'.
  67. #define _Jv_platform_onload_names { "JNI_OnLoad", NULL }
  68. // Type of libffi ABI used by JNICALL methods. NOTE: This must agree
  69. // with the JNICALL definition in jni.h
  70. #define _Jv_platform_ffi_abi FFI_DEFAULT_ABI
  71. #ifndef DISABLE_JAVA_NET
  72. #include <java/net/InetAddress.h>
  73. #endif
  74. extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
  75. extern jlong _Jv_platform_gettimeofday ();
  76. extern jlong _Jv_platform_nanotime ();
  77. extern void _Jv_platform_initialize (void);
  78. extern void _Jv_platform_initProperties (java::util::Properties*);
  79. #ifdef JV_HASH_SYNCHRONIZATION
  80. #ifndef HAVE_USLEEP_DECL
  81. extern "C" int usleep (useconds_t useconds);
  82. #endif /* not HAVE_USLEEP_DECL */
  83. inline void
  84. _Jv_platform_usleep (unsigned long usecs)
  85. {
  86. usleep (usecs);
  87. }
  88. #endif /* JV_HASH_SYNCHRONIZATION */
  89. #ifndef DISABLE_JAVA_NET
  90. #ifndef HAVE_SOCKLEN_T
  91. #define socklen_t int
  92. #endif
  93. static inline int
  94. _Jv_socket (int domain, int type, int protocol)
  95. {
  96. return ::socket (domain, type, protocol);
  97. }
  98. #undef socket
  99. inline int
  100. _Jv_connect (jint fd, sockaddr *ptr, int len)
  101. {
  102. return ::connect (fd, ptr, len);
  103. }
  104. #undef connect
  105. inline int
  106. _Jv_close (jint fd)
  107. {
  108. return ::close (fd);
  109. }
  110. #undef close
  111. // Avoid macro definitions of bind from system headers, e.g. on
  112. // Solaris 7 with _XOPEN_SOURCE. FIXME
  113. inline int
  114. _Jv_bind (int fd, struct sockaddr *addr, int addrlen)
  115. {
  116. return ::bind (fd, addr, addrlen);
  117. }
  118. #undef bind
  119. inline int
  120. _Jv_listen (int fd, int backlog)
  121. {
  122. return ::listen (fd, backlog);
  123. }
  124. #undef listen
  125. inline int
  126. _Jv_write(int s, void *buf, int len)
  127. {
  128. return ::write (s, buf, len);
  129. }
  130. #undef write
  131. inline int
  132. _Jv_read(int s, void *buf, int len)
  133. {
  134. return ::read (s, buf, len);
  135. }
  136. #undef read
  137. #endif /* DISABLE_JAVA_NET */
  138. // Wraps ::pipe
  139. static inline int
  140. _Jv_pipe (int filedes[2])
  141. {
  142. return ::pipe (filedes);
  143. }
  144. // Forward declaration. See java-stack.h for definition.
  145. struct _Jv_AddrInfo;
  146. // Given an address, determine the executable or shared object that defines
  147. // it and the nearest named symbol.
  148. extern int _Jv_platform_dladdr (void *addr, _Jv_AddrInfo *info);
  149. #endif /* __JV_POSIX_H__ */