Deleted Added
full compact
sysv_shm.c (42957) sysv_shm.c (46116)
1/* $Id: sysv_shm.c,v 1.39 1998/10/13 08:24:40 dg Exp $ */
1/* $Id: sysv_shm.c,v 1.40 1999/01/21 08:29:04 dillon 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:

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

215#endif
216
217int
218shmat(p, uap)
219 struct proc *p;
220 struct shmat_args *uap;
221{
222 int error, i, flags;
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:

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

215#endif
216
217int
218shmat(p, uap)
219 struct proc *p;
220 struct shmat_args *uap;
221{
222 int error, i, flags;
223 struct ucred *cred = p->p_ucred;
224 struct shmid_ds *shmseg;
225 struct shmmap_state *shmmap_s = NULL;
226 struct shm_handle *shm_handle;
227 vm_offset_t attach_va;
228 vm_prot_t prot;
229 vm_size_t size;
230 int rv;
231
232 shmmap_s = (struct shmmap_state *)p->p_vmspace->vm_shm;
233 if (shmmap_s == NULL) {
234 size = shminfo.shmseg * sizeof(struct shmmap_state);
235 shmmap_s = malloc(size, M_SHM, M_WAITOK);
236 for (i = 0; i < shminfo.shmseg; i++)
237 shmmap_s[i].shmid = -1;
238 p->p_vmspace->vm_shm = (caddr_t)shmmap_s;
239 }
240 shmseg = shm_find_segment_by_shmid(uap->shmid);
241 if (shmseg == NULL)
242 return EINVAL;
223 struct shmid_ds *shmseg;
224 struct shmmap_state *shmmap_s = NULL;
225 struct shm_handle *shm_handle;
226 vm_offset_t attach_va;
227 vm_prot_t prot;
228 vm_size_t size;
229 int rv;
230
231 shmmap_s = (struct shmmap_state *)p->p_vmspace->vm_shm;
232 if (shmmap_s == NULL) {
233 size = shminfo.shmseg * sizeof(struct shmmap_state);
234 shmmap_s = malloc(size, M_SHM, M_WAITOK);
235 for (i = 0; i < shminfo.shmseg; i++)
236 shmmap_s[i].shmid = -1;
237 p->p_vmspace->vm_shm = (caddr_t)shmmap_s;
238 }
239 shmseg = shm_find_segment_by_shmid(uap->shmid);
240 if (shmseg == NULL)
241 return EINVAL;
243 error = ipcperm(cred, &shmseg->shm_perm,
242 error = ipcperm(p, &shmseg->shm_perm,
244 (uap->shmflg & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W);
245 if (error)
246 return error;
247 for (i = 0; i < shminfo.shmseg; i++) {
248 if (shmmap_s->shmid == -1)
249 break;
250 shmmap_s++;
251 }

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

308
309static int
310oshmctl(p, uap)
311 struct proc *p;
312 struct oshmctl_args *uap;
313{
314#ifdef COMPAT_43
315 int error;
243 (uap->shmflg & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W);
244 if (error)
245 return error;
246 for (i = 0; i < shminfo.shmseg; i++) {
247 if (shmmap_s->shmid == -1)
248 break;
249 shmmap_s++;
250 }

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

307
308static int
309oshmctl(p, uap)
310 struct proc *p;
311 struct oshmctl_args *uap;
312{
313#ifdef COMPAT_43
314 int error;
316 struct ucred *cred = p->p_ucred;
317 struct shmid_ds *shmseg;
318 struct oshmid_ds outbuf;
319
320 shmseg = shm_find_segment_by_shmid(uap->shmid);
321 if (shmseg == NULL)
322 return EINVAL;
323 switch (uap->cmd) {
324 case IPC_STAT:
315 struct shmid_ds *shmseg;
316 struct oshmid_ds outbuf;
317
318 shmseg = shm_find_segment_by_shmid(uap->shmid);
319 if (shmseg == NULL)
320 return EINVAL;
321 switch (uap->cmd) {
322 case IPC_STAT:
325 error = ipcperm(cred, &shmseg->shm_perm, IPC_R);
323 error = ipcperm(p, &shmseg->shm_perm, IPC_R);
326 if (error)
327 return error;
328 outbuf.shm_perm = shmseg->shm_perm;
329 outbuf.shm_segsz = shmseg->shm_segsz;
330 outbuf.shm_cpid = shmseg->shm_cpid;
331 outbuf.shm_lpid = shmseg->shm_lpid;
332 outbuf.shm_nattch = shmseg->shm_nattch;
333 outbuf.shm_atime = shmseg->shm_atime;

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

357#endif
358
359int
360shmctl(p, uap)
361 struct proc *p;
362 struct shmctl_args *uap;
363{
364 int error;
324 if (error)
325 return error;
326 outbuf.shm_perm = shmseg->shm_perm;
327 outbuf.shm_segsz = shmseg->shm_segsz;
328 outbuf.shm_cpid = shmseg->shm_cpid;
329 outbuf.shm_lpid = shmseg->shm_lpid;
330 outbuf.shm_nattch = shmseg->shm_nattch;
331 outbuf.shm_atime = shmseg->shm_atime;

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

355#endif
356
357int
358shmctl(p, uap)
359 struct proc *p;
360 struct shmctl_args *uap;
361{
362 int error;
365 struct ucred *cred = p->p_ucred;
366 struct shmid_ds inbuf;
367 struct shmid_ds *shmseg;
368
369 shmseg = shm_find_segment_by_shmid(uap->shmid);
370 if (shmseg == NULL)
371 return EINVAL;
372 switch (uap->cmd) {
373 case IPC_STAT:
363 struct shmid_ds inbuf;
364 struct shmid_ds *shmseg;
365
366 shmseg = shm_find_segment_by_shmid(uap->shmid);
367 if (shmseg == NULL)
368 return EINVAL;
369 switch (uap->cmd) {
370 case IPC_STAT:
374 error = ipcperm(cred, &shmseg->shm_perm, IPC_R);
371 error = ipcperm(p, &shmseg->shm_perm, IPC_R);
375 if (error)
376 return error;
377 error = copyout((caddr_t)shmseg, uap->buf, sizeof(inbuf));
378 if (error)
379 return error;
380 break;
381 case IPC_SET:
372 if (error)
373 return error;
374 error = copyout((caddr_t)shmseg, uap->buf, sizeof(inbuf));
375 if (error)
376 return error;
377 break;
378 case IPC_SET:
382 error = ipcperm(cred, &shmseg->shm_perm, IPC_M);
379 error = ipcperm(p, &shmseg->shm_perm, IPC_M);
383 if (error)
384 return error;
385 error = copyin(uap->buf, (caddr_t)&inbuf, sizeof(inbuf));
386 if (error)
387 return error;
388 shmseg->shm_perm.uid = inbuf.shm_perm.uid;
389 shmseg->shm_perm.gid = inbuf.shm_perm.gid;
390 shmseg->shm_perm.mode =
391 (shmseg->shm_perm.mode & ~ACCESSPERMS) |
392 (inbuf.shm_perm.mode & ACCESSPERMS);
393 shmseg->shm_ctime = time_second;
394 break;
395 case IPC_RMID:
380 if (error)
381 return error;
382 error = copyin(uap->buf, (caddr_t)&inbuf, sizeof(inbuf));
383 if (error)
384 return error;
385 shmseg->shm_perm.uid = inbuf.shm_perm.uid;
386 shmseg->shm_perm.gid = inbuf.shm_perm.gid;
387 shmseg->shm_perm.mode =
388 (shmseg->shm_perm.mode & ~ACCESSPERMS) |
389 (inbuf.shm_perm.mode & ACCESSPERMS);
390 shmseg->shm_ctime = time_second;
391 break;
392 case IPC_RMID:
396 error = ipcperm(cred, &shmseg->shm_perm, IPC_M);
393 error = ipcperm(p, &shmseg->shm_perm, IPC_M);
397 if (error)
398 return error;
399 shmseg->shm_perm.key = IPC_PRIVATE;
400 shmseg->shm_perm.mode |= SHMSEG_REMOVED;
401 if (shmseg->shm_nattch <= 0) {
402 shm_deallocate_segment(shmseg);
403 shm_last_free = IPCID_TO_IX(uap->shmid);
404 }

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

424static int
425shmget_existing(p, uap, mode, segnum)
426 struct proc *p;
427 struct shmget_args *uap;
428 int mode;
429 int segnum;
430{
431 struct shmid_ds *shmseg;
394 if (error)
395 return error;
396 shmseg->shm_perm.key = IPC_PRIVATE;
397 shmseg->shm_perm.mode |= SHMSEG_REMOVED;
398 if (shmseg->shm_nattch <= 0) {
399 shm_deallocate_segment(shmseg);
400 shm_last_free = IPCID_TO_IX(uap->shmid);
401 }

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

421static int
422shmget_existing(p, uap, mode, segnum)
423 struct proc *p;
424 struct shmget_args *uap;
425 int mode;
426 int segnum;
427{
428 struct shmid_ds *shmseg;
432 struct ucred *cred = p->p_ucred;
433 int error;
434
435 shmseg = &shmsegs[segnum];
436 if (shmseg->shm_perm.mode & SHMSEG_REMOVED) {
437 /*
438 * This segment is in the process of being allocated. Wait
439 * until it's done, and look the key up again (in case the
440 * allocation failed or it was freed).
441 */
442 shmseg->shm_perm.mode |= SHMSEG_WANTED;
443 error = tsleep((caddr_t)shmseg, PLOCK | PCATCH, "shmget", 0);
444 if (error)
445 return error;
446 return EAGAIN;
447 }
429 int error;
430
431 shmseg = &shmsegs[segnum];
432 if (shmseg->shm_perm.mode & SHMSEG_REMOVED) {
433 /*
434 * This segment is in the process of being allocated. Wait
435 * until it's done, and look the key up again (in case the
436 * allocation failed or it was freed).
437 */
438 shmseg->shm_perm.mode |= SHMSEG_WANTED;
439 error = tsleep((caddr_t)shmseg, PLOCK | PCATCH, "shmget", 0);
440 if (error)
441 return error;
442 return EAGAIN;
443 }
448 error = ipcperm(cred, &shmseg->shm_perm, mode);
444 error = ipcperm(p, &shmseg->shm_perm, mode);
449 if (error)
450 return error;
451 if (uap->size && uap->size > shmseg->shm_segsz)
452 return EINVAL;
453 if ((uap->shmflg & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL))
454 return EEXIST;
455 p->p_retval[0] = IXSEQ_TO_IPCID(segnum, shmseg->shm_perm);
456 return 0;

--- 161 unchanged lines hidden ---
445 if (error)
446 return error;
447 if (uap->size && uap->size > shmseg->shm_segsz)
448 return EINVAL;
449 if ((uap->shmflg & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL))
450 return EEXIST;
451 p->p_retval[0] = IXSEQ_TO_IPCID(segnum, shmseg->shm_perm);
452 return 0;

--- 161 unchanged lines hidden ---