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