1 /* Copyright (C) 1995,1997,1998,2000,2004,2006 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.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <sys/syscall.h>
27 #include <bits/wordsize.h>
28 #include <bp-checks.h>
30 #include <kernel-features.h>
31 #include <shlib-compat.h>
35 struct __old_ipc_perm shm_perm
; /* operation permission struct */
36 int shm_segsz
; /* size of segment in bytes */
37 __time_t shm_atime
; /* time of last shmat() */
38 __time_t shm_dtime
; /* time of last shmdt() */
39 __time_t shm_ctime
; /* time of last change by shmctl() */
40 __ipc_pid_t shm_cpid
; /* pid of creator */
41 __ipc_pid_t shm_lpid
; /* pid of last shmop */
42 unsigned short int shm_nattch
; /* number of current attaches */
43 unsigned short int __shm_npages
; /* size of segment (pages) */
44 unsigned long int *__unbounded __shm_pages
; /* array of ptrs to frames -> SHMMAX */
45 struct vm_area_struct
*__unbounded __attaches
; /* descriptors for attaches */
58 # if __ASSUME_32BITUIDS == 0
59 /* This variable is shared with all files that need to check for 32bit
61 extern int __libc_missing_32bit_uids
;
65 /* Provide operations to control over shared memory segments. */
66 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
67 int __old_shmctl (int, int, struct __old_shmid_ds
*);
69 int __new_shmctl (int, int, struct shmid_ds
*);
71 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
73 attribute_compat_text_section
74 __old_shmctl (int shmid
, int cmd
, struct __old_shmid_ds
*buf
)
76 return INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
,
77 shmid
, cmd
, 0, CHECK_1 (buf
));
79 compat_symbol (libc
, __old_shmctl
, shmctl
, GLIBC_2_0
);
83 __new_shmctl (int shmid
, int cmd
, struct shmid_ds
*buf
)
85 #if __ASSUME_32BITUIDS > 0
86 return INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
,
87 shmid
, cmd
| __IPC_64
, 0, CHECK_1 (buf
));
98 return INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
,
99 shmid
, cmd
, 0, CHECK_1 (buf
));
103 struct __old_shmid_ds old
;
106 # ifdef __NR_getuid32
107 if (__libc_missing_32bit_uids
<= 0)
109 if (__libc_missing_32bit_uids
< 0)
111 int save_errno
= errno
;
113 /* Test presence of new IPC by testing for getuid32 syscall. */
114 result
= INLINE_SYSCALL (getuid32
, 0);
115 if (result
== -1 && errno
== ENOSYS
)
116 __libc_missing_32bit_uids
= 1;
118 __libc_missing_32bit_uids
= 0;
119 __set_errno(save_errno
);
121 if (__libc_missing_32bit_uids
<= 0)
122 return INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
,
123 shmid
, cmd
| __IPC_64
, 0, CHECK_1 (buf
));
129 old
.shm_perm
.uid
= buf
->shm_perm
.uid
;
130 old
.shm_perm
.gid
= buf
->shm_perm
.gid
;
131 old
.shm_perm
.mode
= buf
->shm_perm
.mode
;
132 if (old
.shm_perm
.uid
!= buf
->shm_perm
.uid
||
133 old
.shm_perm
.gid
!= buf
->shm_perm
.gid
)
135 __set_errno (EINVAL
);
139 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_shmctl
,
140 shmid
, cmd
, 0, __ptrvalue (&old
));
141 if (result
!= -1 && (cmd
== SHM_STAT
|| cmd
== IPC_STAT
))
143 memset(buf
, 0, sizeof(*buf
));
144 buf
->shm_perm
.__key
= old
.shm_perm
.__key
;
145 buf
->shm_perm
.uid
= old
.shm_perm
.uid
;
146 buf
->shm_perm
.gid
= old
.shm_perm
.gid
;
147 buf
->shm_perm
.cuid
= old
.shm_perm
.cuid
;
148 buf
->shm_perm
.cgid
= old
.shm_perm
.cgid
;
149 buf
->shm_perm
.mode
= old
.shm_perm
.mode
;
150 buf
->shm_perm
.__seq
= old
.shm_perm
.__seq
;
151 buf
->shm_atime
= old
.shm_atime
;
152 buf
->shm_dtime
= old
.shm_dtime
;
153 buf
->shm_ctime
= old
.shm_ctime
;
154 buf
->shm_segsz
= old
.shm_segsz
;
155 buf
->shm_nattch
= old
.shm_nattch
;
156 buf
->shm_cpid
= old
.shm_cpid
;
157 buf
->shm_lpid
= old
.shm_lpid
;
159 # if __WORDSIZE != 32
160 else if (result
!= -1 && cmd
== IPC_INFO
)
162 struct __old_shminfo
*oldi
= (struct __old_shminfo
*)&old
;
163 struct shminfo
*i
= (struct shminfo
*)buf
;
165 memset(i
, 0, sizeof(*i
));
166 i
->shmmax
= oldi
->shmmax
;
167 i
->shmmin
= oldi
->shmmin
;
168 i
->shmmni
= oldi
->shmmni
;
169 i
->shmseg
= oldi
->shmseg
;
170 i
->shmall
= oldi
->shmall
;
178 versioned_symbol (libc
, __new_shmctl
, shmctl
, GLIBC_2_2
);