shm.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. 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. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. see <http://www.gnu.org/licenses/>. */
  15. /* SHMLBA uses it on most of the archs (not mips) */
  16. #define __getpagesize getpagesize
  17. #include <stdlib.h>
  18. #include <errno.h>
  19. #include <sys/shm.h>
  20. #include <syscall.h>
  21. #include "ipc.h"
  22. #if defined(__UCLIBC_USE_TIME64__)
  23. union shmun {
  24. struct shmid_ds* buff;
  25. void *__pad;
  26. };
  27. #endif
  28. #ifdef L_shmat
  29. /* Attach the shared memory segment associated with SHMID to the data
  30. segment of the calling process. SHMADDR and SHMFLG determine how
  31. and where the segment is attached. */
  32. #if defined(__NR_osf_shmat)
  33. # define __NR_shmat __NR_osf_shmat
  34. #endif
  35. #ifdef __NR_shmat
  36. _syscall3(void *, shmat, int, shmid, const void *,shmaddr, int, shmflg)
  37. #else
  38. /* psm: don't remove this, else mips will fail */
  39. #include <unistd.h>
  40. void * shmat (int shmid, const void *shmaddr, int shmflg)
  41. {
  42. int retval;
  43. unsigned long raddr;
  44. retval = __syscall_ipc(IPCOP_shmat, shmid, shmflg, (int) &raddr, (void *) shmaddr, 0);
  45. return ((unsigned long int) retval > -(unsigned long int) SHMLBA
  46. ? (void *) retval : (void *) raddr);
  47. }
  48. #endif
  49. #endif
  50. #ifdef L_shmctl
  51. /* Provide operations to control over shared memory segments. */
  52. #ifdef __NR_shmctl
  53. #define __NR___syscall_shmctl __NR_shmctl
  54. static __always_inline _syscall3(int, __syscall_shmctl, int, shmid, int, cmd, struct shmid_ds *, buf)
  55. #endif
  56. int shmctl(int shmid, int cmd, struct shmid_ds *buf)
  57. {
  58. #ifdef __NR_shmctl
  59. int __ret = __syscall_shmctl(shmid, cmd | __IPC_64, buf);
  60. #if (__WORDSIZE == 32) && defined(__MIPSEL__) && defined(__UCLIBC_USE_TIME64__)
  61. union shmun arg = {.buff = buf};
  62. if (arg.__pad != NULL) {
  63. arg.buff->shm_atime = (__time_t)arg.buff->shm_atime_internal_1 | (__time_t)(arg.buff->shm_atime_internal_2) << 32;
  64. arg.buff->shm_dtime = (__time_t)arg.buff->shm_dtime_internal_1 | (__time_t)(arg.buff->shm_dtime_internal_2) << 32;
  65. arg.buff->shm_ctime = (__time_t)arg.buff->shm_ctime_internal_1 | (__time_t)(arg.buff->shm_ctime_internal_2) << 32;
  66. }
  67. #endif
  68. return __ret;
  69. #else
  70. return __syscall_ipc(IPCOP_shmctl, shmid, cmd | __IPC_64, 0, buf, 0);
  71. #endif
  72. }
  73. #endif
  74. #ifdef L_shmdt
  75. /* Detach shared memory segment starting at address specified by SHMADDR
  76. from the caller's data segment. */
  77. #ifdef __NR_shmdt
  78. _syscall1(int, shmdt, const void *, shmaddr)
  79. #else
  80. int shmdt (const void *shmaddr)
  81. {
  82. return __syscall_ipc(IPCOP_shmdt, 0, 0, 0, (void *) shmaddr, 0);
  83. }
  84. #endif
  85. #endif
  86. #ifdef L_shmget
  87. /* Return an identifier for an shared memory segment of at least size SIZE
  88. which is associated with KEY. */
  89. #ifdef __NR_shmget
  90. _syscall3(int, shmget, key_t, key, size_t, size, int, shmflg)
  91. #else
  92. int shmget (key_t key, size_t size, int shmflg)
  93. {
  94. return __syscall_ipc(IPCOP_shmget, key, size, shmflg, NULL, 0);
  95. }
  96. #endif
  97. #endif