shm.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 on most of the archs (not mips) */
  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. #ifdef L_shmat
  24. /* Attach the shared memory segment associated with SHMID to the data
  25. segment of the calling process. SHMADDR and SHMFLG determine how
  26. and where the segment is attached. */
  27. #if defined(__NR_osf_shmat)
  28. # define __NR_shmat __NR_osf_shmat
  29. #endif
  30. #ifdef __NR_shmat
  31. _syscall3(void *, shmat, int, shmid, const void *,shmaddr, int, shmflg)
  32. #else
  33. /* psm: don't remove this, else mips will fail */
  34. #include <unistd.h>
  35. void * shmat (int shmid, const void *shmaddr, int shmflg)
  36. {
  37. int retval;
  38. unsigned long raddr;
  39. retval = __syscall_ipc(IPCOP_shmat, shmid, shmflg, (int) &raddr, (void *) shmaddr, 0);
  40. return ((unsigned long int) retval > -(unsigned long int) SHMLBA
  41. ? (void *) retval : (void *) raddr);
  42. }
  43. #endif
  44. #endif
  45. #ifdef L_shmctl
  46. /* Provide operations to control over shared memory segments. */
  47. #ifdef __NR_shmctl
  48. #define __NR___libc_shmctl __NR_shmctl
  49. static __inline__ _syscall3(int, __libc_shmctl, int, shmid, int, cmd, struct shmid_ds *, buf);
  50. #endif
  51. int shmctl(int shmid, int cmd, struct shmid_ds *buf)
  52. {
  53. #ifdef __NR_shmctl
  54. return __libc_shmctl(shmid, cmd | __IPC_64, buf);
  55. #else
  56. return __syscall_ipc(IPCOP_shmctl, shmid, cmd | __IPC_64, 0, buf, 0);
  57. #endif
  58. }
  59. #endif
  60. #ifdef L_shmdt
  61. /* Detach shared memory segment starting at address specified by SHMADDR
  62. from the caller's data segment. */
  63. #ifdef __NR_shmdt
  64. _syscall1(int, shmdt, const void *, shmaddr)
  65. #else
  66. int shmdt (const void *shmaddr)
  67. {
  68. return __syscall_ipc(IPCOP_shmdt, 0, 0, 0, (void *) shmaddr, 0);
  69. }
  70. #endif
  71. #endif
  72. #ifdef L_shmget
  73. /* Return an identifier for an shared memory segment of at least size SIZE
  74. which is associated with KEY. */
  75. #ifdef __NR_shmget
  76. _syscall3(int, shmget, key_t, key, size_t, size, int, shmflg)
  77. #else
  78. int shmget (key_t key, size_t size, int shmflg)
  79. {
  80. return __syscall_ipc(IPCOP_shmget, key, size, shmflg, NULL, 0);
  81. }
  82. #endif
  83. #endif