Deleted Added
full compact
sysv_shm.c (12819) sysv_shm.c (12866)
1/* $Id: sysv_shm.c,v 1.13 1995/12/07 12:46:55 davidg Exp $ */
1/* $Id: sysv_shm.c,v 1.14 1995/12/14 08:31:54 phk Exp $ */
2/* $NetBSD: sysv_shm.c,v 1.23 1994/07/04 23:25:12 glass Exp $ */
3
4/*
5 * Copyright (c) 1994 Adam Glass and Charles Hannum. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 36 unchanged lines hidden (view full) ---

46#include <vm/vm_param.h>
47#include <vm/vm_prot.h>
48#include <vm/lock.h>
49#include <vm/pmap.h>
50#include <vm/vm_map.h>
51#include <vm/vm_kern.h>
52#include <vm/vm_extern.h>
53
2/* $NetBSD: sysv_shm.c,v 1.23 1994/07/04 23:25:12 glass Exp $ */
3
4/*
5 * Copyright (c) 1994 Adam Glass and Charles Hannum. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 36 unchanged lines hidden (view full) ---

46#include <vm/vm_param.h>
47#include <vm/vm_prot.h>
48#include <vm/lock.h>
49#include <vm/pmap.h>
50#include <vm/vm_map.h>
51#include <vm/vm_kern.h>
52#include <vm/vm_extern.h>
53
54#ifndef _SYS_SYSPROTO_H_
54struct shmat_args;
55extern int shmat __P((struct proc *p, struct shmat_args *uap, int *retval));
56struct shmctl_args;
57extern int shmctl __P((struct proc *p, struct shmctl_args *uap, int *retval));
58struct shmdt_args;
59extern int shmdt __P((struct proc *p, struct shmdt_args *uap, int *retval));
60struct shmget_args;
61extern int shmget __P((struct proc *p, struct shmget_args *uap, int *retval));
55struct shmat_args;
56extern int shmat __P((struct proc *p, struct shmat_args *uap, int *retval));
57struct shmctl_args;
58extern int shmctl __P((struct proc *p, struct shmctl_args *uap, int *retval));
59struct shmdt_args;
60extern int shmdt __P((struct proc *p, struct shmdt_args *uap, int *retval));
61struct shmget_args;
62extern int shmget __P((struct proc *p, struct shmget_args *uap, int *retval));
63#endif
62
63static void shminit __P((void *));
64SYSINIT(sysv_shm, SI_SUB_SYSV_SHM, SI_ORDER_FIRST, shminit, NULL)
65
66struct oshmctl_args;
67static int oshmctl __P((struct proc *p, struct oshmctl_args *uap, int *retval));
68static int shmget_allocate_segment __P((struct proc *p, struct shmget_args *uap, int mode, int *retval));
69static int shmget_existing __P((struct proc *p, struct shmget_args *uap, int mode, int segnum, int *retval));

--- 96 unchanged lines hidden (view full) ---

166 if ((--shmseg->shm_nattch <= 0) &&
167 (shmseg->shm_perm.mode & SHMSEG_REMOVED)) {
168 shm_deallocate_segment(shmseg);
169 shm_last_free = segnum;
170 }
171 return 0;
172}
173
64
65static void shminit __P((void *));
66SYSINIT(sysv_shm, SI_SUB_SYSV_SHM, SI_ORDER_FIRST, shminit, NULL)
67
68struct oshmctl_args;
69static int oshmctl __P((struct proc *p, struct oshmctl_args *uap, int *retval));
70static int shmget_allocate_segment __P((struct proc *p, struct shmget_args *uap, int mode, int *retval));
71static int shmget_existing __P((struct proc *p, struct shmget_args *uap, int mode, int segnum, int *retval));

--- 96 unchanged lines hidden (view full) ---

168 if ((--shmseg->shm_nattch <= 0) &&
169 (shmseg->shm_perm.mode & SHMSEG_REMOVED)) {
170 shm_deallocate_segment(shmseg);
171 shm_last_free = segnum;
172 }
173 return 0;
174}
175
176#ifndef _SYS_SYSPROTO_H_
174struct shmdt_args {
175 void *shmaddr;
176};
177struct shmdt_args {
178 void *shmaddr;
179};
180#endif
181
177int
178shmdt(p, uap, retval)
179 struct proc *p;
180 struct shmdt_args *uap;
181 int *retval;
182{
183 struct shmmap_state *shmmap_s;
184 int i;

--- 5 unchanged lines hidden (view full) ---

190 if (shmmap_s->shmid != -1 &&
191 shmmap_s->va == (vm_offset_t)uap->shmaddr)
192 break;
193 if (i == shminfo.shmseg)
194 return EINVAL;
195 return shm_delete_mapping(p, shmmap_s);
196}
197
182int
183shmdt(p, uap, retval)
184 struct proc *p;
185 struct shmdt_args *uap;
186 int *retval;
187{
188 struct shmmap_state *shmmap_s;
189 int i;

--- 5 unchanged lines hidden (view full) ---

195 if (shmmap_s->shmid != -1 &&
196 shmmap_s->va == (vm_offset_t)uap->shmaddr)
197 break;
198 if (i == shminfo.shmseg)
199 return EINVAL;
200 return shm_delete_mapping(p, shmmap_s);
201}
202
203#ifndef _SYS_SYSPROTO_H_
198struct shmat_args {
199 int shmid;
200 void *shmaddr;
201 int shmflg;
202};
204struct shmat_args {
205 int shmid;
206 void *shmaddr;
207 int shmflg;
208};
209#endif
210
203int
204shmat(p, uap, retval)
205 struct proc *p;
206 struct shmat_args *uap;
207 int *retval;
208{
209 int error, i, flags;
210 struct ucred *cred = p->p_ucred;

--- 111 unchanged lines hidden (view full) ---

322 return ((sy_call_t *)shmctl)(p, uap, retval);
323 }
324 return 0;
325#else
326 return EINVAL;
327#endif
328}
329
211int
212shmat(p, uap, retval)
213 struct proc *p;
214 struct shmat_args *uap;
215 int *retval;
216{
217 int error, i, flags;
218 struct ucred *cred = p->p_ucred;

--- 111 unchanged lines hidden (view full) ---

330 return ((sy_call_t *)shmctl)(p, uap, retval);
331 }
332 return 0;
333#else
334 return EINVAL;
335#endif
336}
337
338#ifndef _SYS_SYSPROTO_H_
330struct shmctl_args {
331 int shmid;
332 int cmd;
339struct shmctl_args {
340 int shmid;
341 int cmd;
333 struct shmid_ds *ubuf;
342 struct shmid_ds *buf;
334};
343};
344#endif
345
335int
336shmctl(p, uap, retval)
337 struct proc *p;
338 struct shmctl_args *uap;
339 int *retval;
340{
341 int error;
342 struct ucred *cred = p->p_ucred;
343 struct shmid_ds inbuf;
344 struct shmid_ds *shmseg;
345
346 shmseg = shm_find_segment_by_shmid(uap->shmid);
347 if (shmseg == NULL)
348 return EINVAL;
349 switch (uap->cmd) {
350 case IPC_STAT:
351 error = ipcperm(cred, &shmseg->shm_perm, IPC_R);
352 if (error)
353 return error;
346int
347shmctl(p, uap, retval)
348 struct proc *p;
349 struct shmctl_args *uap;
350 int *retval;
351{
352 int error;
353 struct ucred *cred = p->p_ucred;
354 struct shmid_ds inbuf;
355 struct shmid_ds *shmseg;
356
357 shmseg = shm_find_segment_by_shmid(uap->shmid);
358 if (shmseg == NULL)
359 return EINVAL;
360 switch (uap->cmd) {
361 case IPC_STAT:
362 error = ipcperm(cred, &shmseg->shm_perm, IPC_R);
363 if (error)
364 return error;
354 error = copyout((caddr_t)shmseg, uap->ubuf, sizeof(inbuf));
365 error = copyout((caddr_t)shmseg, uap->buf, sizeof(inbuf));
355 if (error)
356 return error;
357 break;
358 case IPC_SET:
359 error = ipcperm(cred, &shmseg->shm_perm, IPC_M);
360 if (error)
361 return error;
366 if (error)
367 return error;
368 break;
369 case IPC_SET:
370 error = ipcperm(cred, &shmseg->shm_perm, IPC_M);
371 if (error)
372 return error;
362 error = copyin(uap->ubuf, (caddr_t)&inbuf, sizeof(inbuf));
373 error = copyin(uap->buf, (caddr_t)&inbuf, sizeof(inbuf));
363 if (error)
364 return error;
365 shmseg->shm_perm.uid = inbuf.shm_perm.uid;
366 shmseg->shm_perm.gid = inbuf.shm_perm.gid;
367 shmseg->shm_perm.mode =
368 (shmseg->shm_perm.mode & ~ACCESSPERMS) |
369 (inbuf.shm_perm.mode & ACCESSPERMS);
370 shmseg->shm_ctime = time.tv_sec;

--- 14 unchanged lines hidden (view full) ---

385 case SHM_UNLOCK:
386#endif
387 default:
388 return EINVAL;
389 }
390 return 0;
391}
392
374 if (error)
375 return error;
376 shmseg->shm_perm.uid = inbuf.shm_perm.uid;
377 shmseg->shm_perm.gid = inbuf.shm_perm.gid;
378 shmseg->shm_perm.mode =
379 (shmseg->shm_perm.mode & ~ACCESSPERMS) |
380 (inbuf.shm_perm.mode & ACCESSPERMS);
381 shmseg->shm_ctime = time.tv_sec;

--- 14 unchanged lines hidden (view full) ---

396 case SHM_UNLOCK:
397#endif
398 default:
399 return EINVAL;
400 }
401 return 0;
402}
403
404#ifndef _SYS_SYSPROTO_H_
393struct shmget_args {
394 key_t key;
395 size_t size;
396 int shmflg;
397};
405struct shmget_args {
406 key_t key;
407 size_t size;
408 int shmflg;
409};
410#endif
411
398static int
399shmget_existing(p, uap, mode, segnum, retval)
400 struct proc *p;
401 struct shmget_args *uap;
402 int mode;
403 int segnum;
404 int *retval;
405{

--- 196 unchanged lines hidden ---
412static int
413shmget_existing(p, uap, mode, segnum, retval)
414 struct proc *p;
415 struct shmget_args *uap;
416 int mode;
417 int segnum;
418 int *retval;
419{

--- 196 unchanged lines hidden ---