Rename kernel-only members of semid_ds and msgid_ds.

This deliberately breaks the API in preperation for future syscall
revisions which will remove these nonstandard members.

In an exp-run a single port (devel/qemu-user-static) was found to
use them which it did becuase it emulates system calls.  This has
been fixed in the ports tree.

PR:		224443 (exp-run)
Reviewed by:	kib, jhb (previous version)
Exp-run by:	antoine
Sponsored by:	DARPA, AFRP
Differential Revision:	https://reviews.freebsd.org/D14490
This commit is contained in:
Brooks Davis 2018-03-02 22:10:48 +00:00
parent 50b779bdc9
commit 93e48a303a
8 changed files with 93 additions and 96 deletions

View File

@ -63,8 +63,8 @@ and contains (amongst others) the following members:
.Bd -literal .Bd -literal
struct msqid_ds { struct msqid_ds {
struct ipc_perm msg_perm; /* msg queue permission bits */ struct ipc_perm msg_perm; /* msg queue permission bits */
struct msg *msg_first; /* first message in the queue */ struct msg *__msg_first; /* kernel data, don't use */
struct msg *msg_last; /* last message in the queue */ struct msg *__msg_last; /* kernel data, don't use */
msglen_t msg_cbytes; /* number of bytes in use on the queue */ msglen_t msg_cbytes; /* number of bytes in use on the queue */
msgqnum_t msg_qnum; /* number of msgs in the queue */ msgqnum_t msg_qnum; /* number of msgs in the queue */
msglen_t msg_qbytes; /* max # of bytes on the queue */ msglen_t msg_qbytes; /* max # of bytes on the queue */

View File

@ -145,7 +145,7 @@ is defined as follows:
.Bd -literal .Bd -literal
struct semid_ds { struct semid_ds {
struct ipc_perm sem_perm; /* operation permission struct */ struct ipc_perm sem_perm; /* operation permission struct */
struct sem *sem_base; /* pointer to first semaphore in set */ struct sem *__sem_base; /* kernel data, don't use */
u_short sem_nsems; /* number of sems in set */ u_short sem_nsems; /* number of sems in set */
time_t sem_otime; /* last operation time */ time_t sem_otime; /* last operation time */
time_t sem_ctime; /* last change time */ time_t sem_ctime; /* last change time */

View File

@ -43,7 +43,7 @@ struct ipc_perm32 {
struct semid_ds32 { struct semid_ds32 {
struct ipc_perm32 sem_perm; struct ipc_perm32 sem_perm;
uint32_t sem_base; uint32_t __sem_base;
unsigned short sem_nsems; unsigned short sem_nsems;
int32_t sem_otime; int32_t sem_otime;
int32_t sem_ctime; int32_t sem_ctime;
@ -69,8 +69,8 @@ union semun32 {
struct msqid_ds32 { struct msqid_ds32 {
struct ipc_perm32 msg_perm; struct ipc_perm32 msg_perm;
uint32_t msg_first; uint32_t __msg_first;
uint32_t msg_last; uint32_t __msg_last;
uint32_t msg_cbytes; uint32_t msg_cbytes;
uint32_t msg_qnum; uint32_t msg_qnum;
uint32_t msg_qbytes; uint32_t msg_qbytes;
@ -143,7 +143,7 @@ struct ipc_perm32_old {
struct semid_ds32_old { struct semid_ds32_old {
struct ipc_perm32_old sem_perm; struct ipc_perm32_old sem_perm;
uint32_t sem_base; uint32_t __sem_base;
unsigned short sem_nsems; unsigned short sem_nsems;
int32_t sem_otime; int32_t sem_otime;
int32_t sem_pad1; int32_t sem_pad1;
@ -154,8 +154,8 @@ struct semid_ds32_old {
struct msqid_ds32_old { struct msqid_ds32_old {
struct ipc_perm32_old msg_perm; struct ipc_perm32_old msg_perm;
uint32_t msg_first; uint32_t __msg_first;
uint32_t msg_last; uint32_t __msg_last;
uint32_t msg_cbytes; uint32_t msg_cbytes;
uint32_t msg_qnum; uint32_t msg_qnum;
uint32_t msg_qbytes; uint32_t msg_qbytes;

View File

@ -73,9 +73,8 @@ cvt_msqid2imsqid(bp, ibp)
struct msqid_ds *bp; struct msqid_ds *bp;
struct ibcs2_msqid_ds *ibp; struct ibcs2_msqid_ds *ibp;
{ {
memset(ibp, 0, sizeof(*ibp));
cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm); cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm);
ibp->msg_first = bp->msg_first;
ibp->msg_last = bp->msg_last;
ibp->msg_cbytes = (u_short)bp->msg_cbytes; ibp->msg_cbytes = (u_short)bp->msg_cbytes;
ibp->msg_qnum = (u_short)bp->msg_qnum; ibp->msg_qnum = (u_short)bp->msg_qnum;
ibp->msg_qbytes = (u_short)bp->msg_qbytes; ibp->msg_qbytes = (u_short)bp->msg_qbytes;
@ -93,8 +92,6 @@ struct ibcs2_msqid_ds *ibp;
struct msqid_ds *bp; struct msqid_ds *bp;
{ {
cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm); cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm);
bp->msg_first = ibp->msg_first;
bp->msg_last = ibp->msg_last;
bp->msg_cbytes = ibp->msg_cbytes; bp->msg_cbytes = ibp->msg_cbytes;
bp->msg_qnum = ibp->msg_qnum; bp->msg_qnum = ibp->msg_qnum;
bp->msg_qbytes = ibp->msg_qbytes; bp->msg_qbytes = ibp->msg_qbytes;
@ -283,8 +280,8 @@ cvt_semid2isemid(bp, ibp)
struct semid_ds *bp; struct semid_ds *bp;
struct ibcs2_semid_ds *ibp; struct ibcs2_semid_ds *ibp;
{ {
memset(ibp, 0, sizeof(*ibp);
cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm); cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm);
ibp->sem_base = (struct ibcs2_sem *)bp->sem_base;
ibp->sem_nsems = bp->sem_nsems; ibp->sem_nsems = bp->sem_nsems;
ibp->sem_otime = bp->sem_otime; ibp->sem_otime = bp->sem_otime;
ibp->sem_ctime = bp->sem_ctime; ibp->sem_ctime = bp->sem_ctime;
@ -297,7 +294,6 @@ struct ibcs2_semid_ds *ibp;
struct semid_ds *bp; struct semid_ds *bp;
{ {
cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm); cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm);
bp->sem_base = (struct sem *)ibp->sem_base;
bp->sem_nsems = ibp->sem_nsems; bp->sem_nsems = ibp->sem_nsems;
bp->sem_otime = ibp->sem_otime; bp->sem_otime = ibp->sem_otime;
bp->sem_ctime = ibp->sem_ctime; bp->sem_ctime = ibp->sem_ctime;

View File

@ -425,7 +425,7 @@ msq_remove(struct msqid_kernel *msqkptr)
msqkptr->cred = NULL; msqkptr->cred = NULL;
/* Free the message headers */ /* Free the message headers */
msghdr = msqkptr->u.msg_first; msghdr = msqkptr->u.__msg_first;
while (msghdr != NULL) { while (msghdr != NULL) {
struct msg *msghdr_tmp; struct msg *msghdr_tmp;
@ -573,7 +573,7 @@ kern_msgctl(td, msqid, cmd, msqbuf)
* thread cannot free a certain msghdr. The msq will get * thread cannot free a certain msghdr. The msq will get
* into an inconsistent state. * into an inconsistent state.
*/ */
for (msghdr = msqkptr->u.msg_first; msghdr != NULL; for (msghdr = msqkptr->u.__msg_first; msghdr != NULL;
msghdr = msghdr->msg_next) { msghdr = msghdr->msg_next) {
error = mac_sysvmsq_check_msgrmid(td->td_ucred, msghdr); error = mac_sysvmsq_check_msgrmid(td->td_ucred, msghdr);
if (error != 0) if (error != 0)
@ -731,8 +731,8 @@ sys_msgget(struct thread *td, struct msgget_args *uap)
msqkptr->cred = crhold(cred); msqkptr->cred = crhold(cred);
/* Make sure that the returned msqid is unique */ /* Make sure that the returned msqid is unique */
msqkptr->u.msg_perm.seq = (msqkptr->u.msg_perm.seq + 1) & 0x7fff; msqkptr->u.msg_perm.seq = (msqkptr->u.msg_perm.seq + 1) & 0x7fff;
msqkptr->u.msg_first = NULL; msqkptr->u.__msg_first = NULL;
msqkptr->u.msg_last = NULL; msqkptr->u.__msg_last = NULL;
msqkptr->u.msg_cbytes = 0; msqkptr->u.msg_cbytes = 0;
msqkptr->u.msg_qnum = 0; msqkptr->u.msg_qnum = 0;
msqkptr->u.msg_qbytes = msginfo.msgmnb; msqkptr->u.msg_qbytes = msginfo.msgmnb;
@ -1079,14 +1079,14 @@ kern_msgsnd(struct thread *td, int msqid, const void *msgp,
/* /*
* Put the message into the queue * Put the message into the queue
*/ */
if (msqkptr->u.msg_first == NULL) { if (msqkptr->u.__msg_first == NULL) {
msqkptr->u.msg_first = msghdr; msqkptr->u.__msg_first = msghdr;
msqkptr->u.msg_last = msghdr; msqkptr->u.__msg_last = msghdr;
} else { } else {
msqkptr->u.msg_last->msg_next = msghdr; msqkptr->u.__msg_last->msg_next = msghdr;
msqkptr->u.msg_last = msghdr; msqkptr->u.__msg_last = msghdr;
} }
msqkptr->u.msg_last->msg_next = NULL; msqkptr->u.__msg_last->msg_next = NULL;
msqkptr->u.msg_cbytes += msghdr->msg_ts; msqkptr->u.msg_cbytes += msghdr->msg_ts;
msqkptr->u.msg_qnum++; msqkptr->u.msg_qnum++;
@ -1194,7 +1194,7 @@ kern_msgrcv(struct thread *td, int msqid, void *msgp, size_t msgsz, long msgtyp,
msghdr = NULL; msghdr = NULL;
while (msghdr == NULL) { while (msghdr == NULL) {
if (msgtyp == 0) { if (msgtyp == 0) {
msghdr = msqkptr->u.msg_first; msghdr = msqkptr->u.__msg_first;
if (msghdr != NULL) { if (msghdr != NULL) {
if (msgsz < msghdr->msg_ts && if (msgsz < msghdr->msg_ts &&
(msgflg & MSG_NOERROR) == 0) { (msgflg & MSG_NOERROR) == 0) {
@ -1210,12 +1210,13 @@ kern_msgrcv(struct thread *td, int msqid, void *msgp, size_t msgsz, long msgtyp,
if (error != 0) if (error != 0)
goto done2; goto done2;
#endif #endif
if (msqkptr->u.msg_first == msqkptr->u.msg_last) { if (msqkptr->u.__msg_first ==
msqkptr->u.msg_first = NULL; msqkptr->u.__msg_last) {
msqkptr->u.msg_last = NULL; msqkptr->u.__msg_first = NULL;
msqkptr->u.__msg_last = NULL;
} else { } else {
msqkptr->u.msg_first = msghdr->msg_next; msqkptr->u.__msg_first = msghdr->msg_next;
if (msqkptr->u.msg_first == NULL) if (msqkptr->u.__msg_first == NULL)
panic("msg_first/last screwed up #1"); panic("msg_first/last screwed up #1");
} }
} }
@ -1224,7 +1225,7 @@ kern_msgrcv(struct thread *td, int msqid, void *msgp, size_t msgsz, long msgtyp,
struct msg **prev; struct msg **prev;
previous = NULL; previous = NULL;
prev = &(msqkptr->u.msg_first); prev = &(msqkptr->u.__msg_first);
while ((msghdr = *prev) != NULL) { while ((msghdr = *prev) != NULL) {
/* /*
* Is this message's type an exact match or is * Is this message's type an exact match or is
@ -1256,20 +1257,20 @@ kern_msgrcv(struct thread *td, int msqid, void *msgp, size_t msgsz, long msgtyp,
goto done2; goto done2;
#endif #endif
*prev = msghdr->msg_next; *prev = msghdr->msg_next;
if (msghdr == msqkptr->u.msg_last) { if (msghdr == msqkptr->u.__msg_last) {
if (previous == NULL) { if (previous == NULL) {
if (prev != if (prev !=
&msqkptr->u.msg_first) &msqkptr->u.__msg_first)
panic("msg_first/last screwed up #2"); panic("__msg_first/last screwed up #2");
msqkptr->u.msg_first = msqkptr->u.__msg_first =
NULL; NULL;
msqkptr->u.msg_last = msqkptr->u.__msg_last =
NULL; NULL;
} else { } else {
if (prev == if (prev ==
&msqkptr->u.msg_first) &msqkptr->u.__msg_first)
panic("msg_first/last screwed up #3"); panic("__msg_first/last screwed up #3");
msqkptr->u.msg_last = msqkptr->u.__msg_last =
previous; previous;
} }
} }
@ -1461,8 +1462,8 @@ sysctl_msqids(SYSCTL_HANDLER_ARGS)
#endif #endif
{ {
/* Don't leak kernel pointers */ /* Don't leak kernel pointers */
tmsqk.u.msg_first = NULL; tmsqk.u.__msg_first = NULL;
tmsqk.u.msg_last = NULL; tmsqk.u.__msg_last = NULL;
tmsqk.label = NULL; tmsqk.label = NULL;
tmsqk.cred = NULL; tmsqk.cred = NULL;
/* /*
@ -1713,8 +1714,8 @@ freebsd7_freebsd32_msgctl(struct thread *td,
if (error) if (error)
return (error); return (error);
freebsd32_ipcperm_old_in(&msqbuf32.msg_perm, &msqbuf.msg_perm); freebsd32_ipcperm_old_in(&msqbuf32.msg_perm, &msqbuf.msg_perm);
PTRIN_CP(msqbuf32, msqbuf, msg_first); PTRIN_CP(msqbuf32, msqbuf, __msg_first);
PTRIN_CP(msqbuf32, msqbuf, msg_last); PTRIN_CP(msqbuf32, msqbuf, __msg_last);
CP(msqbuf32, msqbuf, msg_cbytes); CP(msqbuf32, msqbuf, msg_cbytes);
CP(msqbuf32, msqbuf, msg_qnum); CP(msqbuf32, msqbuf, msg_qnum);
CP(msqbuf32, msqbuf, msg_qbytes); CP(msqbuf32, msqbuf, msg_qbytes);
@ -1730,8 +1731,8 @@ freebsd7_freebsd32_msgctl(struct thread *td,
if (uap->cmd == IPC_STAT) { if (uap->cmd == IPC_STAT) {
bzero(&msqbuf32, sizeof(msqbuf32)); bzero(&msqbuf32, sizeof(msqbuf32));
freebsd32_ipcperm_old_out(&msqbuf.msg_perm, &msqbuf32.msg_perm); freebsd32_ipcperm_old_out(&msqbuf.msg_perm, &msqbuf32.msg_perm);
PTROUT_CP(msqbuf, msqbuf32, msg_first); PTROUT_CP(msqbuf, msqbuf32, __msg_first);
PTROUT_CP(msqbuf, msqbuf32, msg_last); PTROUT_CP(msqbuf, msqbuf32, __msg_last);
CP(msqbuf, msqbuf32, msg_cbytes); CP(msqbuf, msqbuf32, msg_cbytes);
CP(msqbuf, msqbuf32, msg_qnum); CP(msqbuf, msqbuf32, msg_qnum);
CP(msqbuf, msqbuf32, msg_qbytes); CP(msqbuf, msqbuf32, msg_qbytes);
@ -1758,8 +1759,8 @@ freebsd32_msgctl(struct thread *td, struct freebsd32_msgctl_args *uap)
if (error) if (error)
return (error); return (error);
freebsd32_ipcperm_in(&msqbuf32.msg_perm, &msqbuf.msg_perm); freebsd32_ipcperm_in(&msqbuf32.msg_perm, &msqbuf.msg_perm);
PTRIN_CP(msqbuf32, msqbuf, msg_first); PTRIN_CP(msqbuf32, msqbuf, __msg_first);
PTRIN_CP(msqbuf32, msqbuf, msg_last); PTRIN_CP(msqbuf32, msqbuf, __msg_last);
CP(msqbuf32, msqbuf, msg_cbytes); CP(msqbuf32, msqbuf, msg_cbytes);
CP(msqbuf32, msqbuf, msg_qnum); CP(msqbuf32, msqbuf, msg_qnum);
CP(msqbuf32, msqbuf, msg_qbytes); CP(msqbuf32, msqbuf, msg_qbytes);
@ -1774,8 +1775,8 @@ freebsd32_msgctl(struct thread *td, struct freebsd32_msgctl_args *uap)
return (error); return (error);
if (uap->cmd == IPC_STAT) { if (uap->cmd == IPC_STAT) {
freebsd32_ipcperm_out(&msqbuf.msg_perm, &msqbuf32.msg_perm); freebsd32_ipcperm_out(&msqbuf.msg_perm, &msqbuf32.msg_perm);
PTROUT_CP(msqbuf, msqbuf32, msg_first); PTROUT_CP(msqbuf, msqbuf32, __msg_first);
PTROUT_CP(msqbuf, msqbuf32, msg_last); PTROUT_CP(msqbuf, msqbuf32, __msg_last);
CP(msqbuf, msqbuf32, msg_cbytes); CP(msqbuf, msqbuf32, msg_cbytes);
CP(msqbuf, msqbuf32, msg_qnum); CP(msqbuf, msqbuf32, msg_qnum);
CP(msqbuf, msqbuf32, msg_qbytes); CP(msqbuf, msqbuf32, msg_qbytes);
@ -1883,8 +1884,8 @@ freebsd7_msgctl(struct thread *td, struct freebsd7_msgctl_args *uap)
if (error) if (error)
return (error); return (error);
ipcperm_old2new(&msqold.msg_perm, &msqbuf.msg_perm); ipcperm_old2new(&msqold.msg_perm, &msqbuf.msg_perm);
CP(msqold, msqbuf, msg_first); CP(msqold, msqbuf, __msg_first);
CP(msqold, msqbuf, msg_last); CP(msqold, msqbuf, __msg_last);
CP(msqold, msqbuf, msg_cbytes); CP(msqold, msqbuf, msg_cbytes);
CP(msqold, msqbuf, msg_qnum); CP(msqold, msqbuf, msg_qnum);
CP(msqold, msqbuf, msg_qbytes); CP(msqold, msqbuf, msg_qbytes);
@ -1900,8 +1901,8 @@ freebsd7_msgctl(struct thread *td, struct freebsd7_msgctl_args *uap)
if (uap->cmd == IPC_STAT) { if (uap->cmd == IPC_STAT) {
bzero(&msqold, sizeof(msqold)); bzero(&msqold, sizeof(msqold));
ipcperm_new2old(&msqbuf.msg_perm, &msqold.msg_perm); ipcperm_new2old(&msqbuf.msg_perm, &msqold.msg_perm);
CP(msqbuf, msqold, msg_first); CP(msqbuf, msqold, __msg_first);
CP(msqbuf, msqold, msg_last); CP(msqbuf, msqold, __msg_last);
CP(msqbuf, msqold, msg_cbytes); CP(msqbuf, msqold, msg_cbytes);
CP(msqbuf, msqold, msg_qnum); CP(msqbuf, msqold, msg_qnum);
CP(msqbuf, msqold, msg_qbytes); CP(msqbuf, msqold, msg_qbytes);

View File

@ -287,7 +287,7 @@ seminit(void)
semu = malloc(seminfo.semmnu * seminfo.semusz, M_SEM, M_WAITOK); semu = malloc(seminfo.semmnu * seminfo.semusz, M_SEM, M_WAITOK);
for (i = 0; i < seminfo.semmni; i++) { for (i = 0; i < seminfo.semmni; i++) {
sema[i].u.sem_base = 0; sema[i].u.__sem_base = 0;
sema[i].u.sem_perm.mode = 0; sema[i].u.sem_perm.mode = 0;
sema[i].u.sem_perm.seq = 0; sema[i].u.sem_perm.seq = 0;
#ifdef MAC #ifdef MAC
@ -576,15 +576,15 @@ sem_remove(int semidx, struct ucred *cred)
wakeup(semakptr); wakeup(semakptr);
for (i = 0; i < seminfo.semmni; i++) { for (i = 0; i < seminfo.semmni; i++) {
if ((sema[i].u.sem_perm.mode & SEM_ALLOC) && if ((sema[i].u.sem_perm.mode & SEM_ALLOC) &&
sema[i].u.sem_base > semakptr->u.sem_base) sema[i].u.__sem_base > semakptr->u.__sem_base)
mtx_lock_flags(&sema_mtx[i], LOP_DUPOK); mtx_lock_flags(&sema_mtx[i], LOP_DUPOK);
} }
for (i = semakptr->u.sem_base - sem; i < semtot; i++) for (i = semakptr->u.__sem_base - sem; i < semtot; i++)
sem[i] = sem[i + semakptr->u.sem_nsems]; sem[i] = sem[i + semakptr->u.sem_nsems];
for (i = 0; i < seminfo.semmni; i++) { for (i = 0; i < seminfo.semmni; i++) {
if ((sema[i].u.sem_perm.mode & SEM_ALLOC) && if ((sema[i].u.sem_perm.mode & SEM_ALLOC) &&
sema[i].u.sem_base > semakptr->u.sem_base) { sema[i].u.__sem_base > semakptr->u.__sem_base) {
sema[i].u.sem_base -= semakptr->u.sem_nsems; sema[i].u.__sem_base -= semakptr->u.sem_nsems;
mtx_unlock(&sema_mtx[i]); mtx_unlock(&sema_mtx[i]);
} }
} }
@ -802,7 +802,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd,
error = EINVAL; error = EINVAL;
goto done2; goto done2;
} }
*rval = semakptr->u.sem_base[semnum].semncnt; *rval = semakptr->u.__sem_base[semnum].semncnt;
break; break;
case GETPID: case GETPID:
@ -814,7 +814,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd,
error = EINVAL; error = EINVAL;
goto done2; goto done2;
} }
*rval = semakptr->u.sem_base[semnum].sempid; *rval = semakptr->u.__sem_base[semnum].sempid;
break; break;
case GETVAL: case GETVAL:
@ -826,7 +826,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd,
error = EINVAL; error = EINVAL;
goto done2; goto done2;
} }
*rval = semakptr->u.sem_base[semnum].semval; *rval = semakptr->u.__sem_base[semnum].semval;
break; break;
case GETALL: case GETALL:
@ -860,7 +860,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd,
if ((error = ipcperm(td, &semakptr->u.sem_perm, IPC_R))) if ((error = ipcperm(td, &semakptr->u.sem_perm, IPC_R)))
goto done2; goto done2;
for (i = 0; i < semakptr->u.sem_nsems; i++) for (i = 0; i < semakptr->u.sem_nsems; i++)
array[i] = semakptr->u.sem_base[i].semval; array[i] = semakptr->u.__sem_base[i].semval;
mtx_unlock(sema_mtxp); mtx_unlock(sema_mtxp);
error = copyout(array, arg->array, count * sizeof(*array)); error = copyout(array, arg->array, count * sizeof(*array));
mtx_lock(sema_mtxp); mtx_lock(sema_mtxp);
@ -875,7 +875,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd,
error = EINVAL; error = EINVAL;
goto done2; goto done2;
} }
*rval = semakptr->u.sem_base[semnum].semzcnt; *rval = semakptr->u.__sem_base[semnum].semzcnt;
break; break;
case SETVAL: case SETVAL:
@ -891,7 +891,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd,
error = ERANGE; error = ERANGE;
goto done2; goto done2;
} }
semakptr->u.sem_base[semnum].semval = arg->val; semakptr->u.__sem_base[semnum].semval = arg->val;
SEMUNDO_LOCK(); SEMUNDO_LOCK();
semundo_clear(semidx, semnum); semundo_clear(semidx, semnum);
SEMUNDO_UNLOCK(); SEMUNDO_UNLOCK();
@ -921,7 +921,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd,
error = ERANGE; error = ERANGE;
break; break;
} }
semakptr->u.sem_base[i].semval = usval; semakptr->u.__sem_base[i].semval = usval;
} }
SEMUNDO_LOCK(); SEMUNDO_LOCK();
semundo_clear(semidx, -1); semundo_clear(semidx, -1);
@ -1052,16 +1052,16 @@ sys_semget(struct thread *td, struct semget_args *uap)
sema[semid].u.sem_nsems = nsems; sema[semid].u.sem_nsems = nsems;
sema[semid].u.sem_otime = 0; sema[semid].u.sem_otime = 0;
sema[semid].u.sem_ctime = time_second; sema[semid].u.sem_ctime = time_second;
sema[semid].u.sem_base = &sem[semtot]; sema[semid].u.__sem_base = &sem[semtot];
semtot += nsems; semtot += nsems;
bzero(sema[semid].u.sem_base, bzero(sema[semid].u.__sem_base,
sizeof(sema[semid].u.sem_base[0])*nsems); sizeof(sema[semid].u.__sem_base[0])*nsems);
#ifdef MAC #ifdef MAC
mac_sysvsem_create(cred, &sema[semid]); mac_sysvsem_create(cred, &sema[semid]);
#endif #endif
mtx_unlock(&sema_mtx[semid]); mtx_unlock(&sema_mtx[semid]);
DPRINTF(("sembase = %p, next = %p\n", DPRINTF(("sembase = %p, next = %p\n",
sema[semid].u.sem_base, &sem[semtot])); sema[semid].u.__sem_base, &sem[semtot]));
} else { } else {
DPRINTF(("didn't find it and wasn't asked to create it\n")); DPRINTF(("didn't find it and wasn't asked to create it\n"));
error = ENOENT; error = ENOENT;
@ -1204,12 +1204,12 @@ sys_semop(struct thread *td, struct semop_args *uap)
for (i = 0; i < nsops; i++) { for (i = 0; i < nsops; i++) {
sopptr = &sops[i]; sopptr = &sops[i];
semptr = &semakptr->u.sem_base[sopptr->sem_num]; semptr = &semakptr->u.__sem_base[sopptr->sem_num];
DPRINTF(( DPRINTF((
"semop: semakptr=%p, sem_base=%p, " "semop: semakptr=%p, __sem_base=%p, "
"semptr=%p, sem[%d]=%d : op=%d, flag=%s\n", "semptr=%p, sem[%d]=%d : op=%d, flag=%s\n",
semakptr, semakptr->u.sem_base, semptr, semakptr, semakptr->u.__sem_base, semptr,
sopptr->sem_num, semptr->semval, sopptr->sem_op, sopptr->sem_num, semptr->semval, sopptr->sem_op,
(sopptr->sem_flg & IPC_NOWAIT) ? (sopptr->sem_flg & IPC_NOWAIT) ?
"nowait" : "wait")); "nowait" : "wait"));
@ -1251,7 +1251,7 @@ sys_semop(struct thread *td, struct semop_args *uap)
*/ */
DPRINTF(("semop: rollback 0 through %d\n", i-1)); DPRINTF(("semop: rollback 0 through %d\n", i-1));
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
semakptr->u.sem_base[sops[j].sem_num].semval -= semakptr->u.__sem_base[sops[j].sem_num].semval -=
sops[j].sem_op; sops[j].sem_op;
/* If we detected an error, return it */ /* If we detected an error, return it */
@ -1290,10 +1290,10 @@ sys_semop(struct thread *td, struct semop_args *uap)
/* /*
* Renew the semaphore's pointer after wakeup since * Renew the semaphore's pointer after wakeup since
* during msleep sem_base may have been modified and semptr * during msleep __sem_base may have been modified and semptr
* is not valid any more * is not valid any more
*/ */
semptr = &semakptr->u.sem_base[sopptr->sem_num]; semptr = &semakptr->u.__sem_base[sopptr->sem_num];
/* /*
* The semaphore is still alive. Readjust the count of * The semaphore is still alive. Readjust the count of
@ -1362,7 +1362,7 @@ done:
} }
for (j = 0; j < nsops; j++) for (j = 0; j < nsops; j++)
semakptr->u.sem_base[sops[j].sem_num].semval -= semakptr->u.__sem_base[sops[j].sem_num].semval -=
sops[j].sem_op; sops[j].sem_op;
DPRINTF(("error = %d from semundo_adjust\n", error)); DPRINTF(("error = %d from semundo_adjust\n", error));
@ -1375,7 +1375,7 @@ done:
/* We're definitely done - set the sempid's and time */ /* We're definitely done - set the sempid's and time */
for (i = 0; i < nsops; i++) { for (i = 0; i < nsops; i++) {
sopptr = &sops[i]; sopptr = &sops[i];
semptr = &semakptr->u.sem_base[sopptr->sem_num]; semptr = &semakptr->u.__sem_base[sopptr->sem_num];
semptr->sempid = td->td_proc->p_pid; semptr->sempid = td->td_proc->p_pid;
} }
semakptr->u.sem_otime = time_second; semakptr->u.sem_otime = time_second;
@ -1458,13 +1458,13 @@ semexit_myhook(void *arg, struct proc *p)
suptr->un_proc, suptr->un_ent[ix].un_id, suptr->un_proc, suptr->un_ent[ix].un_id,
suptr->un_ent[ix].un_num, suptr->un_ent[ix].un_num,
suptr->un_ent[ix].un_adjval, suptr->un_ent[ix].un_adjval,
semakptr->u.sem_base[semnum].semval)); semakptr->u.__sem_base[semnum].semval));
if (adjval < 0 && semakptr->u.sem_base[semnum].semval < if (adjval < 0 && semakptr->u.__sem_base[semnum].semval <
-adjval) -adjval)
semakptr->u.sem_base[semnum].semval = 0; semakptr->u.__sem_base[semnum].semval = 0;
else else
semakptr->u.sem_base[semnum].semval += adjval; semakptr->u.__sem_base[semnum].semval += adjval;
wakeup(semakptr); wakeup(semakptr);
DPRINTF(("semexit: back from wakeup\n")); DPRINTF(("semexit: back from wakeup\n"));
@ -1514,7 +1514,7 @@ sysctl_sema(SYSCTL_HANDLER_ARGS)
bzero(&tsemak32, sizeof(tsemak32)); bzero(&tsemak32, sizeof(tsemak32));
freebsd32_ipcperm_out(&tsemak.u.sem_perm, freebsd32_ipcperm_out(&tsemak.u.sem_perm,
&tsemak32.u.sem_perm); &tsemak32.u.sem_perm);
/* Don't copy u.sem_base */ /* Don't copy u.__sem_base */
CP(tsemak, tsemak32, u.sem_nsems); CP(tsemak, tsemak32, u.sem_nsems);
CP(tsemak, tsemak32, u.sem_otime); CP(tsemak, tsemak32, u.sem_otime);
CP(tsemak, tsemak32, u.sem_ctime); CP(tsemak, tsemak32, u.sem_ctime);
@ -1524,7 +1524,7 @@ sysctl_sema(SYSCTL_HANDLER_ARGS)
} else } else
#endif #endif
{ {
tsemak.u.sem_base = NULL; tsemak.u.__sem_base = NULL;
tsemak.label = NULL; tsemak.label = NULL;
tsemak.cred = NULL; tsemak.cred = NULL;
outaddr = &tsemak; outaddr = &tsemak;
@ -1791,7 +1791,7 @@ freebsd7___semctl(struct thread *td, struct freebsd7___semctl_args *uap)
if (error) if (error)
return (error); return (error);
ipcperm_old2new(&dsold.sem_perm, &dsbuf.sem_perm); ipcperm_old2new(&dsold.sem_perm, &dsbuf.sem_perm);
CP(dsold, dsbuf, sem_base); CP(dsold, dsbuf, __sem_base);
CP(dsold, dsbuf, sem_nsems); CP(dsold, dsbuf, sem_nsems);
CP(dsold, dsbuf, sem_otime); CP(dsold, dsbuf, sem_otime);
CP(dsold, dsbuf, sem_ctime); CP(dsold, dsbuf, sem_ctime);
@ -1816,7 +1816,7 @@ freebsd7___semctl(struct thread *td, struct freebsd7___semctl_args *uap)
case IPC_STAT: case IPC_STAT:
bzero(&dsold, sizeof(dsold)); bzero(&dsold, sizeof(dsold));
ipcperm_new2old(&dsbuf.sem_perm, &dsold.sem_perm); ipcperm_new2old(&dsbuf.sem_perm, &dsold.sem_perm);
CP(dsbuf, dsold, sem_base); CP(dsbuf, dsold, __sem_base);
CP(dsbuf, dsold, sem_nsems); CP(dsbuf, dsold, sem_nsems);
CP(dsbuf, dsold, sem_otime); CP(dsbuf, dsold, sem_otime);
CP(dsbuf, dsold, sem_ctime); CP(dsbuf, dsold, sem_ctime);
@ -1888,7 +1888,7 @@ freebsd7_freebsd32_semctl(struct thread *td,
if (error) if (error)
return (error); return (error);
freebsd32_ipcperm_old_in(&dsbuf32.sem_perm, &dsbuf.sem_perm); freebsd32_ipcperm_old_in(&dsbuf32.sem_perm, &dsbuf.sem_perm);
PTRIN_CP(dsbuf32, dsbuf, sem_base); PTRIN_CP(dsbuf32, dsbuf, __sem_base);
CP(dsbuf32, dsbuf, sem_nsems); CP(dsbuf32, dsbuf, sem_nsems);
CP(dsbuf32, dsbuf, sem_otime); CP(dsbuf32, dsbuf, sem_otime);
CP(dsbuf32, dsbuf, sem_ctime); CP(dsbuf32, dsbuf, sem_ctime);
@ -1913,7 +1913,7 @@ freebsd7_freebsd32_semctl(struct thread *td,
case IPC_STAT: case IPC_STAT:
bzero(&dsbuf32, sizeof(dsbuf32)); bzero(&dsbuf32, sizeof(dsbuf32));
freebsd32_ipcperm_old_out(&dsbuf.sem_perm, &dsbuf32.sem_perm); freebsd32_ipcperm_old_out(&dsbuf.sem_perm, &dsbuf32.sem_perm);
PTROUT_CP(dsbuf, dsbuf32, sem_base); PTROUT_CP(dsbuf, dsbuf32, __sem_base);
CP(dsbuf, dsbuf32, sem_nsems); CP(dsbuf, dsbuf32, sem_nsems);
CP(dsbuf, dsbuf32, sem_otime); CP(dsbuf, dsbuf32, sem_otime);
CP(dsbuf, dsbuf32, sem_ctime); CP(dsbuf, dsbuf32, sem_ctime);
@ -1960,7 +1960,7 @@ freebsd32_semctl(struct thread *td, struct freebsd32_semctl_args *uap)
if (error) if (error)
return (error); return (error);
freebsd32_ipcperm_in(&dsbuf32.sem_perm, &dsbuf.sem_perm); freebsd32_ipcperm_in(&dsbuf32.sem_perm, &dsbuf.sem_perm);
PTRIN_CP(dsbuf32, dsbuf, sem_base); PTRIN_CP(dsbuf32, dsbuf, __sem_base);
CP(dsbuf32, dsbuf, sem_nsems); CP(dsbuf32, dsbuf, sem_nsems);
CP(dsbuf32, dsbuf, sem_otime); CP(dsbuf32, dsbuf, sem_otime);
CP(dsbuf32, dsbuf, sem_ctime); CP(dsbuf32, dsbuf, sem_ctime);
@ -1985,7 +1985,7 @@ freebsd32_semctl(struct thread *td, struct freebsd32_semctl_args *uap)
case IPC_STAT: case IPC_STAT:
bzero(&dsbuf32, sizeof(dsbuf32)); bzero(&dsbuf32, sizeof(dsbuf32));
freebsd32_ipcperm_out(&dsbuf.sem_perm, &dsbuf32.sem_perm); freebsd32_ipcperm_out(&dsbuf.sem_perm, &dsbuf32.sem_perm);
PTROUT_CP(dsbuf, dsbuf32, sem_base); PTROUT_CP(dsbuf, dsbuf32, __sem_base);
CP(dsbuf, dsbuf32, sem_nsems); CP(dsbuf, dsbuf32, sem_nsems);
CP(dsbuf, dsbuf32, sem_otime); CP(dsbuf, dsbuf32, sem_otime);
CP(dsbuf, dsbuf32, sem_ctime); CP(dsbuf, dsbuf32, sem_ctime);

View File

@ -64,8 +64,8 @@ typedef __time_t time_t;
defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
struct msqid_ds_old { struct msqid_ds_old {
struct ipc_perm_old msg_perm; /* msg queue permission bits */ struct ipc_perm_old msg_perm; /* msg queue permission bits */
struct msg *msg_first; /* first message in the queue */ struct msg *__msg_first; /* first message in the queue */
struct msg *msg_last; /* last message in the queue */ struct msg *__msg_last; /* last message in the queue */
msglen_t msg_cbytes; /* number of bytes in use on the queue */ msglen_t msg_cbytes; /* number of bytes in use on the queue */
msgqnum_t msg_qnum; /* number of msgs in the queue */ msgqnum_t msg_qnum; /* number of msgs in the queue */
msglen_t msg_qbytes; /* max # of bytes on the queue */ msglen_t msg_qbytes; /* max # of bytes on the queue */
@ -89,8 +89,8 @@ struct msqid_ds_old {
struct msqid_ds { struct msqid_ds {
struct ipc_perm msg_perm; /* msg queue permission bits */ struct ipc_perm msg_perm; /* msg queue permission bits */
struct msg *msg_first; /* first message in the queue */ struct msg *__msg_first; /* first message in the queue */
struct msg *msg_last; /* last message in the queue */ struct msg *__msg_last; /* last message in the queue */
msglen_t msg_cbytes; /* number of bytes in use on the queue */ msglen_t msg_cbytes; /* number of bytes in use on the queue */
msgqnum_t msg_qnum; /* number of msgs in the queue */ msgqnum_t msg_qnum; /* number of msgs in the queue */
msglen_t msg_qbytes; /* max # of bytes on the queue */ msglen_t msg_qbytes; /* max # of bytes on the queue */

View File

@ -34,7 +34,7 @@ typedef __time_t time_t;
defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
struct semid_ds_old { struct semid_ds_old {
struct ipc_perm_old sem_perm; /* operation permission struct */ struct ipc_perm_old sem_perm; /* operation permission struct */
struct sem *sem_base; /* pointer to first semaphore in set */ struct sem *__sem_base; /* pointer to first semaphore in set */
unsigned short sem_nsems; /* number of sems in set */ unsigned short sem_nsems; /* number of sems in set */
time_t sem_otime; /* last operation time */ time_t sem_otime; /* last operation time */
long sem_pad1; /* SVABI/386 says I need this here */ long sem_pad1; /* SVABI/386 says I need this here */
@ -48,7 +48,7 @@ struct semid_ds_old {
struct semid_ds { struct semid_ds {
struct ipc_perm sem_perm; /* operation permission struct */ struct ipc_perm sem_perm; /* operation permission struct */
struct sem *sem_base; /* pointer to first semaphore in set */ struct sem *__sem_base; /* pointer to first semaphore in set */
unsigned short sem_nsems; /* number of sems in set */ unsigned short sem_nsems; /* number of sems in set */
time_t sem_otime; /* last operation time */ time_t sem_otime; /* last operation time */
time_t sem_ctime; /* last change time */ time_t sem_ctime; /* last change time */