s10_brand.c revision e71ca95ca6de23d33b54cb55cefdef30bc7c969b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/archsystm.h>
#include <sys/pathname.h>
#include <sys/machbrand.h>
#include "s10_brand.h"
char *s10_emulation_table = NULL;
void s10_init_brand_data(zone_t *);
void s10_free_brand_data(zone_t *);
void s10_setbrand(proc_t *);
void s10_exec();
int s10_initlwp(klwp_t *);
void s10_freelwp(klwp_t *);
void s10_lwpexit(klwp_t *);
/* s10 brand */
};
#ifdef sparc
struct brand_mach_ops s10_mops = {
};
#else /* sparc */
#ifdef __amd64
struct brand_mach_ops s10_mops = {
NULL,
};
#else /* ! __amd64 */
struct brand_mach_ops s10_mops = {
NULL,
NULL,
NULL,
};
#endif /* __amd64 */
#endif /* _sparc */
"solaris10",
};
&mod_brandops, /* type of module */
"Solaris 10 Brand", /* description of module */
&s10_brand /* driver ops */
};
static struct modlinkage modlinkage = {
};
void
s10_setbrand(proc_t *p)
{
/*
* We should only be called from exec(), when we know the process
* is single-threaded.
*/
}
int
{
return (((s10_zone_data_t *)
}
int
{
return (s10_get_zone_emul_version(curzone));
}
void
{
}
/*ARGSUSED*/
int
{
int num;
if (attr == S10_EMUL_VERSION_NUM) {
if (*bufsize < sizeof (int))
return (ERANGE);
num = s10_get_emul_version();
return (EFAULT);
*bufsize = sizeof (int);
return (0);
}
return (EINVAL);
}
int
{
int num;
if (attr == S10_EMUL_VERSION_NUM) {
if (bufsize > sizeof (int))
return (ERANGE);
return (EFAULT);
return (0);
}
return (EINVAL);
}
#ifdef __amd64
/*
* The Nevada kernel clears %fs for threads in 64-bit x86 processes but S10's
* libc expects %fs to be nonzero. This causes some committed
* libraries, including libdoor. This function sets the specified LWP's %fs
* register to the legacy S10 selector value (LWPFS_SEL).
*
* The best solution to the aforementioned problem is backporting CRs
* 6467491 to Solaris 10 so that 64-bit x86 Solaris 10 processes
* would accept zero for %fs. Backporting the CRs is a requirement for running
* S10 Containers in PV domUs because 64-bit Xen clears %fsbase when %fs is
* nonzero. Such behavior breaks 64-bit processes because Xen has to fetch the
* FS segments' base addresses from the LWPs' GDTs, which are only capable of
* 32-bit addressing.
*/
/*ARGSUSED*/
static void
{
if (lwp_getdatamodel(l) == DATAMODEL_NATIVE) {
}
}
#endif /* __amd64 */
int
{
int len;
/*
* Make sure that the process' interpreter is the native dynamic linker.
* Convention dictates that native processes executing within solaris10-
* branded zones are interpreted by the native dynamic linker (the
* process and its arguments are specified as arguments to the dynamic
* linker). If this convention is violated (i.e.,
* brandsys(B_S10_NATIVE, ...) is invoked by a process that shouldn't be
* native), then do nothing and silently indicate success.
*/
return (0);
return (0);
*p = '\0';
else
if (p != NULL)
*p = ' ';
}
return (0);
}
/*
* Get the address of the user-space system call handler from the user
* process and attach it to the proc structure.
*/
/*ARGSUSED*/
int
{
int err;
*rval = 0;
/*
* B_EXEC_BRAND is redundant
* since the kernel assumes a native process doing an exec
* in a branded zone is going to run a branded processes.
* hence we don't support this operation.
*/
if (cmd == B_EXEC_BRAND)
return (ENOSYS);
if (cmd == B_S10_NATIVE)
return (s10_native());
/* For all other operations this must be a branded process. */
if (p->p_brand == &native_brand)
return (ENOSYS);
switch (cmd) {
case B_EXEC_NATIVE:
err = exec_common(
return (err);
case B_REGISTER:
if (p->p_model == DATAMODEL_NATIVE) {
return (EFAULT);
#if defined(_LP64)
} else {
return (EFAULT);
#endif /* _LP64 */
}
return (ENOTSUP);
return (0);
case B_ELFDATA:
if (p->p_model == DATAMODEL_NATIVE) {
sizeof (s10_elf_data_t)) != 0)
return (EFAULT);
#if defined(_LP64)
} else {
return (EFAULT);
#endif /* _LP64 */
}
return (0);
case B_S10_PIDINFO:
/*
* The s10 brand needs to be able to get the pid of the
* current process and the pid of the zone's init, and it
* needs to do this on every process startup. Early in
* brand startup, we can't call getpid() because calls to
* getpid() represent a magical signal to some old-skool
* debuggers. By merging all of this into one call, we
* make this quite a bit cheaper and easier to handle in
* the brand module.
*/
return (EFAULT);
sizeof (pid_t)) != 0)
return (EFAULT);
return (0);
case B_S10_TRUSS_POINT:
/*
* This subcommand exists so that we can see truss output
* from interposed system calls that return without first
* calling any other system call, meaning they would be
* invisible to truss(1).
*
* If the second argument is set non-zero, set errno to that
* value as well.
*
* Arguments are:
*
* arg1: syscall number
* arg2: errno
*/
#ifdef __amd64
case B_S10_FSREGCORRECTION:
/*
* This subcommand exists so that the SYS_lwp_private and
* SYS_lwp_create syscalls can manually set the current thread's
* %fs register to the legacy S10 selector value for 64-bit x86
* processes.
*/
return (0);
#endif /* __amd64 */
}
return (EINVAL);
}
/*
* Copy the per-process brand data from a parent proc to a child.
*/
void
{
/* Just duplicate all the proc data of the parent for the child */
}
/*ARGSUSED*/
void
{
/*
* We should only be called from proc_exit(), when we know that
* process is single-threaded.
*/
/* upon exit, free our lwp brand data */
/* upon exit, free our proc brand data */
p->p_brand_data = NULL;
}
void
s10_exec()
{
/*
* We should only be called from exec(), when we know the process
* is single-threaded.
*/
/* Upon exec, reset our lwp brand data. */
/*
* Upon exec, reset all the proc brand data, except for the elf
* data associated with the executable we are exec'ing.
*/
}
/*ARGSUSED*/
int
s10_initlwp(klwp_t *l)
{
l->lwp_brand = (void *)-1;
return (0);
}
/*ARGSUSED*/
void
{
/* Both LWPs have already had been initialized via s10_initlwp() */
#ifdef __amd64
/*
* Only correct the child's %fs register if the parent's %fs register
* is LWPFS_SEL. If the parent's %fs register is zero, then the Solaris
* 10 environment that we're emulating uses a version of libc that
* works when %fs is zero (i.e., it contains backports of CRs 6467491
* and 6501650).
*/
#endif /* __amd64 */
}
/*ARGSUSED*/
void
s10_freelwp(klwp_t *l)
{
}
/*ARGSUSED*/
void
s10_lwpexit(klwp_t *l)
{
/*
* We should never be called for the last thread in a process.
* (That case is handled by s10_proc_exit().) There for this lwp
* must be exiting from a multi-threaded process.
*/
}
void
{
}
void
{
KM_SLEEP);
/*
* Initialize the default s10zd_emul_version to S10_EMUL_UNDEF.
* This can be changed by a call to setattr() during zone boot.
*/
}
#if defined(_LP64)
static void
{
}
#endif /* _LP64 */
int
int brand_action)
{
int interp;
int i, err;
char *linker;
/*
* We will exec the brand library and then map in the target
* application and (optionally) the brand's default linker.
*/
linker = S10_LINKER;
#if defined(_LP64)
} else {
#endif /* _LP64 */
}
&nvp)) != 0) {
return (err);
}
#if defined(_LP64)
} else {
#endif /* _LP64 */
}
if (err != 0)
return (err);
/*
* The u_auxv vectors are set up by elfexec to point to the brand
* emulation library and linker. Save these so they can be copied to
* the specific brand aux vectors.
*/
for (i = 0; i < __KERN_NAUXV_IMPL; i++) {
case AT_SUN_LDDATA:
break;
case AT_BASE:
break;
case AT_ENTRY:
break;
case AT_PHDR:
break;
case AT_PHENT:
break;
case AT_PHNUM:
break;
default:
break;
}
}
/* Make sure the emulator has an entry point */
#if defined(_LP64)
} else {
else
#endif /* _LP64 */
}
if (err != 0)
return (err);
/*
* Save off the important properties of the executable. The brand
* library will ask us for this data later, when it is initializing
* and getting ready to transfer control to the brand application.
*/
else
if (interp) {
/*
* This is a shared object executable, so we need to
* pick a reasonable place to put the heap. Just don't
* use the first page.
*/
}
/*
* If the program needs an interpreter (most do), map it in and
* store relevant information about it in the aux vector, where
* the brand library can find it.
*/
return (err);
}
#if defined(_LP64)
} else {
else
#endif /* _LP64 */
}
if (err != 0)
return (err);
/*
* Now that we know the base address of the brand's linker,
* place it in the aux vector.
*/
} else {
/*
* This program has no interpreter. The brand library will
* jump to the address in the AT_SUN_BRAND_LDENTRY aux vector,
* so in this case, put the entry point of the main executable
* there.
*/
/*
* An executable with no interpreter, this must be a
* statically linked executable, which means we loaded
* it at the address specified in the elf header, in
* which case the e_entry field of the elf header is an
* absolute address.
*/
} else {
/*
* A shared object with no interpreter, we use the
* calculated address from above.
*/
/*
* Delay setting the brkbase until the first
* call to brk(); see elfexec() for details.
*/
env.ex_brksize = 0;
}
}
}
setexecenv(&env);
/*
* It's time to manipulate the process aux vectors. First
* we need to update the AT_SUN_AUXFLAGS aux vector to set
* the AF_SUN_NOPLM flag.
*/
sizeof (auxflags_auxv)) != 0)
return (EFAULT);
sizeof (auxflags_auxv)) != 0)
return (EFAULT);
#if defined(_LP64)
} else {
sizeof (auxflags_auxv32)) != 0)
return (EFAULT);
sizeof (auxflags_auxv32)) != 0)
return (EFAULT);
#endif /* _LP64 */
}
/* Second, copy out the brand specific aux vectors. */
{ AT_SUN_BRAND_AUX1, 0 },
{ AT_SUN_BRAND_AUX2, 0 },
{ AT_SUN_BRAND_AUX3, 0 }
};
sizeof (s10_auxv)) != 0)
return (EFAULT);
#if defined(_LP64)
} else {
auxv32_t s10_auxv32[] = {
{ AT_SUN_BRAND_AUX1, 0 },
{ AT_SUN_BRAND_AUX2, 0 },
{ AT_SUN_BRAND_AUX3, 0 }
};
sizeof (s10_auxv32)) != 0)
return (EFAULT);
#endif /* _LP64 */
}
/*
* Third, the the /proc aux vectors set up by elfexec() point to brand
* emulation library and it's linker. Copy these to the /proc brand
* specific aux vector, and update the regular /proc aux vectors to
* point to the executable (and it's linker). This will enable
* debuggers to access the executable via the usual /proc or elf notes
* aux vectors.
*
* The brand emulation library's linker will get it's aux vectors off
* the stack, and then update the stack with the executable's aux
* vectors before jumping to the executable's linker.
*
* Debugging the brand emulation library must be done from
* the global zone, where the librtld_db module knows how to fetch the
* brand specific aux vectors to access the brand emulation libraries
* linker.
*/
for (i = 0; i < __KERN_NAUXV_IMPL; i++) {
case AT_SUN_BRAND_S10_LDDATA:
continue;
case AT_BASE:
break;
case AT_ENTRY:
break;
case AT_PHDR:
break;
case AT_PHENT:
break;
case AT_PHNUM:
break;
case AT_SUN_LDDATA:
break;
default:
continue;
}
/* Hide the entry for static binaries */
}
}
/*
* The last thing we do here is clear spd->spd_handler. This is
* important because if we're already a branded process and if this
* exec succeeds, there is a window between when the exec() first
* returns to the userland of the new process and when our brand
* library get's initialized, during which we don't want system
* calls to be re-directed to our brand library since it hasn't
* been initialized yet.
*/
return (0);
}
int
_init(void)
{
int err;
/*
* Set up the table indicating which system calls we want to
* interpose on. We should probably build this automatically from
* a list of system calls that is shared with the user-space
* library.
*/
#ifdef __amd64
#endif /* __amd64 */
if (err) {
}
return (err);
}
int
{
}
int
_fini(void)
{
int err;
/*
* If there are any zones using this brand, we can't allow it to be
* unloaded.
*/
if (brand_zone_count(&s10_brand))
return (EBUSY);
if (err)
return (err);
}