Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Jan 2010 18:35:55 +0000 (UTC)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r203212 - in projects/capabilities8/lib/csu: amd64 common i386-elf
Message-ID:  <201001301835.o0UIZtXk073618@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rwatson
Date: Sat Jan 30 18:35:55 2010
New Revision: 203212
URL: http://svn.freebsd.org/changeset/base/203212

Log:
  Merge c170404 from the p4 TrustedBSD Capabilities branch to capabilities8:
  
    cap_main and _capstart for both i386 and amd64.
  
  Submitted by:	Jonathan Anderson <jonathan.anderson at cl.cam.ac.uk>

Modified:
  projects/capabilities8/lib/csu/amd64/crt1.c
  projects/capabilities8/lib/csu/common/crtbrand.c
  projects/capabilities8/lib/csu/i386-elf/crt1_c.c

Modified: projects/capabilities8/lib/csu/amd64/crt1.c
==============================================================================
--- projects/capabilities8/lib/csu/amd64/crt1.c	Sat Jan 30 18:33:10 2010	(r203211)
+++ projects/capabilities8/lib/csu/amd64/crt1.c	Sat Jan 30 18:35:55 2010	(r203212)
@@ -31,6 +31,7 @@
 #endif /* lint */
 
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "libc_private.h"
 #include "crtbrand.c"
@@ -95,6 +96,45 @@ __asm__("eprol:");
 }
 
 
+
+/* The Capsicum entry function. */
+void
+_capstart(char **ap, void (*cleanup)(void))
+{
+	int argc;
+	char **argv;
+	char **env;
+	const char *s;
+
+	argc = *(long *)(void *)ap;
+	argv = ap + 1;
+	env = ap + 2 + argc;
+	environ = env;
+	if (argc > 0 && argv[0] != NULL) {
+		__progname = argv[0];
+		for (s = __progname; *s != '\0'; s++)
+			if (*s == '/')
+				__progname = s + 1;
+	}
+
+	if (&_DYNAMIC != NULL)
+		atexit(cleanup);
+	else
+		_init_tls();
+
+#ifdef GCRT
+	atexit(_mcleanup);
+#endif
+	atexit(_fini);
+#ifdef GCRT
+/*	monstartup(&eprol, &etext);*/
+/*__asm__("eprol:");*/             /* JA hope and pray... */
+#endif
+	_init();
+	exit( cap_main(argc, argv, env) );
+}
+
+
 /* The Capsicum entry function. */
 void
 _capstart(char **ap, void (*cleanup)(void))

Modified: projects/capabilities8/lib/csu/common/crtbrand.c
==============================================================================
--- projects/capabilities8/lib/csu/common/crtbrand.c	Sat Jan 30 18:33:10 2010	(r203211)
+++ projects/capabilities8/lib/csu/common/crtbrand.c	Sat Jan 30 18:35:55 2010	(r203212)
@@ -52,10 +52,25 @@ static const struct {
     __FreeBSD_version
 };
 
+
+
+int cap_main(int argc, char **argv, char **env)
+{
+	const char warning[] =
+		"ERROR: attempting to run a regular binary in capability mode!\n\nIf you want to run a binary in a sandbox, you must provide a cap_main() function, which takes the same arguments as main().\n";
+
+	write(2, warning, sizeof(warning));
+}
+
+
 int cap_main(int argc, char **argv, char **env)
 {
 	const char warning[] =
-		"ERROR: attempting to run a regular binary in capability mode.\n\nIf you wish to run a binary in a sandbox, you must provide a cap_main() function which takes the same arguments as main().\n";
+		"ERROR: attempting to run a regular binary in capability mode."
+		"\n\n"
+		"If you wish to run a binary in a sandbox, you must provide a "
+		"cap_main() function which takes the same arguments as main()."
+		"\n";
 
 	write(2, warning, sizeof(warning));
 	return 1;

Modified: projects/capabilities8/lib/csu/i386-elf/crt1_c.c
==============================================================================
--- projects/capabilities8/lib/csu/i386-elf/crt1_c.c	Sat Jan 30 18:33:10 2010	(r203211)
+++ projects/capabilities8/lib/csu/i386-elf/crt1_c.c	Sat Jan 30 18:35:55 2010	(r203212)
@@ -130,6 +130,51 @@ _capstart(char *ap, ...)
 #endif
 	atexit(_fini);
 #ifdef GCRT
+	monstartup(&eprol, &etext);
+__asm__("eprol:");
+#endif
+	_init();
+	exit( cap_main(argc, argv, env) );
+}
+
+
+
+
+/* The Capsicum entry function. */
+void
+_capstart(char *ap, ...)
+{
+	fptr cleanup;
+	int argc;
+	char **argv;
+	char **env;
+	const char *s;
+
+#ifdef __GNUC__
+	__asm__("and $0xfffffff0,%esp");
+#endif
+	cleanup = get_rtld_cleanup();
+	argv = &ap;
+	argc = *(long *)(void *)(argv - 1);
+	env = argv + argc + 1;
+	environ = env;
+	if (argc > 0 && argv[0] != NULL) {
+		__progname = argv[0];
+		for (s = __progname; *s != '\0'; s++)
+			if (*s == '/')
+				__progname = s + 1;
+	}
+
+	if (&_DYNAMIC != NULL)
+		atexit(cleanup);
+	else
+		_init_tls();
+
+#ifdef GCRT
+	atexit(_mcleanup);
+#endif
+	atexit(_fini);
+#ifdef GCRT
 /*	monstartup(&eprol, &etext);
 __asm__("eprol:");*/        /* XXX: does this interfere with profiling? */
 #endif



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