shm.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. /* SHMLBA uses it */
  17. #define __getpagesize getpagesize
  18. #include <stdlib.h>
  19. #include <errno.h>
  20. #include <sys/shm.h>
  21. #include <syscall.h>
  22. #include "ipc.h"
  23. libc_hidden_proto(getpagesize)
  24. #ifdef L_shmat
  25. /* Attach the shared memory segment associated with SHMID to the data
  26. segment of the calling process. SHMADDR and SHMFLG determine how
  27. and where the segment is attached. */
  28. #if defined (__alpha__)
  29. #define __NR_shmat __NR_osf_shmat
  30. #endif
  31. #ifdef __NR_shmat
  32. _syscall3(void *, shmat, int, shmid, const void *,shmaddr, int, shmflg);
  33. #else
  34. void * shmat (int shmid, const void *shmaddr, int shmflg)
  35. {
  36. int retval;
  37. unsigned long raddr;
  38. retval = __syscall_ipc(IPCOP_shmat, shmid, shmflg, (int) &raddr, (void *) shmaddr);
  39. return ((unsigned long int) retval > -(unsigned long int) SHMLBA
  40. ? (void *) retval : (void *) raddr);
  41. }
  42. #endif
  43. #endif
  44. #ifdef L_shmctl
  45. /* Provide operations to control over shared memory segments. */
  46. #ifdef __NR_shmctl
  47. #define __NR___libc_shmctl __NR_shmctl
  48. static inline _syscall3(int, __libc_shmctl, int, shmid, int, cmd, struct shmid_ds *, buf);
  49. #endif
  50. int shmctl(int shmid, int cmd, struct shmid_ds *buf)
  51. {
  52. #ifdef __NR_shmctl
  53. return __libc_shmctl(shmid, cmd | __IPC_64, buf);
  54. #else
  55. return __syscall_ipc(IPCOP_shmctl, shmid, cmd | __IPC_64, 0, buf);
  56. #endif
  57. }
  58. #endif
  59. #ifdef L_shmdt
  60. /* Detach shared memory segment starting at address specified by SHMADDR
  61. from the caller's data segment. */
  62. #ifdef __NR_shmdt
  63. _syscall1(int, shmdt, const void *, shmaddr);
  64. #else
  65. int shmdt (const void *shmaddr)
  66. {
  67. return __syscall_ipc(IPCOP_shmdt, 0, 0, 0, (void *) shmaddr);
  68. }
  69. #endif
  70. #endif
  71. #ifdef L_shmget
  72. /* Return an identifier for an shared memory segment of at least size SIZE
  73. which is associated with KEY. */
  74. #ifdef __NR_shmget
  75. _syscall3(int, shmget, key_t, key, size_t, size, int, shmflg);
  76. #else
  77. int shmget (key_t key, size_t size, int shmflg)
  78. {
  79. return __syscall_ipc(IPCOP_shmget, key, size, shmflg, NULL);
  80. }
  81. #endif
  82. #endif