summaryrefslogtreecommitdiffstats
path: root/sys/kern/sysv_msg.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2010-03-19 11:04:42 +0000
committerkib <kib@FreeBSD.org>2010-03-19 11:04:42 +0000
commitb27fa06f976447590802ac0521932dc2803b4854 (patch)
treec0f64553fae4afa41d4796848ab08f701505e447 /sys/kern/sysv_msg.c
parent610214ed4c4cf8e4c9ec77a65d3b4fee64af5657 (diff)
downloadFreeBSD-src-b27fa06f976447590802ac0521932dc2803b4854.zip
FreeBSD-src-b27fa06f976447590802ac0521932dc2803b4854.tar.gz
Move SysV IPC freebsd32 compat shims from freebsd32_misc.c to corresponding
sysv_{msg,sem,shm}.c files. Mark SysV IPC freebsd32 syscalls as NOSTD and add required SYSCALL_INIT_HELPER/SYSCALL32_INIT_HELPERs to provide auto register/unregister on module load. This makes COMPAT_FREEBSD32 functional with SysV IPC compiled and loaded as modules. Reviewed by: jhb MFC after: 2 weeks
Diffstat (limited to 'sys/kern/sysv_msg.c')
-rw-r--r--sys/kern/sysv_msg.c220
1 files changed, 209 insertions, 11 deletions
diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c
index c7c67d4..01d7f79 100644
--- a/sys/kern/sysv_msg.c
+++ b/sys/kern/sysv_msg.c
@@ -74,7 +74,7 @@ __FBSDID("$FreeBSD$");
static MALLOC_DEFINE(M_MSG, "msg", "SVID compatible message queues");
-static void msginit(void);
+static int msginit(void);
static int msgunload(void);
static int sysvmsg_modload(struct module *, int, void *);
@@ -152,10 +152,45 @@ static struct msg *msghdrs; /* MSGTQL msg headers */
static struct msqid_kernel *msqids; /* MSGMNI msqid_kernel struct's */
static struct mtx msq_mtx; /* global mutex for message queues. */
-static void
+static struct syscall_helper_data msg_syscalls[] = {
+ SYSCALL_INIT_HELPER(msgctl),
+ SYSCALL_INIT_HELPER(msgget),
+ SYSCALL_INIT_HELPER(msgsnd),
+ SYSCALL_INIT_HELPER(msgrcv),
+#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
+ SYSCALL_INIT_HELPER(msgsys),
+ SYSCALL_INIT_HELPER(freebsd7_msgctl),
+#endif
+ SYSCALL_INIT_LAST
+};
+
+#ifdef COMPAT_FREEBSD32
+#include <compat/freebsd32/freebsd32.h>
+#include <compat/freebsd32/freebsd32_ipc.h>
+#include <compat/freebsd32/freebsd32_proto.h>
+#include <compat/freebsd32/freebsd32_signal.h>
+#include <compat/freebsd32/freebsd32_syscall.h>
+#include <compat/freebsd32/freebsd32_util.h>
+
+static struct syscall_helper_data msg32_syscalls[] = {
+ SYSCALL32_INIT_HELPER(freebsd32_msgctl),
+ SYSCALL32_INIT_HELPER(freebsd32_msgsnd),
+ SYSCALL32_INIT_HELPER(freebsd32_msgrcv),
+ SYSCALL32_INIT_HELPER(msgget),
+ SYSCALL32_INIT_HELPER(freebsd32_msgsys),
+#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
+ SYSCALL32_INIT_HELPER(freebsd7_freebsd32_msgctl),
+#endif
+ SYSCALL_INIT_LAST
+};
+#endif
+
+static int
msginit()
{
- register int i;
+ int i, error;
TUNABLE_INT_FETCH("kern.ipc.msgseg", &msginfo.msgseg);
TUNABLE_INT_FETCH("kern.ipc.msgssz", &msginfo.msgssz);
@@ -235,6 +270,16 @@ msginit()
#endif
}
mtx_init(&msq_mtx, "msq", NULL, MTX_DEF);
+
+ error = syscall_helper_register(msg_syscalls);
+ if (error != 0)
+ return (error);
+#ifdef COMPAT_FREEBSD32
+ error = syscall32_helper_register(msg32_syscalls);
+ if (error != 0)
+ return (error);
+#endif
+ return (0);
}
static int
@@ -246,6 +291,11 @@ msgunload()
int i;
#endif
+ syscall_helper_unregister(msg_syscalls);
+#ifdef COMPAT_FREEBSD32
+ syscall32_helper_unregister(msg32_syscalls);
+#endif
+
for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
/*
* Look for an unallocated and unlocked msqid_ds.
@@ -283,7 +333,9 @@ sysvmsg_modload(struct module *module, int cmd, void *arg)
switch (cmd) {
case MOD_LOAD:
- msginit();
+ error = msginit();
+ if (error != 0)
+ msgunload();
break;
case MOD_UNLOAD:
error = msgunload();
@@ -303,11 +355,6 @@ static moduledata_t sysvmsg_mod = {
NULL
};
-SYSCALL_MODULE_HELPER(msgctl);
-SYSCALL_MODULE_HELPER(msgget);
-SYSCALL_MODULE_HELPER(msgsnd);
-SYSCALL_MODULE_HELPER(msgrcv);
-
DECLARE_MODULE(sysvmsg, sysvmsg_mod, SI_SUB_SYSV_MSG, SI_ORDER_FIRST);
MODULE_VERSION(sysvmsg, 1);
@@ -1257,10 +1304,159 @@ SYSCTL_INT(_kern_ipc, OID_AUTO, msgseg, CTLFLAG_RDTUN, &msginfo.msgseg, 0,
SYSCTL_PROC(_kern_ipc, OID_AUTO, msqids, CTLFLAG_RD,
NULL, 0, sysctl_msqids, "", "Message queue IDs");
+#ifdef COMPAT_FREEBSD32
+int
+freebsd32_msgsys(struct thread *td, struct freebsd32_msgsys_args *uap)
+{
+
+#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
+ switch (uap->which) {
+ case 0:
+ return (freebsd7_freebsd32_msgctl(td,
+ (struct freebsd7_freebsd32_msgctl_args *)&uap->a2));
+ case 2:
+ return (freebsd32_msgsnd(td,
+ (struct freebsd32_msgsnd_args *)&uap->a2));
+ case 3:
+ return (freebsd32_msgrcv(td,
+ (struct freebsd32_msgrcv_args *)&uap->a2));
+ default:
+ return (msgsys(td, (struct msgsys_args *)uap));
+ }
+#else
+ return (nosys(td, NULL));
+#endif
+}
+
+#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
+int
+freebsd7_freebsd32_msgctl(struct thread *td,
+ struct freebsd7_freebsd32_msgctl_args *uap)
+{
+ struct msqid_ds msqbuf;
+ struct msqid_ds32_old msqbuf32;
+ int error;
+
+ if (uap->cmd == IPC_SET) {
+ error = copyin(uap->buf, &msqbuf32, sizeof(msqbuf32));
+ if (error)
+ return (error);
+ freebsd32_ipcperm_old_in(&msqbuf32.msg_perm, &msqbuf.msg_perm);
+ PTRIN_CP(msqbuf32, msqbuf, msg_first);
+ PTRIN_CP(msqbuf32, msqbuf, msg_last);
+ CP(msqbuf32, msqbuf, msg_cbytes);
+ CP(msqbuf32, msqbuf, msg_qnum);
+ CP(msqbuf32, msqbuf, msg_qbytes);
+ CP(msqbuf32, msqbuf, msg_lspid);
+ CP(msqbuf32, msqbuf, msg_lrpid);
+ CP(msqbuf32, msqbuf, msg_stime);
+ CP(msqbuf32, msqbuf, msg_rtime);
+ CP(msqbuf32, msqbuf, msg_ctime);
+ }
+ error = kern_msgctl(td, uap->msqid, uap->cmd, &msqbuf);
+ if (error)
+ return (error);
+ if (uap->cmd == IPC_STAT) {
+ bzero(&msqbuf32, sizeof(msqbuf32));
+ freebsd32_ipcperm_old_out(&msqbuf.msg_perm, &msqbuf32.msg_perm);
+ PTROUT_CP(msqbuf, msqbuf32, msg_first);
+ PTROUT_CP(msqbuf, msqbuf32, msg_last);
+ CP(msqbuf, msqbuf32, msg_cbytes);
+ CP(msqbuf, msqbuf32, msg_qnum);
+ CP(msqbuf, msqbuf32, msg_qbytes);
+ CP(msqbuf, msqbuf32, msg_lspid);
+ CP(msqbuf, msqbuf32, msg_lrpid);
+ CP(msqbuf, msqbuf32, msg_stime);
+ CP(msqbuf, msqbuf32, msg_rtime);
+ CP(msqbuf, msqbuf32, msg_ctime);
+ error = copyout(&msqbuf32, uap->buf, sizeof(struct msqid_ds32));
+ }
+ return (error);
+}
+#endif
+
+int
+freebsd32_msgctl(struct thread *td, struct freebsd32_msgctl_args *uap)
+{
+ struct msqid_ds msqbuf;
+ struct msqid_ds32 msqbuf32;
+ int error;
+
+ if (uap->cmd == IPC_SET) {
+ error = copyin(uap->buf, &msqbuf32, sizeof(msqbuf32));
+ if (error)
+ return (error);
+ freebsd32_ipcperm_in(&msqbuf32.msg_perm, &msqbuf.msg_perm);
+ PTRIN_CP(msqbuf32, msqbuf, msg_first);
+ PTRIN_CP(msqbuf32, msqbuf, msg_last);
+ CP(msqbuf32, msqbuf, msg_cbytes);
+ CP(msqbuf32, msqbuf, msg_qnum);
+ CP(msqbuf32, msqbuf, msg_qbytes);
+ CP(msqbuf32, msqbuf, msg_lspid);
+ CP(msqbuf32, msqbuf, msg_lrpid);
+ CP(msqbuf32, msqbuf, msg_stime);
+ CP(msqbuf32, msqbuf, msg_rtime);
+ CP(msqbuf32, msqbuf, msg_ctime);
+ }
+ error = kern_msgctl(td, uap->msqid, uap->cmd, &msqbuf);
+ if (error)
+ return (error);
+ if (uap->cmd == IPC_STAT) {
+ freebsd32_ipcperm_out(&msqbuf.msg_perm, &msqbuf32.msg_perm);
+ PTROUT_CP(msqbuf, msqbuf32, msg_first);
+ PTROUT_CP(msqbuf, msqbuf32, msg_last);
+ CP(msqbuf, msqbuf32, msg_cbytes);
+ CP(msqbuf, msqbuf32, msg_qnum);
+ CP(msqbuf, msqbuf32, msg_qbytes);
+ CP(msqbuf, msqbuf32, msg_lspid);
+ CP(msqbuf, msqbuf32, msg_lrpid);
+ CP(msqbuf, msqbuf32, msg_stime);
+ CP(msqbuf, msqbuf32, msg_rtime);
+ CP(msqbuf, msqbuf32, msg_ctime);
+ error = copyout(&msqbuf32, uap->buf, sizeof(struct msqid_ds32));
+ }
+ return (error);
+}
+
+int
+freebsd32_msgsnd(struct thread *td, struct freebsd32_msgsnd_args *uap)
+{
+ const void *msgp;
+ long mtype;
+ int32_t mtype32;
+ int error;
+
+ msgp = PTRIN(uap->msgp);
+ if ((error = copyin(msgp, &mtype32, sizeof(mtype32))) != 0)
+ return (error);
+ mtype = mtype32;
+ return (kern_msgsnd(td, uap->msqid,
+ (const char *)msgp + sizeof(mtype32),
+ uap->msgsz, uap->msgflg, mtype));
+}
+
+int
+freebsd32_msgrcv(struct thread *td, struct freebsd32_msgrcv_args *uap)
+{
+ void *msgp;
+ long mtype;
+ int32_t mtype32;
+ int error;
+
+ msgp = PTRIN(uap->msgp);
+ if ((error = kern_msgrcv(td, uap->msqid,
+ (char *)msgp + sizeof(mtype32), uap->msgsz,
+ uap->msgtyp, uap->msgflg, &mtype)) != 0)
+ return (error);
+ mtype32 = (int32_t)mtype;
+ return (copyout(&mtype32, msgp, sizeof(mtype32)));
+}
+#endif
+
#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
-SYSCALL_MODULE_HELPER(msgsys);
-SYSCALL_MODULE_HELPER(freebsd7_msgctl);
/* XXX casting to (sy_call_t *) is bogus, as usual. */
static sy_call_t *msgcalls[] = {
@@ -1295,7 +1491,9 @@ msgsys(td, uap)
return (error);
}
+#ifndef CP
#define CP(src, dst, fld) do { (dst).fld = (src).fld; } while (0)
+#endif
#ifndef _SYS_SYSPROTO_H_
struct freebsd7_msgctl_args {
OpenPOWER on IntegriCloud