2 * Copyright (c) 2001 Jake Burkholder.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include "opt_capsicum.h"
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/capsicum.h>
35 #include <sys/malloc.h>
36 #include <sys/mutex.h>
38 #include <sys/sysproto.h>
40 #include <machine/md_var.h>
41 #include <machine/utrap.h>
42 #include <machine/sysarch.h>
44 static int sparc_sigtramp_install(struct thread *td, char *args);
45 static int sparc_utrap_install(struct thread *td, char *args);
47 #ifndef _SYS_SYSPROTO_H_
55 sysarch(struct thread *td, struct sysarch_args *uap)
59 #ifdef CAPABILITY_MODE
61 * When adding new operations, add a new case statement here to
62 * explicitly indicate whether or not the operation is safe to
63 * perform in capability mode.
65 if (IN_CAPABILITY_MODE(td)) {
67 case SPARC_SIGTRAMP_INSTALL:
68 case SPARC_UTRAP_INSTALL:
73 if (KTRPOINT(td, KTR_CAPFAIL))
74 ktrcapfail(CAPFAIL_SYSCALL, NULL, NULL);
83 case SPARC_SIGTRAMP_INSTALL:
84 error = sparc_sigtramp_install(td, uap->parms);
86 case SPARC_UTRAP_INSTALL:
87 error = sparc_utrap_install(td, uap->parms);
98 sparc_sigtramp_install(struct thread *td, char *args)
100 struct sparc_sigtramp_install_args sia;
105 if ((error = copyin(args, &sia, sizeof(sia))) != 0)
107 if (sia.sia_old != NULL) {
108 if (suword(sia.sia_old, (long)p->p_md.md_sigtramp) != 0)
111 p->p_md.md_sigtramp = sia.sia_new;
116 sparc_utrap_install(struct thread *td, char *args)
118 struct sparc_utrap_install_args uia;
119 struct sparc_utrap_args ua;
124 ut = td->td_proc->p_md.md_utrap;
125 if ((error = copyin(args, &uia, sizeof(uia))) != 0)
127 if (uia.num < 0 || uia.num > UT_MAX ||
128 (uia.handlers == NULL && uia.num > 0))
130 for (i = 0; i < uia.num; i++) {
131 if ((error = copyin(&uia.handlers[i], &ua, sizeof(ua))) != 0)
133 if (ua.type != UTH_NOCHANGE &&
134 (ua.type < 0 || ua.type >= UT_MAX))
136 if (ua.old_deferred != NULL) {
137 if ((error = suword(ua.old_deferred, 0)) != 0)
140 if (ua.old_precise != NULL) {
141 error = suword(ua.old_precise,
142 ut != NULL ? (long)ut->ut_precise[ua.type] : 0);
146 if (ua.type != UTH_NOCHANGE) {
149 td->td_proc->p_md.md_utrap = ut;
151 ut->ut_precise[ua.type] = ua.new_precise;