ibcs2_xenix.c revision 141488
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 141488 2005-02-07 22:02:18Z 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 67 code = (tf->tf_eax & 0xff00) >> 8; 68 callp = &xenix_sysent[code]; 69 70 if(code < IBCS2_XENIX_MAXSYSCALL) 71 return((*callp->sy_call)(td, (void *)uap)); 72 else 73 return ENOSYS; 74} 75 76int 77xenix_rdchk(td, uap) 78 struct thread *td; 79 struct xenix_rdchk_args *uap; 80{ 81 int error; 82 struct ioctl_args sa; 83 caddr_t sg = stackgap_init(); 84 85 DPRINTF(("IBCS2: 'xenix rdchk'\n")); 86 sa.fd = uap->fd; 87 sa.com = FIONREAD; 88 sa.data = stackgap_alloc(&sg, sizeof(int)); 89 if ((error = ioctl(td, &sa)) != 0) 90 return error; 91 td->td_retval[0] = (*((int*)sa.data)) ? 1 : 0; 92 return 0; 93} 94 95int 96xenix_chsize(td, uap) 97 struct thread *td; 98 struct xenix_chsize_args *uap; 99{ 100 struct ftruncate_args sa; 101 102 DPRINTF(("IBCS2: 'xenix chsize'\n")); 103 sa.fd = uap->fd; 104 sa.pad = 0; 105 sa.length = uap->size; 106 return ftruncate(td, &sa); 107} 108 109 110int 111xenix_ftime(td, uap) 112 struct thread *td; 113 struct xenix_ftime_args *uap; 114{ 115 struct timeval tv; 116 struct ibcs2_timeb { 117 unsigned long time __packed; 118 unsigned short millitm; 119 short timezone; 120 short dstflag; 121 } itb; 122 123 DPRINTF(("IBCS2: 'xenix ftime'\n")); 124 microtime(&tv); 125 itb.time = tv.tv_sec; 126 itb.millitm = (tv.tv_usec / 1000); 127 itb.timezone = tz_minuteswest; 128 itb.dstflag = tz_dsttime != DST_NONE; 129 130 return copyout((caddr_t)&itb, (caddr_t)uap->tp, 131 sizeof(struct ibcs2_timeb)); 132} 133 134int 135xenix_nap(struct thread *td, struct xenix_nap_args *uap) 136{ 137 long period; 138 139 DPRINTF(("IBCS2: 'xenix nap %d ms'\n", uap->millisec)); 140 period = (long)uap->millisec / (1000/hz); 141 if (period) 142 while (tsleep(&period, PPAUSE, "nap", period) 143 != EWOULDBLOCK) ; 144 return 0; 145} 146 147int 148xenix_utsname(struct thread *td, struct xenix_utsname_args *uap) 149{ 150 struct ibcs2_sco_utsname { 151 char sysname[9]; 152 char nodename[9]; 153 char release[16]; 154 char kernelid[20]; 155 char machine[9]; 156 char bustype[9]; 157 char sysserial[10]; 158 unsigned short sysorigin; 159 unsigned short sysoem; 160 char numusers[9]; 161 unsigned short numcpu; 162 } ibcs2_sco_uname; 163 164 DPRINTF(("IBCS2: 'xenix sco_utsname'\n")); 165 bzero(&ibcs2_sco_uname, sizeof(struct ibcs2_sco_utsname)); 166 strncpy(ibcs2_sco_uname.sysname, ostype, 167 sizeof(ibcs2_sco_uname.sysname) - 1); 168 getcredhostname(td->td_ucred, ibcs2_sco_uname.nodename, 169 sizeof(ibcs2_sco_uname.nodename) - 1); 170 strncpy(ibcs2_sco_uname.release, osrelease, 171 sizeof(ibcs2_sco_uname.release) - 1); 172 strncpy(ibcs2_sco_uname.kernelid, version, 173 sizeof(ibcs2_sco_uname.kernelid) - 1); 174 strncpy(ibcs2_sco_uname.machine, machine, 175 sizeof(ibcs2_sco_uname.machine) - 1); 176 strncpy(ibcs2_sco_uname.bustype, "ISA/EISA", 177 sizeof(ibcs2_sco_uname.bustype) - 1); 178 strncpy(ibcs2_sco_uname.sysserial, "no charge", 179 sizeof(ibcs2_sco_uname.sysserial) - 1); 180 strncpy(ibcs2_sco_uname.numusers, "unlim", 181 sizeof(ibcs2_sco_uname.numusers) - 1); 182 ibcs2_sco_uname.sysorigin = 0xFFFF; 183 ibcs2_sco_uname.sysoem = 0xFFFF; 184 ibcs2_sco_uname.numcpu = 1; 185 return copyout((caddr_t)&ibcs2_sco_uname, 186 (caddr_t)(void *)(intptr_t)uap->addr, 187 sizeof(struct ibcs2_sco_utsname)); 188} 189 190int 191xenix_scoinfo(struct thread *td, struct xenix_scoinfo_args *uap) 192{ 193 /* scoinfo (not documented) */ 194 td->td_retval[0] = 0; 195 return 0; 196} 197 198int 199xenix_eaccess(struct thread *td, struct xenix_eaccess_args *uap) 200{ 201 char *path; 202 int error, bsd_flags; 203 204 bsd_flags = 0; 205 if (uap->flags & IBCS2_R_OK) 206 bsd_flags |= R_OK; 207 if (uap->flags & IBCS2_W_OK) 208 bsd_flags |= W_OK; 209 if (uap->flags & IBCS2_X_OK) 210 bsd_flags |= X_OK; 211 212 CHECKALTEXIST(td, uap->path, &path); 213 error = kern_access(td, path, UIO_SYSSPACE, bsd_flags); 214 free(path, M_TEMP); 215 return (error); 216} 217