Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Apr 2020 20:14:39 +0000 (UTC)
From:      Brooks Davis <brooks@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r360451 - in stable/11/sys: amd64/linux amd64/linux32 compat/freebsd32 compat/linux dev/ipmi dev/mpr dev/mps dev/mpt i386/linux kern sys
Message-ID:  <202004282014.03SKEdNU067658@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: brooks
Date: Tue Apr 28 20:14:38 2020
New Revision: 360451
URL: https://svnweb.freebsd.org/changeset/base/360451

Log:
  MFC r359937:
  
  Centralize compatability translation macros.
  
  Copy the CP, PTRIN, etc macros from freebsd32.h into a sys/abi_compat.h
  and replace existing definitation with includes where required. This
  eliminates duplicate code and allows Linux and FreeBSD compatability
  headers to be included in the same files.
  
  Obtained from:	CheriBSD
  Sponsored by:	DARPA
  Differential Revision:	https://reviews.freebsd.org/D24275

Added:
  stable/11/sys/sys/abi_compat.h
     - copied unchanged from r359937, head/sys/sys/abi_compat.h
Modified:
  stable/11/sys/amd64/linux/linux.h
  stable/11/sys/amd64/linux32/linux.h
  stable/11/sys/compat/freebsd32/freebsd32.h
  stable/11/sys/compat/linux/linux_ioctl.c
  stable/11/sys/compat/linux/linux_timer.h
  stable/11/sys/dev/ipmi/ipmi.c
  stable/11/sys/dev/mpr/mpr_user.c
  stable/11/sys/dev/mps/mps_user.c
  stable/11/sys/dev/mpt/mpt_user.c
  stable/11/sys/i386/linux/linux.h
  stable/11/sys/kern/sysv_sem.c
  stable/11/sys/kern/sysv_shm.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/amd64/linux/linux.h
==============================================================================
--- stable/11/sys/amd64/linux/linux.h	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/amd64/linux/linux.h	Tue Apr 28 20:14:38 2020	(r360451)
@@ -32,6 +32,8 @@
 #ifndef _AMD64_LINUX_H_
 #define	_AMD64_LINUX_H_
 
+#include <sys/abi_compat.h>
+
 #include <compat/linux/linux.h>
 #include <amd64/linux/linux_syscall.h>
 
@@ -47,14 +49,6 @@ extern u_char linux_debug_map[];
 #define	LMSG(fmt)	"linux(%ld/%ld): "fmt"\n",				\
 			(long)td->td_proc->p_pid, (long)td->td_tid
 #define	LINUX_DTRACE	linuxulator
-
-#define	PTRIN(v)	(void *)(v)
-#define	PTROUT(v)	(uintptr_t)(v)
-
-#define	CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
-#define	CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
-#define	PTRIN_CP(src,dst,fld) \
-	do { (dst).fld = PTRIN((src).fld); } while (0)
 
 /*
  * Provide a separate set of types for the Linux types.

Modified: stable/11/sys/amd64/linux32/linux.h
==============================================================================
--- stable/11/sys/amd64/linux32/linux.h	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/amd64/linux32/linux.h	Tue Apr 28 20:14:38 2020	(r360451)
@@ -33,6 +33,8 @@
 #ifndef _AMD64_LINUX_H_
 #define	_AMD64_LINUX_H_
 
+#include <sys/abi_compat.h>
+
 #include <compat/linux/linux.h>
 #include <amd64/linux32/linux32_syscall.h>
 
@@ -58,14 +60,6 @@ extern u_char linux_debug_map[];
 #define	LINUX32_MAXDSIZ		(512 * 1024 * 1024)	/* 512MB */
 #define	LINUX32_MAXSSIZ		(64 * 1024 * 1024)	/* 64MB */
 #define	LINUX32_MAXVMEM		0			/* Unlimited */
-
-#define	PTRIN(v)	(void *)(uintptr_t)(v)
-#define	PTROUT(v)	(l_uintptr_t)(uintptr_t)(v)
-
-#define	CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
-#define	CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
-#define	PTRIN_CP(src,dst,fld) \
-	do { (dst).fld = PTRIN((src).fld); } while (0)
 
 /*
  * Provide a separate set of types for the Linux types.

Modified: stable/11/sys/compat/freebsd32/freebsd32.h
==============================================================================
--- stable/11/sys/compat/freebsd32/freebsd32.h	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/compat/freebsd32/freebsd32.h	Tue Apr 28 20:14:38 2020	(r360451)
@@ -29,19 +29,11 @@
 #ifndef _COMPAT_FREEBSD32_FREEBSD32_H_
 #define _COMPAT_FREEBSD32_FREEBSD32_H_
 
+#include <sys/abi_compat.h>
 #include <sys/procfs.h>
 #include <sys/socket.h>
 #include <sys/user.h>
 
-#define PTRIN(v)	(void *)(uintptr_t) (v)
-#define PTROUT(v)	(u_int32_t)(uintptr_t) (v)
-
-#define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
-#define PTRIN_CP(src,dst,fld) \
-	do { (dst).fld = PTRIN((src).fld); } while (0)
-#define PTROUT_CP(src,dst,fld) \
-	do { (dst).fld = PTROUT((src).fld); } while (0)
-
 /*
  * Being a newer port, 32-bit FreeBSD/MIPS uses 64-bit time_t.
  */
@@ -55,37 +47,21 @@ struct timeval32 {
 	time32_t tv_sec;
 	int32_t tv_usec;
 };
-#define TV_CP(src,dst,fld) do {			\
-	CP((src).fld,(dst).fld,tv_sec);		\
-	CP((src).fld,(dst).fld,tv_usec);	\
-} while (0)
 
 struct timespec32 {
 	time32_t tv_sec;
 	int32_t tv_nsec;
 };
-#define TS_CP(src,dst,fld) do {			\
-	CP((src).fld,(dst).fld,tv_sec);		\
-	CP((src).fld,(dst).fld,tv_nsec);	\
-} while (0)
 
 struct itimerspec32 {
 	struct timespec32  it_interval;
 	struct timespec32  it_value;
 };
-#define ITS_CP(src, dst) do {			\
-	TS_CP((src), (dst), it_interval);	\
-	TS_CP((src), (dst), it_value);		\
-} while (0)
 
 struct bintime32 {
 	uint32_t sec;
 	uint32_t frac[2];
 };
-#define BT_CP(src, dst, fld) do {				\
-	CP((src).fld, (dst).fld, sec);				\
-	*(uint64_t *)&(dst).fld.frac[0] = (src).fld.frac;	\
-} while (0)
 
 struct rusage32 {
 	struct timeval32 ru_utime;

Modified: stable/11/sys/compat/linux/linux_ioctl.c
==============================================================================
--- stable/11/sys/compat/linux/linux_ioctl.c	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/compat/linux/linux_ioctl.c	Tue Apr 28 20:14:38 2020	(r360451)
@@ -34,6 +34,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/sysproto.h>
+#ifdef COMPAT_LINUX32
+#include <sys/abi_compat.h>
+#endif
 #include <sys/capsicum.h>
 #include <sys/cdio.h>
 #include <sys/dvdio.h>
@@ -2687,12 +2690,6 @@ linux_ioctl_drm(struct thread *td, struct linux_ioctl_
 }
 
 #ifdef COMPAT_LINUX32
-#define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
-#define PTRIN_CP(src,dst,fld) \
-	do { (dst).fld = PTRIN((src).fld); } while (0)
-#define PTROUT_CP(src,dst,fld) \
-	do { (dst).fld = PTROUT((src).fld); } while (0)
-
 static int
 linux_ioctl_sg_io(struct thread *td, struct linux_ioctl_args *args)
 {

Modified: stable/11/sys/compat/linux/linux_timer.h
==============================================================================
--- stable/11/sys/compat/linux/linux_timer.h	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/compat/linux/linux_timer.h	Tue Apr 28 20:14:38 2020	(r360451)
@@ -33,6 +33,8 @@
 #ifndef	_LINUX_TIMER_H
 #define	_LINUX_TIMER_H
 
+#include <sys/abi_compat.h>
+
 #ifndef	__LINUX_ARCH_SIGEV_PREAMBLE_SIZE
 #define	__LINUX_ARCH_SIGEV_PREAMBLE_SIZE	\
 	(sizeof(l_int) * 2 + sizeof(l_sigval_t))
@@ -78,16 +80,6 @@
 #define	L_SIGEV_NONE				1
 #define	L_SIGEV_THREAD				2
 #define	L_SIGEV_THREAD_ID			4
-
-#define	TS_CP(src,dst,fld) do {			\
-	CP((src).fld,(dst).fld,tv_sec);		\
-	CP((src).fld,(dst).fld,tv_nsec);	\
-} while (0)
-
-#define	ITS_CP(src, dst) do {			\
-	TS_CP((src), (dst), it_interval);	\
-	TS_CP((src), (dst), it_value);		\
-} while (0)
 
 struct l_sigevent {
 	l_sigval_t sigev_value;

Modified: stable/11/sys/dev/ipmi/ipmi.c
==============================================================================
--- stable/11/sys/dev/ipmi/ipmi.c	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/dev/ipmi/ipmi.c	Tue Apr 28 20:14:38 2020	(r360451)
@@ -49,6 +49,10 @@ __FBSDID("$FreeBSD$");
 #include <dev/ipmi/ipmivars.h>
 #endif
 
+#ifdef IPMICTL_SEND_COMMAND_32
+#include <sys/abi_compat.h>
+#endif
+
 /*
  * Driver request structures are allocated on the stack via alloca() to
  * avoid calling malloc(), especially for the watchdog handler.
@@ -285,11 +289,6 @@ ipmi_handle_attn(struct ipmi_softc *sc)
 
 	return (error);
 }
-#endif
-
-#ifdef IPMICTL_SEND_COMMAND_32
-#define	PTRIN(p)	((void *)(uintptr_t)(p))
-#define	PTROUT(p)	((uintptr_t)(p))
 #endif
 
 static int

Modified: stable/11/sys/dev/mpr/mpr_user.c
==============================================================================
--- stable/11/sys/dev/mpr/mpr_user.c	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/dev/mpr/mpr_user.c	Tue Apr 28 20:14:38 2020	(r360451)
@@ -75,6 +75,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/conf.h>
 #include <sys/bio.h>
+#include <sys/abi_compat.h>
 #include <sys/malloc.h>
 #include <sys/uio.h>
 #include <sys/sysctl.h>
@@ -178,16 +179,6 @@ static int mpr_user_reg_access(struct mpr_softc *sc, m
 static int mpr_user_btdh(struct mpr_softc *sc, mpr_btdh_mapping_t *data);
 
 static MALLOC_DEFINE(M_MPRUSER, "mpr_user", "Buffers for mpr(4) ioctls");
-
-/* Macros from compat/freebsd32/freebsd32.h */
-#define	PTRIN(v)	(void *)(uintptr_t)(v)
-#define	PTROUT(v)	(uint32_t)(uintptr_t)(v)
-
-#define	CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
-#define	PTRIN_CP(src,dst,fld)				\
-	do { (dst).fld = PTRIN((src).fld); } while (0)
-#define	PTROUT_CP(src,dst,fld) \
-	do { (dst).fld = PTROUT((src).fld); } while (0)
 
 /*
  * MPI functions that support IEEE SGLs for SAS3.

Modified: stable/11/sys/dev/mps/mps_user.c
==============================================================================
--- stable/11/sys/dev/mps/mps_user.c	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/dev/mps/mps_user.c	Tue Apr 28 20:14:38 2020	(r360451)
@@ -75,6 +75,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/conf.h>
 #include <sys/bio.h>
+#include <sys/abi_compat.h>
 #include <sys/malloc.h>
 #include <sys/uio.h>
 #include <sys/sysctl.h>
@@ -179,16 +180,6 @@ static int mps_user_reg_access(struct mps_softc *sc, m
 static int mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data);
 
 static MALLOC_DEFINE(M_MPSUSER, "mps_user", "Buffers for mps(4) ioctls");
-
-/* Macros from compat/freebsd32/freebsd32.h */
-#define	PTRIN(v)	(void *)(uintptr_t)(v)
-#define	PTROUT(v)	(uint32_t)(uintptr_t)(v)
-
-#define	CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
-#define	PTRIN_CP(src,dst,fld)				\
-	do { (dst).fld = PTRIN((src).fld); } while (0)
-#define	PTROUT_CP(src,dst,fld) \
-	do { (dst).fld = PTROUT((src).fld); } while (0)
 
 int
 mps_attach_user(struct mps_softc *sc)

Modified: stable/11/sys/dev/mpt/mpt_user.c
==============================================================================
--- stable/11/sys/dev/mpt/mpt_user.c	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/dev/mpt/mpt_user.c	Tue Apr 28 20:14:38 2020	(r360451)
@@ -34,6 +34,9 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
+#ifdef __amd64__
+#include <sys/abi_compat.h>
+#endif
 #include <sys/conf.h>
 #include <sys/errno.h>
 #include <sys/ioccom.h>
@@ -585,11 +588,6 @@ mpt_user_raid_action(struct mpt_softc *mpt, struct mpt
 	mpt_free_request(mpt, req);
 	return (0);
 }
-
-#ifdef __amd64__
-#define	PTRIN(p)		((void *)(uintptr_t)(p))
-#define PTROUT(v)		((u_int32_t)(uintptr_t)(v))
-#endif
 
 static int
 mpt_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)

Modified: stable/11/sys/i386/linux/linux.h
==============================================================================
--- stable/11/sys/i386/linux/linux.h	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/i386/linux/linux.h	Tue Apr 28 20:14:38 2020	(r360451)
@@ -31,6 +31,7 @@
 #ifndef _I386_LINUX_H_
 #define	_I386_LINUX_H_
 
+#include <sys/abi_compat.h>
 #include <sys/signal.h>	/* for sigval union */
 
 #include <compat/linux/linux.h>
@@ -51,14 +52,6 @@ extern u_char linux_debug_map[];
 
 #define	LINUX_SHAREDPAGE	(VM_MAXUSER_ADDRESS - PAGE_SIZE)
 #define	LINUX_USRSTACK		LINUX_SHAREDPAGE
-
-#define	PTRIN(v)	(void *)(v)
-#define	PTROUT(v)	(l_uintptr_t)(v)
-
-#define	CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
-#define	CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
-#define	PTRIN_CP(src,dst,fld) \
-	do { (dst).fld = PTRIN((src).fld); } while (0)
 
 /*
  * Provide a separate set of types for the Linux types.

Modified: stable/11/sys/kern/sysv_sem.c
==============================================================================
--- stable/11/sys/kern/sysv_sem.c	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/kern/sysv_sem.c	Tue Apr 28 20:14:38 2020	(r360451)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/sysproto.h>
+#include <sys/abi_compat.h>
 #include <sys/eventhandler.h>
 #include <sys/kernel.h>
 #include <sys/proc.h>
@@ -1731,10 +1732,6 @@ sys_semsys(td, uap)
 	error = (*semcalls[uap->which])(td, &uap->a2);
 	return (error);
 }
-
-#ifndef CP
-#define CP(src, dst, fld)	do { (dst).fld = (src).fld; } while (0)
-#endif
 
 #ifndef _SYS_SYSPROTO_H_
 struct freebsd7___semctl_args {

Modified: stable/11/sys/kern/sysv_shm.c
==============================================================================
--- stable/11/sys/kern/sysv_shm.c	Tue Apr 28 20:00:17 2020	(r360450)
+++ stable/11/sys/kern/sysv_shm.c	Tue Apr 28 20:14:38 2020	(r360451)
@@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/abi_compat.h>
 #include <sys/kernel.h>
 #include <sys/limits.h>
 #include <sys/lock.h>
@@ -1565,10 +1566,6 @@ done:
 
 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
     defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
-
-#ifndef CP
-#define CP(src, dst, fld)	do { (dst).fld = (src).fld; } while (0)
-#endif
 
 #ifndef _SYS_SYSPROTO_H_
 struct freebsd7_shmctl_args {

Copied: stable/11/sys/sys/abi_compat.h (from r359937, head/sys/sys/abi_compat.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/sys/abi_compat.h	Tue Apr 28 20:14:38 2020	(r360451, copy of r359937, head/sys/sys/abi_compat.h)
@@ -0,0 +1,77 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2001 Doug Rabson
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _COMPAT_H_
+#define	_COMPAT_H_
+
+/*
+ * Helper macros for translating objects between different ABIs.
+ */
+
+#define	PTRIN(v)	(void *)(uintptr_t)(v)
+#define	PTROUT(v)	(uintptr_t)(v)
+
+#define	CP(src, dst, fld) do {			\
+	(dst).fld = (src).fld;			\
+} while (0)
+
+#define	CP2(src, dst, sfld, dfld) do {		\
+	(dst).dfld = (src).sfld;		\
+} while (0)
+
+#define	PTRIN_CP(src, dst, fld) do {		\
+	(dst).fld = PTRIN((src).fld);		\
+} while (0)
+
+#define	PTROUT_CP(src, dst, fld) do {		\
+	(dst).fld = PTROUT((src).fld);		\
+} while (0)
+
+#define	TV_CP(src, dst, fld) do {		\
+	CP((src).fld, (dst).fld, tv_sec);	\
+	CP((src).fld, (dst).fld, tv_usec);	\
+} while (0)
+
+#define	TS_CP(src, dst, fld) do {		\
+	CP((src).fld, (dst).fld, tv_sec);	\
+	CP((src).fld, (dst).fld, tv_nsec);	\
+} while (0)
+
+#define	ITS_CP(src, dst) do {			\
+	TS_CP((src), (dst), it_interval);	\
+	TS_CP((src), (dst), it_value);		\
+} while (0)
+
+#define	BT_CP(src, dst, fld) do {				\
+	CP((src).fld, (dst).fld, sec);				\
+	*(uint64_t *)&(dst).fld.frac[0] = (src).fld.frac;	\
+} while (0)
+
+#endif /* !_COMPAT_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202004282014.03SKEdNU067658>