ibcs2_xenix.c revision 160241
1/*-
2 * Copyright (c) 1994 Sean Eric Fagan
3 * Copyright (c) 1994 S�ren Schmidt
4 * Copyright (c) 1995 Steven Wallace
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer
12 *    in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_xenix.c 160241 2006-07-10 17:59:26Z jhb $");
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/namei.h>
37#include <sys/sysproto.h>
38#include <sys/jail.h>
39#include <sys/kernel.h>
40#include <sys/malloc.h>
41#include <sys/filio.h>
42#include <sys/vnode.h>
43#include <sys/syscallsubr.h>
44#include <sys/sysctl.h>
45#include <sys/sysent.h>
46#include <sys/unistd.h>
47
48#include <machine/cpu.h>
49
50#include <i386/ibcs2/ibcs2_types.h>
51#include <i386/ibcs2/ibcs2_unistd.h>
52#include <i386/ibcs2/ibcs2_signal.h>
53#include <i386/ibcs2/ibcs2_util.h>
54#include <i386/ibcs2/ibcs2_proto.h>
55#include <i386/ibcs2/ibcs2_xenix.h>
56#include <i386/ibcs2/ibcs2_xenix_syscall.h>
57
58
59extern struct sysent xenix_sysent[];
60
61int
62ibcs2_xenix(struct thread *td, struct ibcs2_xenix_args *uap)
63{
64	struct trapframe *tf = td->td_frame;
65        struct sysent *callp;
66        u_int code;
67	int error;
68
69	code = (tf->tf_eax & 0xff00) >> 8;
70	callp = &xenix_sysent[code];
71
72	if (code < IBCS2_XENIX_MAXSYSCALL) {
73		if ((callp->sy_narg & SYF_MPSAFE) == 0)
74			mtx_lock(&Giant);
75		error = ((*callp->sy_call)(td, (void *)uap));
76		if ((callp->sy_narg & SYF_MPSAFE) == 0)
77			mtx_unlock(&Giant);
78	} else
79		error = ENOSYS;
80	return (error);
81}
82
83int
84xenix_rdchk(td, uap)
85	struct thread *td;
86	struct xenix_rdchk_args *uap;
87{
88	int data, error;
89
90	DPRINTF(("IBCS2: 'xenix rdchk'\n"));
91
92	error = kern_ioctl(td, uap->fd, FIONREAD, (caddr_t)&data);
93	if (error)
94		return (error);
95	td->td_retval[0] = data ? 1 : 0;
96	return (0);
97}
98
99int
100xenix_chsize(td, uap)
101	struct thread *td;
102	struct xenix_chsize_args *uap;
103{
104	struct ftruncate_args sa;
105
106	DPRINTF(("IBCS2: 'xenix chsize'\n"));
107	sa.fd = uap->fd;
108	sa.pad = 0;
109	sa.length = uap->size;
110	return ftruncate(td, &sa);
111}
112
113
114int
115xenix_ftime(td, uap)
116	struct thread *td;
117	struct xenix_ftime_args *uap;
118{
119	struct timeval tv;
120	struct ibcs2_timeb {
121		unsigned long time __packed;
122		unsigned short millitm;
123		short timezone;
124		short dstflag;
125	} itb;
126
127	DPRINTF(("IBCS2: 'xenix ftime'\n"));
128	microtime(&tv);
129	itb.time = tv.tv_sec;
130	itb.millitm = (tv.tv_usec / 1000);
131	itb.timezone = tz_minuteswest;
132	itb.dstflag = tz_dsttime != DST_NONE;
133
134	return copyout((caddr_t)&itb, (caddr_t)uap->tp,
135		       sizeof(struct ibcs2_timeb));
136}
137
138int
139xenix_nap(struct thread *td, struct xenix_nap_args *uap)
140{
141	long period;
142
143	DPRINTF(("IBCS2: 'xenix nap %d ms'\n", uap->millisec));
144	period = (long)uap->millisec / (1000/hz);
145	if (period)
146		while (tsleep(&period, PPAUSE, "nap", period)
147		       != EWOULDBLOCK) ;
148	return 0;
149}
150
151int
152xenix_utsname(struct thread *td, struct xenix_utsname_args *uap)
153{
154	struct ibcs2_sco_utsname {
155		char sysname[9];
156		char nodename[9];
157		char release[16];
158		char kernelid[20];
159		char machine[9];
160		char bustype[9];
161		char sysserial[10];
162		unsigned short sysorigin;
163		unsigned short sysoem;
164		char numusers[9];
165		unsigned short numcpu;
166	} ibcs2_sco_uname;
167
168	DPRINTF(("IBCS2: 'xenix sco_utsname'\n"));
169	bzero(&ibcs2_sco_uname, sizeof(struct ibcs2_sco_utsname));
170	strncpy(ibcs2_sco_uname.sysname, ostype,
171		sizeof(ibcs2_sco_uname.sysname) - 1);
172	getcredhostname(td->td_ucred, ibcs2_sco_uname.nodename,
173	    sizeof(ibcs2_sco_uname.nodename) - 1);
174	strncpy(ibcs2_sco_uname.release, osrelease,
175		sizeof(ibcs2_sco_uname.release) - 1);
176	strncpy(ibcs2_sco_uname.kernelid, version,
177		sizeof(ibcs2_sco_uname.kernelid) - 1);
178	strncpy(ibcs2_sco_uname.machine, machine,
179		sizeof(ibcs2_sco_uname.machine) - 1);
180	strncpy(ibcs2_sco_uname.bustype, "ISA/EISA",
181		sizeof(ibcs2_sco_uname.bustype) - 1);
182	strncpy(ibcs2_sco_uname.sysserial, "no charge",
183		sizeof(ibcs2_sco_uname.sysserial) - 1);
184	strncpy(ibcs2_sco_uname.numusers, "unlim",
185		sizeof(ibcs2_sco_uname.numusers) - 1);
186	ibcs2_sco_uname.sysorigin = 0xFFFF;
187	ibcs2_sco_uname.sysoem = 0xFFFF;
188	ibcs2_sco_uname.numcpu = 1;
189	return copyout((caddr_t)&ibcs2_sco_uname,
190		       (caddr_t)(void *)(intptr_t)uap->addr,
191		       sizeof(struct ibcs2_sco_utsname));
192}
193
194int
195xenix_scoinfo(struct thread *td, struct xenix_scoinfo_args *uap)
196{
197  /* scoinfo (not documented) */
198  td->td_retval[0] = 0;
199  return 0;
200}
201
202int
203xenix_eaccess(struct thread *td, struct xenix_eaccess_args *uap)
204{
205	char *path;
206        int error, bsd_flags;
207
208	bsd_flags = 0;
209	if (uap->flags & IBCS2_R_OK)
210		bsd_flags |= R_OK;
211	if (uap->flags & IBCS2_W_OK)
212		bsd_flags |= W_OK;
213	if (uap->flags & IBCS2_X_OK)
214		bsd_flags |= X_OK;
215
216	CHECKALTEXIST(td, uap->path, &path);
217	error = kern_eaccess(td, path, UIO_SYSSPACE, bsd_flags);
218	free(path, M_TEMP);
219        return (error);
220}
221