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: releng/5.0/sys/sparc64/sparc64/sys_machdep.c 95744 2002-04-29 18:08:26Z jake $
27 */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/malloc.h>
32 #include <sys/proc.h>
33 #include <sys/sysproto.h>
34
35 #include <machine/utrap.h>
36 #include <machine/sysarch.h>
37
38 static int sparc_sigtramp_install(struct thread *td, char *args);
39 static int sparc_utrap_install(struct thread *td, char *args);
40
41 #ifndef _SYS_SYSPROTO_H_
42 struct sysarch_args {
43 int op;
44 char *parms;
45 };
46 #endif
47
48 int
49 sysarch(struct thread *td, struct sysarch_args *uap)
50 {
51 int error;
52
53 error = 0;
54 switch (uap->op) {
55 case SPARC_SIGTRAMP_INSTALL:
56 error = sparc_sigtramp_install(td, uap->parms);
57 break;
58 case SPARC_UTRAP_INSTALL:
59 error = sparc_utrap_install(td, uap->parms);
60 break;
61 default:
62 error = EINVAL;
63 break;
64 }
65 return (error);
66 }
67
68 static int
69 sparc_sigtramp_install(struct thread *td, char *args)
70 {
71 struct sparc_sigtramp_install_args sia;
72 struct proc *p;
73 int error;
74
75 p = td->td_proc;
76 if ((error = copyin(args, &sia, sizeof(sia))) != 0)
77 return (error);
78 if (sia.sia_old != NULL) {
79 if (suword(sia.sia_old, (long)p->p_md.md_sigtramp) != 0)
80 return (EFAULT);
81 }
82 p->p_md.md_sigtramp = sia.sia_new;
83 return (0);
84 }
85
86 static int
87 sparc_utrap_install(struct thread *td, char *args)
88 {
89 struct sparc_utrap_install_args uia;
90 struct sparc_utrap_args ua;
91 struct md_utrap *ut;
92 int error;
93 int i;
94
95 ut = td->td_proc->p_md.md_utrap;
96 if ((error = copyin(args, &uia, sizeof(uia))) != 0)
97 return (error);
98 if (uia.num < 0 || uia.num > UT_MAX ||
99 (uia.handlers == NULL && uia.num > 0))
100 return (EINVAL);
101 for (i = 0; i < uia.num; i++) {
102 if ((error = copyin(&uia.handlers[i], &ua, sizeof(ua))) != 0)
103 return (error);
104 if (ua.type != UTH_NOCHANGE &&
105 (ua.type < 0 || ua.type >= UT_MAX))
106 return (EINVAL);
107 if (ua.old_deferred != NULL) {
108 if ((error = suword(ua.old_deferred, 0)) != 0)
109 return (error);
110 }
111 if (ua.old_precise != NULL) {
112 error = suword(ua.old_precise,
113 ut != NULL ? (long)ut->ut_precise[ua.type] : 0);
114 if (error != 0)
115 return (error);
116 }
117 if (ua.type != UTH_NOCHANGE) {
118 if (ut == NULL) {
119 ut = malloc(sizeof *ut, M_SUBPROC,
120 M_WAITOK | M_ZERO);
121 ut->ut_refcnt = 1;
122 td->td_proc->p_md.md_utrap = ut;
123 }
124 ut->ut_precise[ua.type] = ua.new_precise;
125 }
126 }
127 return (0);
128 }
Cache object: cd4f6ee229908b9f136e8e289af7f3a5
|