ibcs2_xenix.c revision 160192
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 160192 2006-07-08 20:12:14Z 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/unistd.h> 46 47#include <machine/cpu.h> 48 49#include <i386/ibcs2/ibcs2_types.h> 50#include <i386/ibcs2/ibcs2_unistd.h> 51#include <i386/ibcs2/ibcs2_signal.h> 52#include <i386/ibcs2/ibcs2_util.h> 53#include <i386/ibcs2/ibcs2_proto.h> 54#include <i386/ibcs2/ibcs2_xenix.h> 55#include <i386/ibcs2/ibcs2_xenix_syscall.h> 56 57 58extern struct sysent xenix_sysent[]; 59 60int 61ibcs2_xenix(struct thread *td, struct ibcs2_xenix_args *uap) 62{ 63 struct trapframe *tf = td->td_frame; 64 struct sysent *callp; 65 u_int code; 66 int error; 67 68 code = (tf->tf_eax & 0xff00) >> 8; 69 callp = &xenix_sysent[code]; 70 71 if (code < IBCS2_XENIX_MAXSYSCALL) { 72 if ((callp->sy_narg & SYF_MPSAFE) == 0) 73 mtx_lock(&Giant); 74 error = ((*callp->sy_call)(td, (void *)uap)); 75 if ((callp->sy_narg & SYF_MPSAFE) == 0) 76 mtx_unlock(&Giant); 77 } else 78 error = ENOSYS; 79 return (error); 80} 81 82int 83xenix_rdchk(td, uap) 84 struct thread *td; 85 struct xenix_rdchk_args *uap; 86{ 87 int data, error; 88 89 DPRINTF(("IBCS2: 'xenix rdchk'\n")); 90 91 error = kern_ioctl(td, uap->fd, FIONREAD, (caddr_t)&data); 92 if (error) 93 return (error); 94 td->td_retval[0] = data ? 1 : 0; 95 return (0); 96} 97 98int 99xenix_chsize(td, uap) 100 struct thread *td; 101 struct xenix_chsize_args *uap; 102{ 103 struct ftruncate_args sa; 104 105 DPRINTF(("IBCS2: 'xenix chsize'\n")); 106 sa.fd = uap->fd; 107 sa.pad = 0; 108 sa.length = uap->size; 109 return 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 while (tsleep(&period, PPAUSE, "nap", period) 146 != EWOULDBLOCK) ; 147 return 0; 148} 149 150int 151xenix_utsname(struct thread *td, struct xenix_utsname_args *uap) 152{ 153 struct ibcs2_sco_utsname { 154 char sysname[9]; 155 char nodename[9]; 156 char release[16]; 157 char kernelid[20]; 158 char machine[9]; 159 char bustype[9]; 160 char sysserial[10]; 161 unsigned short sysorigin; 162 unsigned short sysoem; 163 char numusers[9]; 164 unsigned short numcpu; 165 } ibcs2_sco_uname; 166 167 DPRINTF(("IBCS2: 'xenix sco_utsname'\n")); 168 bzero(&ibcs2_sco_uname, sizeof(struct ibcs2_sco_utsname)); 169 strncpy(ibcs2_sco_uname.sysname, ostype, 170 sizeof(ibcs2_sco_uname.sysname) - 1); 171 getcredhostname(td->td_ucred, ibcs2_sco_uname.nodename, 172 sizeof(ibcs2_sco_uname.nodename) - 1); 173 strncpy(ibcs2_sco_uname.release, osrelease, 174 sizeof(ibcs2_sco_uname.release) - 1); 175 strncpy(ibcs2_sco_uname.kernelid, version, 176 sizeof(ibcs2_sco_uname.kernelid) - 1); 177 strncpy(ibcs2_sco_uname.machine, machine, 178 sizeof(ibcs2_sco_uname.machine) - 1); 179 strncpy(ibcs2_sco_uname.bustype, "ISA/EISA", 180 sizeof(ibcs2_sco_uname.bustype) - 1); 181 strncpy(ibcs2_sco_uname.sysserial, "no charge", 182 sizeof(ibcs2_sco_uname.sysserial) - 1); 183 strncpy(ibcs2_sco_uname.numusers, "unlim", 184 sizeof(ibcs2_sco_uname.numusers) - 1); 185 ibcs2_sco_uname.sysorigin = 0xFFFF; 186 ibcs2_sco_uname.sysoem = 0xFFFF; 187 ibcs2_sco_uname.numcpu = 1; 188 return copyout((caddr_t)&ibcs2_sco_uname, 189 (caddr_t)(void *)(intptr_t)uap->addr, 190 sizeof(struct ibcs2_sco_utsname)); 191} 192 193int 194xenix_scoinfo(struct thread *td, struct xenix_scoinfo_args *uap) 195{ 196 /* scoinfo (not documented) */ 197 td->td_retval[0] = 0; 198 return 0; 199} 200 201int 202xenix_eaccess(struct thread *td, struct xenix_eaccess_args *uap) 203{ 204 char *path; 205 int error, bsd_flags; 206 207 bsd_flags = 0; 208 if (uap->flags & IBCS2_R_OK) 209 bsd_flags |= R_OK; 210 if (uap->flags & IBCS2_W_OK) 211 bsd_flags |= W_OK; 212 if (uap->flags & IBCS2_X_OK) 213 bsd_flags |= X_OK; 214 215 CHECKALTEXIST(td, uap->path, &path); 216 error = kern_eaccess(td, path, UIO_SYSSPACE, bsd_flags); 217 free(path, M_TEMP); 218 return (error); 219} 220