Linus:
Now that the 32-bit UID patches are in (thanks!!), we can make this minor
cleanup to shm.c, since the "u" field of shmid_kernel no longer has to be
a separate structure.
I didn't make this change originally to cut down on the size of the 32-bit
UID patches.
Thanks,
Chris Wing
wingc@engin.umich.edu
Patch against 2.3.39.
Tested and working on i386.
diff -uNr linux-2.3.39/ipc/shm.c linux-ipc/ipc/shm.c
--- linux-2.3.39/ipc/shm.c Mon Jan 10 21:15:58 2000
+++ linux-ipc/ipc/shm.c Tue Jan 11 18:31:28 2000
@@ -31,16 +31,14 @@
struct shmid_kernel /* private to the kernel */
{
- struct {
- struct kern_ipc_perm shm_perm;
- size_t shm_segsz;
- time_t shm_atime;
- time_t shm_dtime;
- time_t shm_ctime;
- pid_t shm_cpid;
- pid_t shm_lpid;
- unsigned long shm_nattch;
- } u;
+ struct kern_ipc_perm shm_perm;
+ size_t shm_segsz;
+ time_t shm_atime;
+ time_t shm_dtime;
+ time_t shm_ctime;
+ pid_t shm_cpid;
+ pid_t shm_lpid;
+ unsigned long shm_nattch;
unsigned long shm_npages; /* size of segment (pages) */
pte_t **shm_dir; /* ptr to array of ptrs to frames -> SHMMAX */
struct vm_area_struct *attaches; /* descriptors for attaches */
@@ -57,7 +55,7 @@
#define shm_get(id) ((struct shmid_kernel*)ipc_get(&shm_ids,id))
#define shm_rmid(id) ((struct shmid_kernel*)ipc_rmid(&shm_ids,id))
#define shm_checkid(s, id) \
- ipc_checkid(&shm_ids,&s->u.shm_perm,id)
+ ipc_checkid(&shm_ids,&s->shm_perm,id)
#define shm_buildid(id, seq) \
ipc_buildid(&shm_ids, id, seq)
@@ -174,7 +172,7 @@
shm_unlock(shmid);
return -EIDRM;
}
- if (ipcperms(&shp->u.shm_perm, flg)) {
+ if (ipcperms(&shp->shm_perm, flg)) {
shm_unlock(shmid);
return -EACCES;
}
@@ -204,28 +202,28 @@
kfree(shp);
return -ENOMEM;
}
- id = ipc_addid(&shm_ids, &shp->u.shm_perm, shm_ctlmni);
+ id = ipc_addid(&shm_ids, &shp->shm_perm, shm_ctlmni);
if(id == -1) {
shm_free(shp->shm_dir,numpages);
kfree(shp);
return -ENOSPC;
}
- shp->u.shm_perm.key = key;
- shp->u.shm_perm.mode = (shmflg & S_IRWXUGO);
- shp->u.shm_segsz = size;
- shp->u.shm_cpid = current->pid;
+ shp->shm_perm.key = key;
+ shp->shm_perm.mode = (shmflg & S_IRWXUGO);
+ shp->shm_segsz = size;
+ shp->shm_cpid = current->pid;
shp->attaches = NULL;
- shp->u.shm_lpid = shp->u.shm_nattch = 0;
- shp->u.shm_atime = shp->u.shm_dtime = 0;
- shp->u.shm_ctime = CURRENT_TIME;
+ shp->shm_lpid = shp->shm_nattch = 0;
+ shp->shm_atime = shp->shm_dtime = 0;
+ shp->shm_ctime = CURRENT_TIME;
shp->shm_npages = numpages;
- shp->id = shm_buildid(id,shp->u.shm_perm.seq);
+ shp->id = shm_buildid(id,shp->shm_perm.seq);
init_MUTEX(&shp->sem);
shm_tot += numpages;
shm_unlock(id);
- return shm_buildid(id,shp->u.shm_perm.seq);
+ return shm_buildid(id,shp->shm_perm.seq);
}
asmlinkage long sys_shmget (key_t key, size_t size, int shmflg)
@@ -247,10 +245,10 @@
shp = shm_lock(id);
if(shp==NULL)
BUG();
- if (ipcperms(&shp->u.shm_perm, shmflg))
+ if (ipcperms(&shp->shm_perm, shmflg))
err = -EACCES;
else
- err = shm_buildid(id, shp->u.shm_perm.seq);
+ err = shm_buildid(id, shp->shm_perm.seq);
shm_unlock(id);
}
up(&shm_ids.sem);
@@ -274,8 +272,8 @@
up(&shm_ids.sem);
return;
}
- if(shm_checkid(shp,shmid) || shp->u.shm_nattch > 0 ||
- !(shp->u.shm_perm.mode & SHM_DEST)) {
+ if(shm_checkid(shp,shmid) || shp->shm_nattch > 0 ||
+ !(shp->shm_perm.mode & SHM_DEST)) {
shm_unlock(shmid);
goto out_up;
}
@@ -464,7 +462,7 @@
err = -EINVAL;
if (shmid > shm_ids.max_id)
goto out_unlock;
- result = shm_buildid(shmid, shp->u.shm_perm.seq);
+ result = shm_buildid(shmid, shp->shm_perm.seq);
} else {
err = -EIDRM;
if(shm_checkid(shp,shmid))
@@ -472,16 +470,16 @@
result = 0;
}
err=-EACCES;
- if (ipcperms (&shp->u.shm_perm, S_IRUGO))
+ if (ipcperms (&shp->shm_perm, S_IRUGO))
goto out_unlock;
- kernel_to_ipc64_perm(&shp->u.shm_perm, &tbuf.shm_perm);
- tbuf.shm_segsz = shp->u.shm_segsz;
- tbuf.shm_atime = shp->u.shm_atime;
- tbuf.shm_dtime = shp->u.shm_dtime;
- tbuf.shm_ctime = shp->u.shm_ctime;
- tbuf.shm_cpid = shp->u.shm_cpid;
- tbuf.shm_lpid = shp->u.shm_lpid;
- tbuf.shm_nattch = shp->u.shm_nattch;
+ kernel_to_ipc64_perm(&shp->shm_perm, &tbuf.shm_perm);
+ tbuf.shm_segsz = shp->shm_segsz;
+ tbuf.shm_atime = shp->shm_atime;
+ tbuf.shm_dtime = shp->shm_dtime;
+ tbuf.shm_ctime = shp->shm_ctime;
+ tbuf.shm_cpid = shp->shm_cpid;
+ tbuf.shm_lpid = shp->shm_lpid;
+ tbuf.shm_nattch = shp->shm_nattch;
shm_unlock(shmid);
if(copy_shmid_to_user (buf, &tbuf, version))
return -EFAULT;
@@ -503,7 +501,7 @@
err=-EIDRM;
if(shm_checkid(shp,shmid))
goto out_unlock;
- ipcp = &shp->u.shm_perm;
+ ipcp = &shp->shm_perm;
if(cmd==SHM_LOCK) {
if (!(ipcp->mode & SHM_LOCKED)) {
ipcp->mode |= SHM_LOCKED;
@@ -538,23 +536,23 @@
if(shm_checkid(shp,shmid))
goto out_unlock_up;
err=-EPERM;
- if (current->euid != shp->u.shm_perm.uid &&
- current->euid != shp->u.shm_perm.cuid &&
+ if (current->euid != shp->shm_perm.uid &&
+ current->euid != shp->shm_perm.cuid &&
!capable(CAP_SYS_ADMIN)) {
goto out_unlock_up;
}
switch (cmd) {
case IPC_SET:
- shp->u.shm_perm.uid = setbuf.uid;
- shp->u.shm_perm.gid = setbuf.gid;
- shp->u.shm_perm.mode = (shp->u.shm_perm.mode & ~S_IRWXUGO)
+ shp->shm_perm.uid = setbuf.uid;
+ shp->shm_perm.gid = setbuf.gid;
+ shp->shm_perm.mode = (shp->shm_perm.mode & ~S_IRWXUGO)
| (setbuf.mode & S_IRWXUGO);
- shp->u.shm_ctime = CURRENT_TIME;
+ shp->shm_ctime = CURRENT_TIME;
break;
case IPC_RMID:
- shp->u.shm_perm.mode |= SHM_DEST;
- if (shp->u.shm_nattch <= 0) {
+ shp->shm_perm.mode |= SHM_DEST;
+ if (shp->shm_nattch <= 0) {
shm_unlock(shmid);
up(&shm_ids.sem);
killseg (shmid);
@@ -662,7 +660,7 @@
goto out_up;
err = -EACCES;
- if (ipcperms(&shp->u.shm_perm, flg))
+ if (ipcperms(&shp->shm_perm, flg))
goto out_unlock_up;
err = -EIDRM;
@@ -675,7 +673,7 @@
err = -ENOMEM;
addr = 0;
again:
- if (!(addr = get_unmapped_area(addr, (unsigned long)shp->u.shm_segsz)))
+ if (!(addr = get_unmapped_area(addr, (unsigned long)shp->shm_segsz)))
goto out_unlock_up;
if(addr & (SHMLBA - 1)) {
addr = (addr + (SHMLBA - 1)) & ~(SHMLBA - 1);
@@ -702,7 +700,7 @@
if (addr < current->mm->start_stack &&
addr > current->mm->start_stack - PAGE_SIZE*(shp->shm_npages + 4))
goto out_unlock_up;
- if (!(shmflg & SHM_REMAP) && find_vma_intersection(current->mm, addr, addr + (unsigned long)shp->u.shm_segsz))
+ if (!(shmflg & SHM_REMAP) && find_vma_intersection(current->mm, addr, addr + (unsigned long)shp->shm_segsz))
goto out_unlock_up;
shm_unlock(shmid);
@@ -726,7 +724,7 @@
shmd->vm_pgoff = 0;
shmd->vm_ops = &shm_vm_ops;
- shp->u.shm_nattch++; /* prevent destruction */
+ shp->shm_nattch++; /* prevent destruction */
shm_unlock(shp->id);
err = shm_map (shmd);
shm_lock(shmid); /* cannot fail */
@@ -735,8 +733,8 @@
insert_attach(shp,shmd); /* insert shmd into shp->attaches */
- shp->u.shm_lpid = current->pid;
- shp->u.shm_atime = CURRENT_TIME;
+ shp->shm_lpid = current->pid;
+ shp->shm_atime = CURRENT_TIME;
*raddr = addr;
err = 0;
@@ -749,7 +747,7 @@
failed_shm_map:
{
int delete = 0;
- if (--shp->u.shm_nattch <= 0 && shp->u.shm_perm.mode & SHM_DEST)
+ if (--shp->shm_nattch <= 0 && shp->shm_perm.mode & SHM_DEST)
delete = 1;
shm_unlock(shmid);
up(¤t->mm->mmap_sem);
@@ -769,9 +767,9 @@
if(shp != shm_lock(shp->id))
BUG();
insert_attach(shp,shmd); /* insert shmd into shp->attaches */
- shp->u.shm_nattch++;
- shp->u.shm_atime = CURRENT_TIME;
- shp->u.shm_lpid = current->pid;
+ shp->shm_nattch++;
+ shp->shm_atime = CURRENT_TIME;
+ shp->shm_lpid = current->pid;
shm_unlock(shp->id);
}
@@ -791,10 +789,10 @@
if(shp != shm_lock(shp->id))
BUG();
remove_attach(shp,shmd); /* remove from shp->attaches */
- shp->u.shm_lpid = current->pid;
- shp->u.shm_dtime = CURRENT_TIME;
+ shp->shm_lpid = current->pid;
+ shp->shm_dtime = CURRENT_TIME;
id=-1;
- if (--shp->u.shm_nattch <= 0 && shp->u.shm_perm.mode & SHM_DEST)
+ if (--shp->shm_nattch <= 0 && shp->shm_perm.mode & SHM_DEST)
id=shp->id;
shm_unlock(shp->id);
if(id!=-1)
@@ -936,7 +934,7 @@
shm_lockall();
check_id:
shp = shm_get(swap_id);
- if(shp==NULL || shp->u.shm_perm.mode & SHM_LOCKED) {
+ if(shp==NULL || shp->shm_perm.mode & SHM_LOCKED) {
next_id:
swap_idx = 0;
if (++swap_id > shm_ids.max_id) {
@@ -1061,20 +1059,20 @@
else
format = BIG_STRING;
len += sprintf(buffer + len, format,
- shp->u.shm_perm.key,
- shm_buildid(i, shp->u.shm_perm.seq),
- shp->u.shm_perm.mode,
- shp->u.shm_segsz,
- shp->u.shm_cpid,
- shp->u.shm_lpid,
- shp->u.shm_nattch,
- shp->u.shm_perm.uid,
- shp->u.shm_perm.gid,
- shp->u.shm_perm.cuid,
- shp->u.shm_perm.cgid,
- shp->u.shm_atime,
- shp->u.shm_dtime,
- shp->u.shm_ctime);
+ shp->shm_perm.key,
+ shm_buildid(i, shp->shm_perm.seq),
+ shp->shm_perm.mode,
+ shp->shm_segsz,
+ shp->shm_cpid,
+ shp->shm_lpid,
+ shp->shm_nattch,
+ shp->shm_perm.uid,
+ shp->shm_perm.gid,
+ shp->shm_perm.cuid,
+ shp->shm_perm.cgid,
+ shp->shm_atime,
+ shp->shm_dtime,
+ shp->shm_ctime);
shm_unlock(i);
pos += len;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Sat Jan 15 2000 - 21:00:19 EST