fold shmat1() back into sys_shmat(), the change in rev 1.64 is not sufficient
for Linux-compatible shmat() behaviour - shmat() for the removed shared memory segment must work from all callers, the shared memory id could be passed e.g. to native X server via MIT-SHM temporarily remove the functionality, the Linux-compatible semantics will be reimplemented differently
This commit is contained in:
parent
2ea7a74e40
commit
68ee548306
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: linux_ipc.c,v 1.28 2003/01/18 08:02:53 thorpej Exp $ */
|
||||
/* $NetBSD: linux_ipc.c,v 1.29 2004/09/28 17:26:25 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: linux_ipc.c,v 1.28 2003/01/18 08:02:53 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: linux_ipc.c,v 1.29 2004/09/28 17:26:25 jdolecek Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_sysv.h"
|
||||
@ -370,18 +370,12 @@ linux_sys_shmat(l, v, retval)
|
||||
syscallarg(int) shmflg;
|
||||
syscallarg(u_long *) raddr;
|
||||
} */ *uap = v;
|
||||
struct proc *p = l->l_proc;
|
||||
int error;
|
||||
vaddr_t attach_va;
|
||||
u_long raddr;
|
||||
|
||||
if ((error = shmat1(p, SCARG(uap, shmid), SCARG(uap, shmaddr),
|
||||
SCARG(uap, shmflg), &attach_va, 1)))
|
||||
if ((error = sys_shmat(l, uap, retval)))
|
||||
return error;
|
||||
|
||||
raddr = (u_long)attach_va;
|
||||
|
||||
if ((error = copyout(&raddr, (caddr_t) SCARG(uap, raddr),
|
||||
if ((error = copyout(&retval[0], (caddr_t) SCARG(uap, raddr),
|
||||
sizeof retval[0])))
|
||||
return error;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sysv_shm.c,v 1.77 2004/04/25 16:42:41 simonb Exp $ */
|
||||
/* $NetBSD: sysv_shm.c,v 1.78 2004/09/28 17:26:25 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
@ -68,7 +68,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.77 2004/04/25 16:42:41 simonb Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.78 2004/09/28 17:26:25 jdolecek Exp $");
|
||||
|
||||
#define SYSVSHM
|
||||
|
||||
@ -88,7 +88,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.77 2004/04/25 16:42:41 simonb Exp $")
|
||||
#include <uvm/uvm_extern.h>
|
||||
#include <uvm/uvm_object.h>
|
||||
|
||||
struct shmid_ds *shm_find_segment_by_shmid(int, int);
|
||||
struct shmid_ds *shm_find_segment_by_shmid(int);
|
||||
|
||||
static MALLOC_DEFINE(M_SHM, "shm", "SVID compatible shared memory segments");
|
||||
|
||||
@ -156,9 +156,8 @@ shm_find_segment_by_key(key)
|
||||
}
|
||||
|
||||
struct shmid_ds *
|
||||
shm_find_segment_by_shmid(shmid, findremoved)
|
||||
shm_find_segment_by_shmid(shmid)
|
||||
int shmid;
|
||||
int findremoved;
|
||||
{
|
||||
int segnum;
|
||||
struct shmid_ds *shmseg;
|
||||
@ -169,7 +168,7 @@ shm_find_segment_by_shmid(shmid, findremoved)
|
||||
shmseg = &shmsegs[segnum];
|
||||
if ((shmseg->shm_perm.mode & SHMSEG_ALLOCATED) == 0)
|
||||
return NULL;
|
||||
if (!findremoved && ((shmseg->shm_perm.mode & SHMSEG_REMOVED) != 0))
|
||||
if ((shmseg->shm_perm.mode & SHMSEG_REMOVED) != 0)
|
||||
return NULL;
|
||||
if (shmseg->shm_perm._seq != IPCID_TO_SEQ(shmid))
|
||||
return NULL;
|
||||
@ -325,28 +324,8 @@ sys_shmat(l, v, retval)
|
||||
syscallarg(const void *) shmaddr;
|
||||
syscallarg(int) shmflg;
|
||||
} */ *uap = v;
|
||||
struct proc *p = l->l_proc;
|
||||
vaddr_t attach_va;
|
||||
int error;
|
||||
|
||||
error = shmat1(p, SCARG(uap, shmid), SCARG(uap, shmaddr),
|
||||
SCARG(uap, shmflg), &attach_va, 0);
|
||||
if (error != 0)
|
||||
return error;
|
||||
retval[0] = attach_va;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
shmat1(p, shmid, shmaddr, shmflg, attachp, findremoved)
|
||||
struct proc *p;
|
||||
int shmid;
|
||||
const void *shmaddr;
|
||||
int shmflg;
|
||||
vaddr_t *attachp;
|
||||
int findremoved;
|
||||
{
|
||||
int error, flags;
|
||||
struct proc *p = l->l_proc;
|
||||
struct ucred *cred = p->p_ucred;
|
||||
struct shmid_ds *shmseg;
|
||||
struct shmmap_state *shmmap_s;
|
||||
@ -356,11 +335,11 @@ shmat1(p, shmid, shmaddr, shmflg, attachp, findremoved)
|
||||
vsize_t size;
|
||||
struct shmmap_entry *shmmap_se;
|
||||
|
||||
shmseg = shm_find_segment_by_shmid(shmid, findremoved);
|
||||
shmseg = shm_find_segment_by_shmid(SCARG(uap, shmid));
|
||||
if (shmseg == NULL)
|
||||
return EINVAL;
|
||||
error = ipcperm(cred, &shmseg->shm_perm,
|
||||
(shmflg & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W);
|
||||
(SCARG(uap, shmflg) & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
@ -370,16 +349,16 @@ shmat1(p, shmid, shmaddr, shmflg, attachp, findremoved)
|
||||
|
||||
size = (shmseg->shm_segsz + PGOFSET) & ~PGOFSET;
|
||||
prot = VM_PROT_READ;
|
||||
if ((shmflg & SHM_RDONLY) == 0)
|
||||
if ((SCARG(uap, shmflg) & SHM_RDONLY) == 0)
|
||||
prot |= VM_PROT_WRITE;
|
||||
flags = MAP_ANON | MAP_SHARED;
|
||||
if (shmaddr) {
|
||||
if (SCARG(uap, shmaddr)) {
|
||||
flags |= MAP_FIXED;
|
||||
if (shmflg & SHM_RND)
|
||||
if (SCARG(uap, shmflg) & SHM_RND)
|
||||
attach_va =
|
||||
(vaddr_t)shmaddr & ~(SHMLBA-1);
|
||||
else if (((vaddr_t)shmaddr & (SHMLBA-1)) == 0)
|
||||
attach_va = (vaddr_t)shmaddr;
|
||||
(vaddr_t)SCARG(uap, shmaddr) & ~(SHMLBA-1);
|
||||
else if (((vaddr_t)SCARG(uap, shmaddr) & (SHMLBA-1)) == 0)
|
||||
attach_va = (vaddr_t)SCARG(uap, shmaddr);
|
||||
else
|
||||
return EINVAL;
|
||||
} else {
|
||||
@ -397,7 +376,7 @@ shmat1(p, shmid, shmaddr, shmflg, attachp, findremoved)
|
||||
}
|
||||
shmmap_se = pool_get(&shmmap_entry_pool, PR_WAITOK);
|
||||
shmmap_se->va = attach_va;
|
||||
shmmap_se->shmid = shmid;
|
||||
shmmap_se->shmid = SCARG(uap, shmid);
|
||||
shmmap_s = shmmap_getprivate(p);
|
||||
#ifdef SHMDEBUG
|
||||
printf("shmat: vm %p: add %d @%lx\n", p->p_vmspace, shmid, attach_va);
|
||||
@ -407,7 +386,8 @@ shmat1(p, shmid, shmaddr, shmflg, attachp, findremoved)
|
||||
shmseg->shm_lpid = p->p_pid;
|
||||
shmseg->shm_atime = time.tv_sec;
|
||||
shmseg->shm_nattch++;
|
||||
*attachp = attach_va;
|
||||
|
||||
retval[0] = attach_va;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -454,7 +434,7 @@ shmctl1(p, shmid, cmd, shmbuf)
|
||||
struct shmid_ds *shmseg;
|
||||
int error = 0;
|
||||
|
||||
shmseg = shm_find_segment_by_shmid(shmid, 0);
|
||||
shmseg = shm_find_segment_by_shmid(shmid);
|
||||
if (shmseg == NULL)
|
||||
return EINVAL;
|
||||
switch (cmd) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: shm.h,v 1.35 2003/10/20 22:16:33 kleink Exp $ */
|
||||
/* $NetBSD: shm.h,v 1.36 2004/09/28 17:26:25 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
@ -187,7 +187,6 @@ void shminit __P((void));
|
||||
void shmfork __P((struct vmspace *, struct vmspace *));
|
||||
void shmexit __P((struct vmspace *));
|
||||
int shmctl1 __P((struct proc *, int, int, struct shmid_ds *));
|
||||
int shmat1 __P((struct proc *, int, const void *, int, vaddr_t *, int));
|
||||
#else /* !_KERNEL */
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
Loading…
Reference in New Issue
Block a user