/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Unistd.java

https://github.com/oracle/graal · Java · 131 lines · 73 code · 30 blank · 28 comment · 0 complexity · 8e346af6a3e0bb0e99439f35d4b74cf3 MD5 · raw file

  1. /*
  2. * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation. Oracle designates this
  8. * particular file as subject to the "Classpath" exception as provided
  9. * by Oracle in the LICENSE file that accompanied this code.
  10. *
  11. * This code is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * version 2 for more details (a copy is included in the LICENSE file that
  15. * accompanied this code).
  16. *
  17. * You should have received a copy of the GNU General Public License version
  18. * 2 along with this work; if not, write to the Free Software Foundation,
  19. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22. * or visit www.oracle.com if you need additional information or have any
  23. * questions.
  24. */
  25. package com.oracle.svm.core.posix.headers;
  26. import org.graalvm.nativeimage.Platform;
  27. import org.graalvm.nativeimage.Platforms;
  28. import org.graalvm.nativeimage.c.CContext;
  29. import org.graalvm.nativeimage.c.constant.CConstant;
  30. import org.graalvm.nativeimage.c.function.CFunction;
  31. import org.graalvm.nativeimage.c.function.CFunction.Transition;
  32. import org.graalvm.nativeimage.c.type.CCharPointer;
  33. import org.graalvm.nativeimage.c.type.CCharPointerPointer;
  34. import org.graalvm.word.PointerBase;
  35. import org.graalvm.word.SignedWord;
  36. import org.graalvm.word.UnsignedWord;
  37. // Checkstyle: stop
  38. /**
  39. * Definitions manually translated from the C header file unistd.h.
  40. */
  41. @CContext(PosixDirectives.class)
  42. public class Unistd {
  43. @CConstant
  44. public static native short SEEK_SET();
  45. @CConstant
  46. public static native short SEEK_CUR();
  47. @CFunction
  48. public static native SignedWord lseek(int fd, SignedWord offset, int whence);
  49. @CFunction
  50. public static native SignedWord write(int fd, PointerBase buf, UnsignedWord n);
  51. @CFunction
  52. public static native CCharPointer getcwd(CCharPointer buf, UnsignedWord size);
  53. @CFunction
  54. public static native int execv(CCharPointer path, CCharPointerPointer argv);
  55. @CConstant
  56. public static native int _SC_CLK_TCK();
  57. @CConstant
  58. public static native int _SC_OPEN_MAX();
  59. @CConstant
  60. public static native int _SC_PAGESIZE();
  61. @CConstant
  62. public static native int _SC_PAGE_SIZE();
  63. @CConstant
  64. @Platforms(Platform.LINUX.class)
  65. public static native int _SC_PHYS_PAGES();
  66. @CConstant
  67. @Platforms(Platform.DARWIN.class)
  68. public static native int _CS_DARWIN_USER_TEMP_DIR();
  69. @CFunction
  70. public static native long sysconf(int name);
  71. @CFunction
  72. public static native UnsignedWord confstr(int name, CCharPointer buf, UnsignedWord len);
  73. @CFunction
  74. public static native int getpid();
  75. @CFunction
  76. public static native int getuid();
  77. @CFunction
  78. public static native int geteuid();
  79. @CFunction
  80. public static native int getgid();
  81. @CFunction
  82. public static native int getegid();
  83. @CFunction
  84. public static native int fork();
  85. @CFunction
  86. public static native int fsync(int fd);
  87. @CFunction
  88. public static native int getpagesize();
  89. @CFunction
  90. public static native int sleep(int seconds);
  91. public static class NoTransitions {
  92. @CFunction(transition = Transition.NO_TRANSITION)
  93. public static native int close(int fd);
  94. @CFunction(transition = Transition.NO_TRANSITION)
  95. public static native SignedWord read(int fd, PointerBase buf, UnsignedWord nbytes);
  96. @CFunction(transition = Transition.NO_TRANSITION)
  97. public static native long sysconf(int name);
  98. @CFunction(transition = Transition.NO_TRANSITION)
  99. public static native SignedWord lseek(int fd, SignedWord offset, int whence);
  100. }
  101. }