1 /* Copyright (C) 1995,1997,1998,2000,2003,2004,2006
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 #include <sys/syscall.h>
28 #include <bits/wordsize.h>
29 #include <shlib-compat.h>
30 #include <bp-checks.h>
32 #include <kernel-features.h>
36 struct __old_ipc_perm shm_perm
; /* operation permission struct */
37 int shm_segsz
; /* size of segment in bytes */
38 __time_t shm_atime
; /* time of last shmat() */
39 __time_t shm_dtime
; /* time of last shmdt() */
40 __time_t shm_ctime
; /* time of last change by shmctl() */
41 __ipc_pid_t shm_cpid
; /* pid of creator */
42 __ipc_pid_t shm_lpid
; /* pid of last shmop */
43 unsigned short int shm_nattch
; /* number of current attaches */
44 unsigned short int __shm_npages
; /* size of segment (pages) */
45 unsigned long int *__unbounded __shm_pages
; /* array of ptrs to frames -> SHMMAX */
46 struct vm_area_struct
*__unbounded __attaches
; /* descriptors for attaches */
58 /* Provide operations to control over shared memory segments. */
59 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
60 int __old_shmctl (int, int, struct __old_shmid_ds
*);
62 int __new_shmctl (int, int, struct shmid_ds
*);
64 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
66 attribute_compat_text_section
67 __old_shmctl (int shmid
, int cmd
, struct __old_shmid_ds
*buf
)
69 return INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
, shmid
,
70 cmd
, 0, CHECK_1_NULL_OK (buf
));
72 compat_symbol (libc
, __old_shmctl
, shmctl
, GLIBC_2_0
);
76 __new_shmctl (int shmid
, int cmd
, struct shmid_ds
*buf
)
78 #if __ASSUME_IPC64 > 0
79 return INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
, shmid
, cmd
| __IPC_64
, 0,
91 return INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
, shmid
, cmd
, 0,
96 int save_errno
= errno
, result
;
99 struct __old_shmid_ds ds
;
100 struct __old_shminfo info
;
103 /* Unfortunately there is no way how to find out for sure whether
104 we should use old or new shmctl. */
105 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
, shmid
, cmd
| __IPC_64
, 0,
107 if (result
!= -1 || errno
!= EINVAL
)
110 __set_errno(save_errno
);
113 old
.ds
.shm_perm
.uid
= buf
->shm_perm
.uid
;
114 old
.ds
.shm_perm
.gid
= buf
->shm_perm
.gid
;
115 old
.ds
.shm_perm
.mode
= buf
->shm_perm
.mode
;
116 if (old
.ds
.shm_perm
.uid
!= buf
->shm_perm
.uid
||
117 old
.ds
.shm_perm
.gid
!= buf
->shm_perm
.gid
)
119 __set_errno (EINVAL
);
123 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
, shmid
, cmd
, 0,
124 __ptrvalue (&old
.ds
));
125 if (result
!= -1 && (cmd
== SHM_STAT
|| cmd
== IPC_STAT
))
127 memset(buf
, 0, sizeof(*buf
));
128 buf
->shm_perm
.__key
= old
.ds
.shm_perm
.__key
;
129 buf
->shm_perm
.uid
= old
.ds
.shm_perm
.uid
;
130 buf
->shm_perm
.gid
= old
.ds
.shm_perm
.gid
;
131 buf
->shm_perm
.cuid
= old
.ds
.shm_perm
.cuid
;
132 buf
->shm_perm
.cgid
= old
.ds
.shm_perm
.cgid
;
133 buf
->shm_perm
.mode
= old
.ds
.shm_perm
.mode
;
134 buf
->shm_perm
.__seq
= old
.ds
.shm_perm
.__seq
;
135 buf
->shm_atime
= old
.ds
.shm_atime
;
136 buf
->shm_dtime
= old
.ds
.shm_dtime
;
137 buf
->shm_ctime
= old
.ds
.shm_ctime
;
138 buf
->shm_segsz
= old
.ds
.shm_segsz
;
139 buf
->shm_nattch
= old
.ds
.shm_nattch
;
140 buf
->shm_cpid
= old
.ds
.shm_cpid
;
141 buf
->shm_lpid
= old
.ds
.shm_lpid
;
144 else if (result
!= -1 && cmd
== IPC_INFO
)
146 struct shminfo
*i
= (struct shminfo
*)buf
;
148 memset(i
, 0, sizeof(*i
));
149 i
->shmmax
= old
.info
.shmmax
;
150 i
->shmmin
= old
.info
.shmmin
;
151 i
->shmmni
= old
.info
.shmmni
;
152 i
->shmseg
= old
.info
.shmseg
;
153 i
->shmall
= old
.info
.shmall
;
161 versioned_symbol (libc
, __new_shmctl
, shmctl
, GLIBC_2_2
);