Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/netbsd32 move the static inline conversion functi...



details:   https://anonhg.NetBSD.org/src/rev/a34302700e63
branches:  trunk
changeset: 503509:a34302700e63
user:      mrg <mrg%NetBSD.org@localhost>
date:      Wed Feb 07 15:22:39 2001 +0000

description:
move the static inline conversion functions into a header file so other
files can see these.  note a bunch of functions that should be moved
into their own files.

diffstat:

 sys/compat/netbsd32/netbsd32_conv.h   |  527 +++++++++++++++++++++++++++++++++
 sys/compat/netbsd32/netbsd32_netbsd.c |  528 +++------------------------------
 2 files changed, 579 insertions(+), 476 deletions(-)

diffs (truncated from 1409 to 300 lines):

diff -r fac71bd7b017 -r a34302700e63 sys/compat/netbsd32/netbsd32_conv.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/netbsd32/netbsd32_conv.h       Wed Feb 07 15:22:39 2001 +0000
@@ -0,0 +1,527 @@
+/*     $NetBSD: netbsd32_conv.h,v 1.1 2001/02/07 15:22:39 mrg Exp $    */
+
+/*
+ * Copyright (c) 1998, 2001 Matthew R. Green
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _COMPAT_NETBSD32_NETBSD32_CONV_H_
+#define _COMPAT_NETBSD32_NETBSD32_CONV_H_
+
+/*
+ * Though COMPAT_OLDSOCK is needed only for COMPAT_43, SunOS, Linux,
+ * HP-UX, FreeBSD, Ultrix, OSF1, we define it unconditionally so that
+ * this would be LKM-safe.
+ */
+#define COMPAT_OLDSOCK /* used by <sys/socket.h> */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#define msg __msg /* Don't ask me! */
+#include <sys/sem.h>
+#include <sys/shm.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+
+#include <compat/netbsd32/netbsd32.h>
+
+static __inline void netbsd32_from_timeval __P((struct timeval *, struct netbsd32_timeval *));
+static __inline void netbsd32_to_timeval __P((struct netbsd32_timeval *, struct timeval *));
+static __inline void netbsd32_from_itimerval __P((struct itimerval *, struct netbsd32_itimerval *));
+static __inline void netbsd32_to_itimerval __P((struct netbsd32_itimerval *, struct itimerval *));
+static __inline void netbsd32_to_timespec __P((struct netbsd32_timespec *, struct timespec *));
+static __inline void netbsd32_from_timespec __P((struct timespec *, struct netbsd32_timespec *));
+static __inline void netbsd32_from_rusage __P((struct rusage *, struct netbsd32_rusage *));
+static __inline void netbsd32_to_rusage __P((struct netbsd32_rusage *, struct rusage *));
+static __inline int netbsd32_to_iovecin __P((struct netbsd32_iovec *, struct iovec *, int));
+static __inline void netbsd32_to_msghdr __P((struct netbsd32_msghdr *, struct msghdr *));
+static __inline void netbsd32_from_msghdr __P((struct netbsd32_msghdr *, struct msghdr *));
+static __inline void netbsd32_from_statfs __P((struct statfs *, struct netbsd32_statfs *));
+static __inline void netbsd32_from_timex __P((struct timex *, struct netbsd32_timex *));
+static __inline void netbsd32_to_timex __P((struct netbsd32_timex *, struct timex *));
+static __inline void netbsd32_from___stat13 __P((struct stat *, struct netbsd32_stat *));
+static __inline void netbsd32_to_ipc_perm __P((struct netbsd32_ipc_perm *, struct ipc_perm *));
+static __inline void netbsd32_from_ipc_perm __P((struct ipc_perm *, struct netbsd32_ipc_perm *));
+static __inline void netbsd32_to_msg __P((struct netbsd32_msg *, struct msg *));
+static __inline void netbsd32_from_msg __P((struct msg *, struct netbsd32_msg *));
+static __inline void netbsd32_to_msqid_ds __P((struct netbsd32_msqid_ds *, struct msqid_ds *));
+static __inline void netbsd32_from_msqid_ds __P((struct msqid_ds *, struct netbsd32_msqid_ds *));
+static __inline void netbsd32_to_shmid_ds __P((struct netbsd32_shmid_ds *, struct shmid_ds *));
+static __inline void netbsd32_from_shmid_ds __P((struct shmid_ds *, struct netbsd32_shmid_ds *));
+static __inline void netbsd32_to_semid_ds __P((struct  netbsd32_semid_ds *, struct  semid_ds *));
+static __inline void netbsd32_from_semid_ds __P((struct  semid_ds *, struct  netbsd32_semid_ds *));
+static __inline void netbsd32_from_loadavg __P((struct netbsd32_loadavg *, struct loadavg *));
+
+/* converters for structures that we need */
+static __inline void
+netbsd32_from_timeval(tv, tv32)
+       struct timeval *tv;
+       struct netbsd32_timeval *tv32;
+{
+
+       tv32->tv_sec = (netbsd32_long)tv->tv_sec;
+       tv32->tv_usec = (netbsd32_long)tv->tv_usec;
+}
+
+static __inline void
+netbsd32_to_timeval(tv32, tv)
+       struct netbsd32_timeval *tv32;
+       struct timeval *tv;
+{
+
+       tv->tv_sec = (long)tv32->tv_sec;
+       tv->tv_usec = (long)tv32->tv_usec;
+}
+
+static __inline void
+netbsd32_from_itimerval(itv, itv32)
+       struct itimerval *itv;
+       struct netbsd32_itimerval *itv32;
+{
+
+       netbsd32_from_timeval(&itv->it_interval, 
+                            &itv32->it_interval);
+       netbsd32_from_timeval(&itv->it_value, 
+                            &itv32->it_value);
+}
+
+static __inline void
+netbsd32_to_itimerval(itv32, itv)
+       struct netbsd32_itimerval *itv32;
+       struct itimerval *itv;
+{
+
+       netbsd32_to_timeval(&itv32->it_interval, &itv->it_interval);
+       netbsd32_to_timeval(&itv32->it_value, &itv->it_value);
+}
+
+static __inline void
+netbsd32_to_timespec(s32p, p)
+       struct netbsd32_timespec *s32p;
+       struct timespec *p;
+{
+
+       p->tv_sec = (time_t)s32p->tv_sec;
+       p->tv_nsec = (long)s32p->tv_nsec;
+}
+
+static __inline void
+netbsd32_from_timespec(p, s32p)
+       struct timespec *p;
+       struct netbsd32_timespec *s32p;
+{
+
+       s32p->tv_sec = (netbsd32_time_t)p->tv_sec;
+       s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
+}
+
+static __inline void
+netbsd32_from_rusage(rup, ru32p)
+       struct rusage *rup;
+       struct netbsd32_rusage *ru32p;
+{
+
+       netbsd32_from_timeval(&rup->ru_utime, &ru32p->ru_utime);
+       netbsd32_from_timeval(&rup->ru_stime, &ru32p->ru_stime);
+#define C(var) ru32p->var = (netbsd32_long)rup->var
+       C(ru_maxrss);
+       C(ru_ixrss);
+       C(ru_idrss);
+       C(ru_isrss);
+       C(ru_minflt);
+       C(ru_majflt);
+       C(ru_nswap);
+       C(ru_inblock);
+       C(ru_oublock);
+       C(ru_msgsnd);
+       C(ru_msgrcv);
+       C(ru_nsignals);
+       C(ru_nvcsw);
+       C(ru_nivcsw);
+#undef C
+}
+
+static __inline void
+netbsd32_to_rusage(ru32p, rup)
+       struct netbsd32_rusage *ru32p;
+       struct rusage *rup;
+{
+
+       netbsd32_to_timeval(&ru32p->ru_utime, &rup->ru_utime);
+       netbsd32_to_timeval(&ru32p->ru_stime, &rup->ru_stime);
+#define C(var) rup->var = (long)ru32p->var
+       C(ru_maxrss);
+       C(ru_ixrss);
+       C(ru_idrss);
+       C(ru_isrss);
+       C(ru_minflt);
+       C(ru_majflt);
+       C(ru_nswap);
+       C(ru_inblock);
+       C(ru_oublock);
+       C(ru_msgsnd);
+       C(ru_msgrcv);
+       C(ru_nsignals);
+       C(ru_nvcsw);
+       C(ru_nivcsw);
+#undef C
+}
+
+static __inline int
+netbsd32_to_iovecin(iov32p, iovp, len)
+       struct netbsd32_iovec *iov32p;
+       struct iovec *iovp;
+       int len;
+{
+       int i, error=0;
+       u_int32_t iov_base;
+       u_int32_t iov_len;
+       /* 
+        * We could allocate an iov32p, do a copyin, and translate
+        * each field and then free it all up, or we could copyin
+        * each field separately.  I'm doing the latter to reduce
+        * the number of MALLOC()s.
+        */
+       for (i = 0; i < len; i++, iovp++, iov32p++) {
+               if ((error = copyin((caddr_t)&iov32p->iov_base, &iov_base, sizeof(iov_base))))
+                   return (error);
+               if ((error = copyin((caddr_t)&iov32p->iov_len, &iov_len, sizeof(iov_len))))
+                   return (error);
+               iovp->iov_base = (void *)(u_long)iov_base;
+               iovp->iov_len = (size_t)iov_len;
+       }
+       return error;
+}
+
+/* msg_iov must be done separately */
+static __inline void
+netbsd32_to_msghdr(mhp32, mhp)
+       struct netbsd32_msghdr *mhp32;
+       struct msghdr *mhp;
+{
+
+       mhp->msg_name = (caddr_t)(u_long)mhp32->msg_name;
+       mhp->msg_namelen = mhp32->msg_namelen;
+       mhp->msg_iovlen = (size_t)mhp32->msg_iovlen;
+       mhp->msg_control = (caddr_t)(u_long)mhp32->msg_control;
+       mhp->msg_controllen = mhp32->msg_controllen;
+       mhp->msg_flags = mhp32->msg_flags;
+}
+
+/* msg_iov must be done separately */
+static __inline void
+netbsd32_from_msghdr(mhp32, mhp)
+       struct netbsd32_msghdr *mhp32;
+       struct msghdr *mhp;
+{
+
+       mhp32->msg_name = mhp32->msg_name;
+       mhp32->msg_namelen = mhp32->msg_namelen;
+       mhp32->msg_iovlen = mhp32->msg_iovlen;
+       mhp32->msg_control = mhp32->msg_control;
+       mhp32->msg_controllen = mhp->msg_controllen;
+       mhp32->msg_flags = mhp->msg_flags;
+}
+
+static __inline void
+netbsd32_from_statfs(sbp, sb32p)
+       struct statfs *sbp;
+       struct netbsd32_statfs *sb32p;
+{
+       sb32p->f_type = sbp->f_type;
+       sb32p->f_flags = sbp->f_flags;
+       sb32p->f_bsize = (netbsd32_long)sbp->f_bsize;
+       sb32p->f_iosize = (netbsd32_long)sbp->f_iosize;
+       sb32p->f_blocks = (netbsd32_long)sbp->f_blocks;
+       sb32p->f_bfree = (netbsd32_long)sbp->f_bfree;
+       sb32p->f_bavail = (netbsd32_long)sbp->f_bavail;
+       sb32p->f_files = (netbsd32_long)sbp->f_files;
+       sb32p->f_ffree = (netbsd32_long)sbp->f_ffree;
+       sb32p->f_fsid = sbp->f_fsid;
+       sb32p->f_owner = sbp->f_owner;
+       sb32p->f_spare[0] = 0;
+       sb32p->f_spare[1] = 0;
+       sb32p->f_spare[2] = 0;
+       sb32p->f_spare[3] = 0;
+#if 1
+       /* May as well do the whole batch in one go */
+       memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN+MNAMELEN+MNAMELEN);
+#else
+       /* If we want to be careful */
+       memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN);
+       memcpy(sb32p->f_mntonname, sbp->f_mntonname, MNAMELEN);
+       memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, MNAMELEN);
+#endif
+}
+
+static __inline void
+netbsd32_from_timex(txp, tx32p)
+       struct timex *txp;
+       struct netbsd32_timex *tx32p;
+{
+
+       tx32p->modes = txp->modes;
+       tx32p->offset = (netbsd32_long)txp->offset;
+       tx32p->freq = (netbsd32_long)txp->freq;
+       tx32p->maxerror = (netbsd32_long)txp->maxerror;
+       tx32p->esterror = (netbsd32_long)txp->esterror;
+       tx32p->status = txp->status;



Home | Main Index | Thread Index | Old Index