1 /*-
2 * Copyright (c) 2001 Jake Burkholder.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/lock.h>
32 #include <sys/malloc.h>
33 #include <sys/mutex.h>
34 #include <sys/proc.h>
35 #include <sys/sysproto.h>
36
37 #include <machine/md_var.h>
38 #include <machine/utrap.h>
39 #include <machine/sysarch.h>
40
41 static int sparc_sigtramp_install(struct thread *td, char *args);
42 static int sparc_utrap_install(struct thread *td, char *args);
43
44 #ifndef _SYS_SYSPROTO_H_
45 struct sysarch_args {
46 int op;
47 char *parms;
48 };
49 #endif
50
51 int
52 sysarch(struct thread *td, struct sysarch_args *uap)
53 {
54 int error;
55
56 mtx_lock(&Giant);
57 switch (uap->op) {
58 case SPARC_SIGTRAMP_INSTALL:
59 error = sparc_sigtramp_install(td, uap->parms);
60 break;
61 case SPARC_UTRAP_INSTALL:
62 error = sparc_utrap_install(td, uap->parms);
63 break;
64 default:
65 error = EINVAL;
66 break;
67 }
68 mtx_unlock(&Giant);
69 return (error);
70 }
71
72 static int
73 sparc_sigtramp_install(struct thread *td, char *args)
74 {
75 struct sparc_sigtramp_install_args sia;
76 struct proc *p;
77 int error;
78
79 p = td->td_proc;
80 if ((error = copyin(args, &sia, sizeof(sia))) != 0)
81 return (error);
82 if (sia.sia_old != NULL) {
83 if (suword(sia.sia_old, (long)p->p_md.md_sigtramp) != 0)
84 return (EFAULT);
85 }
86 p->p_md.md_sigtramp = sia.sia_new;
87 return (0);
88 }
89
90 static int
91 sparc_utrap_install(struct thread *td, char *args)
92 {
93 struct sparc_utrap_install_args uia;
94 struct sparc_utrap_args ua;
95 struct md_utrap *ut;
96 int error;
97 int i;
98
99 ut = td->td_proc->p_md.md_utrap;
100 if ((error = copyin(args, &uia, sizeof(uia))) != 0)
101 return (error);
102 if (uia.num < 0 || uia.num > UT_MAX ||
103 (uia.handlers == NULL && uia.num > 0))
104 return (EINVAL);
105 for (i = 0; i < uia.num; i++) {
106 if ((error = copyin(&uia.handlers[i], &ua, sizeof(ua))) != 0)
107 return (error);
108 if (ua.type != UTH_NOCHANGE &&
109 (ua.type < 0 || ua.type >= UT_MAX))
110 return (EINVAL);
111 if (ua.old_deferred != NULL) {
112 if ((error = suword(ua.old_deferred, 0)) != 0)
113 return (error);
114 }
115 if (ua.old_precise != NULL) {
116 error = suword(ua.old_precise,
117 ut != NULL ? (long)ut->ut_precise[ua.type] : 0);
118 if (error != 0)
119 return (error);
120 }
121 if (ua.type != UTH_NOCHANGE) {
122 if (ut == NULL) {
123 ut = utrap_alloc();
124 td->td_proc->p_md.md_utrap = ut;
125 }
126 ut->ut_precise[ua.type] = ua.new_precise;
127 }
128 }
129 return (0);
130 }
Cache object: 4d520dad9fed1b973cacb1d7f8ba9e05
|