1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #ifndef _SYS_LX_H
  28 #define _SYS_LX_H
  29 
  30 #include <stdio.h>
  31 #include <alloca.h>
  32 #include <sys/types.h>
  33 #include <sys/param.h>
  34 #include <sys/lwp.h>
  35 
  36 #include <sys/lx_brand.h>
  37 
  38 #ifdef __cplusplus
  39 extern "C" {
  40 #endif
  41 
  42 extern char lx_release[128];
  43 extern pid_t zoneinit_pid;
  44 
  45 /*
  46  * Support for the unfortunate RPM race condition workaround.
  47  */
  48 extern int lx_rpm_delay;
  49 extern boolean_t lx_is_rpm;
  50 
  51 /*
  52  * Values Linux expects for init
  53  */
  54 #define LX_INIT_PGID    0
  55 #define LX_INIT_SID     0
  56 #define LX_INIT_PID     1
  57 
  58 /*
  59  * Codes to reboot(2).
  60  */
  61 #define LINUX_REBOOT_MAGIC1             0xfee1dead
  62 #define LINUX_REBOOT_MAGIC2             672274793
  63 #define LINUX_REBOOT_MAGIC2A            85072278
  64 #define LINUX_REBOOT_MAGIC2B            369367448
  65 #define LINUX_REBOOT_MAGIC2C            537993216
  66 
  67 /*
  68  * This was observed as coming from Red Hat's init process, but it's not in
  69  * their reboot(2) man page.
  70  */
  71 #define LINUX_REBOOT_MAGIC2D            0x28121969
  72 
  73 #define LINUX_REBOOT_CMD_RESTART        0x1234567
  74 #define LINUX_REBOOT_CMD_HALT           0xcdef0123
  75 #define LINUX_REBOOT_CMD_POWER_OFF      0x4321fedc
  76 #define LINUX_REBOOT_CMD_RESTART2       0xa1b2c3d4
  77 #define LINUX_REBOOT_CMD_CAD_ON         0x89abcdef
  78 #define LINUX_REBOOT_CMD_CAD_OFF        0
  79 
  80 /*
  81  * the maximum length of messages to be output with lx_msg(), lx_err(),
  82  * lx_debug(), or lx_unsupported().
  83  */
  84 #define LX_MSG_MAXLEN                   (128 + MAXPATHLEN)
  85 
  86 /*
  87  * Linux scheduler priority ranges.
  88  */
  89 #define LX_SCHED_PRIORITY_MIN_OTHER     0
  90 #define LX_SCHED_PRIORITY_MAX_OTHER     0
  91 #define LX_SCHED_PRIORITY_MIN_RRFIFO    1
  92 #define LX_SCHED_PRIORITY_MAX_RRFIFO    99
  93 
  94 /*
  95  * Constants to indicate who getrusage() should return information about.
  96  */
  97 #define LX_RUSAGE_SELF          0
  98 #define LX_RUSAGE_CHILDREN      (-1)
  99 
 100 /*
 101  * normally we never want to write to stderr or stdout because it's unsafe
 102  * to make assumptions about the underlying file descriptors.  to protect
 103  * against writes to these file descriptors we go ahead and close them
 104  * our brand process initalization code.  but there are still occasions
 105  * where we are willing to make assumptions about our file descriptors
 106  * and write to them.  at thes times we should use one lx_msg() or
 107  * lx_msg_error()
 108  */
 109 extern void lx_msg(char *, ...);
 110 extern void lx_err(char *, ...);
 111 extern void lx_err_fatal(char *, ...);
 112 extern void lx_unsupported(char *, ...);
 113 
 114 struct ucontext;
 115 
 116 extern void lx_handler_table(void);
 117 extern void lx_handler_trace_table(void);
 118 extern void lx_emulate_done(void);
 119 extern lx_regs_t *lx_syscall_regs(void);
 120 
 121 extern char *lx_fd_to_path(int fd, char *buf, int buf_size);
 122 extern int lx_lpid_to_spair(pid_t, pid_t *, lwpid_t *);
 123 extern int lx_lpid_to_spid(pid_t, pid_t *);
 124 
 125 extern int lx_ptrace_wait(siginfo_t *);
 126 extern void lx_ptrace_fork(void);
 127 
 128 extern int lx_get_kern_version(void);
 129 
 130 extern int lx_check_alloca(size_t);
 131 #define SAFE_ALLOCA(sz) (lx_check_alloca(sz) ? alloca(sz) : NULL)
 132 
 133 extern int ltos_at_flag(int lflag, int allow);
 134 
 135 /*
 136  * NO_UUCOPY disables calls to the uucopy* system calls to help with
 137  * debugging brand library accesses to linux application memory.
 138  */
 139 #ifdef NO_UUCOPY
 140 
 141 int uucopy_unsafe(const void *src, void *dst, size_t n);
 142 int uucopystr_unsafe(const void *src, void *dst, size_t n);
 143 
 144 #define uucopy(src, dst, n)     uucopy_unsafe((src), (dst), (n))
 145 #define uucopystr(src, dst, n)  uucopystr_unsafe((src), (dst), (n))
 146 
 147 #endif /* NO_UUCOPY */
 148 
 149 #ifdef  __cplusplus
 150 }
 151 #endif
 152 
 153 #endif  /* _SYS_LX_H */