brand.c revision 93cf283ac1d0119d2ee3842f515f8d0e1bc7cbdb
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * CDDL HEADER START
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * The contents of this file are subject to the terms of the
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Common Development and Distribution License (the "License").
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * You may not use this file except in compliance with the License.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * See the License for the specific language governing permissions
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * and limitations under the License.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * When distributing Covered Code, include this CDDL HEADER in each
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * If applicable, add the following below this CDDL HEADER, with the
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * fields enclosed by brackets "[]" replaced with your own identifying
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * information: Portions Copyright [yyyy] [name of copyright owner]
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * CDDL HEADER END
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn#if defined(__sparcv9)
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp/* sparcv9 uses system wide brand interposition hooks */
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edpstatic void brand_plat_interposition_enable(void);
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edpstatic void brand_plat_interposition_disable(void);
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp#else /* !__sparcv9 */
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp#endif /* !__sparcv9 */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Used to maintain a list of all the brands currently loaded into the
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * This lock protects the integrity of the brand list.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "brand '%s' was built to run on older versions "
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "of Solaris.",
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "brand '%s' was built to run on a newer version "
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "of Solaris.",
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn /* Sanity checks */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn /* Add the brand to the list of loaded brands. */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Check to be sure we haven't already registered this brand.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn for (scan = brand_list; scan != NULL; scan = scan->bl_next) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn if (strcmp(brand->b_name, scan->bl_brand->b_name) == 0) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "Invalid attempt to load a second instance of "
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp#if defined(__sparcv9)
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp /* sparcv9 uses system wide brand interposition hooks */
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp#endif /* __sparcv9 */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn return (0);
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * The kernel module implementing this brand is being unloaded, so remove
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * it from the list of active brands.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn /* Sanity checks */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn for (list = brand_list; list != NULL; list = list->bl_next) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn cmn_err(CE_WARN, "Brand %s wasn't registered", brand->b_name);
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn cmn_err(CE_WARN, "Unregistering brand %s which is still in use",
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn /* Remove brand from the list */
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp#if defined(__sparcv9)
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp /* sparcv9 uses system wide brand interposition hooks */
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp#endif /* __sparcv9 */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn return (0);
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Record that a zone of this brand has been instantiated. If the kernel
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * module implementing this brand's functionality is not present, this
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * routine attempts to load the module as a side effect.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "Branded zones are not allowed on labeled systems.");
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * We make at most two passes through this loop. The first time
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * through, we're looking to see if this is a new user of an
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * already loaded brand. If the brand hasn't been loaded, we
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * call ddi_modopen() to force it to be loaded and then make a
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * second pass through the list of brands. If we don't find the
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * brand the second time through it means that the modname
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * specified in the brand_attr structure doesn't provide the brand
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * specified in the brandname field. This would suggest a bug in
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * the brand's config.xml file. We close the module and return
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * 'NULL' to the caller.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn for (;;) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Search list of loaded brands
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * We didn't find that the requested brand has been loaded
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * yet, so we trigger the load of the appropriate kernel
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * module and search the list again.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * If we found the matching brand, bump its reference count.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Return the number of zones currently using this brand.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn for (list = brand_list; list != NULL; list = list->bl_next) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * We should only be called from exec(), when we know the process
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * is single-threaded.
e9f7cbf00b5dbfafe45ffb00125fa0cc683595c6Vamsi Naginenibrand_clearbrand(proc_t *p, boolean_t no_lwps)
e9f7cbf00b5dbfafe45ffb00125fa0cc683595c6Vamsi Nagineni * If called from exec_common() or proc_exit(),
e9f7cbf00b5dbfafe45ffb00125fa0cc683595c6Vamsi Nagineni * we know the process is single-threaded.
e9f7cbf00b5dbfafe45ffb00125fa0cc683595c6Vamsi Nagineni * If called from fork_fail, p_tlist is NULL.
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp#if defined(__sparcv9)
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp * Currently, only sparc has system level brand syscall interposition.
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * On x86 we're able to enable syscall interposition on a per-cpu basis
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * when a branded thread is scheduled to run on a cpu.
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp/* Local variables needed for dynamic syscall interposition support */
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp/* Trap Table syscall entry hot patch points */
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edpextern void syscall_trap_patch_point(void);
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edpextern void syscall_trap32_patch_point(void);
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp/* Alternate syscall entry handlers used when branded zones are running */
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edpextern void syscall_wrapper(void);
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edpextern void syscall_wrapper32(void);
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp/* Macros used to facilitate sparcv9 instruction generation */
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp ((((uintptr_t)(to) - (uintptr_t)(from)) >> 2) & 0x3fffff)
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp/*ARGSUSED*/
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edpstatic void
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * Before we hot patch the kernel save the current instructions
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edp * so that we can restore them later.
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * Modify the trap table at the patch points.
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * We basically replace the first instruction at the patch
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * point with a ba,a instruction that will transfer control
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * to syscall_wrapper or syscall_wrapper32 for 64-bit and
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * 32-bit syscalls respectively. It's important to note that
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * the annul bit is set in the branch so we don't execute
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * the instruction directly following the one we're patching
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * during the branch's delay slot.
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * It also doesn't matter that we're not atomically updating both
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * the 64 and 32 bit syscall paths at the same time since there's
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * no actual branded processes running on the system yet.
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp hot_patch_kernel_text((caddr_t)syscall_trap_patch_point,
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp BA_A_INSTR | DISP22(syscall_trap_patch_point, syscall_wrapper),
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp hot_patch_kernel_text((caddr_t)syscall_trap32_patch_point,
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp BA_A_INSTR | DISP22(syscall_trap32_patch_point, syscall_wrapper32),
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp/*ARGSUSED*/
725deb8fd64fbf9c978c9fe35c9d5cc1e4a7b6c2edpstatic void
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * Restore the original instructions at the trap table syscall
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * patch points to disable the brand syscall interposition
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp * mechanism.
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp hot_patch_kernel_text((caddr_t)syscall_trap_patch_point,
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp hot_patch_kernel_text((caddr_t)syscall_trap32_patch_point,
59f2ff5c96304fcfa3d97e66fbe1c521f42ac103edp#endif /* __sparcv9 */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * The following functions can be shared among kernel brand modules which
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * implement Solaris-derived brands, all of which need to do similar tasks
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * to manage the brand.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
80e2ca8596e3435bc3b76f3c597833ea0a87f85estatic void
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Return -1 if the cmd was not handled by this function.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e/*ARGSUSED*/
80e2ca8596e3435bc3b76f3c597833ea0a87f85ebrand_solaris_cmd(int cmd, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3,
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * There is one operation that is supported for a native
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * process; B_EXEC_BRAND. This brand operaion is redundant
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * since the kernel assumes a native process doing an exec
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * in a branded zone is going to run a branded processes.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * hence we don't support this operation.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e /* For all other operations this must be a branded process. */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e switch ((cmd)) {
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (err);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Get the address of the user-space system call handler from
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * the user process and attach it to the proc structure.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (0);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e sizeof (brand_elf_data_t)) != 0)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (0);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * The B_TRUSS_POINT subcommand exists so that we can see
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * truss output from interposed system calls that return
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * without first calling any other system call, meaning they
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * would be invisible to truss(1).
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * If the second argument is set non-zero, set errno to that
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * value as well.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Common arguments seen with truss are:
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * arg1: syscall number
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * arg2: errno
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (-1);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e/*ARGSUSED*/
80e2ca8596e3435bc3b76f3c597833ea0a87f85ebrand_solaris_copy_procdata(proc_t *child, proc_t *parent, struct brand *pbrand)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Just duplicate all the proc data of the parent for the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e bcopy(parent->p_brand_data, spd, sizeof (brand_proc_data_t));
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65static void
80e2ca8596e3435bc3b76f3c597833ea0a87f85e/*ARGSUSED*/
80e2ca8596e3435bc3b76f3c597833ea0a87f85ebrand_solaris_elfexec(vnode_t *vp, execa_t *uap, uarg_t *args,
80e2ca8596e3435bc3b76f3c597833ea0a87f85e intpdata_t *idatap, int level, long *execsz, int setid, caddr_t exec_file,
80e2ca8596e3435bc3b76f3c597833ea0a87f85e cred_t *cred, int brand_action, struct brand *pbrand, char *bname,
80e2ca8596e3435bc3b76f3c597833ea0a87f85e char *brandlib, char *brandlib32, char *brandlinker, char *brandlinker32)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * We will exec the brand library and then map in the target
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * application and (optionally) the brand's default linker.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e if ((err = lookupname(args->emulator, UIO_SYSSPACE, FOLLOW,
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (err);
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * The following elf{32}exec call changes the execenv in the proc
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * struct which includes changing the p_exec member to be the vnode
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * for the brand library (e.g. /.SUNWnative/usr/lib/s10_brand.so.1).
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * We will eventually set the p_exec member to be the vnode for the new
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * executable when we call setexecenv(). However, if we get an error
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * before that call we need to restore the execenv to its original
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * values so that when we return to the caller fop_close() works
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * properly while cleaning up from the failed exec(). Restoring the
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * original value will also properly decrement the 2nd VN_RELE that we
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 * took on the brand library.
93cf283ac1d0119d2ee3842f515f8d0e1bc7cbdbJerry Jelinek err = elfexec(nvp, uap, args, idatap, INTP_MAXDEPTH + 1, execsz,
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
93cf283ac1d0119d2ee3842f515f8d0e1bc7cbdbJerry Jelinek err = elf32exec(nvp, uap, args, idatap, INTP_MAXDEPTH + 1,
93cf283ac1d0119d2ee3842f515f8d0e1bc7cbdbJerry Jelinek execsz, setid, exec_file, cred, brand_action);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 if (err != 0) {
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (err);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * The u_auxv veCTors are set up by elfexec to point to the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * brand emulation library and linker. Save these so they can
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * be copied to the specific brand aux vectors.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e for (i = 0; i < __KERN_NAUXV_IMPL; i++) {
80e2ca8596e3435bc3b76f3c597833ea0a87f85e /* Make sure the emulator has an entry point */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 if (err != 0) {
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (err);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Save off the important properties of the executable. The
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * brand library will ask us for this data later, when it is
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * initializing and getting ready to transfer control to the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * brand application.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * This is a shared object executable, so we
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * need to pick a reasonable place to put the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * heap. Just don't use the first page.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * If the program needs an interpreter (most do), map
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * it in and store relevant information about it in the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * aux vector, where the brand library can find it.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (err);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
2ab1f1ec9729e08cce7a029b9e0e7180098a2d65 if (err != 0) {
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (err);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Now that we know the base address of the brand's
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * linker, place it in the aux vector.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * This program has no interpreter. The brand library
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * will jump to the address in the AT_SUN_BRAND_LDENTRY
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * aux vector, so in this case, put the entry point of
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * the main executable there.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * An executable with no interpreter, this must
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * be a statically linked executable, which
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * means we loaded it at the address specified
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * in the elf header, in which case the e_entry
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * field of the elf header is an absolute
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * address.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * A shared object with no interpreter, we use
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * the calculated address from above.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Delay setting the brkbase until the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * first call to brk(); see elfexec()
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * for details.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * It's time to manipulate the process aux vectors. First
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * we need to update the AT_SUN_AUXFLAGS aux vector to set
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * the AF_SUN_NOPLM flag.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e sizeof (auxflags_auxv)) != 0)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e sizeof (auxflags_auxv)) != 0)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e sizeof (auxflags_auxv32)) != 0)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e sizeof (auxflags_auxv32)) != 0)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e /* Second, copy out the brand specific aux vectors. */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e sizeof (brand_auxv)) != 0)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#if defined(_LP64)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e ASSERT(brand_auxv32[0].a_type == AT_SUN_BRAND_COMMON_LDDATA);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e sizeof (brand_auxv32)) != 0)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e#endif /* _LP64 */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Third, the /proc aux vectors set up by elfexec() point to
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * brand emulation library and it's linker. Copy these to the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * /proc brand specific aux vector, and update the regular
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * /proc aux vectors to point to the executable (and it's
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * linker). This will enable debuggers to access the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * executable via the usual /proc or elf notes aux vectors.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * The brand emulation library's linker will get it's aux
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * vectors off the stack, and then update the stack with the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * executable's aux vectors before jumping to the executable's
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * linker.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Debugging the brand emulation library must be done from
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * the global zone, where the librtld_db module knows how to
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * fetch the brand specific aux vectors to access the brand
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * emulation libraries linker.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e for (i = 0; i < __KERN_NAUXV_IMPL; i++) {
80e2ca8596e3435bc3b76f3c597833ea0a87f85e continue;
80e2ca8596e3435bc3b76f3c597833ea0a87f85e continue;
80e2ca8596e3435bc3b76f3c597833ea0a87f85e /* Hide the entry for static binaries */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * The last thing we do here is clear spd->spd_handler. This
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * is important because if we're already a branded process and
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * if this exec succeeds, there is a window between when the
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * exec() first returns to the userland of the new process and
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * when our brand library get's initialized, during which we
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * don't want system calls to be re-directed to our brand
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * library since it hasn't been initialized yet.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (0);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * We should only be called from exec(), when we know the process
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * is single-threaded.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e /* Upon exec, reset our lwp brand data. */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Upon exec, reset all the proc brand data, except for the elf
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * data associated with the executable we are exec'ing.
80e2ca8596e3435bc3b76f3c597833ea0a87f85ebrand_solaris_fini(char **emul_table, struct modlinkage *modlinkage,
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * If there are any zones using this brand, we can't allow it
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * to be unloaded.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (err);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e/*ARGSUSED*/
80e2ca8596e3435bc3b76f3c597833ea0a87f85ebrand_solaris_forklwp(klwp_t *p, klwp_t *c, struct brand *pbrand)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Both LWPs have already had been initialized via
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * brand_solaris_initlwp().
80e2ca8596e3435bc3b76f3c597833ea0a87f85e/*ARGSUSED*/
80e2ca8596e3435bc3b76f3c597833ea0a87f85e/*ARGSUSED*/
80e2ca8596e3435bc3b76f3c597833ea0a87f85e return (0);
80e2ca8596e3435bc3b76f3c597833ea0a87f85e/*ARGSUSED*/
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * We should never be called for the last thread in a process.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * (That case is handled by brand_solaris_proc_exit().)
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * Therefore this lwp must be exiting from a multi-threaded
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * process.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e/*ARGSUSED*/
80e2ca8596e3435bc3b76f3c597833ea0a87f85ebrand_solaris_proc_exit(struct proc *p, klwp_t *l, struct brand *pbrand)
e9f7cbf00b5dbfafe45ffb00125fa0cc683595c6Vamsi Nagineni * When called from proc_exit(), we know that process is
e9f7cbf00b5dbfafe45ffb00125fa0cc683595c6Vamsi Nagineni * single-threaded and free our lwp brand data.
e9f7cbf00b5dbfafe45ffb00125fa0cc683595c6Vamsi Nagineni * otherwise just free p_brand_data and return.
80e2ca8596e3435bc3b76f3c597833ea0a87f85e /* upon exit, free our proc brand data */
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * We should only be called from exec(), when we know the process
80e2ca8596e3435bc3b76f3c597833ea0a87f85e * is single-threaded.