shm.c 2.6 KB

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