socketcall.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* ID for functions called via socketcall system call.
  2. Copyright (C) 1995-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_SOCKETCALL_H
  16. #define _SYS_SOCKETCALL_H 1
  17. /* Define unique numbers for the operations permitted on socket. Linux
  18. uses a single system call for all these functions. The relevant code
  19. file is /usr/include/linux/net.h.
  20. We cannot use an enum here because the values are used in assembler
  21. code. */
  22. #define SOCKOP_invalid -1
  23. #define SOCKOP_socket 1
  24. #define SOCKOP_bind 2
  25. #define SOCKOP_connect 3
  26. #define SOCKOP_listen 4
  27. #define SOCKOP_accept 5
  28. #define SOCKOP_getsockname 6
  29. #define SOCKOP_getpeername 7
  30. #define SOCKOP_socketpair 8
  31. #define SOCKOP_send 9
  32. #define SOCKOP_recv 10
  33. #define SOCKOP_sendto 11
  34. #define SOCKOP_recvfrom 12
  35. #define SOCKOP_shutdown 13
  36. #define SOCKOP_setsockopt 14
  37. #define SOCKOP_getsockopt 15
  38. #define SOCKOP_sendmsg 16
  39. #define SOCKOP_recvmsg 17
  40. #define SOCKOP_accept4 18
  41. #define SOCKOP_recvmmsg 19
  42. #define SOCKOP_sendmmsg 20
  43. #define __SOCKETCALL1(name, a1) \
  44. INLINE_SYSCALL (socketcall, 2, name, \
  45. ((long int [1]) { (long int) (a1) }))
  46. #define __SOCKETCALL2(name, a1, a2) \
  47. INLINE_SYSCALL (socketcall, 2, name, \
  48. ((long int [2]) { (long int) (a1), (long int) (a2) }))
  49. #define __SOCKETCALL3(name, a1, a2, a3) \
  50. INLINE_SYSCALL (socketcall, 2, name, \
  51. ((long int [3]) { (long int) (a1), (long int) (a2), (long int) (a3) }))
  52. #define __SOCKETCALL4(name, a1, a2, a3, a4) \
  53. INLINE_SYSCALL (socketcall, 2, name, \
  54. ((long int [4]) { (long int) (a1), (long int) (a2), (long int) (a3), \
  55. (long int) (a4) }))
  56. #define __SOCKETCALL5(name, a1, a2, a3, a4, a5) \
  57. INLINE_SYSCALL (socketcall, 2, name, \
  58. ((long int [5]) { (long int) (a1), (long int) (a2), (long int) (a3), \
  59. (long int) (a4), (long int) (a5) }))
  60. #define __SOCKETCALL6(name, a1, a2, a3, a4, a5, a6) \
  61. INLINE_SYSCALL (socketcall, 2, name, \
  62. ((long int [6]) { (long int) (a1), (long int) (a2), (long int) (a3), \
  63. (long int) (a4), (long int) (a5), (long int) (a6) }))
  64. #define __SOCKETCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
  65. #define __SOCKETCALL_NARGS(...) \
  66. __SOCKETCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,)
  67. #define __SOCKETCALL_CONCAT_X(a,b) a##b
  68. #define __SOCKETCALL_CONCAT(a,b) __SOCKETCALL_CONCAT_X (a, b)
  69. #define __SOCKETCALL_DISP(b,...) \
  70. __SOCKETCALL_CONCAT (b,__SOCKETCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
  71. #define __SOCKETCALL(...) __SOCKETCALL_DISP (__SOCKETCALL, __VA_ARGS__)
  72. #define SOCKETCALL(name, args...) \
  73. ({ \
  74. long int sc_ret = __SOCKETCALL (SOCKOP_##name, args); \
  75. sc_ret; \
  76. })
  77. #if IS_IN (libc)
  78. # define __pthread_enable_asynccancel __libc_enable_asynccancel
  79. # define __pthread_disable_asynccancel __libc_disable_asynccancel
  80. #endif
  81. #define SOCKETCALL_CANCEL(name, args...) \
  82. ({ \
  83. int oldtype = LIBC_CANCEL_ASYNC (); \
  84. long int sc_ret = __SOCKETCALL (SOCKOP_##name, args); \
  85. LIBC_CANCEL_RESET (oldtype); \
  86. sc_ret; \
  87. })
  88. #endif /* sys/socketcall.h */