From owner-svn-src-projects@FreeBSD.ORG Sat Jan 30 18:35:56 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 062AC1065670; Sat, 30 Jan 2010 18:35:56 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E9BC08FC27; Sat, 30 Jan 2010 18:35:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0UIZtrh073622; Sat, 30 Jan 2010 18:35:55 GMT (envelope-from rwatson@svn.freebsd.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0UIZtXk073618; Sat, 30 Jan 2010 18:35:55 GMT (envelope-from rwatson@svn.freebsd.org) Message-Id: <201001301835.o0UIZtXk073618@svn.freebsd.org> From: Robert Watson Date: Sat, 30 Jan 2010 18:35:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r203212 - in projects/capabilities8/lib/csu: amd64 common i386-elf X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Jan 2010 18:35:56 -0000 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 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 +#include #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 = ≈ + 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