PERFORCE change 164564 for review

Robert Watson rwatson at FreeBSD.org
Wed Jun 17 11:03:15 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=164564

Change 164564 by rwatson at 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)
 {


More information about the p4-projects mailing list