1 /* Copyright (C) 1995, 1997, 1998, 2000, 2003 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"
34 struct __old_ipc_perm shm_perm
; /* operation permission struct */
35 int shm_segsz
; /* size of segment in bytes */
36 __time_t shm_atime
; /* time of last shmat() */
37 __time_t shm_dtime
; /* time of last shmdt() */
38 __time_t shm_ctime
; /* time of last change by shmctl() */
39 __ipc_pid_t shm_cpid
; /* pid of creator */
40 __ipc_pid_t shm_lpid
; /* pid of last shmop */
41 unsigned short int shm_nattch
; /* number of current attaches */
42 unsigned short int __shm_npages
; /* size of segment (pages) */
43 unsigned long int *__unbounded __shm_pages
; /* array of ptrs to frames -> SHMMAX */
44 struct vm_area_struct
*__unbounded __attaches
; /* descriptors for attaches */
56 /* Provide operations to control over shared memory segments. */
57 int __new_shmctl (int, int, struct shmid_ds
*);
60 __new_shmctl (int shmid
, int cmd
, struct shmid_ds
*buf
)
62 #if __ASSUME_32BITUIDS > 0
63 return INLINE_SYSCALL (shmctl
, 3, shmid
, cmd
| __IPC_64
, CHECK_1 (buf
));
72 return INLINE_SYSCALL (shmctl
, 3, shmid
, cmd
, CHECK_1 (buf
));
76 int save_errno
= errno
, result
;
77 struct __old_shmid_ds old
;
79 /* Unfortunately there is no way how to find out for sure whether
80 we should use old or new shmctl. */
81 result
= INLINE_SYSCALL (shmctl
, 3, shmid
, cmd
| __IPC_64
, CHECK_1 (buf
));
82 if (result
!= -1 || errno
!= EINVAL
)
85 __set_errno(save_errno
);
88 old
.shm_perm
.uid
= buf
->shm_perm
.uid
;
89 old
.shm_perm
.gid
= buf
->shm_perm
.gid
;
90 old
.shm_perm
.mode
= buf
->shm_perm
.mode
;
91 if (old
.shm_perm
.uid
!= buf
->shm_perm
.uid
||
92 old
.shm_perm
.gid
!= buf
->shm_perm
.gid
)
98 result
= INLINE_SYSCALL (shmctl
, 3, shmid
, cmd
, __ptrvalue (&old
));
99 if (result
!= -1 && (cmd
== SHM_STAT
|| cmd
== IPC_STAT
))
101 memset(buf
, 0, sizeof(*buf
));
102 buf
->shm_perm
.__key
= old
.shm_perm
.__key
;
103 buf
->shm_perm
.uid
= old
.shm_perm
.uid
;
104 buf
->shm_perm
.gid
= old
.shm_perm
.gid
;
105 buf
->shm_perm
.cuid
= old
.shm_perm
.cuid
;
106 buf
->shm_perm
.cgid
= old
.shm_perm
.cgid
;
107 buf
->shm_perm
.mode
= old
.shm_perm
.mode
;
108 buf
->shm_perm
.__seq
= old
.shm_perm
.__seq
;
109 buf
->shm_atime
= old
.shm_atime
;
110 buf
->shm_dtime
= old
.shm_dtime
;
111 buf
->shm_ctime
= old
.shm_ctime
;
112 buf
->shm_segsz
= old
.shm_segsz
;
113 buf
->shm_nattch
= old
.shm_nattch
;
114 buf
->shm_cpid
= old
.shm_cpid
;
115 buf
->shm_lpid
= old
.shm_lpid
;
117 else if (result
!= -1 && cmd
== IPC_INFO
)
119 struct __old_shminfo
*oldi
= (void *)&old
;
120 struct shminfo
*i
= (struct shminfo
*)buf
;
122 memset(i
, 0, sizeof(*i
));
123 i
->shmmax
= oldi
->shmmax
;
124 i
->shmmin
= oldi
->shmmin
;
125 i
->shmmni
= oldi
->shmmni
;
126 i
->shmseg
= oldi
->shmseg
;
127 i
->shmall
= oldi
->shmall
;
134 #include <shlib-compat.h>
135 versioned_symbol (libc
, __new_shmctl
, shmctl
, GLIBC_2_2
);