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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 #include <sys/errno.h>
  27 #include <sys/exec.h>
  28 #include <sys/kmem.h>
  29 #include <sys/modctl.h>
  30 #include <sys/model.h>
  31 #include <sys/proc.h>
  32 #include <sys/syscall.h>
  33 #include <sys/systm.h>
  34 #include <sys/thread.h>
  35 #include <sys/cmn_err.h>
  36 #include <sys/archsystm.h>
  37 #include <sys/pathname.h>
  38 
  39 #include <sys/machbrand.h>
  40 #include <sys/brand.h>
  41 #include "sn1_brand.h"
  42 
  43 char *sn1_emulation_table = NULL;
  44 
  45 void    sn1_init_brand_data(zone_t *);
  46 void    sn1_free_brand_data(zone_t *);
  47 void    sn1_setbrand(proc_t *);
  48 int     sn1_getattr(zone_t *, int, void *, size_t *);
  49 int     sn1_setattr(zone_t *, int, void *, size_t);
  50 int     sn1_brandsys(int, int64_t *, uintptr_t, uintptr_t, uintptr_t,
  51                 uintptr_t, uintptr_t, uintptr_t);
  52 void    sn1_copy_procdata(proc_t *, proc_t *);
  53 void    sn1_proc_exit(struct proc *, klwp_t *);
  54 void    sn1_exec();
  55 int     sn1_initlwp(klwp_t *);
  56 void    sn1_forklwp(klwp_t *, klwp_t *);
  57 void    sn1_freelwp(klwp_t *);
  58 void    sn1_lwpexit(klwp_t *);
  59 int     sn1_elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
  60         long *, int, caddr_t, cred_t *, int);
  61 
  62 /* sn1 brand */
  63 struct brand_ops sn1_brops = {
  64         sn1_init_brand_data,
  65         sn1_free_brand_data,
  66         sn1_brandsys,
  67         sn1_setbrand,
  68         sn1_getattr,
  69         sn1_setattr,
  70         sn1_copy_procdata,
  71         sn1_proc_exit,
  72         sn1_exec,
  73         lwp_setrval,
  74         sn1_initlwp,
  75         sn1_forklwp,
  76         sn1_freelwp,
  77         sn1_lwpexit,
  78         sn1_elfexec,
  79         NULL,
  80         NULL,
  81         NSIG,
  82 };
  83 
  84 #ifdef  sparc
  85 
  86 struct brand_mach_ops sn1_mops = {
  87         sn1_brand_syscall_callback,
  88         sn1_brand_syscall32_callback
  89 };
  90 
  91 #else   /* sparc */
  92 
  93 #ifdef  __amd64
  94 
  95 struct brand_mach_ops sn1_mops = {
  96         sn1_brand_sysenter_callback,
  97         sn1_brand_int91_callback,
  98         sn1_brand_syscall_callback,
  99         sn1_brand_syscall32_callback
 100 };
 101 
 102 #else   /* ! __amd64 */
 103 
 104 struct brand_mach_ops sn1_mops = {
 105         sn1_brand_sysenter_callback,
 106         NULL,
 107         sn1_brand_syscall_callback,
 108         NULL
 109 };
 110 #endif  /* __amd64 */
 111 
 112 #endif  /* _sparc */
 113 
 114 struct brand    sn1_brand = {
 115         BRAND_VER_1,
 116         "sn1",
 117         &sn1_brops,
 118         &sn1_mops
 119 };
 120 
 121 static struct modlbrand modlbrand = {
 122         &mod_brandops,              /* type of module */
 123         "Solaris N-1 Brand",    /* description of module */
 124         &sn1_brand          /* driver ops */
 125 };
 126 
 127 static struct modlinkage modlinkage = {
 128         MODREV_1, (void *)&modlbrand, NULL
 129 };
 130 
 131 void
 132 sn1_setbrand(proc_t *p)
 133 {
 134         brand_solaris_setbrand(p, &sn1_brand);
 135 }
 136 
 137 /* ARGSUSED */
 138 int
 139 sn1_getattr(zone_t *zone, int attr, void *buf, size_t *bufsize)
 140 {
 141         return (EINVAL);
 142 }
 143 
 144 /* ARGSUSED */
 145 int
 146 sn1_setattr(zone_t *zone, int attr, void *buf, size_t bufsize)
 147 {
 148         return (EINVAL);
 149 }
 150 
 151 /*ARGSUSED*/
 152 int
 153 sn1_brandsys(int cmd, int64_t *rval, uintptr_t arg1, uintptr_t arg2,
 154     uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t arg6)
 155 {
 156         int     res;
 157 
 158         *rval = 0;
 159 
 160         res = brand_solaris_cmd(cmd, arg1, arg2, arg3, &sn1_brand, SN1_VERSION);
 161         if (res >= 0)
 162                 return (res);
 163 
 164         return (EINVAL);
 165 }
 166 
 167 void
 168 sn1_copy_procdata(proc_t *child, proc_t *parent)
 169 {
 170         brand_solaris_copy_procdata(child, parent, &sn1_brand);
 171 }
 172 
 173 void
 174 sn1_proc_exit(struct proc *p, klwp_t *l)
 175 {
 176         brand_solaris_proc_exit(p, l, &sn1_brand);
 177 }
 178 
 179 void
 180 sn1_exec()
 181 {
 182         brand_solaris_exec(&sn1_brand);
 183 }
 184 
 185 int
 186 sn1_initlwp(klwp_t *l)
 187 {
 188         return (brand_solaris_initlwp(l, &sn1_brand));
 189 }
 190 
 191 void
 192 sn1_forklwp(klwp_t *p, klwp_t *c)
 193 {
 194         brand_solaris_forklwp(p, c, &sn1_brand);
 195 }
 196 
 197 void
 198 sn1_freelwp(klwp_t *l)
 199 {
 200         brand_solaris_freelwp(l, &sn1_brand);
 201 }
 202 
 203 void
 204 sn1_lwpexit(klwp_t *l)
 205 {
 206         brand_solaris_lwpexit(l, &sn1_brand);
 207 }
 208 
 209 /*ARGSUSED*/
 210 void
 211 sn1_free_brand_data(zone_t *zone)
 212 {
 213 }
 214 
 215 /*ARGSUSED*/
 216 void
 217 sn1_init_brand_data(zone_t *zone)
 218 {
 219 }
 220 
 221 int
 222 sn1_elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
 223         int level, long *execsz, int setid, caddr_t exec_file, cred_t *cred,
 224         int brand_action)
 225 {
 226         return (brand_solaris_elfexec(vp, uap, args, idatap, level, execsz,
 227             setid, exec_file, cred, brand_action, &sn1_brand, SN1_BRANDNAME,
 228             SN1_LIB, SN1_LIB32, SN1_LINKER, SN1_LINKER32));
 229 }
 230 
 231 int
 232 _init(void)
 233 {
 234         int err;
 235 
 236         /*
 237          * Set up the table indicating which system calls we want to
 238          * interpose on.  We should probably build this automatically from
 239          * a list of system calls that is shared with the user-space
 240          * library.
 241          */
 242         sn1_emulation_table = kmem_zalloc(NSYSCALL, KM_SLEEP);
 243         sn1_emulation_table[SYS_read] = 1;                      /*   3 */
 244         sn1_emulation_table[SYS_write] = 1;                     /*   4 */
 245         sn1_emulation_table[SYS_time] = 1;                      /*  13 */
 246         sn1_emulation_table[SYS_getpid] = 1;                    /*  20 */
 247         sn1_emulation_table[SYS_mount] = 1;                     /*  21 */
 248         sn1_emulation_table[SYS_getuid] = 1;                    /*  24 */
 
 | 
 
 
   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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2016 Joyent, Inc.
  25  */
  26 
  27 #include <sys/errno.h>
  28 #include <sys/exec.h>
  29 #include <sys/kmem.h>
  30 #include <sys/modctl.h>
  31 #include <sys/model.h>
  32 #include <sys/proc.h>
  33 #include <sys/syscall.h>
  34 #include <sys/systm.h>
  35 #include <sys/thread.h>
  36 #include <sys/cmn_err.h>
  37 #include <sys/archsystm.h>
  38 #include <sys/pathname.h>
  39 
  40 #include <sys/machbrand.h>
  41 #include <sys/brand.h>
  42 #include "sn1_brand.h"
  43 
  44 char *sn1_emulation_table = NULL;
  45 
  46 void    sn1_init_brand_data(zone_t *, kmutex_t *);
  47 void    sn1_free_brand_data(zone_t *);
  48 void    sn1_setbrand(proc_t *);
  49 int     sn1_getattr(zone_t *, int, void *, size_t *);
  50 int     sn1_setattr(zone_t *, int, void *, size_t);
  51 int     sn1_brandsys(int, int64_t *, uintptr_t, uintptr_t, uintptr_t,
  52                 uintptr_t);
  53 void    sn1_copy_procdata(proc_t *, proc_t *);
  54 void    sn1_proc_exit(struct proc *);
  55 void    sn1_exec();
  56 void    sn1_initlwp(klwp_t *, void *);
  57 void    sn1_forklwp(klwp_t *, klwp_t *);
  58 void    sn1_freelwp(klwp_t *);
  59 void    sn1_lwpexit(klwp_t *);
  60 int     sn1_elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
  61         long *, int, caddr_t, cred_t *, int *);
  62 
  63 /* sn1 brand */
  64 struct brand_ops sn1_brops = {
  65         sn1_init_brand_data,            /* b_init_brand_data */
  66         sn1_free_brand_data,            /* b_free_brand_data */
  67         sn1_brandsys,                   /* b_brandsys */
  68         sn1_setbrand,                   /* b_setbrand */
  69         sn1_getattr,                    /* b_getattr */
  70         sn1_setattr,                    /* b_setattr */
  71         sn1_copy_procdata,              /* b_copy_procdata */
  72         sn1_proc_exit,                  /* b_proc_exit */
  73         sn1_exec,                       /* b_exec */
  74         lwp_setrval,                    /* b_lwp_setrval */
  75         NULL,                           /* b_lwpdata_alloc */
  76         NULL,                           /* b_lwpdata_free */
  77         sn1_initlwp,                    /* b_initlwp */
  78         NULL,                           /* b_initlwp_post */
  79         sn1_forklwp,                    /* b_forklwp */
  80         sn1_freelwp,                    /* b_freelwp */
  81         sn1_lwpexit,                    /* b_lwpexit */
  82         sn1_elfexec,                    /* b_elfexec */
  83         NULL,                           /* b_sigset_native_to_brand */
  84         NULL,                           /* b_sigset_brand_to_native */
  85         NULL,                           /* b_sigfd_translate */
  86         NSIG,                           /* b_nsig */
  87         NULL,                           /* b_exit_with_sig */
  88         NULL,                           /* b_wait_filter */
  89         NULL,                           /* b_native_exec */
  90         NULL,                           /* b_map32limit */
  91         NULL,                           /* b_stop_notify */
  92         NULL,                           /* b_waitid_helper */
  93         NULL,                           /* b_sigcld_repost */
  94         NULL,                           /* b_issig_stop */
  95         NULL,                           /* b_sig_ignorable */
  96         NULL,                           /* b_savecontext */
  97 #if defined(_SYSCALL32_IMPL)
  98         NULL,                           /* b_savecontext32 */
  99 #endif
 100         NULL,                           /* b_restorecontext */
 101         NULL,                           /* b_sendsig_stack */
 102         NULL,                           /* b_sendsig */
 103         NULL,                           /* b_setid_clear */
 104         NULL,                           /* b_pagefault */
 105         B_TRUE                          /* b_intp_parse_arg */
 106 };
 107 
 108 #ifdef  sparc
 109 
 110 struct brand_mach_ops sn1_mops = {
 111         sn1_brand_syscall_callback,
 112         sn1_brand_syscall32_callback
 113 };
 114 
 115 #else   /* sparc */
 116 
 117 #ifdef  __amd64
 118 
 119 struct brand_mach_ops sn1_mops = {
 120         sn1_brand_sysenter_callback,
 121         NULL,
 122         sn1_brand_int91_callback,
 123         sn1_brand_syscall_callback,
 124         sn1_brand_syscall32_callback,
 125         NULL,
 126         NULL
 127 };
 128 
 129 #else   /* ! __amd64 */
 130 
 131 struct brand_mach_ops sn1_mops = {
 132         sn1_brand_sysenter_callback,
 133         NULL,
 134         NULL,
 135         sn1_brand_syscall_callback,
 136         NULL,
 137         NULL,
 138         NULL
 139 };
 140 #endif  /* __amd64 */
 141 
 142 #endif  /* _sparc */
 143 
 144 struct brand    sn1_brand = {
 145         BRAND_VER_1,
 146         "sn1",
 147         &sn1_brops,
 148         &sn1_mops,
 149         sizeof (brand_proc_data_t),
 150 };
 151 
 152 static struct modlbrand modlbrand = {
 153         &mod_brandops,              /* type of module */
 154         "Solaris N-1 Brand",    /* description of module */
 155         &sn1_brand          /* driver ops */
 156 };
 157 
 158 static struct modlinkage modlinkage = {
 159         MODREV_1, (void *)&modlbrand, NULL
 160 };
 161 
 162 void
 163 sn1_setbrand(proc_t *p)
 164 {
 165         brand_solaris_setbrand(p, &sn1_brand);
 166 }
 167 
 168 /* ARGSUSED */
 169 int
 170 sn1_getattr(zone_t *zone, int attr, void *buf, size_t *bufsize)
 171 {
 172         return (EINVAL);
 173 }
 174 
 175 /* ARGSUSED */
 176 int
 177 sn1_setattr(zone_t *zone, int attr, void *buf, size_t bufsize)
 178 {
 179         return (EINVAL);
 180 }
 181 
 182 /* ARGSUSED5 */
 183 int
 184 sn1_brandsys(int cmd, int64_t *rval, uintptr_t arg1, uintptr_t arg2,
 185     uintptr_t arg3, uintptr_t arg4)
 186 {
 187         int     res;
 188 
 189         *rval = 0;
 190 
 191         res = brand_solaris_cmd(cmd, arg1, arg2, arg3, &sn1_brand, SN1_VERSION);
 192         if (res >= 0)
 193                 return (res);
 194 
 195         return (EINVAL);
 196 }
 197 
 198 void
 199 sn1_copy_procdata(proc_t *child, proc_t *parent)
 200 {
 201         brand_solaris_copy_procdata(child, parent, &sn1_brand);
 202 }
 203 
 204 void
 205 sn1_proc_exit(struct proc *p)
 206 {
 207         brand_solaris_proc_exit(p, &sn1_brand);
 208 }
 209 
 210 void
 211 sn1_exec()
 212 {
 213         brand_solaris_exec(&sn1_brand);
 214 }
 215 
 216 /* ARGSUSED */
 217 void
 218 sn1_initlwp(klwp_t *l, void *bd)
 219 {
 220         brand_solaris_initlwp(l, &sn1_brand);
 221 }
 222 
 223 void
 224 sn1_forklwp(klwp_t *p, klwp_t *c)
 225 {
 226         brand_solaris_forklwp(p, c, &sn1_brand);
 227 }
 228 
 229 void
 230 sn1_freelwp(klwp_t *l)
 231 {
 232         brand_solaris_freelwp(l, &sn1_brand);
 233 }
 234 
 235 void
 236 sn1_lwpexit(klwp_t *l)
 237 {
 238         brand_solaris_lwpexit(l, &sn1_brand);
 239 }
 240 
 241 /*ARGSUSED*/
 242 void
 243 sn1_free_brand_data(zone_t *zone)
 244 {
 245 }
 246 
 247 /*ARGSUSED*/
 248 void
 249 sn1_init_brand_data(zone_t *zone, kmutex_t *zsl)
 250 {
 251 }
 252 
 253 int
 254 sn1_elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
 255     int level, long *execsz, int setid, caddr_t exec_file, cred_t *cred,
 256     int *brand_action)
 257 {
 258         return (brand_solaris_elfexec(vp, uap, args, idatap, level, execsz,
 259             setid, exec_file, cred, brand_action, &sn1_brand, SN1_BRANDNAME,
 260             SN1_LIB, SN1_LIB32));
 261 }
 262 
 263 int
 264 _init(void)
 265 {
 266         int err;
 267 
 268         /*
 269          * Set up the table indicating which system calls we want to
 270          * interpose on.  We should probably build this automatically from
 271          * a list of system calls that is shared with the user-space
 272          * library.
 273          */
 274         sn1_emulation_table = kmem_zalloc(NSYSCALL, KM_SLEEP);
 275         sn1_emulation_table[SYS_read] = 1;                      /*   3 */
 276         sn1_emulation_table[SYS_write] = 1;                     /*   4 */
 277         sn1_emulation_table[SYS_time] = 1;                      /*  13 */
 278         sn1_emulation_table[SYS_getpid] = 1;                    /*  20 */
 279         sn1_emulation_table[SYS_mount] = 1;                     /*  21 */
 280         sn1_emulation_table[SYS_getuid] = 1;                    /*  24 */
 
 |