Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/compat/linux32/common Add routines to convert from linux...
details: https://anonhg.NetBSD.org/src/rev/f4ad10051219
branches: trunk
changeset: 1023640:f4ad10051219
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun Sep 19 22:30:28 2021 +0000
description:
Add routines to convert from linux32 to native sigevent_t.
diffstat:
sys/compat/linux32/arch/amd64/linux32_siginfo.h | 7 +-
sys/compat/linux32/common/linux32_sigevent.h | 66 +++++++++++++++++++++++++
sys/compat/linux32/common/linux32_signal.c | 59 +++++++++++++++++++++-
3 files changed, 125 insertions(+), 7 deletions(-)
diffs (178 lines):
diff -r a067f7920d1c -r f4ad10051219 sys/compat/linux32/arch/amd64/linux32_siginfo.h
--- a/sys/compat/linux32/arch/amd64/linux32_siginfo.h Sun Sep 19 22:09:31 2021 +0000
+++ b/sys/compat/linux32/arch/amd64/linux32_siginfo.h Sun Sep 19 22:30:28 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux32_siginfo.h,v 1.1 2011/11/18 04:08:56 christos Exp $ */
+/* $NetBSD: linux32_siginfo.h,v 1.2 2021/09/19 22:30:28 thorpej Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -32,10 +32,7 @@
#ifndef _AMD64_LINUX32_SIGINFO_H
#define _AMD64_LINUX32_SIGINFO_H
-typedef union linux32_sigval {
- int sival_int;
- netbsd32_voidp sival_ptr;
-} linux32_sigval_t;
+#include <compat/linux32/common/linux32_sigevent.h>
#define SI_MAX_SIZE 128
#define SI_PAD_SIZE ((SI_MAX_SIZE/sizeof(int)) - 3)
diff -r a067f7920d1c -r f4ad10051219 sys/compat/linux32/common/linux32_sigevent.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux32/common/linux32_sigevent.h Sun Sep 19 22:30:28 2021 +0000
@@ -0,0 +1,66 @@
+/* $NetBSD: linux32_sigevent.h,v 1.2 2021/09/19 22:30:28 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Frank van der Linden.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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 _LINUX32_SIGEVENT_H
+#define _LINUX32_SIGEVENT_H
+
+typedef union linux32_sigval {
+ int sival_int;
+ netbsd32_voidp sival_ptr;
+} linux32_sigval_t;
+
+#define LINUX32_SIGEV_MAX 64
+#ifndef LINUX32_SIGEV_PAD
+#define LINUX32_SIGEV_PAD ((LINUX32_SIGEV_MAX - \
+ (sizeof(linux32_sigval_t) + (sizeof(int) * 2))) / \
+ sizeof(int))
+#endif
+
+typedef struct linux32_sigevent {
+ linux32_sigval_t sigev_value; /* sizeof(pointer) */
+ int sigev_signo;
+ int sigev_notify;
+ /* guaranteed to have natural pointer alignment */
+ union {
+ int pad[LINUX32_SIGEV_PAD];
+ int tid;
+ struct {
+ void (*func)(linux32_sigval_t);
+ void *attr;
+ } _sigev_thread;
+ } _sigev_un;
+} linux32_sigevent_t;
+
+int linux32_to_native_sigevent(struct sigevent *,
+ const struct linux32_sigevent *);
+int linux32_sigevent_copyin(const void *, void *, size_t);
+
+#endif /* _LINUX32_SIGEVENT_H */
diff -r a067f7920d1c -r f4ad10051219 sys/compat/linux32/common/linux32_signal.c
--- a/sys/compat/linux32/common/linux32_signal.c Sun Sep 19 22:09:31 2021 +0000
+++ b/sys/compat/linux32/common/linux32_signal.c Sun Sep 19 22:30:28 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux32_signal.c,v 1.21 2021/09/07 11:43:04 riastradh Exp $ */
+/* $NetBSD: linux32_signal.c,v 1.22 2021/09/19 22:30:28 thorpej Exp $ */
/*-
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_signal.c,v 1.21 2021/09/07 11:43:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_signal.c,v 1.22 2021/09/19 22:30:28 thorpej Exp $");
#include <sys/param.h>
#include <sys/ucred.h>
@@ -46,9 +46,11 @@
#include <compat/linux/common/linux_types.h>
#include <compat/linux/common/linux_signal.h>
+#include <compat/linux/common/linux_sigevent.h>
#include <compat/linux32/common/linux32_types.h>
#include <compat/linux32/common/linux32_signal.h>
+#include <compat/linux32/common/linux32_sigevent.h>
#include <compat/linux32/common/linux32_siginfo.h>
#include <compat/linux32/linux32_syscallargs.h>
#include <compat/linux32/common/linux32_errno.h>
@@ -654,3 +656,56 @@
return sts;
}
+
+int
+linux32_to_native_sigevent(struct sigevent *nsep,
+ const struct linux32_sigevent *lsep)
+{
+ memset(nsep, 0, sizeof(*nsep));
+
+ switch (lsep->sigev_notify) {
+ case LINUX_SIGEV_SIGNAL:
+ nsep->sigev_notify = SIGEV_SIGNAL;
+ break;
+
+ case LINUX_SIGEV_NONE:
+ nsep->sigev_notify = SIGEV_NONE;
+ break;
+
+ case LINUX_SIGEV_THREAD:
+ case LINUX_SIGEV_THREAD_ID:
+ default:
+ return ENOTSUP;
+ }
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ nsep->sigev_value.sival_ptr =
+ NETBSD32PTR64(lsep->sigev_value.sival_ptr);
+#else
+#error This is probably broken on big-endian platforms.
+#endif
+
+ if (lsep->sigev_signo < 0 || lsep->sigev_signo >= LINUX32__NSIG) {
+ return EINVAL;
+ }
+ nsep->sigev_signo = linux32_to_native_signo[lsep->sigev_signo];
+
+ return 0;
+}
+
+int
+linux32_sigevent_copyin(const void *src, void *dst, size_t size)
+{
+ struct linux32_sigevent lse;
+ struct sigevent *sep = dst;
+ int error;
+
+ KASSERT(size == sizeof(*sep));
+
+ error = copyin(src, &lse, sizeof(lse));
+ if (error) {
+ return error;
+ }
+
+ return linux32_to_native_sigevent(sep, &lse);
+}
Home |
Main Index |
Thread Index |
Old Index