ibcs2_xenix.c revision 162954
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 162954 2006-10-02 12:59:59Z phk $"); 33115684Sobrien 343584Ssos#include <sys/param.h> 3511397Sswallace#include <sys/systm.h> 3614885Sswallace#include <sys/namei.h> 3711397Sswallace#include <sys/sysproto.h> 38162954Sphk#include <sys/clock.h> 3991388Srobert#include <sys/jail.h> 4011397Sswallace#include <sys/kernel.h> 41141488Sjhb#include <sys/malloc.h> 4224205Sbde#include <sys/filio.h> 4311397Sswallace#include <sys/vnode.h> 44141488Sjhb#include <sys/syscallsubr.h> 4511397Sswallace#include <sys/sysctl.h> 46160241Sjhb#include <sys/sysent.h> 47141488Sjhb#include <sys/unistd.h> 4811397Sswallace 493584Ssos#include <machine/cpu.h> 503584Ssos 5111397Sswallace#include <i386/ibcs2/ibcs2_types.h> 5214885Sswallace#include <i386/ibcs2/ibcs2_unistd.h> 5311397Sswallace#include <i386/ibcs2/ibcs2_signal.h> 5411397Sswallace#include <i386/ibcs2/ibcs2_util.h> 5511397Sswallace#include <i386/ibcs2/ibcs2_proto.h> 5611397Sswallace#include <i386/ibcs2/ibcs2_xenix.h> 5711397Sswallace#include <i386/ibcs2/ibcs2_xenix_syscall.h> 583584Ssos 5954655Seivind 6011397Sswallaceextern struct sysent xenix_sysent[]; 6111397Sswallace 6211397Sswallaceint 6383366Sjulianibcs2_xenix(struct thread *td, struct ibcs2_xenix_args *uap) 643584Ssos{ 6583366Sjulian struct trapframe *tf = td->td_frame; 6611397Sswallace struct sysent *callp; 67147820Sjhb u_int code; 68147820Sjhb int error; 693584Ssos 7011397Sswallace code = (tf->tf_eax & 0xff00) >> 8; 7111397Sswallace callp = &xenix_sysent[code]; 7211397Sswallace 73160798Sjhb if (code < IBCS2_XENIX_MAXSYSCALL) 74147820Sjhb error = ((*callp->sy_call)(td, (void *)uap)); 75160798Sjhb else 76147820Sjhb error = ENOSYS; 77147820Sjhb return (error); 783584Ssos} 793584Ssos 8011397Sswallaceint 8183366Sjulianxenix_rdchk(td, uap) 8283366Sjulian struct thread *td; 8311397Sswallace struct xenix_rdchk_args *uap; 8411397Sswallace{ 85160192Sjhb int data, error; 863584Ssos 8711397Sswallace DPRINTF(("IBCS2: 'xenix rdchk'\n")); 88160192Sjhb 89160192Sjhb error = kern_ioctl(td, uap->fd, FIONREAD, (caddr_t)&data); 90160192Sjhb if (error) 91160192Sjhb return (error); 92160192Sjhb td->td_retval[0] = data ? 1 : 0; 93160192Sjhb return (0); 9411397Sswallace} 9511397Sswallace 9611397Sswallaceint 9783366Sjulianxenix_chsize(td, uap) 9883366Sjulian struct thread *td; 9911397Sswallace struct xenix_chsize_args *uap; 1003584Ssos{ 10111397Sswallace struct ftruncate_args sa; 1023584Ssos 10311397Sswallace DPRINTF(("IBCS2: 'xenix chsize'\n")); 104107849Salfred sa.fd = uap->fd; 105107849Salfred sa.pad = 0; 106107849Salfred sa.length = uap->size; 10783366Sjulian return ftruncate(td, &sa); 1083584Ssos} 1093584Ssos 1103584Ssos 11111397Sswallaceint 11283366Sjulianxenix_ftime(td, uap) 11383366Sjulian struct thread *td; 11411397Sswallace struct xenix_ftime_args *uap; 1153584Ssos{ 11611397Sswallace struct timeval tv; 11726819Ssef struct ibcs2_timeb { 118103870Salfred unsigned long time __packed; 11926819Ssef unsigned short millitm; 12026819Ssef short timezone; 12126819Ssef short dstflag; 12226819Ssef } itb; 12311397Sswallace 12411397Sswallace DPRINTF(("IBCS2: 'xenix ftime'\n")); 12511397Sswallace microtime(&tv); 12611397Sswallace itb.time = tv.tv_sec; 12711397Sswallace itb.millitm = (tv.tv_usec / 1000); 128110299Sphk itb.timezone = tz_minuteswest; 129110299Sphk itb.dstflag = tz_dsttime != DST_NONE; 13011397Sswallace 131107849Salfred return copyout((caddr_t)&itb, (caddr_t)uap->tp, 13226819Ssef sizeof(struct ibcs2_timeb)); 13311397Sswallace} 13411397Sswallace 13511397Sswallaceint 13683366Sjulianxenix_nap(struct thread *td, struct xenix_nap_args *uap) 13711397Sswallace{ 1383584Ssos long period; 1393584Ssos 140107849Salfred DPRINTF(("IBCS2: 'xenix nap %d ms'\n", uap->millisec)); 141107849Salfred period = (long)uap->millisec / (1000/hz); 1423584Ssos if (period) 14336582Sdyson while (tsleep(&period, PPAUSE, "nap", period) 1443584Ssos != EWOULDBLOCK) ; 1453584Ssos return 0; 1463584Ssos} 1473584Ssos 14811397Sswallaceint 14983366Sjulianxenix_utsname(struct thread *td, struct xenix_utsname_args *uap) 1503584Ssos{ 1513584Ssos struct ibcs2_sco_utsname { 1523584Ssos char sysname[9]; 1533584Ssos char nodename[9]; 1543584Ssos char release[16]; 1553584Ssos char kernelid[20]; 1563584Ssos char machine[9]; 1573584Ssos char bustype[9]; 1583584Ssos char sysserial[10]; 1593584Ssos unsigned short sysorigin; 1603584Ssos unsigned short sysoem; 1613584Ssos char numusers[9]; 1623584Ssos unsigned short numcpu; 1633584Ssos } ibcs2_sco_uname; 1643584Ssos 16511397Sswallace DPRINTF(("IBCS2: 'xenix sco_utsname'\n")); 1663584Ssos bzero(&ibcs2_sco_uname, sizeof(struct ibcs2_sco_utsname)); 16741514Sarchie strncpy(ibcs2_sco_uname.sysname, ostype, 16841514Sarchie sizeof(ibcs2_sco_uname.sysname) - 1); 16991393Srobert getcredhostname(td->td_ucred, ibcs2_sco_uname.nodename, 17091388Srobert sizeof(ibcs2_sco_uname.nodename) - 1); 17141514Sarchie strncpy(ibcs2_sco_uname.release, osrelease, 17241514Sarchie sizeof(ibcs2_sco_uname.release) - 1); 17341514Sarchie strncpy(ibcs2_sco_uname.kernelid, version, 17441514Sarchie sizeof(ibcs2_sco_uname.kernelid) - 1); 17541514Sarchie strncpy(ibcs2_sco_uname.machine, machine, 17641514Sarchie sizeof(ibcs2_sco_uname.machine) - 1); 17741514Sarchie strncpy(ibcs2_sco_uname.bustype, "ISA/EISA", 17841514Sarchie sizeof(ibcs2_sco_uname.bustype) - 1); 17941514Sarchie strncpy(ibcs2_sco_uname.sysserial, "no charge", 18041514Sarchie sizeof(ibcs2_sco_uname.sysserial) - 1); 18141514Sarchie strncpy(ibcs2_sco_uname.numusers, "unlim", 18241514Sarchie sizeof(ibcs2_sco_uname.numusers) - 1); 1833584Ssos ibcs2_sco_uname.sysorigin = 0xFFFF; 1843584Ssos ibcs2_sco_uname.sysoem = 0xFFFF; 1853584Ssos ibcs2_sco_uname.numcpu = 1; 18638354Sbde return copyout((caddr_t)&ibcs2_sco_uname, 18738354Sbde (caddr_t)(void *)(intptr_t)uap->addr, 1883584Ssos sizeof(struct ibcs2_sco_utsname)); 1893584Ssos} 1903584Ssos 1913584Ssosint 19283366Sjulianxenix_scoinfo(struct thread *td, struct xenix_scoinfo_args *uap) 1933584Ssos{ 19411397Sswallace /* scoinfo (not documented) */ 19583366Sjulian td->td_retval[0] = 0; 19611397Sswallace return 0; 1973584Ssos} 19814885Sswallace 19914885Sswallaceint 20083366Sjulianxenix_eaccess(struct thread *td, struct xenix_eaccess_args *uap) 20114885Sswallace{ 202141488Sjhb char *path; 203141488Sjhb int error, bsd_flags; 20414885Sswallace 205141488Sjhb bsd_flags = 0; 206141488Sjhb if (uap->flags & IBCS2_R_OK) 207141488Sjhb bsd_flags |= R_OK; 208141488Sjhb if (uap->flags & IBCS2_W_OK) 209141488Sjhb bsd_flags |= W_OK; 210141488Sjhb if (uap->flags & IBCS2_X_OK) 211141488Sjhb bsd_flags |= X_OK; 21214885Sswallace 213141488Sjhb CHECKALTEXIST(td, uap->path, &path); 214155401Sjhb error = kern_eaccess(td, path, UIO_SYSSPACE, bsd_flags); 215141488Sjhb free(path, M_TEMP); 216141488Sjhb return (error); 21714885Sswallace} 218