#!/bin/sh
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)s9_prctl.sh	1.1	08/05/06 SMI"
#

#
# All native executables must be run using the native linker.
# By default, the kernel loads the linker at /lib/ld.so.1, which
# in an s9 zone is the s9 linker.  Hence when we run the native
# executable below, we explicitly specify /.SUNWnative/lib/ld.so.1 as our
# linker.  For convience we define "n" to be the native path prefix.
#
# prctl(1m) uses the agent lwp to execute the rctlsys system call inside
# the target process.  The rctlsys system call has changed since Solaris 9.
#
#    1.  rctl_opaque_t has changed, which is the structure used to pass
#	 rctl values between libc and the kernel.
#    2.  Many new resource controls have been added.
#    3.  project.cpu-shares no longer accepts the "deny" action.
# 
# The brandZ framework does not emulate system calls executed by agent
# lwps.  This is because of the complex argument and return value mechanism
# used by Psyscall(3libproc), which copies arguments to the calling agent
# lwp after the system call is entered, can copies back the return value
# after the system call exits.
#
# To work around these issues, we simply execute the Solaris 9 prctl command
# using the native libc, and interpose on libproc functions instead of relying
# on the rctlsys system call emulation.  Standard binary compatability allows
# us to run the solaris9 prctl command using the native libc.

# Run the Solaris 9 prctl using the native libc.  This 
#
n=/.SUNWnative
LD_NOCONFIG=1
LD_LIBRARY_PATH_32=$n/lib:$n/usr/lib:$n/usr/lib/mps:$n/usr/lib/brand/solaris9
LD_LIBRARY_PATH_64=$n/lib/64:$n/usr/lib/64:$n/usr/lib/mps/64
LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64:$n//usr/lib/brand/solaris9/64
LD_PRELOAD_32="s9_npreload.so.1 s9_prctl.so.1"
LD_PRELOAD_64="s9_npreload.so.1 s9_prctl.so.1"
export LD_NOCONFIG
export LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 LD_PRELOAD_32 LD_PRELOAD_64
exec /.SUNWnative/usr/lib/brand/solaris9/s9_native \
	/.SUNWnative/lib/sparcv9/ld.so.1 /usr/bin/sparcv9/prctl.pre_p2v $@
