svn commit: r332443 - in head/lib/libc: amd64 amd64/sys gen i386 i386/sys mips/sys powerpc powerpc/sys powerpc64 powerpc64/sys sparc64 sparc64/sys

Brooks Davis brooks at FreeBSD.org
Thu Apr 12 18:23:17 UTC 2018


Author: brooks
Date: Thu Apr 12 18:23:14 2018
New Revision: 332443
URL: https://svnweb.freebsd.org/changeset/base/332443

Log:
  Replace MD assembly exect() with a portable version.
  
  Originally, on the VAX exect() enable tracing once the new executable
  image was loaded.  This was possible because tracing was controllable
  through user space code by setting the PSL_T flag.  The following
  instruction is a system call that activated tracing (as all
  instructions do) by copying PSL_T to PSL_TP (trace pending).  The
  first instruction of the new executable image would trigger a trace
  fault.
  
  This is not portable to all platforms and the behavior was replaced with
  ptrace(PT_TRACE_ME, ...) since FreeBSD forked off of the CSRG repository.
  Platforms either incorrectly call execve(), trigger trace faults inside
  the original executable, or do contain an implementation of this
  function.
  
  The exect() interfaces is deprecated or removed on NetBSD and OpenBSD.
  
  Submitted by:	Ali Mashtizadeh <ali at mashtizadeh.com>
  Reviewed by:	kib
  Differential Revision:	https://reviews.freebsd.org/D14989

Added:
  head/lib/libc/gen/exect.c   (contents, props changed)
Deleted:
  head/lib/libc/amd64/sys/exect.S
  head/lib/libc/i386/sys/exect.S
  head/lib/libc/mips/sys/exect.S
  head/lib/libc/powerpc/sys/exect.S
  head/lib/libc/powerpc64/sys/exect.S
  head/lib/libc/sparc64/sys/exect.S
Modified:
  head/lib/libc/amd64/Symbol.map
  head/lib/libc/amd64/sys/Makefile.inc
  head/lib/libc/gen/Makefile.inc
  head/lib/libc/gen/Symbol.map
  head/lib/libc/i386/Symbol.map
  head/lib/libc/i386/sys/Makefile.inc
  head/lib/libc/mips/sys/Makefile.inc
  head/lib/libc/powerpc/Symbol.map
  head/lib/libc/powerpc/sys/Makefile.inc
  head/lib/libc/powerpc64/Symbol.map
  head/lib/libc/powerpc64/sys/Makefile.inc
  head/lib/libc/sparc64/Symbol.map
  head/lib/libc/sparc64/sys/Makefile.inc

Modified: head/lib/libc/amd64/Symbol.map
==============================================================================
--- head/lib/libc/amd64/Symbol.map	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/amd64/Symbol.map	Thu Apr 12 18:23:14 2018	(r332443)
@@ -40,7 +40,6 @@ FBSD_1.0 {
 	amd64_set_fsbase;
 	amd64_set_gsbase;
 	brk;
-	exect;
 	sbrk;
 	vfork;
 };

Modified: head/lib/libc/amd64/sys/Makefile.inc
==============================================================================
--- head/lib/libc/amd64/sys/Makefile.inc	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/amd64/sys/Makefile.inc	Thu Apr 12 18:23:14 2018	(r332443)
@@ -8,8 +8,7 @@ SRCS+=	\
 	amd64_set_fsbase.c \
 	amd64_set_gsbase.c
 
-MDASM=	vfork.S brk.S cerror.S exect.S getcontext.S \
-	sbrk.S
+MDASM=	vfork.S brk.S cerror.S getcontext.S sbrk.S
 
 # Don't generate default code for these syscalls:
 NOASM+=	vfork.o

Modified: head/lib/libc/gen/Makefile.inc
==============================================================================
--- head/lib/libc/gen/Makefile.inc	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/gen/Makefile.inc	Thu Apr 12 18:23:14 2018	(r332443)
@@ -41,6 +41,7 @@ SRCS+=	__getosreldate.c \
 	errlst.c \
 	errno.c \
 	exec.c \
+	exect.c \
 	fdevname.c \
 	feature_present.c \
 	fmtcheck.c \

Modified: head/lib/libc/gen/Symbol.map
==============================================================================
--- head/lib/libc/gen/Symbol.map	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/gen/Symbol.map	Thu Apr 12 18:23:14 2018	(r332443)
@@ -105,6 +105,7 @@ FBSD_1.0 {
 	sys_errlist;
 	sys_nerr;
 	errno;
+	exect;
 	execl;
 	execle;
 	execlp;

Added: head/lib/libc/gen/exect.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libc/gen/exect.c	Thu Apr 12 18:23:14 2018	(r332443)
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 2018 Ali Mashtizadeh <ali at mashtizadeh.com>
+ * 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 ``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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/ptrace.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+int
+exect(const char *path, char *const argv[], char *const envp[])
+{
+
+	if (ptrace(PT_TRACE_ME, 0, 0, 0) != 0) {
+		if (errno != EBUSY)
+			return (-1);
+	}
+
+	return (execve(path, argv, envp));
+}

Modified: head/lib/libc/i386/Symbol.map
==============================================================================
--- head/lib/libc/i386/Symbol.map	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/i386/Symbol.map	Thu Apr 12 18:23:14 2018	(r332443)
@@ -31,7 +31,6 @@ FBSD_1.0 {
 	ntohs;
 	vfork;
 	brk;
-	exect;
 	i386_clr_watch;
 	i386_get_fsbase;
 	i386_get_gsbase;

Modified: head/lib/libc/i386/sys/Makefile.inc
==============================================================================
--- head/lib/libc/i386/sys/Makefile.inc	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/i386/sys/Makefile.inc	Thu Apr 12 18:23:14 2018	(r332443)
@@ -7,8 +7,7 @@ SRCS+=	i386_clr_watch.c i386_set_watch.c i386_vm86.c
 SRCS+=	i386_get_fsbase.c i386_get_gsbase.c i386_get_ioperm.c i386_get_ldt.c \
 	i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c
 
-MDASM=	Ovfork.S brk.S cerror.S exect.S getcontext.S \
-	sbrk.S syscall.S
+MDASM=	Ovfork.S brk.S cerror.S getcontext.S sbrk.S syscall.S
 
 NOASM+=	vfork.o
 

Modified: head/lib/libc/mips/sys/Makefile.inc
==============================================================================
--- head/lib/libc/mips/sys/Makefile.inc	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/mips/sys/Makefile.inc	Thu Apr 12 18:23:14 2018	(r332443)
@@ -2,8 +2,7 @@
 
 SRCS+=	trivial-vdso_tc.c
 
-MDASM=  Ovfork.S brk.S cerror.S exect.S \
-	sbrk.S syscall.S
+MDASM=  Ovfork.S brk.S cerror.S sbrk.S syscall.S
 
 # Don't generate default code for these syscalls:
 NOASM+=	vfork.o

Modified: head/lib/libc/powerpc/Symbol.map
==============================================================================
--- head/lib/libc/powerpc/Symbol.map	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/powerpc/Symbol.map	Thu Apr 12 18:23:14 2018	(r332443)
@@ -33,7 +33,6 @@ FBSD_1.0 {
 	ntohl;
 	ntohs;
 	brk;
-	exect;
 	sbrk;
 	vfork;
 };

Modified: head/lib/libc/powerpc/sys/Makefile.inc
==============================================================================
--- head/lib/libc/powerpc/sys/Makefile.inc	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/powerpc/sys/Makefile.inc	Thu Apr 12 18:23:14 2018	(r332443)
@@ -1,3 +1,3 @@
 # $FreeBSD$
 
-MDASM+=	brk.S cerror.S exect.S sbrk.S
+MDASM+=	brk.S cerror.S sbrk.S

Modified: head/lib/libc/powerpc64/Symbol.map
==============================================================================
--- head/lib/libc/powerpc64/Symbol.map	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/powerpc64/Symbol.map	Thu Apr 12 18:23:14 2018	(r332443)
@@ -33,7 +33,6 @@ FBSD_1.0 {
 	ntohl;
 	ntohs;
 	brk;
-	exect;
 	sbrk;
 	vfork;
 };

Modified: head/lib/libc/powerpc64/sys/Makefile.inc
==============================================================================
--- head/lib/libc/powerpc64/sys/Makefile.inc	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/powerpc64/sys/Makefile.inc	Thu Apr 12 18:23:14 2018	(r332443)
@@ -1,3 +1,3 @@
 # $FreeBSD$
 
-MDASM+=	brk.S cerror.S exect.S sbrk.S
+MDASM+=	brk.S cerror.S sbrk.S

Modified: head/lib/libc/sparc64/Symbol.map
==============================================================================
--- head/lib/libc/sparc64/Symbol.map	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/sparc64/Symbol.map	Thu Apr 12 18:23:14 2018	(r332443)
@@ -33,7 +33,6 @@ FBSD_1.0 {
 	ntohl;
 	ntohs;
 	brk;
-	exect;
 	sbrk;
 	vfork;
 
@@ -82,8 +81,6 @@ FBSDprivate_1.0 {
 	__siglongjmp;
 	__sys_brk;
 	_brk;
-	__sys_exect;
-	_exect;
 	_end;
 	__sys_sbrk;
 	_sbrk;

Modified: head/lib/libc/sparc64/sys/Makefile.inc
==============================================================================
--- head/lib/libc/sparc64/sys/Makefile.inc	Thu Apr 12 17:47:36 2018	(r332442)
+++ head/lib/libc/sparc64/sys/Makefile.inc	Thu Apr 12 18:23:14 2018	(r332443)
@@ -12,4 +12,4 @@ SRCS+=	__sparc_sigtramp_setup.c \
 
 CFLAGS+= -I${LIBC_SRCTOP}/sparc64/fpu
 
-MDASM+=	brk.S cerror.S exect.S sbrk.S sigaction1.S
+MDASM+=	brk.S cerror.S sbrk.S sigaction1.S


More information about the svn-src-all mailing list