blob: 27e871f27cf3fed623c65cdf55e1edb8793be469 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20/* SHMLBA uses it on most of the archs (not mips) */
21#define __getpagesize getpagesize
22
23#include <stdlib.h>
24#include <errno.h>
25#include <sys/shm.h>
26#include <syscall.h>
27#include "ipc.h"
28
29#ifdef L_shmat
30/* Attach the shared memory segment associated with SHMID to the data
31 segment of the calling process. SHMADDR and SHMFLG determine how
32 and where the segment is attached. */
33#if defined(__NR_osf_shmat)
34# define __NR_shmat __NR_osf_shmat
35#endif
36#ifdef __NR_shmat
37_syscall3(void *, shmat, int, shmid, const void *,shmaddr, int, shmflg)
38#else
39/* psm: don't remove this, else mips will fail */
40#include <unistd.h>
41
42void * shmat (int shmid, const void *shmaddr, int shmflg)
43{
44 int retval;
45 unsigned long raddr;
46
47 retval = __syscall_ipc(IPCOP_shmat, shmid, shmflg, (int) &raddr, (void *) shmaddr, 0);
48 return ((unsigned long int) retval > -(unsigned long int) SHMLBA
49 ? (void *) retval : (void *) raddr);
50}
51#endif
52#endif
53
54#ifdef L_shmctl
55/* Provide operations to control over shared memory segments. */
56#ifdef __NR_shmctl
57#define __NR___libc_shmctl __NR_shmctl
58static __inline__ _syscall3(int, __libc_shmctl, int, shmid, int, cmd, struct shmid_ds *, buf)
59#endif
60int shmctl(int shmid, int cmd, struct shmid_ds *buf)
61{
62#ifdef __NR_shmctl
63 return __libc_shmctl(shmid, cmd | __IPC_64, buf);
64#else
65 return __syscall_ipc(IPCOP_shmctl, shmid, cmd | __IPC_64, 0, buf, 0);
66#endif
67}
68#endif
69
70
71#ifdef L_shmdt
72/* Detach shared memory segment starting at address specified by SHMADDR
73 from the caller's data segment. */
74#ifdef __NR_shmdt
75_syscall1(int, shmdt, const void *, shmaddr)
76#else
77int shmdt (const void *shmaddr)
78{
79 return __syscall_ipc(IPCOP_shmdt, 0, 0, 0, (void *) shmaddr, 0);
80}
81#endif
82#endif
83
84#ifdef L_shmget
85/* Return an identifier for an shared memory segment of at least size SIZE
86 which is associated with KEY. */
87#ifdef __NR_shmget
88_syscall3(int, shmget, key_t, key, size_t, size, int, shmflg)
89#else
90int shmget (key_t key, size_t size, int shmflg)
91{
92 return __syscall_ipc(IPCOP_shmget, key, size, shmflg, NULL, 0);
93}
94#endif
95#endif