/*
* 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
*/
/*
*/
#ifndef _BRAND_MISC_H
#define _BRAND_MISC_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* This header file must uses _ASM defines to allow it to be included
* in assmebly source files
*/
#include <sys/asm_linkage.h>
#if !defined(_ASM)
#endif
#include "assym.h"
/*
* Our syscall emulation callback handler adds one argument to each
* system call, so we'll need to allocate space for one more argument
* above the maximum number of arguments that a system call can normally
* take. Also, we assume that each syscall argument is a long, ie, we
* don't support long long syscall parameters.
*/
#if defined(__sparc)
/*
* 32-bit and 64-bit sparc syscalls can take up to 8 arguments.
* 32-bit sparc indirect syscalls can take up to 9 arguments.
* Arguments 1 - 6 are passed via %o0 - %o5.
* Additional arguments are passed on the stack.
* So make space for 4 arguments on the stack.
*/
/*
* amd64 syscalls can take up to 8 arguments.
* Arguments 1 - 6 are passed via: %rdi, %rsi, %rdx, %r10, %r8, %r9
* Additional arguments are passed on the stack.
* So make space for 3 arguments on the stack.
*/
#else /* !__sparc && !__amd64 */
/*
* ia32 syscalls can take up to 8 arguments.
* All arguments are passed on the stack.
* So make space for 9 arguments on the stack.
*/
#endif /* !__sparc && !__amd64 */
#if defined(__sparc)
/*
* On sparc, all emulation callback handler variable access is done
* relative to %sp, so access offsets are positive.
*/
#else /* !__sparc */
/*
* On x86, all emulation callback handler variable access is done
* relative to %ebp/%rbp, so access offsets are negative.
*/
#define EH_LOCALS_END_TGT 0
#endif /* !__sparc */
/*
* In our emulation callback handler, our stack will look like:
* -------------------------------------------------
* %bp | long rvflag |
* | | sysret_t sysret |
* v | gregset_t gregs |
* %sp | long callback args[EH_ARGS_COUNT] |
* -------------------------------------------------
* For ia32, use %ebp and %esp instead of %bp and %sp.
* For amd64, use %rbp and %rsp instead of %bp and %sp.
*
* Our emulation callback handler always saves enough space to hold the
* maximum number of stack arguments to a system call. This is architecture
* specific and is defined via EH_ARGS_COUNT.
*/
#if (EH_LOCALS_END != EH_LOCALS_END_TGT)
#error "brand_misc.h EH_LOCALS_* macros don't add up"
#endif /* (EH_LOCALS_END != EH_LOCALS_END_TGT) */
/*
* The second parameter of each entry in the {BRAND}_sysent_table
* contains the number of parameters and flags that describe the
* syscall return value encoding.
*
* When declaring new syscall emulation functions, it is very important
* to to set the proper RV_* flags in the brand_sysent_table. Upon failure,
* syscall emulation fuctions should return an errno value. Upon success
* syscall emulation functions should return 0 and set the sysret_t return
* value parameters accordingly.
*
* There are five possible syscall macro wrappers used in the kernel's system
* call sysent table. These turn into the following return values:
* SYSENT_CL -> SYSENT_C or SYSENT_CI
* SYSENT_C SE_64RVAL RV_DEFAULT
* SYSENT_CI SE_32RVAL1 RV_DEFAULT
* SYSENT_2CI SE_32RVAL1|SE_32RVAL2 RV_32RVAL2
* SYSENT_AP SE_64RVAL RV_64RVAL
*
*/
#if !defined(_ASM)
/*
* We define our own version of assert because the default one will
* try to emit a localized message. That is bad because first, we can't
* emit messages to random file descriptors, and second localizing a message
* requires allocating memory and we can't do that either.
*/
typedef long (*sysent_cb_t)();
typedef struct brand_sysent_table {
/*
* These macros invoke a brandsys subcommand, B_TRUSS_POINT, used to expose
* a call to an interpositioned syscall that would have otherwise gone
* unnoticed by truss(1) because the interpositioned system call did not call
* any system calls before returning.
*/
(a4))
/*
* From runexe.s
*/
extern void brand_runexe(void *, ulong_t);
/*
* From handler.s
*/
extern void brand_handler_table(void);
extern void brand_handler(void);
extern void brand_error(void);
extern void brand_success(void);
/*
* From brand_util.c
*/
extern void _brand_abort(int, const char *, const char *, int);
extern int brand_uucopy(const void *, void *, size_t);
extern int brand_uucopystr(const void *, void *, size_t);
extern void brand_pre_init();
extern ulong_t brand_post_init(int, int, char **, char **);
#endif /* __sparc && !__sparcv9 */
#endif /* !_ASM */
#ifdef __cplusplus
}
#endif
#endif /* _BRAND_MISC_H */