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