From owner-p4-projects@FreeBSD.ORG Wed Jun 17 11:03:15 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1B8541065670; Wed, 17 Jun 2009 11:03:15 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CF8B8106566B for ; Wed, 17 Jun 2009 11:03:14 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id A167B8FC1D for ; Wed, 17 Jun 2009 11:03:14 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n5HB3EgN073696 for ; Wed, 17 Jun 2009 11:03:14 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5HB3EmP073686 for perforce@freebsd.org; Wed, 17 Jun 2009 11:03:14 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 17 Jun 2009 11:03:14 GMT Message-Id: <200906171103.n5HB3EmP073686@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 164564 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jun 2009 11:03:15 -0000 http://perforce.freebsd.org/chv.cgi?CH=164564 Change 164564 by rwatson@rwatson_freebsd_capabilities on 2009/06/17 11:02:49 In capability mode, prefer 'cap_main' to the normal ELF entry point, if the symbol is dynamic/defined. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/libexec/rtld-elf/rtld.c#19 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/libexec/rtld-elf/rtld.c#19 (text+ko) ==== @@ -105,7 +105,9 @@ static bool donelist_check(DoneList *, const Obj_Entry *); static void errmsg_restore(char *); static char *errmsg_save(void); -#ifndef IN_RTLD_CAP +#ifdef IN_RTLD_CAP +static void *find_cap_main(const Obj_Entry *); +#else static void *fill_search_info(const char *, size_t, void *); static char *find_library(const char *, const Obj_Entry *); static const char *gethints(void); @@ -346,6 +348,7 @@ #ifdef IN_RTLD_CAP struct stat sb; Elf_Auxinfo aux_execfd; + void *cap_main_ptr; #endif Elf_Auxinfo *aux_info[AT_COUNT]; int i; @@ -646,6 +649,17 @@ /* Return the exit procedure and the program entry point. */ *exit_proc = rtld_exit; *objp = obj_main; + +#ifdef IN_RTLD_CAP + /* + * If the object provides an alternative capability-mode specific entry + * point, prefer that to the ELF default entry point. Otherwise, use the + * ELF default. + */ + cap_main_ptr = find_cap_main(obj_main); + if (cap_main_ptr != NULL) + return (func_ptr_type) cap_main_ptr; +#endif return (func_ptr_type) obj_main->entry; } @@ -813,6 +827,26 @@ return (res4); } +#ifdef IN_RTLD_CAP +static void * +find_cap_main(const Obj_Entry *obj) +{ + const char *cap_main_str = "cap_main"; + const Elf_Sym *def; + const Obj_Entry *defobj; + unsigned long hash; + + hash = elf_hash(cap_main_str); + def = symlook_default(cap_main_str, hash, obj, &defobj, NULL, + SYMLOOK_IN_PLT); + if (def == NULL) + return (NULL); + if (ELF_ST_TYPE(def->st_info) != STT_FUNC) + return (NULL); + return (make_function_pointer(def, defobj)); +} +#endif + static void die(void) {