1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1990, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department and Ralph Campbell.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: hpux_compat.c 1.41 91/04/06$
13  *
14  *	@(#)ultrix_compat.c	8.1 (Berkeley) 06/10/93
15  */
16 
17 /*
18  * Various ULTRIX compatibility routines
19  */
20 
21 #ifdef ULTRIXCOMPAT
22 
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/signalvar.h>
26 #include <sys/kernel.h>
27 #include <sys/filedesc.h>
28 #include <sys/proc.h>
29 #include <sys/buf.h>
30 #include <sys/wait.h>
31 #include <sys/file.h>
32 #include <sys/namei.h>
33 #include <sys/vnode.h>
34 #include <sys/ioctl.h>
35 #include <sys/ptrace.h>
36 #include <sys/stat.h>
37 #include <sys/syslog.h>
38 #include <sys/malloc.h>
39 #include <sys/mount.h>
40 #include <sys/ipc.h>
41 #include <sys/user.h>
42 
43 #include <machine/cpu.h>
44 #include <machine/reg.h>
45 #include <machine/psl.h>
46 #include <machine/vmparam.h>
47 
48 #ifdef DEBUG
49 int unimpresponse = 0;
50 #endif
51 
52 /* YP domainname */
53 char	domainname[MAXHOSTNAMELEN] = "unknown";
54 int	domainnamelen = 7;
55 
56 notimp(p, uap, retval)
57 	struct proc *p;
58 	void *uap;
59 	int *retval;
60 {
61 	int error = 0;
62 #ifdef notdef
63 	register int *argp = uap;
64 	extern char *ultrixsyscallnames[];
65 
66 	printf("ULTRIX %s(", ultrixsyscallnames[code]);
67 	if (nargs)
68 		while (nargs--)
69 			printf("%x%c", *argp++, nargs? ',' : ')');
70 	else
71 		printf(")");
72 	printf("\n");
73 	switch (unimpresponse) {
74 	case 0:
75 		error = nosys(p, uap, retval);
76 		break;
77 	case 1:
78 		error = EINVAL;
79 		break;
80 	}
81 #else
82 	uprintf("ULTRIX system call %d not implemented\n", p->p_md.md_regs[V0]);
83 	error = nosys(p, uap, retval);
84 #endif
85 	return (error);
86 }
87 
88 struct wait3_args {
89 	int	*status;
90 	int	options;
91 	int	rusage;
92 };
93 
94 ultrixwait3(p, uap, retval)
95 	struct proc *p;
96 	struct wait3_args *uap;
97 	int *retval;
98 {
99 	struct {
100 		int	pid;
101 		int	*status;
102 		int	options;
103 		struct	rusage *rusage;
104 		int	compat;
105 	} bsd_uap;
106 
107 	/* rusage pointer must be zero */
108 	if (uap->rusage)
109 		return (EINVAL);
110 	bsd_uap.pid = WAIT_ANY;
111 	bsd_uap.status = uap->status;
112 	bsd_uap.options = 0;
113 	bsd_uap.rusage = 0;
114 	bsd_uap.compat = 0;
115 	return (wait1(p, &bsd_uap, retval));
116 }
117 
118 struct domainname_args {
119 	char	*domainname;
120 	u_int	len;
121 };
122 
123 ultrixgetdomainname(p, uap, retval)
124 	struct proc *p;
125 	register struct domainname_args *uap;
126 	int *retval;
127 {
128 	if (uap->len > domainnamelen + 1)
129 		uap->len = domainnamelen + 1;
130 	return (copyout(domainname, uap->domainname, uap->len));
131 }
132 
133 ultrixsetdomainname(p, uap, retval)
134 	struct proc *p;
135 	register struct domainname_args *uap;
136 	int *retval;
137 {
138 	int error;
139 
140 	if (error = suser(p->p_ucred, &p->p_acflag))
141 		return (error);
142 	if (uap->len > sizeof (domainname) - 1)
143 		return (EINVAL);
144 	domainnamelen = uap->len;
145 	error = copyin(uap->domainname, domainname, uap->len);
146 	domainname[domainnamelen] = 0;
147 	return (error);
148 }
149 
150 struct getpgrp_args {
151 	int pid;
152 };
153 
154 /*
155  * This is the equivalent of BSD getpgrp but with more restrictions.
156  * Note we do not check the real uid or "saved" uid.
157  */
158 ultrixgetpgrp(cp, uap, retval)
159 	struct proc *cp;
160 	register struct getpgrp_args *uap;
161 	int *retval;
162 {
163 	register struct proc *p;
164 
165 	if (uap->pid == 0)
166 		uap->pid = cp->p_pid;
167 	p = pfind(uap->pid);
168 	if (p == 0)
169 		return (ESRCH);
170 	if (cp->p_ucred->cr_uid && p->p_ucred->cr_uid != cp->p_ucred->cr_uid &&
171 	    !inferior(p))
172 		return (EPERM);
173 	*retval = p->p_pgid;
174 	return (0);
175 }
176 
177 struct setpgrp_args {
178 	int	pid;
179 	int	pgrp;
180 } *uap;
181 /*
182  * This is the equivalent of BSD setpgrp but with more restrictions.
183  * Note we do not check the real uid or "saved" uid or pgrp.
184  */
185 ultrixsetpgrp(p, uap, retval)
186 	struct proc *p;
187 	struct setpgrp_args *uap;
188 	int *retval;
189 {
190 	/* empirically determined */
191 	if (uap->pgrp < 0 || uap->pgrp >= 30000)
192 		return (EINVAL);
193 	return (setpgid(p, uap, retval));
194 }
195 
196 struct sigvec_args {
197 	int	signo;
198 	struct	sigvec *nsv;
199 	struct	sigvec *osv;
200 	caddr_t	sigcode;	/* handler return address */
201 };
202 
203 ultrixsigvec(p, uap, retval)
204 	struct proc *p;
205 	register struct sigvec_args *uap;
206 	int *retval;
207 {
208 	return (osigvec(p, uap, retval));
209 }
210 
211 ultrixsigcleanup(p, uap, retval)
212 	struct proc *p;
213 	void *uap;
214 	int *retval;
215 {
216 	printf("ultrixsigcleanup %s %d\n", p->p_comm, p->p_pid); /* XXX */
217 	return (ENOSYS);
218 }
219 
220 ultrixsigreturn(p, uap, retval)
221 	struct proc *p;
222 	void *uap;
223 	int *retval;
224 {
225 	printf("ultrixsigreturn %s %d\n", p->p_comm, p->p_pid); /* XXX */
226 	return (ENOSYS);
227 }
228 
229 /*
230  * Switch process from ULTRIX emulation to BSD.
231  */
232 ultrixtobsd(p, uap, retval)
233 	struct proc *p;
234 	void *uap;
235 	int *retval;
236 {
237 
238 	p->p_md.md_flags &= ~MDP_ULTRIX;
239 	return (0);
240 }
241 
242 ultrixgetsysinfo(p, uap, retval)
243 	struct proc *p;
244 	void *uap;
245 	int *retval;
246 {
247 
248 	/*
249 	 * Just return a 0.  This says that the requested information is
250 	 * not available which is certainly true for the most part.
251 	 */
252 	retval[0] = 0;
253 	return (0);
254 }
255 
256 #endif
257