2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2001 Jake Burkholder.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include "opt_capsicum.h"
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/capsicum.h>
37 #include <sys/malloc.h>
38 #include <sys/mutex.h>
40 #include <sys/sysproto.h>
42 #include <machine/md_var.h>
43 #include <machine/utrap.h>
44 #include <machine/sysarch.h>
46 static int sparc_sigtramp_install(struct thread *td, char *args);
47 static int sparc_utrap_install(struct thread *td, char *args);
49 #ifndef _SYS_SYSPROTO_H_
57 sysarch(struct thread *td, struct sysarch_args *uap)
61 #ifdef CAPABILITY_MODE
63 * When adding new operations, add a new case statement here to
64 * explicitly indicate whether or not the operation is safe to
65 * perform in capability mode.
67 if (IN_CAPABILITY_MODE(td)) {
69 case SPARC_SIGTRAMP_INSTALL:
70 case SPARC_UTRAP_INSTALL:
75 if (KTRPOINT(td, KTR_CAPFAIL))
76 ktrcapfail(CAPFAIL_SYSCALL, NULL, NULL);
85 case SPARC_SIGTRAMP_INSTALL:
86 error = sparc_sigtramp_install(td, uap->parms);
88 case SPARC_UTRAP_INSTALL:
89 error = sparc_utrap_install(td, uap->parms);
100 sparc_sigtramp_install(struct thread *td, char *args)
102 struct sparc_sigtramp_install_args sia;
107 if ((error = copyin(args, &sia, sizeof(sia))) != 0)
109 if (sia.sia_old != NULL) {
110 if (suword(sia.sia_old, (long)p->p_md.md_sigtramp) != 0)
113 p->p_md.md_sigtramp = sia.sia_new;
118 sparc_utrap_install(struct thread *td, char *args)
120 struct sparc_utrap_install_args uia;
121 struct sparc_utrap_args ua;
126 ut = td->td_proc->p_md.md_utrap;
127 if ((error = copyin(args, &uia, sizeof(uia))) != 0)
129 if (uia.num < 0 || uia.num > UT_MAX ||
130 (uia.handlers == NULL && uia.num > 0))
132 for (i = 0; i < uia.num; i++) {
133 if ((error = copyin(&uia.handlers[i], &ua, sizeof(ua))) != 0)
135 if (ua.type != UTH_NOCHANGE &&
136 (ua.type < 0 || ua.type >= UT_MAX))
138 if (ua.old_deferred != NULL) {
139 if ((error = suword(ua.old_deferred, 0)) != 0)
142 if (ua.old_precise != NULL) {
143 error = suword(ua.old_precise,
144 ut != NULL ? (long)ut->ut_precise[ua.type] : 0);
148 if (ua.type != UTH_NOCHANGE) {
151 td->td_proc->p_md.md_utrap = ut;
153 ut->ut_precise[ua.type] = ua.new_precise;