ibcs2_xenix.c revision 147820
13584Ssos/*-
23584Ssos * Copyright (c) 1994 Sean Eric Fagan
33584Ssos * Copyright (c) 1994 S�ren Schmidt
411397Sswallace * Copyright (c) 1995 Steven Wallace
53584Ssos * All rights reserved.
63584Ssos *
73584Ssos * Redistribution and use in source and binary forms, with or without
83584Ssos * modification, are permitted provided that the following conditions
93584Ssos * are met:
103584Ssos * 1. Redistributions of source code must retain the above copyright
113584Ssos *    notice, this list of conditions and the following disclaimer
123584Ssos *    in this position and unchanged.
133584Ssos * 2. Redistributions in binary form must reproduce the above copyright
143584Ssos *    notice, this list of conditions and the following disclaimer in the
153584Ssos *    documentation and/or other materials provided with the distribution.
163584Ssos * 3. The name of the author may not be used to endorse or promote products
1797748Sschweikh *    derived from this software without specific prior written permission
183584Ssos *
193584Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
203584Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
213584Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223584Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
233584Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
243584Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
253584Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
263584Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
273584Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
283584Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
293584Ssos */
303584Ssos
31115684Sobrien#include <sys/cdefs.h>
32115684Sobrien__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_xenix.c 147820 2005-07-07 19:28:55Z jhb $");
33115684Sobrien
343584Ssos#include <sys/param.h>
3511397Sswallace#include <sys/systm.h>
3614885Sswallace#include <sys/namei.h>
3711397Sswallace#include <sys/sysproto.h>
3891388Srobert#include <sys/jail.h>
3911397Sswallace#include <sys/kernel.h>
40141488Sjhb#include <sys/malloc.h>
4124205Sbde#include <sys/filio.h>
4211397Sswallace#include <sys/vnode.h>
43141488Sjhb#include <sys/syscallsubr.h>
4411397Sswallace#include <sys/sysctl.h>
45141488Sjhb#include <sys/unistd.h>
4611397Sswallace
473584Ssos#include <machine/cpu.h>
483584Ssos
4911397Sswallace#include <i386/ibcs2/ibcs2_types.h>
5014885Sswallace#include <i386/ibcs2/ibcs2_unistd.h>
5111397Sswallace#include <i386/ibcs2/ibcs2_signal.h>
5211397Sswallace#include <i386/ibcs2/ibcs2_util.h>
5311397Sswallace#include <i386/ibcs2/ibcs2_proto.h>
5411397Sswallace#include <i386/ibcs2/ibcs2_xenix.h>
5511397Sswallace#include <i386/ibcs2/ibcs2_xenix_syscall.h>
563584Ssos
5754655Seivind
5811397Sswallaceextern struct sysent xenix_sysent[];
5911397Sswallace
6011397Sswallaceint
6183366Sjulianibcs2_xenix(struct thread *td, struct ibcs2_xenix_args *uap)
623584Ssos{
6383366Sjulian	struct trapframe *tf = td->td_frame;
6411397Sswallace        struct sysent *callp;
65147820Sjhb        u_int code;
66147820Sjhb	int error;
673584Ssos
6811397Sswallace	code = (tf->tf_eax & 0xff00) >> 8;
6911397Sswallace	callp = &xenix_sysent[code];
7011397Sswallace
71147820Sjhb	if (code < IBCS2_XENIX_MAXSYSCALL) {
72147820Sjhb		if ((callp->sy_narg & SYF_MPSAFE) == 0)
73147820Sjhb			mtx_lock(&Giant);
74147820Sjhb		error = ((*callp->sy_call)(td, (void *)uap));
75147820Sjhb		if ((callp->sy_narg & SYF_MPSAFE) == 0)
76147820Sjhb			mtx_unlock(&Giant);
77147820Sjhb	} else
78147820Sjhb		error = ENOSYS;
79147820Sjhb	return (error);
803584Ssos}
813584Ssos
8211397Sswallaceint
8383366Sjulianxenix_rdchk(td, uap)
8483366Sjulian	struct thread *td;
8511397Sswallace	struct xenix_rdchk_args *uap;
8611397Sswallace{
8711397Sswallace	int error;
8811397Sswallace	struct ioctl_args sa;
8911397Sswallace	caddr_t sg = stackgap_init();
903584Ssos
9111397Sswallace	DPRINTF(("IBCS2: 'xenix rdchk'\n"));
92107849Salfred	sa.fd = uap->fd;
93107849Salfred	sa.com = FIONREAD;
94107849Salfred	sa.data = stackgap_alloc(&sg, sizeof(int));
9583366Sjulian	if ((error = ioctl(td, &sa)) != 0)
9611397Sswallace		return error;
97107849Salfred	td->td_retval[0] = (*((int*)sa.data)) ? 1 : 0;
9811397Sswallace	return 0;
9911397Sswallace}
10011397Sswallace
10111397Sswallaceint
10283366Sjulianxenix_chsize(td, uap)
10383366Sjulian	struct thread *td;
10411397Sswallace	struct xenix_chsize_args *uap;
1053584Ssos{
10611397Sswallace	struct ftruncate_args sa;
1073584Ssos
10811397Sswallace	DPRINTF(("IBCS2: 'xenix chsize'\n"));
109107849Salfred	sa.fd = uap->fd;
110107849Salfred	sa.pad = 0;
111107849Salfred	sa.length = uap->size;
11283366Sjulian	return ftruncate(td, &sa);
1133584Ssos}
1143584Ssos
1153584Ssos
11611397Sswallaceint
11783366Sjulianxenix_ftime(td, uap)
11883366Sjulian	struct thread *td;
11911397Sswallace	struct xenix_ftime_args *uap;
1203584Ssos{
12111397Sswallace	struct timeval tv;
12226819Ssef	struct ibcs2_timeb {
123103870Salfred		unsigned long time __packed;
12426819Ssef		unsigned short millitm;
12526819Ssef		short timezone;
12626819Ssef		short dstflag;
12726819Ssef	} itb;
12811397Sswallace
12911397Sswallace	DPRINTF(("IBCS2: 'xenix ftime'\n"));
13011397Sswallace	microtime(&tv);
13111397Sswallace	itb.time = tv.tv_sec;
13211397Sswallace	itb.millitm = (tv.tv_usec / 1000);
133110299Sphk	itb.timezone = tz_minuteswest;
134110299Sphk	itb.dstflag = tz_dsttime != DST_NONE;
13511397Sswallace
136107849Salfred	return copyout((caddr_t)&itb, (caddr_t)uap->tp,
13726819Ssef		       sizeof(struct ibcs2_timeb));
13811397Sswallace}
13911397Sswallace
14011397Sswallaceint
14183366Sjulianxenix_nap(struct thread *td, struct xenix_nap_args *uap)
14211397Sswallace{
1433584Ssos	long period;
1443584Ssos
145107849Salfred	DPRINTF(("IBCS2: 'xenix nap %d ms'\n", uap->millisec));
146107849Salfred	period = (long)uap->millisec / (1000/hz);
1473584Ssos	if (period)
14836582Sdyson		while (tsleep(&period, PPAUSE, "nap", period)
1493584Ssos		       != EWOULDBLOCK) ;
1503584Ssos	return 0;
1513584Ssos}
1523584Ssos
15311397Sswallaceint
15483366Sjulianxenix_utsname(struct thread *td, struct xenix_utsname_args *uap)
1553584Ssos{
1563584Ssos	struct ibcs2_sco_utsname {
1573584Ssos		char sysname[9];
1583584Ssos		char nodename[9];
1593584Ssos		char release[16];
1603584Ssos		char kernelid[20];
1613584Ssos		char machine[9];
1623584Ssos		char bustype[9];
1633584Ssos		char sysserial[10];
1643584Ssos		unsigned short sysorigin;
1653584Ssos		unsigned short sysoem;
1663584Ssos		char numusers[9];
1673584Ssos		unsigned short numcpu;
1683584Ssos	} ibcs2_sco_uname;
1693584Ssos
17011397Sswallace	DPRINTF(("IBCS2: 'xenix sco_utsname'\n"));
1713584Ssos	bzero(&ibcs2_sco_uname, sizeof(struct ibcs2_sco_utsname));
17241514Sarchie	strncpy(ibcs2_sco_uname.sysname, ostype,
17341514Sarchie		sizeof(ibcs2_sco_uname.sysname) - 1);
17491393Srobert	getcredhostname(td->td_ucred, ibcs2_sco_uname.nodename,
17591388Srobert	    sizeof(ibcs2_sco_uname.nodename) - 1);
17641514Sarchie	strncpy(ibcs2_sco_uname.release, osrelease,
17741514Sarchie		sizeof(ibcs2_sco_uname.release) - 1);
17841514Sarchie	strncpy(ibcs2_sco_uname.kernelid, version,
17941514Sarchie		sizeof(ibcs2_sco_uname.kernelid) - 1);
18041514Sarchie	strncpy(ibcs2_sco_uname.machine, machine,
18141514Sarchie		sizeof(ibcs2_sco_uname.machine) - 1);
18241514Sarchie	strncpy(ibcs2_sco_uname.bustype, "ISA/EISA",
18341514Sarchie		sizeof(ibcs2_sco_uname.bustype) - 1);
18441514Sarchie	strncpy(ibcs2_sco_uname.sysserial, "no charge",
18541514Sarchie		sizeof(ibcs2_sco_uname.sysserial) - 1);
18641514Sarchie	strncpy(ibcs2_sco_uname.numusers, "unlim",
18741514Sarchie		sizeof(ibcs2_sco_uname.numusers) - 1);
1883584Ssos	ibcs2_sco_uname.sysorigin = 0xFFFF;
1893584Ssos	ibcs2_sco_uname.sysoem = 0xFFFF;
1903584Ssos	ibcs2_sco_uname.numcpu = 1;
19138354Sbde	return copyout((caddr_t)&ibcs2_sco_uname,
19238354Sbde		       (caddr_t)(void *)(intptr_t)uap->addr,
1933584Ssos		       sizeof(struct ibcs2_sco_utsname));
1943584Ssos}
1953584Ssos
1963584Ssosint
19783366Sjulianxenix_scoinfo(struct thread *td, struct xenix_scoinfo_args *uap)
1983584Ssos{
19911397Sswallace  /* scoinfo (not documented) */
20083366Sjulian  td->td_retval[0] = 0;
20111397Sswallace  return 0;
2023584Ssos}
20314885Sswallace
20414885Sswallaceint
20583366Sjulianxenix_eaccess(struct thread *td, struct xenix_eaccess_args *uap)
20614885Sswallace{
207141488Sjhb	char *path;
208141488Sjhb        int error, bsd_flags;
20914885Sswallace
210141488Sjhb	bsd_flags = 0;
211141488Sjhb	if (uap->flags & IBCS2_R_OK)
212141488Sjhb		bsd_flags |= R_OK;
213141488Sjhb	if (uap->flags & IBCS2_W_OK)
214141488Sjhb		bsd_flags |= W_OK;
215141488Sjhb	if (uap->flags & IBCS2_X_OK)
216141488Sjhb		bsd_flags |= X_OK;
21714885Sswallace
218141488Sjhb	CHECKALTEXIST(td, uap->path, &path);
219141488Sjhb	error = kern_access(td, path, UIO_SYSSPACE, bsd_flags);
220141488Sjhb	free(path, M_TEMP);
221141488Sjhb        return (error);
22214885Sswallace}
223