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) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <sys/param.h>
27 #include <sys/vmparam.h>
28 #include <sys/types.h>
29 #include <sys/sysmacros.h>
30 #include <sys/systm.h>
31 #include <sys/signal.h>
32 #include <sys/stack.h>
33 #include <sys/cred.h>
34 #include <sys/cmn_err.h>
35 #include <sys/user.h>
36 #include <sys/privregs.h>
37 #include <sys/psw.h>
38 #include <sys/debug.h>
39 #include <sys/errno.h>
40 #include <sys/proc.h>
41 #include <sys/modctl.h>
42 #include <sys/var.h>
43 #include <sys/inline.h>
1185 /*ARGSUSED*/
1186 int64_t
1187 loadable_syscall(
1188 long a0, long a1, long a2, long a3,
1189 long a4, long a5, long a6, long a7)
1190 {
1191 klwp_t *lwp = ttolwp(curthread);
1192 int64_t rval;
1193 struct sysent *callp;
1194 struct sysent *se = LWP_GETSYSENT(lwp);
1195 krwlock_t *module_lock;
1196 int code, error = 0;
1197
1198 code = curthread->t_sysnum;
1199 callp = se + code;
1200
1201 /*
1202 * Try to autoload the system call if necessary
1203 */
1204 module_lock = lock_syscall(se, code);
1205 THREAD_KPRI_RELEASE(); /* drop priority given by rw_enter */
1206
1207 /*
1208 * we've locked either the loaded syscall or nosys
1209 */
1210
1211 if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE) {
1212 #if defined(_LP64)
1213 if (callp->sy_flags & SE_ARGC) {
1214 rval = (int64_t)(*callp->sy_call)(a0, a1, a2, a3,
1215 a4, a5);
1216 } else {
1217 rval = syscall_ap();
1218 }
1219 } else {
1220 #endif
1221 /*
1222 * Now that it's loaded, make sure enough args were copied.
1223 */
1224 if (COPYIN_ARGS32(lwptoregs(lwp), lwp->lwp_ap, callp->sy_narg))
1225 error = EFAULT;
1226 if (error) {
1227 rval = set_errno(error);
1228 } else if (callp->sy_flags & SE_ARGC) {
1229 rval = (int64_t)(*callp->sy_call)(lwp->lwp_ap[0],
1230 lwp->lwp_ap[1], lwp->lwp_ap[2], lwp->lwp_ap[3],
1231 lwp->lwp_ap[4], lwp->lwp_ap[5]);
1232 } else {
1233 rval = syscall_ap();
1234 }
1235 }
1236
1237 THREAD_KPRI_REQUEST(); /* regain priority from read lock */
1238 rw_exit(module_lock);
1239 return (rval);
1240 }
1241
1242 /*
1243 * Indirect syscall handled in libc on x86 architectures
1244 */
1245 int64_t
1246 indir()
1247 {
1248 return (nosys());
1249 }
1250
1251 /*
1252 * set_errno - set an error return from the current system call.
1253 * This could be a macro.
1254 * This returns the value it is passed, so that the caller can
1255 * use tail-recursion-elimination and do return (set_errno(ERRNO));
1256 */
1257 uint_t
|
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) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2019 Joyent, Inc.
25 */
26
27 #include <sys/param.h>
28 #include <sys/vmparam.h>
29 #include <sys/types.h>
30 #include <sys/sysmacros.h>
31 #include <sys/systm.h>
32 #include <sys/signal.h>
33 #include <sys/stack.h>
34 #include <sys/cred.h>
35 #include <sys/cmn_err.h>
36 #include <sys/user.h>
37 #include <sys/privregs.h>
38 #include <sys/psw.h>
39 #include <sys/debug.h>
40 #include <sys/errno.h>
41 #include <sys/proc.h>
42 #include <sys/modctl.h>
43 #include <sys/var.h>
44 #include <sys/inline.h>
1186 /*ARGSUSED*/
1187 int64_t
1188 loadable_syscall(
1189 long a0, long a1, long a2, long a3,
1190 long a4, long a5, long a6, long a7)
1191 {
1192 klwp_t *lwp = ttolwp(curthread);
1193 int64_t rval;
1194 struct sysent *callp;
1195 struct sysent *se = LWP_GETSYSENT(lwp);
1196 krwlock_t *module_lock;
1197 int code, error = 0;
1198
1199 code = curthread->t_sysnum;
1200 callp = se + code;
1201
1202 /*
1203 * Try to autoload the system call if necessary
1204 */
1205 module_lock = lock_syscall(se, code);
1206
1207 /*
1208 * we've locked either the loaded syscall or nosys
1209 */
1210
1211 if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE) {
1212 #if defined(_LP64)
1213 if (callp->sy_flags & SE_ARGC) {
1214 rval = (int64_t)(*callp->sy_call)(a0, a1, a2, a3,
1215 a4, a5);
1216 } else {
1217 rval = syscall_ap();
1218 }
1219 } else {
1220 #endif
1221 /*
1222 * Now that it's loaded, make sure enough args were copied.
1223 */
1224 if (COPYIN_ARGS32(lwptoregs(lwp), lwp->lwp_ap, callp->sy_narg))
1225 error = EFAULT;
1226 if (error) {
1227 rval = set_errno(error);
1228 } else if (callp->sy_flags & SE_ARGC) {
1229 rval = (int64_t)(*callp->sy_call)(lwp->lwp_ap[0],
1230 lwp->lwp_ap[1], lwp->lwp_ap[2], lwp->lwp_ap[3],
1231 lwp->lwp_ap[4], lwp->lwp_ap[5]);
1232 } else {
1233 rval = syscall_ap();
1234 }
1235 }
1236
1237 rw_exit(module_lock);
1238 return (rval);
1239 }
1240
1241 /*
1242 * Indirect syscall handled in libc on x86 architectures
1243 */
1244 int64_t
1245 indir()
1246 {
1247 return (nosys());
1248 }
1249
1250 /*
1251 * set_errno - set an error return from the current system call.
1252 * This could be a macro.
1253 * This returns the value it is passed, so that the caller can
1254 * use tail-recursion-elimination and do return (set_errno(ERRNO));
1255 */
1256 uint_t
|