diff options
Diffstat (limited to 'sys/compat/svr4')
56 files changed, 14053 insertions, 0 deletions
diff --git a/sys/compat/svr4/Makefile b/sys/compat/svr4/Makefile new file mode 100644 index 0000000..d8fd59b --- /dev/null +++ b/sys/compat/svr4/Makefile @@ -0,0 +1,13 @@ +# Makefile for syscall tables +# +# $Id: Makefile,v 1.3 1997/03/29 11:17:26 peter Exp $ + +all: + @echo "make svr4_sysent.c only" + +svr4_sysent.c svr4_syscall.h svr4_proto.h: ../kern/makesyscalls.sh \ + syscalls.master syscalls.conf + -mv -f svr4_sysent.c svr4_sysent.c.bak + -mv -f svr4_syscall.h svr4_syscall.h.bak + -mv -f svr4_proto.h svr4_proto.h.bak + sh ../kern/makesyscalls.sh syscalls.master syscalls.conf diff --git a/sys/compat/svr4/imgact_svr4.c b/sys/compat/svr4/imgact_svr4.c new file mode 100644 index 0000000..1324805 --- /dev/null +++ b/sys/compat/svr4/imgact_svr4.c @@ -0,0 +1,237 @@ +/*- + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994-1996 Søren Schmidt + * All rights reserved. + * + * Based heavily on /sys/kern/imgact_aout.c which is: + * Copyright (c) 1993, David Greenman + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/resourcevar.h> +#include <sys/exec.h> +#include <sys/mman.h> +#include <sys/imgact.h> +#include <sys/imgact_aout.h> +#include <sys/kernel.h> +#include <sys/lock.h> +#include <sys/proc.h> +#include <sys/vnode.h> + +#include <vm/vm.h> +#include <vm/vm_kern.h> +#include <vm/vm_param.h> +#include <vm/pmap.h> +#include <vm/vm_map.h> +#include <vm/vm_prot.h> +#include <vm/vm_extern.h> + +#include <svr4/svr4.h> + +static int exec_svr4_imgact __P((struct image_params *iparams)); + +static int +exec_svr4_imgact(imgp) + struct image_params *imgp; +{ + const struct exec *a_out = (const struct exec *) imgp->image_header; + struct vmspace *vmspace; + vm_offset_t vmaddr; + unsigned long virtual_offset, file_offset; + vm_offset_t buffer; + unsigned long bss_size; + int error; + + if (((a_out->a_magic >> 16) & 0xff) != 0x64) + return -1; + + /* + * Set file/virtual offset based on a.out variant. + */ + switch ((int)(a_out->a_magic & 0xffff)) { + case 0413: + virtual_offset = 0; + file_offset = 1024; + break; + case 0314: + virtual_offset = 4096; + file_offset = 0; + break; + default: + return (-1); + } + bss_size = round_page(a_out->a_bss); +#ifdef DEBUG + printf("imgact: text: %08x, data: %08x, bss: %08x\n", a_out->a_text, a_out->a_data, bss_size); +#endif + + /* + * Check various fields in header for validity/bounds. + */ + if (a_out->a_entry < virtual_offset || + a_out->a_entry >= virtual_offset + a_out->a_text || + a_out->a_text & PAGE_MASK || a_out->a_data & PAGE_MASK) + return (-1); + + /* text + data can't exceed file size */ + if (a_out->a_data + a_out->a_text > imgp->attr->va_size) + return (EFAULT); + /* + * text/data/bss must not exceed limits + */ + if (a_out->a_text > MAXTSIZ || + a_out->a_data + bss_size > imgp->proc->p_rlimit[RLIMIT_DATA].rlim_cur) + return (ENOMEM); + + /* copy in arguments and/or environment from old process */ + error = exec_extract_strings(imgp); + if (error) + return (error); + + /* + * Destroy old process VM and create a new one (with a new stack) + */ + exec_new_vmspace(imgp); + vmspace = imgp->proc->p_vmspace; + + /* + * Check if file_offset page aligned,. + * Currently we cannot handle misalinged file offsets, + * and so we read in the entire image (what a waste). + */ + if (file_offset & PAGE_MASK) { +#ifdef DEBUG + printf("imgact: Non page aligned binary %d\n", file_offset); +#endif + /* + * Map text+data+bss read/write/execute + */ + vmaddr = virtual_offset; + error = vm_map_find(&vmspace->vm_map, NULL, 0, &vmaddr, + a_out->a_text + a_out->a_data + bss_size, FALSE, + VM_PROT_ALL, VM_PROT_ALL, 0); + if (error) + return error; + + error = vm_mmap(kernel_map, &buffer, + round_page(a_out->a_text + a_out->a_data + file_offset), + VM_PROT_READ, VM_PROT_READ, 0, + (caddr_t) imgp->vp, trunc_page(file_offset)); + if (error) + return error; + + error = copyout((caddr_t)(buffer + file_offset), (caddr_t)vmaddr, + a_out->a_text + a_out->a_data); + + vm_map_remove(kernel_map, buffer, + buffer + round_page(a_out->a_text + a_out->a_data + file_offset)); + + if (error) + return error; + + /* + * remove write enable on the 'text' part + */ + error = vm_map_protect(&vmspace->vm_map, + vmaddr, + vmaddr + a_out->a_text, + VM_PROT_EXECUTE|VM_PROT_READ, + TRUE); + if (error) + return error; + } + else { +#ifdef DEBUG + printf("imgact: Page aligned binary %d\n", file_offset); +#endif + /* + * Map text+data read/execute + */ + vmaddr = virtual_offset; + error = vm_mmap(&vmspace->vm_map, &vmaddr, + a_out->a_text + a_out->a_data, + VM_PROT_READ | VM_PROT_EXECUTE, + VM_PROT_ALL, + MAP_PRIVATE | MAP_FIXED, + (caddr_t)imgp->vp, file_offset); + if (error) + return (error); + +#ifdef DEBUG + printf("imgact: startaddr=%08x, length=%08x\n", vmaddr, a_out->a_text + a_out->a_data); +#endif + /* + * allow read/write of data + */ + error = vm_map_protect(&vmspace->vm_map, + vmaddr + a_out->a_text, + vmaddr + a_out->a_text + a_out->a_data, + VM_PROT_ALL, + FALSE); + if (error) + return (error); + + /* + * Allocate anon demand-zeroed area for uninitialized data + */ + if (bss_size != 0) { + vmaddr = virtual_offset + a_out->a_text + a_out->a_data; + error = vm_map_find(&vmspace->vm_map, NULL, 0, &vmaddr, + bss_size, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0); + if (error) + return (error); +#ifdef DEBUG + printf("imgact: bssaddr=%08x, length=%08x\n", vmaddr, bss_size); +#endif + + } + /* Indicate that this file should not be modified */ + imgp->vp->v_flag |= VTEXT; + } + /* Fill in process VM information */ + vmspace->vm_tsize = round_page(a_out->a_text) >> PAGE_SHIFT; + vmspace->vm_dsize = round_page(a_out->a_data + bss_size) >> PAGE_SHIFT; + vmspace->vm_taddr = (caddr_t)virtual_offset; + vmspace->vm_daddr = (caddr_t)virtual_offset + a_out->a_text; + + /* Fill in image_params */ + imgp->interpreted = 0; + imgp->entry_addr = a_out->a_entry; + + imgp->proc->p_sysent = &svr4_sysvec; + return (0); +} + +/* + * Tell kern_execve.c about it, with a little help from the linker. + * Since `const' objects end up in the text segment, TEXT_SET is the + * correct directive to use. Do not staticize; used by Linux LKM. + */ +const struct execsw svr4_execsw = { exec_svr4_imgact, "svr4 ELF" }; +TEXT_SET(execsw_set, svr4_execsw); + diff --git a/sys/compat/svr4/svr4.h b/sys/compat/svr4/svr4.h new file mode 100644 index 0000000..45e08b3 --- /dev/null +++ b/sys/compat/svr4/svr4.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 1998 Mark Newton + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if !defined(_SVR4_H) +#define _SVR4_H + +extern struct sysentvec svr4_sysvec; + +#define memset(x,y,z) bzero(x,z) + +#define COMPAT_SVR4_SOLARIS2 +#define KTRACE + +#endif diff --git a/sys/compat/svr4/svr4_acl.h b/sys/compat/svr4/svr4_acl.h new file mode 100644 index 0000000..2d4f10f --- /dev/null +++ b/sys/compat/svr4/svr4_acl.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1996 Christos Zoulas. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SVR4_ACL_H_ +#define _SVR4_ACL_H_ + +typedef struct svr4_aclent { + int a_type; + svr4_uid_t a_id; + svr4_o_mode_t a_perm; +} svr4_aclent_t; + +#define SVR4_SYS_GETACL 1 +#define SVR4_SYS_SETACL 2 +#define SVR4_SYS_GETACLCNT 3 + +#endif /* !_SVR4_ACL_H_ */ diff --git a/sys/compat/svr4/svr4_dirent.h b/sys/compat/svr4/svr4_dirent.h new file mode 100644 index 0000000..a2e8a59 --- /dev/null +++ b/sys/compat/svr4/svr4_dirent.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_DIRENT_H_ +#define _SVR4_DIRENT_H_ + +#define SVR4_MAXNAMLEN 512 + +struct svr4_dirent { + svr4_ino_t d_ino; + svr4_off_t d_off; + u_short d_reclen; + char d_name[SVR4_MAXNAMLEN + 1]; +}; + +struct svr4_dirent64 { + svr4_ino64_t d_ino; + svr4_off64_t d_off; + u_short d_reclen; + char d_name[SVR4_MAXNAMLEN + 1]; +}; + +#define SVR4_NAMEOFF(dp) ((char *)&(dp)->d_name - (char *)dp) +#define SVR4_RECLEN(de,namlen) ALIGN((SVR4_NAMEOFF(de) + (namlen) + 1)) + +#endif /* !_SVR4_DIRENT_H_ */ diff --git a/sys/compat/svr4/svr4_errno.h b/sys/compat/svr4/svr4_errno.h new file mode 100644 index 0000000..42de6d0 --- /dev/null +++ b/sys/compat/svr4/svr4_errno.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_ERRNO_H_ +#define _SVR4_ERRNO_H_ + +#define SVR4_EPERM 1 +#define SVR4_ENOENT 2 +#define SVR4_ESRCH 3 +#define SVR4_EINTR 4 +#define SVR4_EIO 5 +#define SVR4_ENXIO 6 +#define SVR4_E2BIG 7 +#define SVR4_ENOEXEC 8 +#define SVR4_EBADF 9 +#define SVR4_ECHILD 10 +#define SVR4_EAGAIN 11 +#define SVR4_ENOMEM 12 +#define SVR4_EACCES 13 +#define SVR4_EFAULT 14 +#define SVR4_ENOTBLK 15 +#define SVR4_EBUSY 16 +#define SVR4_EEXIST 17 +#define SVR4_EXDEV 18 +#define SVR4_ENODEV 19 +#define SVR4_ENOTDIR 20 +#define SVR4_EISDIR 21 +#define SVR4_EINVAL 22 +#define SVR4_ENFILE 23 +#define SVR4_EMFILE 24 +#define SVR4_ENOTTY 25 +#define SVR4_ETXTBSY 26 +#define SVR4_EFBIG 27 +#define SVR4_ENOSPC 28 +#define SVR4_ESPIPE 29 +#define SVR4_EROFS 30 +#define SVR4_EMLINK 31 +#define SVR4_EPIPE 32 +#define SVR4_EDOM 33 +#define SVR4_ERANGE 34 +#define SVR4_ENOMSG 35 +#define SVR4_EIDRM 36 +#define SVR4_ECHRNG 37 +#define SVR4_EL2NSYNC 38 +#define SVR4_EL3HLT 39 +#define SVR4_EL3RST 40 +#define SVR4_ELNRNG 41 +#define SVR4_EUNATCH 42 +#define SVR4_ENOCSI 43 +#define SVR4_EL2HLT 44 +#define SVR4_EDEADLK 45 +#define SVR4_ENOLCK 46 +#define SVR4_EBADE 50 +#define SVR4_EBADR 51 +#define SVR4_EXFULL 52 +#define SVR4_ENOANO 53 +#define SVR4_EBADRQC 54 +#define SVR4_EBADSLT 55 +#define SVR4_EDEADLOCK 56 +#define SVR4_EBFONT 57 +#define SVR4_ENOSTR 60 +#define SVR4_ENODATA 61 +#define SVR4_ETIME 62 +#define SVR4_ENOSR 63 +#define SVR4_ENONET 64 +#define SVR4_ENOPKG 65 +#define SVR4_EREMOTE 66 +#define SVR4_ENOLINK 67 +#define SVR4_EADV 68 +#define SVR4_ESRMNT 69 +#define SVR4_ECOMM 70 +#define SVR4_EPROTO 71 +#define SVR4_EMULTIHOP 74 +#define SVR4_EBADMSG 77 +#define SVR4_ENAMETOOLONG 78 +#define SVR4_EOVERFLOW 79 +#define SVR4_ENOTUNIQ 80 +#define SVR4_EBADFD 81 +#define SVR4_EREMCHG 82 +#define SVR4_ELIBACC 83 +#define SVR4_ELIBBAD 84 +#define SVR4_ELIBSCN 85 +#define SVR4_ELIBMAX 86 +#define SVR4_ELIBEXEC 87 +#define SVR4_EILSEQ 88 +#define SVR4_ENOSYS 89 +#define SVR4_ELOOP 90 +#define SVR4_ERESTART 91 +#define SVR4_ESTRPIPE 92 +#define SVR4_ENOTEMPTY 93 +#define SVR4_EUSERS 94 +#define SVR4_ENOTSOCK 95 +#define SVR4_EDESTADDRREQ 96 +#define SVR4_EMSGSIZE 97 +#define SVR4_EPROTOTYPE 98 +#define SVR4_ENOPROTOOPT 99 +#define SVR4_EPROTONOSUPPORT 120 +#define SVR4_ESOCKTNOSUPPORT 121 +#define SVR4_EOPNOTSUPP 122 +#define SVR4_EPFNOSUPPORT 123 +#define SVR4_EAFNOSUPPORT 124 +#define SVR4_EADDRINUSE 125 +#define SVR4_EADDRNOTAVAIL 126 +#define SVR4_ENETDOWN 127 +#define SVR4_ENETUNREACH 128 +#define SVR4_ENETRESET 129 +#define SVR4_ECONNABORTED 130 +#define SVR4_ECONNRESET 131 +#define SVR4_ENOBUFS 132 +#define SVR4_EISCONN 133 +#define SVR4_ENOTCONN 134 +#define SVR4_EUCLEAN 135 +#define SVR4_ENOTNAM 137 +#define SVR4_ENAVAIL 138 +#define SVR4_EISNAM 139 +#define SVR4_EREMOTEIO 140 +#define SVR4_EINIT 141 +#define SVR4_EREMDEV 142 +#define SVR4_ESHUTDOWN 143 +#define SVR4_ETOOMANYREFS 144 +#define SVR4_ETIMEDOUT 145 +#define SVR4_ECONNREFUSED 146 +#define SVR4_EHOSTDOWN 147 +#define SVR4_EHOSTUNREACH 148 +#define SVR4_EWOULDBLOCK SVR4_EAGAIN +#define SVR4_EALREADY 149 +#define SVR4_EINPROGRESS 150 +#define SVR4_ESTALE 151 +#define SVR4_EIORESID 500 + +/* + * These ones are not translated... + */ +#define SVR4_EPROCLIM SVR4_ENOSYS +#define SVR4_EDQUOT SVR4_ENOSYS +#define SVR4_EBADRPC SVR4_ENOSYS +#define SVR4_ERPCMISMATCH SVR4_ENOSYS +#define SVR4_EPROGUNAVAIL SVR4_ENOSYS +#define SVR4_EPROGMISMATCH SVR4_ENOSYS +#define SVR4_EPROCUNAVAIL SVR4_ENOSYS +#define SVR4_EFTYPE SVR4_ENOSYS +#define SVR4_EAUTH SVR4_ENOSYS +#define SVR4_ENEEDAUTH SVR4_ENOSYS + +#endif /* !_SVR4_ERRNO_H_ */ diff --git a/sys/compat/svr4/svr4_exec.h b/sys/compat/svr4/svr4_exec.h new file mode 100644 index 0000000..84fcd3d --- /dev/null +++ b/sys/compat/svr4/svr4_exec.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_EXEC_H_ +#define _SVR4_EXEC_H_ + +#ifdef SVR4_COMPAT_SOLARIS2 +# define SVR4_AUX_ARGSIZ (sizeof(AuxInfo) * 12 / sizeof(char *)) +#else +# define SVR4_AUX_ARGSIZ (sizeof(AuxInfo) * 8 / sizeof(char *)) +#endif + +#if 0 +/* Don't think we need all this NetBSD stuff */ +/* + * The following is horrible; there must be a better way. I need to + * play with brk(2) a bit more. + */ +#ifdef i386 +/* + * I cannot load the interpreter after the data segment because brk(2) + * breaks. I have to load it somewhere before. Programs start at + * 0x08000000 so I load the interpreter far before. + */ +#define SVR4_INTERP_ADDR 0x01000000 +#endif + +#ifdef sparc +/* + * Here programs load at 0x00010000, so I load the interpreter far after + * the end of the data segment. + */ +#define SVR4_INTERP_ADDR 0x10000000 +#endif + +#ifndef SVR4_INTERP_ADDR +# define SVR4_INTERP_ADDR 0 +#endif +#endif + +/*void svr4_setregs __P((struct proc *, struct exec_package *, u_long));*/ + +#endif /* !_SVR4_EXEC_H_ */ diff --git a/sys/compat/svr4/svr4_fcntl.c b/sys/compat/svr4/svr4_fcntl.c new file mode 100644 index 0000000..9bd403c --- /dev/null +++ b/sys/compat/svr4/svr4_fcntl.c @@ -0,0 +1,721 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994, 1997 Christos Zoulas. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/namei.h> +#include <sys/proc.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <sys/filedesc.h> +/*#include <sys/ioctl.h>*/ +#include <sys/kernel.h> +#include <sys/mount.h> +#include <sys/malloc.h> +#include <sys/vnode.h> +#include <sys/unistd.h> + +#include <sys/sysproto.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_fcntl.h> + +static int svr4_to_bsd_flags __P((int)); +static u_long svr4_to_bsd_cmd __P((u_long)); +static int fd_revoke __P((struct proc *, int)); +static int fd_truncate __P((struct proc *, int, struct flock *)); +static int bsd_to_svr4_flags __P((int)); +static void bsd_to_svr4_flock __P((struct flock *, struct svr4_flock *)); +static void svr4_to_bsd_flock __P((struct svr4_flock *, struct flock *)); +static void bsd_to_svr4_flock64 __P((struct flock *, struct svr4_flock64 *)); +static void svr4_to_bsd_flock64 __P((struct svr4_flock64 *, struct flock *)); + +static u_long +svr4_to_bsd_cmd(cmd) + u_long cmd; +{ + switch (cmd) { + case SVR4_F_DUPFD: + return F_DUPFD; + case SVR4_F_GETFD: + return F_GETFD; + case SVR4_F_SETFD: + return F_SETFD; + case SVR4_F_GETFL: + return F_GETFL; + case SVR4_F_SETFL: + return F_SETFL; + case SVR4_F_GETLK: + return F_GETLK; + case SVR4_F_SETLK: + return F_SETLK; + case SVR4_F_SETLKW: + return F_SETLKW; + default: + return -1; + } +} + +static int +svr4_to_bsd_flags(l) + int l; +{ + int r = 0; + r |= (l & SVR4_O_RDONLY) ? O_RDONLY : 0; + r |= (l & SVR4_O_WRONLY) ? O_WRONLY : 0; + r |= (l & SVR4_O_RDWR) ? O_RDWR : 0; + r |= (l & SVR4_O_NDELAY) ? O_NONBLOCK : 0; + r |= (l & SVR4_O_APPEND) ? O_APPEND : 0; + r |= (l & SVR4_O_SYNC) ? O_FSYNC : 0; + r |= (l & SVR4_O_NONBLOCK) ? O_NONBLOCK : 0; + r |= (l & SVR4_O_PRIV) ? O_EXLOCK : 0; + r |= (l & SVR4_O_CREAT) ? O_CREAT : 0; + r |= (l & SVR4_O_TRUNC) ? O_TRUNC : 0; + r |= (l & SVR4_O_EXCL) ? O_EXCL : 0; + r |= (l & SVR4_O_NOCTTY) ? O_NOCTTY : 0; + return r; +} + +static int +bsd_to_svr4_flags(l) + int l; +{ + int r = 0; + r |= (l & O_RDONLY) ? SVR4_O_RDONLY : 0; + r |= (l & O_WRONLY) ? SVR4_O_WRONLY : 0; + r |= (l & O_RDWR) ? SVR4_O_RDWR : 0; + r |= (l & O_NDELAY) ? SVR4_O_NONBLOCK : 0; + r |= (l & O_APPEND) ? SVR4_O_APPEND : 0; + r |= (l & O_FSYNC) ? SVR4_O_SYNC : 0; + r |= (l & O_NONBLOCK) ? SVR4_O_NONBLOCK : 0; + r |= (l & O_EXLOCK) ? SVR4_O_PRIV : 0; + r |= (l & O_CREAT) ? SVR4_O_CREAT : 0; + r |= (l & O_TRUNC) ? SVR4_O_TRUNC : 0; + r |= (l & O_EXCL) ? SVR4_O_EXCL : 0; + r |= (l & O_NOCTTY) ? SVR4_O_NOCTTY : 0; + return r; +} + + +static void +bsd_to_svr4_flock(iflp, oflp) + struct flock *iflp; + struct svr4_flock *oflp; +{ + switch (iflp->l_type) { + case F_RDLCK: + oflp->l_type = SVR4_F_RDLCK; + break; + case F_WRLCK: + oflp->l_type = SVR4_F_WRLCK; + break; + case F_UNLCK: + oflp->l_type = SVR4_F_UNLCK; + break; + default: + oflp->l_type = -1; + break; + } + + oflp->l_whence = (short) iflp->l_whence; + oflp->l_start = (svr4_off_t) iflp->l_start; + oflp->l_len = (svr4_off_t) iflp->l_len; + oflp->l_sysid = 0; + oflp->l_pid = (svr4_pid_t) iflp->l_pid; +} + + +static void +svr4_to_bsd_flock(iflp, oflp) + struct svr4_flock *iflp; + struct flock *oflp; +{ + switch (iflp->l_type) { + case SVR4_F_RDLCK: + oflp->l_type = F_RDLCK; + break; + case SVR4_F_WRLCK: + oflp->l_type = F_WRLCK; + break; + case SVR4_F_UNLCK: + oflp->l_type = F_UNLCK; + break; + default: + oflp->l_type = -1; + break; + } + + oflp->l_whence = iflp->l_whence; + oflp->l_start = (off_t) iflp->l_start; + oflp->l_len = (off_t) iflp->l_len; + oflp->l_pid = (pid_t) iflp->l_pid; + +} + +static void +bsd_to_svr4_flock64(iflp, oflp) + struct flock *iflp; + struct svr4_flock64 *oflp; +{ + switch (iflp->l_type) { + case F_RDLCK: + oflp->l_type = SVR4_F_RDLCK; + break; + case F_WRLCK: + oflp->l_type = SVR4_F_WRLCK; + break; + case F_UNLCK: + oflp->l_type = SVR4_F_UNLCK; + break; + default: + oflp->l_type = -1; + break; + } + + oflp->l_whence = (short) iflp->l_whence; + oflp->l_start = (svr4_off64_t) iflp->l_start; + oflp->l_len = (svr4_off64_t) iflp->l_len; + oflp->l_sysid = 0; + oflp->l_pid = (svr4_pid_t) iflp->l_pid; +} + + +static void +svr4_to_bsd_flock64(iflp, oflp) + struct svr4_flock64 *iflp; + struct flock *oflp; +{ + switch (iflp->l_type) { + case SVR4_F_RDLCK: + oflp->l_type = F_RDLCK; + break; + case SVR4_F_WRLCK: + oflp->l_type = F_WRLCK; + break; + case SVR4_F_UNLCK: + oflp->l_type = F_UNLCK; + break; + default: + oflp->l_type = -1; + break; + } + + oflp->l_whence = iflp->l_whence; + oflp->l_start = (off_t) iflp->l_start; + oflp->l_len = (off_t) iflp->l_len; + oflp->l_pid = (pid_t) iflp->l_pid; + +} + + +static int +fd_revoke(p, fd) + struct proc *p; + int fd; +{ + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + struct vattr vattr; + int error, *retval; + + retval = p->p_retval; + if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) + return EBADF; + + switch (fp->f_type) { + case DTYPE_VNODE: + vp = (struct vnode *) fp->f_data; + + case DTYPE_SOCKET: + return EINVAL; + + default: + panic("svr4_fcntl(F_REVOKE)"); + /*NOTREACHED*/ + } + + if (vp->v_type != VCHR && vp->v_type != VBLK) { + error = EINVAL; + goto out; + } + + if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0) + goto out; + + if (p->p_ucred->cr_uid != vattr.va_uid && + (error = suser(p->p_ucred, &p->p_acflag)) != 0) + goto out; + + if (vp->v_usecount > 1 || (vp->v_flag & VALIASED)) + VOP_REVOKE(vp, REVOKEALL); +out: + vrele(vp); + return error; +} + + +static int +fd_truncate(p, fd, flp) + struct proc *p; + int fd; + struct flock *flp; +{ + struct filedesc *fdp = p->p_fd; + struct file *fp; + off_t start, length; + struct vnode *vp; + struct vattr vattr; + int error, *retval; + struct ftruncate_args ft; + + retval = p->p_retval; + + /* + * We only support truncating the file. + */ + if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) + return EBADF; + + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) + return ESPIPE; + + if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0) + return error; + + length = vattr.va_size; + + switch (flp->l_whence) { + case SEEK_CUR: + start = fp->f_offset + flp->l_start; + break; + + case SEEK_END: + start = flp->l_start + length; + break; + + case SEEK_SET: + start = flp->l_start; + break; + + default: + return EINVAL; + } + + if (start + flp->l_len < length) { + /* We don't support free'ing in the middle of the file */ + return EINVAL; + } + + SCARG(&ft, fd) = fd; + SCARG(&ft, length) = start; + + return ftruncate(p, &ft); +} + +int +svr4_sys_open(p, uap) + register struct proc *p; + struct svr4_sys_open_args *uap; +{ + int error, retval; + struct open_args cup; + + caddr_t sg = stackgap_init(); + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + (&cup)->path = uap->path; + (&cup)->flags = svr4_to_bsd_flags(uap->flags); + (&cup)->mode = uap->mode; + error = open(p, &cup); + + if (error) { + /* uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path, + uap->flags, uap->mode, error);*/ + return error; + } + + retval = p->p_retval[0]; + + if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) && + !(p->p_flag & P_CONTROLT)) { +#if defined(NOTYET) + struct filedesc *fdp = p->p_fd; + struct file *fp = fdp->fd_ofiles[retval]; + + /* ignore any error, just give it a try */ + if (fp->f_type == DTYPE_VNODE) + (fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p); +#endif + } + return error; +} + +int +svr4_sys_open64(p, uap) + register struct proc *p; + struct svr4_sys_open64_args *uap; +{ + return svr4_sys_open(p, (struct svr4_sys_open_args *)uap); +} + +int +svr4_sys_creat(p, uap) + register struct proc *p; + struct svr4_sys_creat_args *uap; +{ + struct open_args cup; + + caddr_t sg = stackgap_init(); + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, mode) = SCARG(uap, mode); + SCARG(&cup, flags) = O_WRONLY | O_CREAT | O_TRUNC; + + return open(p, &cup); +} + +int +svr4_sys_creat64(p, uap) + register struct proc *p; + struct svr4_sys_creat64_args *uap; +{ + return svr4_sys_creat(p, (struct svr4_sys_creat_args *)uap); +} + +int +svr4_sys_llseek(p, v) + register struct proc *p; + struct svr4_sys_llseek_args *v; +{ + struct svr4_sys_llseek_args *uap = v; + struct lseek_args ap; + + SCARG(&ap, fd) = SCARG(uap, fd); + +#if BYTE_ORDER == BIG_ENDIAN + SCARG(&ap, offset) = (((long long) SCARG(uap, offset1)) << 32) | + SCARG(uap, offset2); +#else + SCARG(&ap, offset) = (((long long) SCARG(uap, offset2)) << 32) | + SCARG(uap, offset1); +#endif + SCARG(&ap, whence) = SCARG(uap, whence); + + return lseek(p, &ap); +} + +int +svr4_sys_access(p, uap) + register struct proc *p; + struct svr4_sys_access_args *uap; +{ + struct access_args cup; + int *retval; + + caddr_t sg = stackgap_init(); + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + retval = p->p_retval; + + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, flags) = SCARG(uap, flags); + + return access(p, &cup); +} + +#if defined(NOTYET) +int +svr4_sys_pread(p, uap) + register struct proc *p; + struct svr4_sys_pread_args *uap; +{ + struct pread_args pra; + + /* + * Just translate the args structure and call the NetBSD + * pread(2) system call (offset type is 64-bit in NetBSD). + */ + SCARG(&pra, fd) = SCARG(uap, fd); + SCARG(&pra, buf) = SCARG(uap, buf); + SCARG(&pra, nbyte) = SCARG(uap, nbyte); + SCARG(&pra, offset) = SCARG(uap, off); + + return pread(p, &pra); +} +#endif + +#if defined(NOTYET) +int +svr4_sys_pread64(p, v, retval) + register struct proc *p; + void *v; + register_t *retval; +{ + + struct svr4_sys_pread64_args *uap = v; + struct sys_pread_args pra; + + /* + * Just translate the args structure and call the NetBSD + * pread(2) system call (offset type is 64-bit in NetBSD). + */ + SCARG(&pra, fd) = SCARG(uap, fd); + SCARG(&pra, buf) = SCARG(uap, buf); + SCARG(&pra, nbyte) = SCARG(uap, nbyte); + SCARG(&pra, offset) = SCARG(uap, off); + + return (sys_pread(p, &pra, retval)); +} +#endif /* NOTYET */ + +#if defined(NOTYET) +int +svr4_sys_pwrite(p, uap) + register struct proc *p; + struct svr4_sys_pwrite_args *uap; +{ + struct pwrite_args pwa; + + /* + * Just translate the args structure and call the NetBSD + * pwrite(2) system call (offset type is 64-bit in NetBSD). + */ + SCARG(&pwa, fd) = SCARG(uap, fd); + SCARG(&pwa, buf) = SCARG(uap, buf); + SCARG(&pwa, nbyte) = SCARG(uap, nbyte); + SCARG(&pwa, offset) = SCARG(uap, off); + + return pwrite(p, &pwa); +} +#endif + +#if defined(NOTYET) +int +svr4_sys_pwrite64(p, v, retval) + register struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_pwrite64_args *uap = v; + struct sys_pwrite_args pwa; + + /* + * Just translate the args structure and call the NetBSD + * pwrite(2) system call (offset type is 64-bit in NetBSD). + */ + SCARG(&pwa, fd) = SCARG(uap, fd); + SCARG(&pwa, buf) = SCARG(uap, buf); + SCARG(&pwa, nbyte) = SCARG(uap, nbyte); + SCARG(&pwa, offset) = SCARG(uap, off); + + return (sys_pwrite(p, &pwa, retval)); +} +#endif /* NOTYET */ + +int +svr4_sys_fcntl(p, uap) + register struct proc *p; + struct svr4_sys_fcntl_args *uap; +{ + int error; + struct fcntl_args fa; + int *retval; + + retval = p->p_retval; + + SCARG(&fa, fd) = SCARG(uap, fd); + SCARG(&fa, cmd) = svr4_to_bsd_cmd(SCARG(uap, cmd)); + + switch (SCARG(&fa, cmd)) { + case F_DUPFD: + case F_GETFD: + case F_SETFD: + SCARG(&fa, arg) = (long) SCARG(uap, arg); + return fcntl(p, &fa); + + case F_GETFL: + SCARG(&fa, arg) = (long) SCARG(uap, arg); + error = fcntl(p, &fa); + if (error) + return error; + *retval = bsd_to_svr4_flags(*retval); + return error; + + case F_SETFL: + { + /* + * we must save the O_ASYNC flag, as that is + * handled by ioctl(_, I_SETSIG, _) emulation. + */ + long cmd; + int flags; + + DPRINTF(("Setting flags 0x%x\n", SCARG(uap, arg))); + cmd = SCARG(&fa, cmd); /* save it for a while */ + + SCARG(&fa, cmd) = F_GETFL; + if ((error = fcntl(p, &fa)) != 0) + return error; + flags = *retval; + flags &= O_ASYNC; + flags |= svr4_to_bsd_flags((u_long) SCARG(uap, arg)); + SCARG(&fa, cmd) = cmd; + SCARG(&fa, arg) = (long) flags; + return fcntl(p, &fa); + } + + case F_GETLK: + case F_SETLK: + case F_SETLKW: + { + struct svr4_flock ifl; + struct flock *flp, fl; + caddr_t sg = stackgap_init(); + + flp = stackgap_alloc(&sg, sizeof(struct flock)); + SCARG(&fa, arg) = (long) flp; + + error = copyin(SCARG(uap, arg), &ifl, sizeof ifl); + if (error) + return error; + + svr4_to_bsd_flock(&ifl, &fl); + + error = copyout(&fl, flp, sizeof fl); + if (error) + return error; + + error = fcntl(p, &fa); + if (error || SCARG(&fa, cmd) != F_GETLK) + return error; + + error = copyin(flp, &fl, sizeof fl); + if (error) + return error; + + bsd_to_svr4_flock(&fl, &ifl); + + return copyout(&ifl, SCARG(uap, arg), sizeof ifl); + } + case -1: + switch (SCARG(uap, cmd)) { + case SVR4_F_DUP2FD: + { + struct dup2_args du; + + SCARG(&du, from) = SCARG(uap, fd); + SCARG(&du, to) = (int)SCARG(uap, arg); + error = dup2(p, &du); + if (error) + return error; + *retval = SCARG(&du, to); + return 0; + } + + case SVR4_F_FREESP: + { + struct svr4_flock ifl; + struct flock fl; + + error = copyin(SCARG(uap, arg), &ifl, + sizeof ifl); + if (error) + return error; + svr4_to_bsd_flock(&ifl, &fl); + return fd_truncate(p, SCARG(uap, fd), &fl); + } + + case SVR4_F_GETLK64: + case SVR4_F_SETLK64: + case SVR4_F_SETLKW64: + { + struct svr4_flock64 ifl; + struct flock *flp, fl; + caddr_t sg = stackgap_init(); + + flp = stackgap_alloc(&sg, sizeof(struct flock)); + SCARG(&fa, arg) = (long) flp; + + error = copyin(SCARG(uap, arg), &ifl, + sizeof ifl); + if (error) + return error; + + svr4_to_bsd_flock64(&ifl, &fl); + + error = copyout(&fl, flp, sizeof fl); + if (error) + return error; + + error = fcntl(p, &fa); + if (error || SCARG(&fa, cmd) != F_GETLK) + return error; + + error = copyin(flp, &fl, sizeof fl); + if (error) + return error; + + bsd_to_svr4_flock64(&fl, &ifl); + + return copyout(&ifl, SCARG(uap, arg), + sizeof ifl); + } + + case SVR4_F_FREESP64: + { + struct svr4_flock64 ifl; + struct flock fl; + + error = copyin(SCARG(uap, arg), &ifl, + sizeof ifl); + if (error) + return error; + svr4_to_bsd_flock64(&ifl, &fl); + return fd_truncate(p, SCARG(uap, fd), &fl); + } + + case SVR4_F_REVOKE: + return fd_revoke(p, SCARG(uap, fd)); + + default: + return ENOSYS; + } + + default: + return ENOSYS; + } +} diff --git a/sys/compat/svr4/svr4_fcntl.h b/sys/compat/svr4/svr4_fcntl.h new file mode 100644 index 0000000..8c202f2 --- /dev/null +++ b/sys/compat/svr4/svr4_fcntl.h @@ -0,0 +1,132 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_FCNTL_H_ +#define _SVR4_FCNTL_H_ + +#include <svr4/svr4_types.h> +#include <sys/fcntl.h> + +#define SVR4_O_RDONLY 0x0000 +#define SVR4_O_WRONLY 0x0001 +#define SVR4_O_RDWR 0x0002 +#define SVR4_O_ACCMODE 0x0003 +#define SVR4_O_NDELAY 0x0004 +#define SVR4_O_APPEND 0x0008 +#define SVR4_O_SYNC 0x0010 +#define SVR4_O_NONBLOCK 0x0080 +#define SVR4_O_CREAT 0x0100 +#define SVR4_O_TRUNC 0x0200 +#define SVR4_O_EXCL 0x0400 +#define SVR4_O_NOCTTY 0x0800 +#define SVR4_O_PRIV 0x1000 + + +#define SVR4_FD_CLOEXEC 1 + +#define SVR4_F_DUPFD 0 +#define SVR4_F_GETFD 1 +#define SVR4_F_SETFD 2 +#define SVR4_F_GETFL 3 +#define SVR4_F_SETFL 4 +#define SVR4_F_GETLK_SVR3 5 +#define SVR4_F_SETLK 6 +#define SVR4_F_SETLKW 7 +#define SVR4_F_CHKFL 8 +#define SVR4_F_DUP2FD 9 +#define SVR4_F_ALLOCSP 10 +#define SVR4_F_FREESP 11 + +#define SVR4_F_ISSTREAM 13 +#define SVR4_F_GETLK 14 +#define SVR4_F_PRIV 15 +#define SVR4_F_NPRIV 16 +#define SVR4_F_QUOTACTL 17 +#define SVR4_F_BLOCKS 18 +#define SVR4_F_BLKSIZE 19 +#define SVR4_F_RSETLK 20 +#define SVR4_F_RGETLK 21 +#define SVR4_F_RSETLKW 22 +#define SVR4_F_GETOWN 23 +#define SVR4_F_SETOWN 24 +#define SVR4_F_REVOKE 25 +#define SVR4_F_HASREMOTELOCKS 26 +#define SVR4_F_FREESP64 27 + +#define SVR4_F_GETLK64 33 +#define SVR4_F_SETLK64 34 +#define SVR4_F_SETLKW64 35 + +#define SVR4_F_SHARE 40 +#define SVR4_F_UNSHARE 41 + +#define SVR4_F_CHSIZE_XENIX 0x6000 +#define SVR4_F_RDCHK_XENIX 0x6001 +#define SVR4_F_LK_UNLCK_XENIX 0x6300 +#define SVR4_F_LK_LOCK_XENIX 0x7200 +#define SVR4_F_LK_NBLCK_XENIX 0x6200 +#define SVR4_F_LK_RLCK_XENIX 0x7100 +#define SVR4_F_LK_NBRLCK_XENIX 0x6100 + +#define SVR4_LK_CMDTYPE(x) (((x) >> 12) & 0x7) +#define SVR4_LK_LCKTYPE(x) (((x) >> 8) & 0x7) + +#define SVR4_F_RDLCK 1 +#define SVR4_F_WRLCK 2 +#define SVR4_F_UNLCK 3 + +struct svr4_flock_svr3 { + short l_type; + short l_whence; + svr4_off_t l_start; + svr4_off_t l_len; + short l_sysid; + svr4_o_pid_t l_pid; +}; + + +struct svr4_flock { + short l_type; + short l_whence; + svr4_off_t l_start; + svr4_off_t l_len; + long l_sysid; + svr4_pid_t l_pid; + long pad[4]; +}; + +struct svr4_flock64 { + short l_type; + short l_whence; + svr4_off64_t l_start; + svr4_off64_t l_len; + long l_sysid; + svr4_pid_t l_pid; + long pad[4]; +}; +#endif /* !_SVR4_FCNTL_H_ */ diff --git a/sys/compat/svr4/svr4_filio.c b/sys/compat/svr4/svr4_filio.c new file mode 100644 index 0000000..c82b09b --- /dev/null +++ b/sys/compat/svr4/svr4_filio.c @@ -0,0 +1,245 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/file.h> +#include <sys/filio.h> +#include <sys/fcntl.h> +#include <sys/signal.h> +#include <sys/unistd.h> +#include <sys/filedesc.h> +#include <sys/termios.h> +#include <sys/tty.h> +#include <sys/poll.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#include <sys/mount.h> +#include <net/if.h> +#include <sys/malloc.h> + +#include <sys/sysproto.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_ioctl.h> +#include <svr4/svr4_filio.h> + +/*#define GROTTY_READ_HACK*/ + +int +svr4_sys_poll(p, uap) + struct proc *p; + struct svr4_sys_poll_args *uap; +{ + int error; + struct poll_args pa; + struct pollfd *pfd; + int idx = 0, cerr; + u_long siz; + + SCARG(&pa, fds) = SCARG(uap, fds); + SCARG(&pa, nfds) = SCARG(uap, nfds); + SCARG(&pa, timeout) = SCARG(uap, timeout); + + siz = SCARG(uap, nfds) * sizeof(struct pollfd); + pfd = (struct pollfd *)malloc(siz, M_TEMP, M_WAITOK); + + error = poll(p, (struct poll_args *)uap); + + if ((cerr = copyin(SCARG(uap, fds), pfd, siz)) != 0) { + error = cerr; + goto done; + } + + for (idx = 0; idx < SCARG(uap, nfds); idx++) { + /* POLLWRNORM already equals POLLOUT, so we don't worry about that */ + if (pfd[idx].revents & (POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI)) + pfd[idx].revents |= (POLLIN | POLLRDBAND | POLLRDNORM | POLLPRI); + if (pfd[idx].revents & (POLLOUT | POLLWRNORM | POLLWRBAND)) + pfd[idx].revents |= (POLLOUT | POLLWRNORM | POLLWRBAND); + pfd[idx].revents &= POLLSTANDARD; /* don't want to surprise SysV */ + + DPRINTF(("pollfd[%d]->fd = %d\n", idx, pfd[idx].fd)); + DPRINTF(("pollfd[%d]->events = %x\n", idx, pfd[idx].events)); + DPRINTF(("pollfd[%d]->revents = %x\n", idx, pfd[idx].revents)); + } + DPRINTF(("poll(%x, %x, %d) = %d\n", SCARG(uap, fds), SCARG(uap, nfds), + SCARG(uap, timeout), p->p_retval[0])); + if ((cerr = copyout(pfd, SCARG(uap, fds), siz)) != 0) { + error = cerr; + goto done; /* yeah, I know it's the next line, but this way I won't + forget to update it if I add more code */ + } +done: + free(pfd, M_TEMP); + return error; +} + +#if defined(READ_TEST) +int +svr4_sys_read(p, uap) + struct proc *p; + struct svr4_sys_read_args *uap; +{ + struct read_args ra; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct socket *so = NULL; + int so_state; + sigset_t sigmask; + int rv; + + SCARG(&ra, fd) = SCARG(uap, fd); + SCARG(&ra, buf) = SCARG(uap, buf); + SCARG(&ra, nbyte) = SCARG(uap, nbyte); + + if ((fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) { + DPRINTF(("Something fishy with the user-supplied file descriptor...\n")); + return EBADF; + } + + if (fp->f_type == DTYPE_SOCKET) { + so = (struct socket *)fp->f_data; + DPRINTF(("fd %d is a socket\n", SCARG(uap, fd))); + if (so->so_state & SS_ASYNC) { + DPRINTF(("fd %d is an ASYNC socket!\n", SCARG(uap, fd))); + } + DPRINTF(("Here are its flags: 0x%x\n", so->so_state)); +#if defined(GROTTY_READ_HACK) + so_state = so->so_state; + so->so_state &= ~SS_NBIO; +#endif + } + + rv = read(p, &ra); + + DPRINTF(("svr4_read(%d, 0x%0x, %d) = %d\n", + SCARG(uap, fd), SCARG(uap, buf), SCARG(uap, nbyte), rv)); + if (rv == EAGAIN) { + DPRINTF(("sigmask = 0x%x\n", p->p_sigmask)); + DPRINTF(("sigignore = 0x%x\n", p->p_sigignore)); + DPRINTF(("sigcaught = 0x%x\n", p->p_sigcatch)); + DPRINTF(("siglist = 0x%x\n", p->p_siglist)); + } + +#if defined(GROTTY_READ_HACK) + if (so) { /* We've already checked to see if this is a socket */ + so->so_state = so_state; + } +#endif + + return(rv); +} +#endif /* READ_TEST */ + +#if defined(BOGUS) +int +svr4_sys_write(p, uap) + struct proc *p; + struct svr4_sys_write_args *uap; +{ + struct write_args wa; + struct filedesc *fdp; + struct file *fp; + int rv; + + SCARG(&wa, fd) = SCARG(uap, fd); + SCARG(&wa, buf) = SCARG(uap, buf); + SCARG(&wa, nbyte) = SCARG(uap, nbyte); + + rv = write(p, &wa); + + DPRINTF(("svr4_write(%d, 0x%0x, %d) = %d\n", + SCARG(uap, fd), SCARG(uap, buf), SCARG(uap, nbyte), rv)); + + return(rv); +} +#endif /* BOGUS */ + +int +svr4_fil_ioctl(fp, p, retval, fd, cmd, data) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t data; +{ + int error; + int num; + struct filedesc *fdp = p->p_fd; + int (*ctl) __P((struct file *, u_long, caddr_t, struct proc *)) = + fp->f_ops->fo_ioctl; + + *retval = 0; + + switch (cmd) { + case SVR4_FIOCLEX: + fdp->fd_ofileflags[fd] |= UF_EXCLOSE; + return 0; + + case SVR4_FIONCLEX: + fdp->fd_ofileflags[fd] &= ~UF_EXCLOSE; + return 0; + + case SVR4_FIOGETOWN: + case SVR4_FIOSETOWN: + case SVR4_FIOASYNC: + case SVR4_FIONBIO: + case SVR4_FIONREAD: + if ((error = copyin(data, &num, sizeof(num))) != 0) + return error; + + switch (cmd) { + case SVR4_FIOGETOWN: cmd = FIOGETOWN; break; + case SVR4_FIOSETOWN: cmd = FIOSETOWN; break; + case SVR4_FIOASYNC: cmd = FIOASYNC; break; + case SVR4_FIONBIO: cmd = FIONBIO; break; + case SVR4_FIONREAD: cmd = FIONREAD; break; + } + +#ifdef SVR4_DEBUG + if (cmd == FIOASYNC) DPRINTF(("FIOASYNC\n")); +#endif + error = (*ctl)(fp, cmd, (caddr_t) &num, p); + + if (error) + return error; + + return copyout(&num, data, sizeof(num)); + + default: + DPRINTF(("Unknown svr4 filio %lx\n", cmd)); + return 0; /* ENOSYS really */ + } +} diff --git a/sys/compat/svr4/svr4_filio.h b/sys/compat/svr4/svr4_filio.h new file mode 100644 index 0000000..2f105a7 --- /dev/null +++ b/sys/compat/svr4/svr4_filio.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_FILIO_H_ +#define _SVR4_FILIO_H_ + +#define SVR4_FIOC ('f' << 8) + +#define SVR4_FIOCLEX SVR4_IO('f', 1) +#define SVR4_FIONCLEX SVR4_IO('f', 2) + +#define SVR4_FIOGETOWN SVR4_IOR('f', 123, int) +#define SVR4_FIOSETOWN SVR4_IOW('f', 124, int) +#define SVR4_FIOASYNC SVR4_IOW('f', 125, int) +#define SVR4_FIONBIO SVR4_IOW('f', 126, int) +#define SVR4_FIONREAD SVR4_IOR('f', 127, int) + +#endif /* !_SVR4_FILIO_H_ */ diff --git a/sys/compat/svr4/svr4_fuser.h b/sys/compat/svr4/svr4_fuser.h new file mode 100644 index 0000000..669d527 --- /dev/null +++ b/sys/compat/svr4/svr4_fuser.h @@ -0,0 +1,96 @@ +/* + * Derived from: + * $NetBSD: svr4_fuser.h,v 1.4 1998/09/04 19:54:38 christos Exp $ */ + +/*- + * Original Copyright: + * + * Copyright (c) 1994 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Portions of this code have been derived from code contributed to the + * FreeBSD Project by Mark Newton. + * + * Copyright (c) 1999 Mark Newton + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_FUSER_H_ +#define _SVR4_FUSER_H_ + +#include <svr4/svr4_types.h> + +struct svr4_f_user { + svr4_pid_t fu_pid; + int fu_flags; + uid_t fu_uid; +}; + + +#define SVR4_F_FILE_ONLY 1 +#define SVR4_F_CONTAINED 2 + +#define SVR4_F_CDIR 0x01 +#define SVR4_F_RDIR 0x02 +#define SVR4_F_TEXT 0x04 +#define SVR4_F_MAP 0x08 +#define SVR4_F_OPEN 0x10 +#define SVR4_F_TRACE 0x20 +#define SVR4_F_TTY 0x40 + +#endif /* !_SVR4_FUSER_H_ */ diff --git a/sys/compat/svr4/svr4_hrt.h b/sys/compat/svr4/svr4_hrt.h new file mode 100644 index 0000000..ce54ad0 --- /dev/null +++ b/sys/compat/svr4/svr4_hrt.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_HRT_H_ +#define _SVR4_HRT_H_ + +#define SVR4_HRT_CNTL 0 +#define SVR4_HRT_CNTL_RES 0 +#define SVR4_HRT_CNTL_TOFD 1 +#define SVR4_HRT_CNTL_START 2 +#define SVR4_HRT_CNTL_GET 3 + +#define SVR4_HRT_ALRM 1 +#define SVR4_HRT_ALRM_DO 4 +#define SVR4_HRT_ALRM_REP 5 +#define SVR4_HRT_ALRM_TOD 6 +#define SVR4_HRT_ALRM_FUTREP 7 +#define SVR4_HRT_ALRM_TODREP 8 +#define SVR4_HRT_ALRM_PEND 9 + +#define SVR4_HRT_SLP 2 +#define SVR4_HRT_SLP_INT 10 +#define SVR4_HRT_SLP_TOD 11 + +#define SVR4_HRT_BSD 12 +#define SVR4_HRT_BSD_PEND 13 +#define SVR4_HRT_BSD_REP1 14 +#define SVR4_HRT_BSD_REP2 15 +#define SVR4_HRT_BSD_CANCEL 16 + +#define SVR4_HRT_CAN 3 + +#define SVR4_HRT_SEC 1 +#define SVR4_HRT_MSEC 1000 +#define SVR4_HRT_USEC 1000000 +#define SVR4_HRT_NSEC 1000000000 + +#define SVR4_HRT_TRUNC 0 +#define SVR4_HRT_RND 1 + +typedef struct { + u_long i_word1; + u_long i_word2; + int i_clock; +} svr4_hrt_interval_t; + +typedef struct { + u_long h_sec; + long h_rem; + u_long h_res; +} svr4_hrt_time_t; + +#define SVR4_HRT_DONE 1 +#define SVR4_HRT_ERROR 2 + +#define SVR4_HRT_CLK_STD 1 +#define SVR4_HRT_CLK_USERVIRT 2 +#define SVR4_HRT_CLK_PROCVIRT 4 + +#endif /* !_SVR4_HRT_H_ */ diff --git a/sys/compat/svr4/svr4_ioctl.c b/sys/compat/svr4/svr4_ioctl.c new file mode 100644 index 0000000..2ce3004 --- /dev/null +++ b/sys/compat/svr4/svr4_ioctl.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/file.h> +#include <sys/filedesc.h> +#include <sys/unistd.h> +#include <sys/fcntl.h> +#include <sys/termios.h> +#include <sys/tty.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#include <sys/mount.h> +#include <net/if.h> +#include <sys/malloc.h> + +#include <sys/sysproto.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_stropts.h> +#include <svr4/svr4_ioctl.h> +#include <svr4/svr4_termios.h> +#include <svr4/svr4_ttold.h> +#include <svr4/svr4_filio.h> +#include <svr4/svr4_sockio.h> + +#ifdef DEBUG_SVR4 +static void svr4_decode_cmd __P((u_long, char *, char *, int *, int *)); +/* + * Decode an ioctl command symbolically + */ +static void +svr4_decode_cmd(cmd, dir, c, num, argsiz) + u_long cmd; + char *dir, *c; + int *num, *argsiz; +{ + if (cmd & SVR4_IOC_VOID) + *dir++ = 'V'; + if (cmd & SVR4_IOC_IN) + *dir++ = 'R'; + if (cmd & SVR4_IOC_OUT) + *dir++ = 'W'; + *dir = '\0'; + if (cmd & SVR4_IOC_INOUT) + *argsiz = (cmd >> 16) & 0xff; + else + *argsiz = -1; + + *c = (cmd >> 8) & 0xff; + *num = cmd & 0xff; +} +#endif + +int +svr4_sys_ioctl(p, uap) + register struct proc *p; + struct svr4_sys_ioctl_args *uap; +{ + int *retval; + struct file *fp; + struct filedesc *fdp; + u_long cmd; + int (*fun) __P((struct file *, struct proc *, register_t *, + int, u_long, caddr_t)); +#ifdef DEBUG_SVR4 + char dir[4]; + char c; + int num; + int argsiz; + + svr4_decode_cmd(SCARG(uap, com), dir, &c, &num, &argsiz); + + DPRINTF(("svr4_ioctl[%x](%d, _IO%s(%c, %d, %d), %p);\n", SCARG(uap, com), SCARG(uap, fd), + dir, c, num, argsiz, SCARG(uap, data))); +#endif + retval = p->p_retval; + fdp = p->p_fd; + cmd = SCARG(uap, com); + + if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) + return EBADF; + + if ((fp->f_flag & (FREAD | FWRITE)) == 0) + return EBADF; + +#if defined(DEBUG_SVR4) + if (fp->f_type == DTYPE_SOCKET) { + struct socket *so = fp->f_data; + DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state)); + } +#endif + + switch (cmd & 0xff00) { + case SVR4_tIOC: + DPRINTF(("ttold\n")); + fun = svr4_ttold_ioctl; + break; + + case SVR4_TIOC: + DPRINTF(("term\n")); + fun = svr4_term_ioctl; + break; + + case SVR4_STR: + DPRINTF(("stream\n")); + fun = svr4_stream_ioctl; + break; + + case SVR4_FIOC: + DPRINTF(("file\n")); + fun = svr4_fil_ioctl; + break; + + case SVR4_SIOC: + DPRINTF(("socket\n")); + fun = svr4_sock_ioctl; + break; + + case SVR4_XIOC: + /* We do not support those */ + return EINVAL; + + default: + DPRINTF(("Unimplemented ioctl %lx\n", cmd)); + return 0; /* XXX: really ENOSYS */ + } +#if defined(DEBUG_SVR4) + if (fp->f_type == DTYPE_SOCKET) { + struct socket *so = fp->f_data; + DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state)); + } +#endif + return (*fun)(fp, p, retval, SCARG(uap, fd), cmd, SCARG(uap, data)); +} diff --git a/sys/compat/svr4/svr4_ioctl.h b/sys/compat/svr4/svr4_ioctl.h new file mode 100644 index 0000000..e95fa5a --- /dev/null +++ b/sys/compat/svr4/svr4_ioctl.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_IOCTL_H_ +#define _SVR4_IOCTL_H_ + +#define SVR4_IOC_VOID 0x20000000 +#define SVR4_IOC_OUT 0x40000000 +#define SVR4_IOC_IN 0x80000000 +#define SVR4_IOC_INOUT (SVR4_IOC_IN|SVR4_IOC_OUT) + +#define SVR4_IOC(inout,group,num,len) \ + (inout | ((len & 0xff) << 16) | ((group) << 8) | (num)) + +#define SVR4_XIOC ('X' << 8) + +#define SVR4_IO(g,n) SVR4_IOC(SVR4_IOC_VOID, (g), (n), 0) +#define SVR4_IOR(g,n,t) SVR4_IOC(SVR4_IOC_OUT, (g), (n), sizeof(t)) +#define SVR4_IOW(g,n,t) SVR4_IOC(SVR4_IOC_IN, (g), (n), sizeof(t)) +#define SVR4_IOWR(g,n,t) SVR4_IOC(SVR4_IOC_INOUT,(g), (n), sizeof(t)) + +int svr4_stream_ti_ioctl __P((struct file *, struct proc *, register_t *, + int, u_long, caddr_t)); +int svr4_stream_ioctl __P((struct file *, struct proc *, register_t *, + int, u_long, caddr_t)); +int svr4_term_ioctl __P((struct file *, struct proc *, register_t *, + int, u_long, caddr_t)); +int svr4_ttold_ioctl __P((struct file *, struct proc *, register_t *, + int, u_long, caddr_t)); +int svr4_fil_ioctl __P((struct file *, struct proc *, register_t *, + int, u_long, caddr_t)); +int svr4_sock_ioctl __P((struct file *, struct proc *, register_t *, + int, u_long, caddr_t)); + +#endif /* !_SVR4_IOCTL_H_ */ diff --git a/sys/compat/svr4/svr4_ipc.c b/sys/compat/svr4/svr4_ipc.c new file mode 100644 index 0000000..8bb661b --- /dev/null +++ b/sys/compat/svr4/svr4_ipc.c @@ -0,0 +1,831 @@ +/* + * Derived from: + * $NetBSD: svr4_ipc.c,v 1.7 1998/10/19 22:43:00 tron Exp $ */ + +/*- + * Original copyright: + * + * Copyright (c) 1995 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Portions of this code have been derived from software contributed + * to the FreeBSD Project by Mark Newton. + * + * Copyright (c) 1999 Mark Newton + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * XXX- This code is presently a no-op on FreeBSD (and isn't compiled due + * to preprocessor conditionals). A nice project for a kernel hacking + * novice might be to MakeItGo, but I have more important fish to fry + * at present. + * + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/shm.h> +#include <sys/msg.h> +#include <sys/sem.h> +#include <sys/proc.h> +#include <sys/uio.h> +#include <sys/time.h> +#include <sys/malloc.h> +#include <sys/mman.h> +#include <sys/systm.h> +#include <sys/stat.h> + +#include <sys/mount.h> +#include <sys/sysproto.h> + +#include <svr4/svr4_types.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_ipc.h> + +#if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM) +static void svr4_to_bsd_ipc_perm __P((const struct svr4_ipc_perm *, + struct ipc_perm *)); +static void bsd_to_svr4_ipc_perm __P((const struct ipc_perm *, + struct svr4_ipc_perm *)); +#endif + +#ifdef SYSVSEM +static void bsd_to_svr4_semid_ds __P((const struct semid_ds *, + struct svr4_semid_ds *)); +static void svr4_to_bsd_semid_ds __P((const struct svr4_semid_ds *, + struct semid_ds *)); +static int svr4_setsemun __P((caddr_t *sgp, union semun **argp, + union semun *usp)); +static int svr4_semop __P((struct proc *, void *, register_t *)); +static int svr4_semget __P((struct proc *, void *, register_t *)); +static int svr4_semctl __P((struct proc *, void *, register_t *)); +#endif + +#ifdef SYSVMSG +static void bsd_to_svr4_msqid_ds __P((const struct msqid_ds *, + struct svr4_msqid_ds *)); +static void svr4_to_bsd_msqid_ds __P((const struct svr4_msqid_ds *, + struct msqid_ds *)); +static int svr4_msgsnd __P((struct proc *, void *, register_t *)); +static int svr4_msgrcv __P((struct proc *, void *, register_t *)); +static int svr4_msgget __P((struct proc *, void *, register_t *)); +static int svr4_msgctl __P((struct proc *, void *, register_t *)); +#endif + +#ifdef SYSVSHM +static void bsd_to_svr4_shmid_ds __P((const struct shmid_ds *, + struct svr4_shmid_ds *)); +static void svr4_to_bsd_shmid_ds __P((const struct svr4_shmid_ds *, + struct shmid_ds *)); +static int svr4_shmat __P((struct proc *, void *, register_t *)); +static int svr4_shmdt __P((struct proc *, void *, register_t *)); +static int svr4_shmget __P((struct proc *, void *, register_t *)); +static int svr4_shmctl __P((struct proc *, void *, register_t *)); +#endif + +#if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM) + +static void +svr4_to_bsd_ipc_perm(spp, bpp) + const struct svr4_ipc_perm *spp; + struct ipc_perm *bpp; +{ + bpp->key = spp->key; + bpp->uid = spp->uid; + bpp->gid = spp->gid; + bpp->cuid = spp->cuid; + bpp->cgid = spp->cgid; + bpp->mode = spp->mode; + bpp->seq = spp->seq; +} + +static void +bsd_to_svr4_ipc_perm(bpp, spp) + const struct ipc_perm *bpp; + struct svr4_ipc_perm *spp; +{ + spp->key = bpp->key; + spp->uid = bpp->uid; + spp->gid = bpp->gid; + spp->cuid = bpp->cuid; + spp->cgid = bpp->cgid; + spp->mode = bpp->mode; + spp->seq = bpp->seq; +} +#endif + +#ifdef SYSVSEM +static void +bsd_to_svr4_semid_ds(bds, sds) + const struct semid_ds *bds; + struct svr4_semid_ds *sds; +{ + bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm); + sds->sem_base = (struct svr4_sem *) bds->sem_base; + sds->sem_nsems = bds->sem_nsems; + sds->sem_otime = bds->sem_otime; + sds->sem_pad1 = bds->sem_pad1; + sds->sem_ctime = bds->sem_ctime; + sds->sem_pad2 = bds->sem_pad2; +} + +static void +svr4_to_bsd_semid_ds(sds, bds) + const struct svr4_semid_ds *sds; + struct semid_ds *bds; +{ + svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm); + bds->sem_base = (struct sem *) bds->sem_base; + bds->sem_nsems = sds->sem_nsems; + bds->sem_otime = sds->sem_otime; + bds->sem_pad1 = sds->sem_pad1; + bds->sem_ctime = sds->sem_ctime; + bds->sem_pad2 = sds->sem_pad2; +} + +static int +svr4_setsemun(sgp, argp, usp) + caddr_t *sgp; + union semun **argp; + union semun *usp; +{ + *argp = stackgap_alloc(sgp, sizeof(union semun)); + return copyout((caddr_t)usp, *argp, sizeof(union semun)); +} + +struct svr4_sys_semctl_args { + syscallarg(int) what; + syscallarg(int) semid; + syscallarg(int) semnum; + syscallarg(int) cmd; + syscallarg(union semun) arg; +}; + +static int +svr4_semctl(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + int error; + struct svr4_sys_semctl_args *uap = v; + struct sys___semctl_args ap; + struct svr4_semid_ds ss; + struct semid_ds bs, *bsp; + caddr_t sg = stackgap_init(p->p_emul); + + SCARG(&ap, semid) = SCARG(uap, semid); + SCARG(&ap, semnum) = SCARG(uap, semnum); + + switch (SCARG(uap, cmd)) { + case SVR4_SEM_GETZCNT: + case SVR4_SEM_GETNCNT: + case SVR4_SEM_GETPID: + case SVR4_SEM_GETVAL: + switch (SCARG(uap, cmd)) { + case SVR4_SEM_GETZCNT: + SCARG(&ap, cmd) = GETZCNT; + break; + case SVR4_SEM_GETNCNT: + SCARG(&ap, cmd) = GETNCNT; + break; + case SVR4_SEM_GETPID: + SCARG(&ap, cmd) = GETPID; + break; + case SVR4_SEM_GETVAL: + SCARG(&ap, cmd) = GETVAL; + break; + } + return sys___semctl(p, &ap, retval); + + case SVR4_SEM_SETVAL: + error = svr4_setsemun(&sg, &SCARG(&ap, arg), &SCARG(uap, arg)); + if (error) + return error; + SCARG(&ap, cmd) = SETVAL; + return sys___semctl(p, &ap, retval); + + case SVR4_SEM_GETALL: + error = svr4_setsemun(&sg, &SCARG(&ap, arg), &SCARG(uap, arg)); + if (error) + return error; + SCARG(&ap, cmd) = GETVAL; + return sys___semctl(p, &ap, retval); + + case SVR4_SEM_SETALL: + error = svr4_setsemun(&sg, &SCARG(&ap, arg), &SCARG(uap, arg)); + if (error) + return error; + SCARG(&ap, cmd) = SETVAL; + return sys___semctl(p, &ap, retval); + + case SVR4_IPC_STAT: + SCARG(&ap, cmd) = IPC_STAT; + bsp = stackgap_alloc(&sg, sizeof(bs)); + error = svr4_setsemun(&sg, &SCARG(&ap, arg), + (union semun *)&bsp); + if (error) + return error; + if ((error = sys___semctl(p, &ap, retval)) != 0) + return error; + error = copyin((caddr_t)bsp, (caddr_t)&bs, sizeof(bs)); + if (error) + return error; + bsd_to_svr4_semid_ds(&bs, &ss); + return copyout(&ss, SCARG(uap, arg).buf, sizeof(ss)); + + case SVR4_IPC_SET: + SCARG(&ap, cmd) = IPC_SET; + bsp = stackgap_alloc(&sg, sizeof(bs)); + error = svr4_setsemun(&sg, &SCARG(&ap, arg), + (union semun *)&bsp); + if (error) + return error; + error = copyin(SCARG(uap, arg).buf, (caddr_t) &ss, sizeof ss); + if (error) + return error; + svr4_to_bsd_semid_ds(&ss, &bs); + error = copyout(&bs, bsp, sizeof(bs)); + if (error) + return error; + return sys___semctl(p, &ap, retval); + + case SVR4_IPC_RMID: + SCARG(&ap, cmd) = IPC_RMID; + bsp = stackgap_alloc(&sg, sizeof(bs)); + error = svr4_setsemun(&sg, &SCARG(&ap, arg), + (union semun *)&bsp); + if (error) + return error; + error = copyin(SCARG(uap, arg).buf, &ss, sizeof ss); + if (error) + return error; + svr4_to_bsd_semid_ds(&ss, &bs); + error = copyout(&bs, bsp, sizeof(bs)); + if (error) + return error; + return sys___semctl(p, &ap, retval); + + default: + return EINVAL; + } +} + +struct svr4_sys_semget_args { + syscallarg(int) what; + syscallarg(svr4_key_t) key; + syscallarg(int) nsems; + syscallarg(int) semflg; +}; + +static int +svr4_semget(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_semget_args *uap = v; + struct sys_semget_args ap; + + SCARG(&ap, key) = SCARG(uap, key); + SCARG(&ap, nsems) = SCARG(uap, nsems); + SCARG(&ap, semflg) = SCARG(uap, semflg); + + return sys_semget(p, &ap, retval); +} + +struct svr4_sys_semop_args { + syscallarg(int) what; + syscallarg(int) semid; + syscallarg(struct svr4_sembuf *) sops; + syscallarg(u_int) nsops; +}; + +static int +svr4_semop(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_semop_args *uap = v; + struct sys_semop_args ap; + + SCARG(&ap, semid) = SCARG(uap, semid); + /* These are the same */ + SCARG(&ap, sops) = (struct sembuf *) SCARG(uap, sops); + SCARG(&ap, nsops) = SCARG(uap, nsops); + + return sys_semop(p, &ap, retval); +} + +int +svr4_sys_semsys(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_semsys_args *uap = v; + + DPRINTF(("svr4_semsys(%d)\n", SCARG(uap, what))); + + switch (SCARG(uap, what)) { + case SVR4_semctl: + return svr4_semctl(p, v, retval); + case SVR4_semget: + return svr4_semget(p, v, retval); + case SVR4_semop: + return svr4_semop(p, v, retval); + default: + return EINVAL; + } +} +#endif + +#ifdef SYSVMSG +static void +bsd_to_svr4_msqid_ds(bds, sds) + const struct msqid_ds *bds; + struct svr4_msqid_ds *sds; +{ + bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm); + sds->msg_first = (struct svr4_msg *) bds->msg_first; + sds->msg_last = (struct svr4_msg *) bds->msg_last; + sds->msg_cbytes = bds->msg_cbytes; + sds->msg_qnum = bds->msg_qnum; + sds->msg_qbytes = bds->msg_qbytes; + sds->msg_lspid = bds->msg_lspid; + sds->msg_lrpid = bds->msg_lrpid; + sds->msg_stime = bds->msg_stime; + sds->msg_pad1 = bds->msg_pad1; + sds->msg_rtime = bds->msg_rtime; + sds->msg_pad2 = bds->msg_pad2; + sds->msg_ctime = bds->msg_ctime; + sds->msg_pad3 = bds->msg_pad3; + + /* use the padding for the rest of the fields */ + { + const short *pad = (const short *) bds->msg_pad4; + sds->msg_cv = pad[0]; + sds->msg_qnum_cv = pad[1]; + } +} + +static void +svr4_to_bsd_msqid_ds(sds, bds) + const struct svr4_msqid_ds *sds; + struct msqid_ds *bds; +{ + svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm); + bds->msg_first = (struct msg *) sds->msg_first; + bds->msg_last = (struct msg *) sds->msg_last; + bds->msg_cbytes = sds->msg_cbytes; + bds->msg_qnum = sds->msg_qnum; + bds->msg_qbytes = sds->msg_qbytes; + bds->msg_lspid = sds->msg_lspid; + bds->msg_lrpid = sds->msg_lrpid; + bds->msg_stime = sds->msg_stime; + bds->msg_pad1 = sds->msg_pad1; + bds->msg_rtime = sds->msg_rtime; + bds->msg_pad2 = sds->msg_pad2; + bds->msg_ctime = sds->msg_ctime; + bds->msg_pad3 = sds->msg_pad3; + + /* use the padding for the rest of the fields */ + { + short *pad = (short *) bds->msg_pad4; + pad[0] = sds->msg_cv; + pad[1] = sds->msg_qnum_cv; + } +} + +struct svr4_sys_msgsnd_args { + syscallarg(int) what; + syscallarg(int) msqid; + syscallarg(void *) msgp; + syscallarg(size_t) msgsz; + syscallarg(int) msgflg; +}; + +static int +svr4_msgsnd(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_msgsnd_args *uap = v; + struct sys_msgsnd_args ap; + + SCARG(&ap, msqid) = SCARG(uap, msqid); + SCARG(&ap, msgp) = SCARG(uap, msgp); + SCARG(&ap, msgsz) = SCARG(uap, msgsz); + SCARG(&ap, msgflg) = SCARG(uap, msgflg); + + return sys_msgsnd(p, &ap, retval); +} + +struct svr4_sys_msgrcv_args { + syscallarg(int) what; + syscallarg(int) msqid; + syscallarg(void *) msgp; + syscallarg(size_t) msgsz; + syscallarg(long) msgtyp; + syscallarg(int) msgflg; +}; + +static int +svr4_msgrcv(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_msgrcv_args *uap = v; + struct sys_msgrcv_args ap; + + SCARG(&ap, msqid) = SCARG(uap, msqid); + SCARG(&ap, msgp) = SCARG(uap, msgp); + SCARG(&ap, msgsz) = SCARG(uap, msgsz); + SCARG(&ap, msgtyp) = SCARG(uap, msgtyp); + SCARG(&ap, msgflg) = SCARG(uap, msgflg); + + return sys_msgrcv(p, &ap, retval); +} + +struct svr4_sys_msgget_args { + syscallarg(int) what; + syscallarg(svr4_key_t) key; + syscallarg(int) msgflg; +}; + +static int +svr4_msgget(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_msgget_args *uap = v; + struct sys_msgget_args ap; + + SCARG(&ap, key) = SCARG(uap, key); + SCARG(&ap, msgflg) = SCARG(uap, msgflg); + + return sys_msgget(p, &ap, retval); +} + +struct svr4_sys_msgctl_args { + syscallarg(int) what; + syscallarg(int) msqid; + syscallarg(int) cmd; + syscallarg(struct svr4_msqid_ds *) buf; +}; + +static int +svr4_msgctl(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + int error; + struct svr4_sys_msgctl_args *uap = v; + struct sys_msgctl_args ap; + struct svr4_msqid_ds ss; + struct msqid_ds bs; + caddr_t sg = stackgap_init(p->p_emul); + + SCARG(&ap, msqid) = SCARG(uap, msqid); + SCARG(&ap, cmd) = SCARG(uap, cmd); + SCARG(&ap, buf) = stackgap_alloc(&sg, sizeof(bs)); + + switch (SCARG(uap, cmd)) { + case SVR4_IPC_STAT: + SCARG(&ap, cmd) = IPC_STAT; + if ((error = sys_msgctl(p, &ap, retval)) != 0) + return error; + error = copyin(&bs, SCARG(&ap, buf), sizeof bs); + if (error) + return error; + bsd_to_svr4_msqid_ds(&bs, &ss); + return copyout(&ss, SCARG(uap, buf), sizeof ss); + + case SVR4_IPC_SET: + SCARG(&ap, cmd) = IPC_SET; + error = copyin(SCARG(uap, buf), &ss, sizeof ss); + if (error) + return error; + svr4_to_bsd_msqid_ds(&ss, &bs); + error = copyout(&bs, SCARG(&ap, buf), sizeof bs); + if (error) + return error; + return sys_msgctl(p, &ap, retval); + + case SVR4_IPC_RMID: + SCARG(&ap, cmd) = IPC_RMID; + error = copyin(SCARG(uap, buf), &ss, sizeof ss); + if (error) + return error; + svr4_to_bsd_msqid_ds(&ss, &bs); + error = copyout(&bs, SCARG(&ap, buf), sizeof bs); + if (error) + return error; + return sys_msgctl(p, &ap, retval); + + default: + return EINVAL; + } +} + +int +svr4_sys_msgsys(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_msgsys_args *uap = v; + + DPRINTF(("svr4_msgsys(%d)\n", SCARG(uap, what))); + + switch (SCARG(uap, what)) { + case SVR4_msgsnd: + return svr4_msgsnd(p, v, retval); + case SVR4_msgrcv: + return svr4_msgrcv(p, v, retval); + case SVR4_msgget: + return svr4_msgget(p, v, retval); + case SVR4_msgctl: + return svr4_msgctl(p, v, retval); + default: + return EINVAL; + } +} +#endif + +#ifdef SYSVSHM + +static void +bsd_to_svr4_shmid_ds(bds, sds) + const struct shmid_ds *bds; + struct svr4_shmid_ds *sds; +{ + bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm); + sds->shm_segsz = bds->shm_segsz; + sds->shm_lkcnt = 0; + sds->shm_lpid = bds->shm_lpid; + sds->shm_cpid = bds->shm_cpid; + sds->shm_amp = bds->shm_internal; + sds->shm_nattch = bds->shm_nattch; + sds->shm_cnattch = 0; + sds->shm_atime = bds->shm_atime; + sds->shm_pad1 = 0; + sds->shm_dtime = bds->shm_dtime; + sds->shm_pad2 = 0; + sds->shm_ctime = bds->shm_ctime; + sds->shm_pad3 = 0; +} + +static void +svr4_to_bsd_shmid_ds(sds, bds) + const struct svr4_shmid_ds *sds; + struct shmid_ds *bds; +{ + svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm); + bds->shm_segsz = sds->shm_segsz; + bds->shm_lpid = sds->shm_lpid; + bds->shm_cpid = sds->shm_cpid; + bds->shm_internal = sds->shm_amp; + bds->shm_nattch = sds->shm_nattch; + bds->shm_atime = sds->shm_atime; + bds->shm_dtime = sds->shm_dtime; + bds->shm_ctime = sds->shm_ctime; +} + +struct svr4_sys_shmat_args { + syscallarg(int) what; + syscallarg(int) shmid; + syscallarg(void *) shmaddr; + syscallarg(int) shmflg; +}; + +static int +svr4_shmat(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_shmat_args *uap = v; + struct sys_shmat_args ap; + + SCARG(&ap, shmid) = SCARG(uap, shmid); + SCARG(&ap, shmaddr) = SCARG(uap, shmaddr); + SCARG(&ap, shmflg) = SCARG(uap, shmflg); + + return sys_shmat(p, &ap, retval); +} + +struct svr4_sys_shmdt_args { + syscallarg(int) what; + syscallarg(void *) shmaddr; +}; + +static int +svr4_shmdt(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_shmdt_args *uap = v; + struct sys_shmdt_args ap; + + SCARG(&ap, shmaddr) = SCARG(uap, shmaddr); + + return sys_shmdt(p, &ap, retval); +} + +struct svr4_sys_shmget_args { + syscallarg(int) what; + syscallarg(key_t) key; + syscallarg(int) size; + syscallarg(int) shmflg; +}; + +static int +svr4_shmget(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_shmget_args *uap = v; + struct sys_shmget_args ap; + + SCARG(&ap, key) = SCARG(uap, key); + SCARG(&ap, size) = SCARG(uap, size); + SCARG(&ap, shmflg) = SCARG(uap, shmflg); + + return sys_shmget(p, &ap, retval); +} + +struct svr4_sys_shmctl_args { + syscallarg(int) what; + syscallarg(int) shmid; + syscallarg(int) cmd; + syscallarg(struct svr4_shmid_ds *) buf; +}; + +int +svr4_shmctl(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_shmctl_args *uap = v; + int error; + caddr_t sg = stackgap_init(p->p_emul); + struct sys_shmctl_args ap; + struct shmid_ds bs; + struct svr4_shmid_ds ss; + + SCARG(&ap, shmid) = SCARG(uap, shmid); + + if (SCARG(uap, buf) != NULL) { + SCARG(&ap, buf) = stackgap_alloc(&sg, sizeof (struct shmid_ds)); + switch (SCARG(uap, cmd)) { + case SVR4_IPC_SET: + case SVR4_IPC_RMID: + case SVR4_SHM_LOCK: + case SVR4_SHM_UNLOCK: + error = copyin(SCARG(uap, buf), (caddr_t) &ss, + sizeof ss); + if (error) + return error; + svr4_to_bsd_shmid_ds(&ss, &bs); + error = copyout(&bs, SCARG(&ap, buf), sizeof bs); + if (error) + return error; + break; + default: + break; + } + } + else + SCARG(&ap, buf) = NULL; + + + switch (SCARG(uap, cmd)) { + case SVR4_IPC_STAT: + SCARG(&ap, cmd) = IPC_STAT; + if ((error = sys_shmctl(p, &ap, retval)) != 0) + return error; + if (SCARG(uap, buf) == NULL) + return 0; + error = copyin(&bs, SCARG(&ap, buf), sizeof bs); + if (error) + return error; + bsd_to_svr4_shmid_ds(&bs, &ss); + return copyout(&ss, SCARG(uap, buf), sizeof ss); + + case SVR4_IPC_SET: + SCARG(&ap, cmd) = IPC_SET; + return sys_shmctl(p, &ap, retval); + + case SVR4_IPC_RMID: + case SVR4_SHM_LOCK: + case SVR4_SHM_UNLOCK: + switch (SCARG(uap, cmd)) { + case SVR4_IPC_RMID: + SCARG(&ap, cmd) = IPC_RMID; + break; + case SVR4_SHM_LOCK: + SCARG(&ap, cmd) = SHM_LOCK; + break; + case SVR4_SHM_UNLOCK: + SCARG(&ap, cmd) = SHM_UNLOCK; + break; + default: + return EINVAL; + } + return sys_shmctl(p, &ap, retval); + + default: + return EINVAL; + } +} + +int +svr4_sys_shmsys(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct svr4_sys_shmsys_args *uap = v; + + DPRINTF(("svr4_shmsys(%d)\n", SCARG(uap, what))); + + switch (SCARG(uap, what)) { + case SVR4_shmat: + return svr4_shmat(p, v, retval); + case SVR4_shmdt: + return svr4_shmdt(p, v, retval); + case SVR4_shmget: + return svr4_shmget(p, v, retval); + case SVR4_shmctl: + return svr4_shmctl(p, v, retval); + default: + return ENOSYS; + } +} +#endif /* SYSVSHM */ diff --git a/sys/compat/svr4/svr4_ipc.h b/sys/compat/svr4/svr4_ipc.h new file mode 100644 index 0000000..798920d --- /dev/null +++ b/sys/compat/svr4/svr4_ipc.h @@ -0,0 +1,174 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1995 Christos Zoulas. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_IPC_H_ +#define _SVR4_IPC_H_ + +/* + * General IPC + */ +#define SVR4_IPC_RMID 10 +#define SVR4_IPC_SET 11 +#define SVR4_IPC_STAT 12 + +struct svr4_ipc_perm { + svr4_uid_t uid; + svr4_gid_t gid; + svr4_uid_t cuid; + svr4_gid_t cgid; + svr4_mode_t mode; + u_long seq; + svr4_key_t key; + long pad[4]; +}; + +/* + * Message queues + */ +#define SVR4_msgget 0 +#define SVR4_msgctl 1 +#define SVR4_msgrcv 2 +#define SVR4_msgsnd 3 + +struct svr4_msg { + struct svr4_msg *msg_next; + long msg_type; + u_short msg_ts; + short msg_spot; +}; + +struct svr4_msqid_ds { + struct svr4_ipc_perm msg_perm; + struct svr4_msg *msg_first; + struct svr4_msg *msg_last; + u_long msg_cbytes; + u_long msg_qnum; + u_long msg_qbytes; + svr4_pid_t msg_lspid; + svr4_pid_t msg_lrpid; + svr4_time_t msg_stime; + long msg_pad1; + svr4_time_t msg_rtime; + long msg_pad2; + svr4_time_t msg_ctime; + long msg_pad3; + short msg_cv; + short msg_qnum_cv; + long msg_pad4[3]; +}; + +struct svr4_msgbuf { + long mtype; /* message type */ + char mtext[1]; /* message text */ +}; + +struct svr4_msginfo { + int msgmap; + int msgmax; + int msgmnb; + int msgmni; + int msgssz; + int msgtql; + u_short msgseg; +}; + +/* + * Shared memory + */ +#define SVR4_shmat 0 +#define SVR4_shmctl 1 +#define SVR4_shmdt 2 +#define SVR4_shmget 3 + +/* shmctl() operations */ +#define SVR4_SHM_LOCK 3 +#define SVR4_SHM_UNLOCK 4 + +struct svr4_shmid_ds { + struct svr4_ipc_perm shm_perm; + int shm_segsz; + void *shm_amp; + u_short shm_lkcnt; + svr4_pid_t shm_lpid; + svr4_pid_t shm_cpid; + u_long shm_nattch; + u_long shm_cnattch; + svr4_time_t shm_atime; + long shm_pad1; + svr4_time_t shm_dtime; + long shm_pad2; + svr4_time_t shm_ctime; + long shm_pad3; + long shm_pad4[4]; +}; + +/* + * Semaphores + */ +#define SVR4_semctl 0 +#define SVR4_semget 1 +#define SVR4_semop 2 + +/* semctl() operations */ +#define SVR4_SEM_GETNCNT 3 +#define SVR4_SEM_GETPID 4 +#define SVR4_SEM_GETVAL 5 +#define SVR4_SEM_GETALL 6 +#define SVR4_SEM_GETZCNT 7 +#define SVR4_SEM_SETVAL 8 +#define SVR4_SEM_SETALL 9 + +struct svr4_sem { + u_short semval; + svr4_pid_t sempid; + u_short semncnt; + u_short semzcnt; + u_short semncnt_cv; + u_short semzcnt_cv; +}; + +struct svr4_semid_ds { + struct svr4_ipc_perm sem_perm; + struct svr4_sem *sem_base; + u_short sem_nsems; + svr4_time_t sem_otime; + long sem_pad1; + svr4_time_t sem_ctime; + long sem_pad2; + long sem_pad3[4]; +}; + +struct svr4_sembuf { + u_short sem_num; + short sem_op; + short sem_flg; +}; + +#endif /* _SVR4_IPC_H */ diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c new file mode 100644 index 0000000..5b537c6 --- /dev/null +++ b/sys/compat/svr4/svr4_misc.c @@ -0,0 +1,1629 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * SVR4 compatibility module. + * + * SVR4 system calls that are implemented differently in BSD are + * handled here. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/namei.h> +#include <sys/dirent.h> +#include <sys/proc.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/file.h> +#include <sys/filedesc.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/mbuf.h> +#include <sys/mman.h> +#include <sys/mount.h> +#include <sys/resource.h> +#include <sys/resourcevar.h> +#include <sys/socket.h> +#include <sys/vnode.h> +#include <sys/uio.h> +#include <sys/wait.h> +#include <sys/utsname.h> +#include <sys/unistd.h> +#include <sys/times.h> +#include <sys/fcntl.h> +#include <sys/sem.h> +#include <sys/msg.h> +#include <sys/ptrace.h> +#include <sys/signalvar.h> +#include <ufs/ufs/dir.h> +#include <vm/vm_zone.h> + +#include <sys/sysproto.h> + +#include <netinet/in.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_sysconfig.h> +#include <svr4/svr4_dirent.h> +#include <svr4/svr4_acl.h> +#include <svr4/svr4_time.h> +#include <svr4/svr4_ulimit.h> +#include <svr4/svr4_statvfs.h> +#include <svr4/svr4_hrt.h> +#include <svr4/svr4_mman.h> +#include <svr4/svr4_wait.h> + +#include <machine/vmparam.h> +#include <vm/vm.h> +#include <vm/vm_param.h> +#include <vm/vm_map.h> +#include <vm/vm_prot.h> + +#if defined(NetBSD) +# if defined(UVM) +# include <uvm/uvm_extern.h> +# endif +#endif + +#define BSD_DIRENT(cp) ((struct dirent *)(cp)) + +extern void *M_ZOMBIE; +extern void *M_SUBPROC; + +extern int bsd_to_svr4_sig[]; +static int svr4_mknod __P((struct proc *, register_t *, char *, + svr4_mode_t, svr4_dev_t)); + +static __inline clock_t timeval_to_clock_t __P((struct timeval *)); +static int svr4_setinfo __P((struct proc *, int, svr4_siginfo_t *)); + +struct svr4_hrtcntl_args; +static int svr4_hrtcntl __P((struct proc *, struct svr4_hrtcntl_args *, + register_t *)); +static void bsd_statfs_to_svr4_statvfs __P((const struct statfs *, + struct svr4_statvfs *)); +static void bsd_statfs_to_svr4_statvfs64 __P((const struct statfs *, + struct svr4_statvfs64 *)); +static struct proc *svr4_pfind __P((pid_t pid)); + +/* BOGUS noop */ +#if defined(BOGUS) +int +svr4_sys_setitimer(p, uap) + register struct proc *p; + struct svr4_sys_setitimer_args *uap; +{ + p->p_retval[0] = 0; + return 0; +} +#endif + +int +svr4_sys_wait(p, uap) + struct proc *p; + struct svr4_sys_wait_args *uap; +{ + struct wait_args w4; + int error, *retval = p->p_retval, st, sig; + size_t sz = sizeof(*SCARG(&w4, status)); + + SCARG(&w4, rusage) = NULL; + SCARG(&w4, options) = 0; + + if (SCARG(uap, status) == NULL) { + caddr_t sg = stackgap_init(); + + SCARG(&w4, status) = stackgap_alloc(&sg, sz); + } + else + SCARG(&w4, status) = SCARG(uap, status); + + SCARG(&w4, pid) = WAIT_ANY; + + if ((error = wait4(p, &w4)) != 0) + return error; + + if ((error = copyin(SCARG(&w4, status), &st, sizeof(st))) != 0) + return error; + + if (WIFSIGNALED(st)) { + sig = WTERMSIG(st); + if (sig >= 0 && sig < NSIG) + st = (st & ~0177) | bsd_to_svr4_sig[sig]; + } else if (WIFSTOPPED(st)) { + sig = WSTOPSIG(st); + if (sig >= 0 && sig < NSIG) + st = (st & ~0xff00) | (bsd_to_svr4_sig[sig] << 8); + } + + /* + * It looks like wait(2) on svr4/solaris/2.4 returns + * the status in retval[1], and the pid on retval[0]. + */ + retval[1] = st; + + if (SCARG(uap, status)) + if ((error = copyout(&st, SCARG(uap, status), sizeof(st))) != 0) + return error; + + return 0; +} + +int +svr4_sys_execv(p, uap) + struct proc *p; + struct svr4_sys_execv_args *uap; +{ + struct execve_args ap; + caddr_t sg; + + sg = stackgap_init(); + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + SCARG(&ap, fname) = SCARG(uap, path); + SCARG(&ap, argv) = SCARG(uap, argp); + SCARG(&ap, envv) = NULL; + + return execve(p, &ap); +} + +int +svr4_sys_execve(p, uap) + struct proc *p; + struct svr4_sys_execve_args *uap; +{ + struct execve_args ap; + caddr_t sg; + + sg = stackgap_init(); + CHECKALTEXIST(p, &sg, uap->path); + + SCARG(&ap, fname) = SCARG(uap, path); + SCARG(&ap, argv) = SCARG(uap, argp); + SCARG(&ap, envv) = SCARG(uap, envp); + + return execve(p, &ap); +} + +int +svr4_sys_time(p, v) + struct proc *p; + struct svr4_sys_time_args *v; +{ + struct svr4_sys_time_args *uap = v; + int error = 0; + struct timeval tv; + + microtime(&tv); + if (SCARG(uap, t)) + error = copyout(&tv.tv_sec, SCARG(uap, t), + sizeof(*(SCARG(uap, t)))); + p->p_retval[0] = (int) tv.tv_sec; + + return error; +} + + +/* + * Read SVR4-style directory entries. We suck them into kernel space so + * that they can be massaged before being copied out to user code. Like + * SunOS, we squish out `empty' entries. + * + * This is quite ugly, but what do you expect from compatibility code? + */ + +int +svr4_sys_getdents64(p, uap) + struct proc *p; + struct svr4_sys_getdents64_args *uap; +{ + struct dirent *bdp; + struct vnode *vp; + caddr_t inp, buf; /* BSD-format */ + int len, reclen; /* BSD-format */ + caddr_t outp; /* SVR4-format */ + int resid, svr4_reclen; /* SVR4-format */ + struct file *fp; + struct uio auio; + struct iovec aiov; + struct svr4_dirent64 idb; + off_t off; /* true file offset */ + int buflen, error, eofflag; + u_long *cookiebuf = NULL, *cookie; + int ncookies = 0, retval = 0, offcnt = 0; + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + + if ((fp->f_flag & FREAD) == 0) + return (EBADF); + + vp = (struct vnode *)fp->f_data; + if (vp->v_type != VDIR) + return (EINVAL); + + buflen = min(MAXBSIZE, SCARG(uap, nbytes)); + DPRINTF(("buflen = %d, spec = %d\n", buflen, SCARG(uap, nbytes))); + buf = malloc(buflen, M_TEMP, M_WAITOK); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + off = fp->f_offset; +again: + aiov.iov_base = buf; + aiov.iov_len = buflen; + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_rw = UIO_READ; + auio.uio_segflg = UIO_SYSSPACE; + auio.uio_procp = p; + auio.uio_resid = buflen; + auio.uio_offset = off; + DPRINTF((">>> off = %d\n", off)); + + /* + * First we read into the malloc'ed buffer, then + * we massage it into user space, one record at a time. + */ + error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, + &cookiebuf); + if (error) + goto out; + + inp = buf; + outp = SCARG(uap, dp); + resid = SCARG(uap, nbytes); + if ((len = buflen - auio.uio_resid) == 0) + goto eof; + + for (cookie = cookiebuf; len > 0; len -= reclen) { + bdp = (struct dirent *)inp; + reclen = bdp->d_reclen; + if (reclen & 3) + panic("svr4_getdents64: bad reclen"); + if (bdp->d_fileno == 0) { + inp += reclen; /* it is a hole; squish it out */ +#if 0 + off = *cookie++; +#else + off += reclen; +#endif + DPRINTF(("+++ off = %d\n", off)); + continue; + } + svr4_reclen = SVR4_RECLEN(&idb, (bdp->d_namlen)); + + if (reclen > len || resid < svr4_reclen) { + /* entry too big for buffer, so just stop */ + outp++; + DPRINTF(("+++ off = %d\n", off)); + break; + } +#if 0 + off = *cookie++; /* each entry points to the next */ +#else + off += reclen; +#endif + DPRINTF(("+++ off = %d\n", off)); + + /* + * Massage in place to make a SVR4-shaped dirent (otherwise + * we have to worry about touching user memory outside of + * the copyout() call). + */ + idb.d_ino = (svr4_ino64_t)bdp->d_fileno; + idb.d_off = (svr4_off64_t)off; + idb.d_reclen = (u_short)svr4_reclen; + strcpy(idb.d_name, bdp->d_name); + if ((error = copyout((caddr_t)&idb, outp, svr4_reclen))) + goto out; + DPRINTF(("d_ino = %d\nd_off = %d\nd_reclen = %d\n", + idb.d_ino, idb.d_off, (u_short)idb.d_reclen)); + DPRINTF(("d_name = %s\n", idb.d_name)); + DPRINTF(("(bdp->d_type = %d, reclen = %d, bdp->d_namelen = %d)\n", bdp->d_type, svr4_reclen, bdp->d_namlen)); + /* advance past this real entry */ + inp += reclen; + /* advance output past SVR4-shaped entry */ + outp += svr4_reclen; + resid -= svr4_reclen; + offcnt += svr4_reclen; + } + DPRINTF(("block finished\n")); + /* if we squished out the whole block, try again */ + fp->f_offset = off; /* update the vnode offset */ + if (outp == SCARG(uap, dp)) + goto again; + +eof: + retval = offcnt; /* SCARG(uap, nbytes) - resid;*/ +out: + VOP_UNLOCK(vp, 0, p); + if (cookiebuf) + free(cookiebuf, M_TEMP); + free(buf, M_TEMP); + DPRINTF(("\t\treturning %d\n", retval)); + p->p_retval[0] = retval; + return error; +} + + +int +svr4_sys_getdents(p, uap) + struct proc *p; + struct svr4_sys_getdents_args *uap; +{ + struct dirent *bdp; + struct vnode *vp; + caddr_t inp, buf; /* BSD-format */ + int len, reclen; /* BSD-format */ + caddr_t outp; /* SVR4-format */ + int resid, svr4_reclen; /* SVR4-format */ + struct file *fp; + struct uio auio; + struct iovec aiov; + struct svr4_dirent idb; + off_t off; /* true file offset */ + int buflen, error, eofflag; + u_long *cookiebuf = NULL, *cookie; + int ncookies = 0, *retval = p->p_retval; + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + + if ((fp->f_flag & FREAD) == 0) + return (EBADF); + + vp = (struct vnode *)fp->f_data; + if (vp->v_type != VDIR) + return (EINVAL); + + buflen = min(MAXBSIZE, SCARG(uap, nbytes)); + buf = malloc(buflen, M_TEMP, M_WAITOK); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + off = fp->f_offset; +again: + aiov.iov_base = buf; + aiov.iov_len = buflen; + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_rw = UIO_READ; + auio.uio_segflg = UIO_SYSSPACE; + auio.uio_procp = p; + auio.uio_resid = buflen; + auio.uio_offset = off; + /* + * First we read into the malloc'ed buffer, then + * we massage it into user space, one record at a time. + */ + error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, + &cookiebuf); + if (error) + goto out; + + inp = buf; + outp = SCARG(uap, buf); + resid = SCARG(uap, nbytes); + if ((len = buflen - auio.uio_resid) == 0) + goto eof; + + for (cookie = cookiebuf; len > 0; len -= reclen) { + bdp = (struct dirent *)inp; + reclen = bdp->d_reclen; + if (reclen & 3) + panic("svr4_getdents: bad reclen"); + off = *cookie++; /* each entry points to the next */ + if ((off >> 32) != 0) { + uprintf("svr4_getdents: dir offset too large for emulated program"); + error = EINVAL; + goto out; + } + if (bdp->d_fileno == 0) { + inp += reclen; /* it is a hole; squish it out */ + continue; + } + svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen); + if (reclen > len || resid < svr4_reclen) { + /* entry too big for buffer, so just stop */ + outp++; + break; + } + /* + * Massage in place to make a SVR4-shaped dirent (otherwise + * we have to worry about touching user memory outside of + * the copyout() call). + */ + idb.d_ino = (svr4_ino_t)bdp->d_fileno; + idb.d_off = (svr4_off_t)off; + idb.d_reclen = (u_short)svr4_reclen; + strcpy(idb.d_name, bdp->d_name); + if ((error = copyout((caddr_t)&idb, outp, svr4_reclen))) + goto out; + /* advance past this real entry */ + inp += reclen; + /* advance output past SVR4-shaped entry */ + outp += svr4_reclen; + resid -= svr4_reclen; + } + + /* if we squished out the whole block, try again */ + if (outp == SCARG(uap, buf)) + goto again; + fp->f_offset = off; /* update the vnode offset */ + +eof: + *retval = SCARG(uap, nbytes) - resid; +out: + VOP_UNLOCK(vp, 0, p); + if (cookiebuf) + free(cookiebuf, M_TEMP); + free(buf, M_TEMP); + return error; +} + + +int +svr4_sys_mmap(p, uap) + struct proc *p; + struct svr4_sys_mmap_args *uap; +{ + struct mmap_args mm; + int *retval; + + retval = p->p_retval; +#define _MAP_NEW 0x80000000 + /* + * Verify the arguments. + */ + if (SCARG(uap, prot) & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) + return EINVAL; /* XXX still needed? */ + + if (SCARG(uap, len) == 0) + return EINVAL; + + SCARG(&mm, prot) = SCARG(uap, prot); + SCARG(&mm, len) = SCARG(uap, len); + SCARG(&mm, flags) = SCARG(uap, flags) & ~_MAP_NEW; + SCARG(&mm, fd) = SCARG(uap, fd); + SCARG(&mm, addr) = SCARG(uap, addr); + SCARG(&mm, pos) = SCARG(uap, pos); + + return mmap(p, &mm); +} + +int +svr4_sys_mmap64(p, uap) + struct proc *p; + struct svr4_sys_mmap64_args *uap; +{ + struct mmap_args mm; + void *rp; + +#define _MAP_NEW 0x80000000 + /* + * Verify the arguments. + */ + if (SCARG(uap, prot) & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) + return EINVAL; /* XXX still needed? */ + + if (SCARG(uap, len) == 0) + return EINVAL; + + SCARG(&mm, prot) = SCARG(uap, prot); + SCARG(&mm, len) = SCARG(uap, len); + SCARG(&mm, flags) = SCARG(uap, flags) & ~_MAP_NEW; + SCARG(&mm, fd) = SCARG(uap, fd); + SCARG(&mm, addr) = SCARG(uap, addr); + SCARG(&mm, pos) = SCARG(uap, pos); + + rp = (void *) round_page((vm_offset_t)(p->p_vmspace->vm_daddr + MAXDSIZ)); + if ((SCARG(&mm, flags) & MAP_FIXED) == 0 && + SCARG(&mm, addr) != 0 && (void *)SCARG(&mm, addr) < rp) + SCARG(&mm, addr) = rp; + + return mmap(p, &mm); +} + + +int +svr4_sys_fchroot(p, uap) + struct proc *p; + struct svr4_sys_fchroot_args *uap; +{ + struct filedesc *fdp = p->p_fd; + struct vnode *vp; + struct file *fp; + int error; + + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) + return error; + if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0) + return error; + vp = (struct vnode *) fp->f_data; + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_type != VDIR) + error = ENOTDIR; + else + error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p); + VOP_UNLOCK(vp, 0, p); + if (error) + return error; + VREF(vp); + if (fdp->fd_rdir != NULL) + vrele(fdp->fd_rdir); + fdp->fd_rdir = vp; + return 0; +} + + +static int +svr4_mknod(p, retval, path, mode, dev) + struct proc *p; + register_t *retval; + char *path; + svr4_mode_t mode; + svr4_dev_t dev; +{ + caddr_t sg = stackgap_init(); + + CHECKALTEXIST(p, &sg, path); + + if (S_ISFIFO(mode)) { + struct mkfifo_args ap; + SCARG(&ap, path) = path; + SCARG(&ap, mode) = mode; + return mkfifo(p, &ap); + } else { + struct mknod_args ap; + SCARG(&ap, path) = path; + SCARG(&ap, mode) = mode; + SCARG(&ap, dev) = dev; + return mknod(p, &ap); + } +} + + +int +svr4_sys_mknod(p, uap) + register struct proc *p; + struct svr4_sys_mknod_args *uap; +{ + int *retval = p->p_retval; + return svr4_mknod(p, retval, + SCARG(uap, path), SCARG(uap, mode), + svr4_to_bsd_odev_t(SCARG(uap, dev))); +} + + +int +svr4_sys_xmknod(p, uap) + struct proc *p; + struct svr4_sys_xmknod_args *uap; +{ + int *retval = p->p_retval; + return svr4_mknod(p, retval, + SCARG(uap, path), SCARG(uap, mode), + svr4_to_bsd_dev_t(SCARG(uap, dev))); +} + + +int +svr4_sys_vhangup(p, uap) + struct proc *p; + struct svr4_sys_vhangup_args *uap; +{ + return 0; +} + + +int +svr4_sys_sysconfig(p, uap) + struct proc *p; + struct svr4_sys_sysconfig_args *uap; +{ + int *retval; + + retval = &(p->p_retval[0]); + + switch (SCARG(uap, name)) { + case SVR4_CONFIG_UNUSED: + *retval = 0; + break; + case SVR4_CONFIG_NGROUPS: + *retval = NGROUPS_MAX; + break; + case SVR4_CONFIG_CHILD_MAX: + *retval = maxproc; + break; + case SVR4_CONFIG_OPEN_FILES: + *retval = maxfiles; + break; + case SVR4_CONFIG_POSIX_VER: + *retval = 198808; + break; + case SVR4_CONFIG_PAGESIZE: + *retval = PAGE_SIZE; + break; + case SVR4_CONFIG_CLK_TCK: + *retval = 60; /* should this be `hz', ie. 100? */ + break; + case SVR4_CONFIG_XOPEN_VER: + *retval = 2; /* XXX: What should that be? */ + break; + case SVR4_CONFIG_PROF_TCK: + *retval = 60; /* XXX: What should that be? */ + break; + case SVR4_CONFIG_NPROC_CONF: + *retval = 1; /* Only one processor for now */ + break; + case SVR4_CONFIG_NPROC_ONLN: + *retval = 1; /* And it better be online */ + break; + case SVR4_CONFIG_AIO_LISTIO_MAX: + case SVR4_CONFIG_AIO_MAX: + case SVR4_CONFIG_AIO_PRIO_DELTA_MAX: + *retval = 0; /* No aio support */ + break; + case SVR4_CONFIG_DELAYTIMER_MAX: + *retval = 0; /* No delaytimer support */ + break; + case SVR4_CONFIG_MQ_OPEN_MAX: + *retval = msginfo.msgmni; + break; + case SVR4_CONFIG_MQ_PRIO_MAX: + *retval = 0; /* XXX: Don't know */ + break; + case SVR4_CONFIG_RTSIG_MAX: + *retval = 0; + break; + case SVR4_CONFIG_SEM_NSEMS_MAX: + *retval = seminfo.semmni; + break; + case SVR4_CONFIG_SEM_VALUE_MAX: + *retval = seminfo.semvmx; + break; + case SVR4_CONFIG_SIGQUEUE_MAX: + *retval = 0; /* XXX: Don't know */ + break; + case SVR4_CONFIG_SIGRT_MIN: + case SVR4_CONFIG_SIGRT_MAX: + *retval = 0; /* No real time signals */ + break; + case SVR4_CONFIG_TIMER_MAX: + *retval = 3; /* XXX: real, virtual, profiling */ + break; +#if defined(NOTYET) + case SVR4_CONFIG_PHYS_PAGES: +#if defined(UVM) + *retval = uvmexp.free; /* XXX: free instead of total */ +#else + *retval = cnt.v_free_count; /* XXX: free instead of total */ +#endif + break; + case SVR4_CONFIG_AVPHYS_PAGES: +#if defined(UVM) + *retval = uvmexp.active; /* XXX: active instead of avg */ +#else + *retval = cnt.v_active_count; /* XXX: active instead of avg */ +#endif + break; +#endif /* NOTYET */ + + default: + return EINVAL; + } + return 0; +} + +extern int swap_pager_full; + +/* ARGSUSED */ +int +svr4_sys_break(p, uap) + struct proc *p; + struct svr4_sys_break_args *uap; +{ + struct vmspace *vm = p->p_vmspace; + vm_offset_t new, old, base, ns; + int rv; + + base = round_page((vm_offset_t) vm->vm_daddr); + ns = (vm_offset_t)SCARG(uap, nsize); + new = round_page(ns); + if (new > base) { + if ((new - base) > (unsigned) p->p_rlimit[RLIMIT_DATA].rlim_cur) { + return ENOMEM; + } + if (new >= VM_MAXUSER_ADDRESS) { + return (ENOMEM); + } + } else if (new < base) { + /* + * This is simply an invalid value. If someone wants to + * do fancy address space manipulations, mmap and munmap + * can do most of what the user would want. + */ + return EINVAL; + } + + old = base + ctob(vm->vm_dsize); + + if (new > old) { + vm_size_t diff; + if (swap_pager_full) { + return (ENOMEM); + } + diff = new - old; + rv = vm_map_find(&vm->vm_map, NULL, 0, &old, diff, FALSE, + VM_PROT_ALL, VM_PROT_ALL, 0); + if (rv != KERN_SUCCESS) { + return (ENOMEM); + } + vm->vm_dsize += btoc(diff); + } else if (new < old) { + rv = vm_map_remove(&vm->vm_map, new, old); + if (rv != KERN_SUCCESS) { + return (ENOMEM); + } + vm->vm_dsize -= btoc(old - new); + } + + return (0); +} + +static __inline clock_t +timeval_to_clock_t(tv) + struct timeval *tv; +{ + return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz); +} + + +int +svr4_sys_times(p, uap) + struct proc *p; + struct svr4_sys_times_args *uap; +{ + int error, *retval = p->p_retval; + struct tms tms; + struct timeval t; + struct rusage *ru; + struct rusage r; + struct getrusage_args ga; + + caddr_t sg = stackgap_init(); + ru = stackgap_alloc(&sg, sizeof(struct rusage)); + + SCARG(&ga, who) = RUSAGE_SELF; + SCARG(&ga, rusage) = ru; + + error = getrusage(p, &ga); + if (error) + return error; + + if ((error = copyin(ru, &r, sizeof r)) != 0) + return error; + + tms.tms_utime = timeval_to_clock_t(&r.ru_utime); + tms.tms_stime = timeval_to_clock_t(&r.ru_stime); + + SCARG(&ga, who) = RUSAGE_CHILDREN; + error = getrusage(p, &ga); + if (error) + return error; + + if ((error = copyin(ru, &r, sizeof r)) != 0) + return error; + + tms.tms_cutime = timeval_to_clock_t(&r.ru_utime); + tms.tms_cstime = timeval_to_clock_t(&r.ru_stime); + + microtime(&t); + *retval = timeval_to_clock_t(&t); + + return copyout(&tms, SCARG(uap, tp), sizeof(tms)); +} + + +int +svr4_sys_ulimit(p, uap) + struct proc *p; + struct svr4_sys_ulimit_args *uap; +{ + int *retval = p->p_retval; + + switch (SCARG(uap, cmd)) { + case SVR4_GFILLIM: + *retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur / 512; + if (*retval == -1) + *retval = 0x7fffffff; + return 0; + + case SVR4_SFILLIM: + { + int error; + struct __setrlimit_args srl; + struct rlimit krl; + caddr_t sg = stackgap_init(); + struct rlimit *url = (struct rlimit *) + stackgap_alloc(&sg, sizeof *url); + + krl.rlim_cur = SCARG(uap, newlimit) * 512; + krl.rlim_max = p->p_rlimit[RLIMIT_FSIZE].rlim_max; + + error = copyout(&krl, url, sizeof(*url)); + if (error) + return error; + + SCARG(&srl, which) = RLIMIT_FSIZE; + SCARG(&srl, rlp) = (struct orlimit *)url; + + error = setrlimit(p, &srl); + if (error) + return error; + + *retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur; + if (*retval == -1) + *retval = 0x7fffffff; + return 0; + } + + case SVR4_GMEMLIM: + { + struct vmspace *vm = p->p_vmspace; + register_t r = p->p_rlimit[RLIMIT_DATA].rlim_cur; + + if (r == -1) + r = 0x7fffffff; + r += (long) vm->vm_daddr; + if (r < 0) + r = 0x7fffffff; + *retval = r; + return 0; + } + + case SVR4_GDESLIM: + *retval = p->p_rlimit[RLIMIT_NOFILE].rlim_cur; + if (*retval == -1) + *retval = 0x7fffffff; + return 0; + + default: + return EINVAL; + } +} + +static struct proc * +svr4_pfind(pid) + pid_t pid; +{ + struct proc *p; + + /* look in the live processes */ + if ((p = pfind(pid)) != NULL) + return p; + + /* look in the zombies */ + for (p = zombproc.lh_first; p != 0; p = p->p_list.le_next) + if (p->p_pid == pid) + return p; + + return NULL; +} + + +int +svr4_sys_pgrpsys(p, uap) + struct proc *p; + struct svr4_sys_pgrpsys_args *uap; +{ + int *retval = p->p_retval; + + switch (SCARG(uap, cmd)) { + case 1: /* setpgrp() */ + /* + * SVR4 setpgrp() (which takes no arguments) has the + * semantics that the session ID is also created anew, so + * in almost every sense, setpgrp() is identical to + * setsid() for SVR4. (Under BSD, the difference is that + * a setpgid(0,0) will not create a new session.) + */ + setsid(p, NULL); + /*FALLTHROUGH*/ + + case 0: /* getpgrp() */ + *retval = p->p_pgrp->pg_id; + return 0; + + case 2: /* getsid(pid) */ + if (SCARG(uap, pid) != 0 && + (p = svr4_pfind(SCARG(uap, pid))) == NULL) + return ESRCH; + /* + * This has already been initialized to the pid of + * the session leader. + */ + *retval = (register_t) p->p_session->s_leader->p_pid; + return 0; + + case 3: /* setsid() */ + return setsid(p, NULL); + + case 4: /* getpgid(pid) */ + + if (SCARG(uap, pid) != 0 && + (p = svr4_pfind(SCARG(uap, pid))) == NULL) + return ESRCH; + + *retval = (int) p->p_pgrp->pg_id; + return 0; + + case 5: /* setpgid(pid, pgid); */ + { + struct setpgid_args sa; + + SCARG(&sa, pid) = SCARG(uap, pid); + SCARG(&sa, pgid) = SCARG(uap, pgid); + return setpgid(p, &sa); + } + + default: + return EINVAL; + } +} + +#define syscallarg(x) union { x datum; register_t pad; } + +struct svr4_hrtcntl_args { + int cmd; + int fun; + int clk; + svr4_hrt_interval_t * iv; + svr4_hrt_time_t * ti; +}; + + +static int +svr4_hrtcntl(p, uap, retval) + struct proc *p; + struct svr4_hrtcntl_args *uap; + register_t *retval; +{ + switch (SCARG(uap, fun)) { + case SVR4_HRT_CNTL_RES: + DPRINTF(("htrcntl(RES)\n")); + *retval = SVR4_HRT_USEC; + return 0; + + case SVR4_HRT_CNTL_TOFD: + DPRINTF(("htrcntl(TOFD)\n")); + { + struct timeval tv; + svr4_hrt_time_t t; + if (SCARG(uap, clk) != SVR4_HRT_CLK_STD) { + DPRINTF(("clk == %d\n", SCARG(uap, clk))); + return EINVAL; + } + if (SCARG(uap, ti) == NULL) { + DPRINTF(("ti NULL\n")); + return EINVAL; + } + microtime(&tv); + t.h_sec = tv.tv_sec; + t.h_rem = tv.tv_usec; + t.h_res = SVR4_HRT_USEC; + return copyout(&t, SCARG(uap, ti), sizeof(t)); + } + + case SVR4_HRT_CNTL_START: + DPRINTF(("htrcntl(START)\n")); + return ENOSYS; + + case SVR4_HRT_CNTL_GET: + DPRINTF(("htrcntl(GET)\n")); + return ENOSYS; + default: + DPRINTF(("Bad htrcntl command %d\n", SCARG(uap, fun))); + return ENOSYS; + } +} + + +int +svr4_sys_hrtsys(p, uap) + struct proc *p; + struct svr4_sys_hrtsys_args *uap; +{ + int *retval = p->p_retval; + + switch (SCARG(uap, cmd)) { + case SVR4_HRT_CNTL: + return svr4_hrtcntl(p, (struct svr4_hrtcntl_args *) uap, + retval); + + case SVR4_HRT_ALRM: + DPRINTF(("hrtalarm\n")); + return ENOSYS; + + case SVR4_HRT_SLP: + DPRINTF(("hrtsleep\n")); + return ENOSYS; + + case SVR4_HRT_CAN: + DPRINTF(("hrtcancel\n")); + return ENOSYS; + + default: + DPRINTF(("Bad hrtsys command %d\n", SCARG(uap, cmd))); + return EINVAL; + } +} + + +static int +svr4_setinfo(p, st, s) + struct proc *p; + int st; + svr4_siginfo_t *s; +{ + svr4_siginfo_t i; + int sig; + + memset(&i, 0, sizeof(i)); + + i.si_signo = SVR4_SIGCHLD; + i.si_errno = 0; /* XXX? */ + + if (p) { + i.si_pid = p->p_pid; + if (p->p_stat == SZOMB) { + i.si_stime = p->p_ru->ru_stime.tv_sec; + i.si_utime = p->p_ru->ru_utime.tv_sec; + } + else { + i.si_stime = p->p_stats->p_ru.ru_stime.tv_sec; + i.si_utime = p->p_stats->p_ru.ru_utime.tv_sec; + } + } + + if (WIFEXITED(st)) { + i.si_status = WEXITSTATUS(st); + i.si_code = SVR4_CLD_EXITED; + } else if (WIFSTOPPED(st)) { + sig = WSTOPSIG(st); + if (sig >= 0 && sig < NSIG) + i.si_status = bsd_to_svr4_sig[sig]; + + if (i.si_status == SVR4_SIGCONT) + i.si_code = SVR4_CLD_CONTINUED; + else + i.si_code = SVR4_CLD_STOPPED; + } else { + sig = WTERMSIG(st); + if (sig >= 0 && sig < NSIG) + i.si_status = bsd_to_svr4_sig[sig]; + + if (WCOREDUMP(st)) + i.si_code = SVR4_CLD_DUMPED; + else + i.si_code = SVR4_CLD_KILLED; + } + + DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n", + i.si_pid, i.si_signo, i.si_code, i.si_errno, i.si_status)); + + return copyout(&i, s, sizeof(i)); +} + + +int +svr4_sys_waitsys(p, uap) + struct proc *p; + struct svr4_sys_waitsys_args *uap; +{ + int nfound; + int error, *retval = p->p_retval; + struct proc *q, *t; + + + switch (SCARG(uap, grp)) { + case SVR4_P_PID: + break; + + case SVR4_P_PGID: + SCARG(uap, id) = -p->p_pgid; + break; + + case SVR4_P_ALL: + SCARG(uap, id) = WAIT_ANY; + break; + + default: + return EINVAL; + } + + DPRINTF(("waitsys(%d, %d, %p, %x)\n", + SCARG(uap, grp), SCARG(uap, id), + SCARG(uap, info), SCARG(uap, options))); + +loop: + nfound = 0; + for (q = p->p_children.lh_first; q != 0; q = q->p_sibling.le_next) { + if (SCARG(uap, id) != WAIT_ANY && + q->p_pid != SCARG(uap, id) && + q->p_pgid != -SCARG(uap, id)) { + DPRINTF(("pid %d pgid %d != %d\n", q->p_pid, + q->p_pgid, SCARG(uap, id))); + continue; + } + nfound++; + if (q->p_stat == SZOMB && + ((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)))) { + *retval = 0; + DPRINTF(("found %d\n", q->p_pid)); + if ((error = svr4_setinfo(q, q->p_xstat, + SCARG(uap, info))) != 0) + return error; + + + if ((SCARG(uap, options) & SVR4_WNOWAIT)) { + DPRINTF(("Don't wait\n")); + return 0; + } + + /* + * If we got the child via ptrace(2) or procfs, and + * the parent is different (meaning the process was + * attached, rather than run as a child), then we need + * to give it back to the ol dparent, and send the + * parent a SIGCHLD. The rest of the cleanup will be + * done when the old parent waits on the child. + */ + if ((q->p_flag & P_TRACED) && + q->p_oppid != q->p_pptr->p_pid) { + t = pfind(q->p_oppid); + proc_reparent(q, t ? t : initproc); + q->p_oppid = 0; + q->p_flag &= ~(P_TRACED | P_WAITED); + wakeup((caddr_t)q->p_pptr); + return 0; + } + q->p_xstat = 0; + ruadd(&p->p_stats->p_cru, q->p_ru); + + FREE(q->p_ru, M_ZOMBIE); + + /* + * Finally finished with old proc entry. + * Unlink it from its process group and free it. + */ + leavepgrp(q); + + LIST_REMOVE(q, p_list); /* off zombproc */ + + LIST_REMOVE(q, p_sibling); + + /* + * Decrement the count of procs running with this uid. + */ + (void)chgproccnt(q->p_cred->p_ruid, -1); + + /* + * Free up credentials. + */ + if (--q->p_cred->p_refcnt == 0) { + crfree(q->p_cred->pc_ucred); + FREE(q->p_cred, M_SUBPROC); + } + + /* + * Release reference to text vnode + */ + if (q->p_textvp) + vrele(q->p_textvp); + + /* + * Give machine-dependent layer a chance + * to free anything that cpu_exit couldn't + * release while still running in process context. + */ + cpu_wait(q); +#if defined(__NetBSD__) + pool_put(&proc_pool, q); +#endif + nprocs--; + return 0; + } + if (q->p_stat == SSTOP && (q->p_flag & P_WAITED) == 0 && + (q->p_flag & P_TRACED || + (SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED)))) { + DPRINTF(("jobcontrol %d\n", q->p_pid)); + if (((SCARG(uap, options) & SVR4_WNOWAIT)) == 0) + q->p_flag |= P_WAITED; + *retval = 0; + return svr4_setinfo(q, W_STOPCODE(q->p_xstat), + SCARG(uap, info)); + } + } + + if (nfound == 0) + return ECHILD; + + if (SCARG(uap, options) & SVR4_WNOHANG) { + *retval = 0; + if ((error = svr4_setinfo(NULL, 0, SCARG(uap, info))) != 0) + return error; + return 0; + } + + if ((error = tsleep((caddr_t)p, PWAIT | PCATCH, "svr4_wait", 0)) != 0) + return error; + goto loop; +} + + +static void +bsd_statfs_to_svr4_statvfs(bfs, sfs) + const struct statfs *bfs; + struct svr4_statvfs *sfs; +{ + sfs->f_bsize = bfs->f_iosize; /* XXX */ + sfs->f_frsize = bfs->f_bsize; + sfs->f_blocks = bfs->f_blocks; + sfs->f_bfree = bfs->f_bfree; + sfs->f_bavail = bfs->f_bavail; + sfs->f_files = bfs->f_files; + sfs->f_ffree = bfs->f_ffree; + sfs->f_favail = bfs->f_ffree; + sfs->f_fsid = bfs->f_fsid.val[0]; + memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype)); + sfs->f_flag = 0; + if (bfs->f_flags & MNT_RDONLY) + sfs->f_flag |= SVR4_ST_RDONLY; + if (bfs->f_flags & MNT_NOSUID) + sfs->f_flag |= SVR4_ST_NOSUID; + sfs->f_namemax = MAXNAMLEN; + memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */ + memset(sfs->f_filler, 0, sizeof(sfs->f_filler)); +} + + +static void +bsd_statfs_to_svr4_statvfs64(bfs, sfs) + const struct statfs *bfs; + struct svr4_statvfs64 *sfs; +{ + sfs->f_bsize = bfs->f_iosize; /* XXX */ + sfs->f_frsize = bfs->f_bsize; + sfs->f_blocks = bfs->f_blocks; + sfs->f_bfree = bfs->f_bfree; + sfs->f_bavail = bfs->f_bavail; + sfs->f_files = bfs->f_files; + sfs->f_ffree = bfs->f_ffree; + sfs->f_favail = bfs->f_ffree; + sfs->f_fsid = bfs->f_fsid.val[0]; + memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype)); + sfs->f_flag = 0; + if (bfs->f_flags & MNT_RDONLY) + sfs->f_flag |= SVR4_ST_RDONLY; + if (bfs->f_flags & MNT_NOSUID) + sfs->f_flag |= SVR4_ST_NOSUID; + sfs->f_namemax = MAXNAMLEN; + memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */ + memset(sfs->f_filler, 0, sizeof(sfs->f_filler)); +} + + +int +svr4_sys_statvfs(p, uap) + struct proc *p; + struct svr4_sys_statvfs_args *uap; +{ + struct statfs_args fs_args; + caddr_t sg = stackgap_init(); + struct statfs *fs = stackgap_alloc(&sg, sizeof(struct statfs)); + struct statfs bfs; + struct svr4_statvfs sfs; + int error; + + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + SCARG(&fs_args, path) = SCARG(uap, path); + SCARG(&fs_args, buf) = fs; + + if ((error = statfs(p, &fs_args)) != 0) + return error; + + if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0) + return error; + + bsd_statfs_to_svr4_statvfs(&bfs, &sfs); + + return copyout(&sfs, SCARG(uap, fs), sizeof(sfs)); +} + + +int +svr4_sys_fstatvfs(p, uap) + struct proc *p; + struct svr4_sys_fstatvfs_args *uap; +{ + struct fstatfs_args fs_args; + caddr_t sg = stackgap_init(); + struct statfs *fs = stackgap_alloc(&sg, sizeof(struct statfs)); + struct statfs bfs; + struct svr4_statvfs sfs; + int error; + + SCARG(&fs_args, fd) = SCARG(uap, fd); + SCARG(&fs_args, buf) = fs; + + if ((error = fstatfs(p, &fs_args)) != 0) + return error; + + if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0) + return error; + + bsd_statfs_to_svr4_statvfs(&bfs, &sfs); + + return copyout(&sfs, SCARG(uap, fs), sizeof(sfs)); +} + + +int +svr4_sys_statvfs64(p, uap) + struct proc *p; + struct svr4_sys_statvfs64_args *uap; +{ + struct statfs_args fs_args; + caddr_t sg = stackgap_init(); + struct statfs *fs = stackgap_alloc(&sg, sizeof(struct statfs)); + struct statfs bfs; + struct svr4_statvfs64 sfs; + int error; + + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + SCARG(&fs_args, path) = SCARG(uap, path); + SCARG(&fs_args, buf) = fs; + + if ((error = statfs(p, &fs_args)) != 0) + return error; + + if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0) + return error; + + bsd_statfs_to_svr4_statvfs64(&bfs, &sfs); + + return copyout(&sfs, SCARG(uap, fs), sizeof(sfs)); +} + + +int +svr4_sys_fstatvfs64(p, uap) + struct proc *p; + struct svr4_sys_fstatvfs64_args *uap; +{ + struct fstatfs_args fs_args; + caddr_t sg = stackgap_init(); + struct statfs *fs = stackgap_alloc(&sg, sizeof(struct statfs)); + struct statfs bfs; + struct svr4_statvfs64 sfs; + int error; + + SCARG(&fs_args, fd) = SCARG(uap, fd); + SCARG(&fs_args, buf) = fs; + + if ((error = fstatfs(p, &fs_args)) != 0) + return error; + + if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0) + return error; + + bsd_statfs_to_svr4_statvfs64(&bfs, &sfs); + + return copyout(&sfs, SCARG(uap, fs), sizeof(sfs)); +} + +int +svr4_sys_alarm(p, uap) + struct proc *p; + struct svr4_sys_alarm_args *uap; +{ + int error; + struct itimerval *itp, *oitp; + struct setitimer_args sa; + caddr_t sg = stackgap_init(); + + itp = stackgap_alloc(&sg, sizeof(*itp)); + oitp = stackgap_alloc(&sg, sizeof(*oitp)); + timevalclear(&itp->it_interval); + itp->it_value.tv_sec = SCARG(uap, sec); + itp->it_value.tv_usec = 0; + + SCARG(&sa, which) = ITIMER_REAL; + SCARG(&sa, itv) = itp; + SCARG(&sa, oitv) = oitp; + error = setitimer(p, &sa); + if (error) + return error; + if (oitp->it_value.tv_usec) + oitp->it_value.tv_sec++; + p->p_retval[0] = oitp->it_value.tv_sec; + return 0; + +} + +int +svr4_sys_gettimeofday(p, uap) + struct proc *p; + struct svr4_sys_gettimeofday_args *uap; +{ + if (SCARG(uap, tp)) { + struct timeval atv; + + microtime(&atv); + return copyout(&atv, SCARG(uap, tp), sizeof (atv)); + } + + return 0; +} + +int +svr4_sys_facl(p, uap) + struct proc *p; + struct svr4_sys_facl_args *uap; +{ + int *retval; + + retval = p->p_retval; + *retval = 0; + + switch (SCARG(uap, cmd)) { + case SVR4_SYS_SETACL: + /* We don't support acls on any filesystem */ + return ENOSYS; + + case SVR4_SYS_GETACL: + return copyout(retval, &SCARG(uap, num), + sizeof(SCARG(uap, num))); + + case SVR4_SYS_GETACLCNT: + return 0; + + default: + return EINVAL; + } +} + + +int +svr4_sys_acl(p, uap) + struct proc *p; + struct svr4_sys_acl_args *uap; +{ + /* XXX: for now the same */ + return svr4_sys_facl(p, (struct svr4_sys_facl_args *)uap); +} + +int +svr4_sys_auditsys(p, uap) + struct proc *p; + struct svr4_sys_auditsys_args *uap; +{ + /* + * XXX: Big brother is *not* watching. + */ + return 0; +} + +int +svr4_sys_memcntl(p, uap) + struct proc *p; + struct svr4_sys_memcntl_args *uap; +{ + switch (SCARG(uap, cmd)) { + case SVR4_MC_SYNC: + { + struct msync_args msa; + + SCARG(&msa, addr) = SCARG(uap, addr); + SCARG(&msa, len) = SCARG(uap, len); + SCARG(&msa, flags) = (int)SCARG(uap, arg); + + return msync(p, &msa); + } + case SVR4_MC_ADVISE: + { + struct madvise_args maa; + + SCARG(&maa, addr) = SCARG(uap, addr); + SCARG(&maa, len) = SCARG(uap, len); + SCARG(&maa, behav) = (int)SCARG(uap, arg); + + return madvise(p, &maa); + } + case SVR4_MC_LOCK: + case SVR4_MC_UNLOCK: + case SVR4_MC_LOCKAS: + case SVR4_MC_UNLOCKAS: + return EOPNOTSUPP; + default: + return ENOSYS; + } +} + + +int +svr4_sys_nice(p, uap) + struct proc *p; + struct svr4_sys_nice_args *uap; +{ + struct setpriority_args ap; + int error; + + SCARG(&ap, which) = PRIO_PROCESS; + SCARG(&ap, who) = 0; + SCARG(&ap, prio) = SCARG(uap, prio); + + if ((error = setpriority(p, &ap)) != 0) + return error; + + /* the cast is stupid, but the structures are the same */ + if ((error = getpriority(p, (struct getpriority_args *)&ap)) != 0) + return error; + + return 0; +} + +int +svr4_sys_resolvepath(p, uap) + struct proc *p; + struct svr4_sys_resolvepath_args *uap; +{ + struct nameidata nd; + int error, *retval = p->p_retval; + + NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE, + SCARG(uap, path), p); + + if ((error = namei(&nd)) != 0) + return error; + + if ((error = copyout(nd.ni_cnd.cn_pnbuf, SCARG(uap, buf), + SCARG(uap, bufsiz))) != 0) + goto bad; + + *retval = strlen(nd.ni_cnd.cn_pnbuf) < SCARG(uap, bufsiz) ? + strlen(nd.ni_cnd.cn_pnbuf) + 1 : SCARG(uap, bufsiz); +bad: + vput(nd.ni_vp); + zfree(namei_zone, nd.ni_cnd.cn_pnbuf); + return error; +} diff --git a/sys/compat/svr4/svr4_mman.h b/sys/compat/svr4/svr4_mman.h new file mode 100644 index 0000000..9a7f213 --- /dev/null +++ b/sys/compat/svr4/svr4_mman.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1997 Todd Vierling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_MMAN_H_ +#define _SVR4_MMAN_H_ + +/* + * Commands and flags passed to memcntl(). + * Most of them are the same as <sys/mman.h>, but we need the MC_ + * memcntl command definitions. + */ + +#define SVR4_MC_SYNC 1 +#define SVR4_MC_LOCK 2 +#define SVR4_MC_UNLOCK 3 +#define SVR4_MC_ADVISE 4 +#define SVR4_MC_LOCKAS 5 +#define SVR4_MC_UNLOCKAS 6 + +#endif /* !_SVR4_MMAN_H */ diff --git a/sys/compat/svr4/svr4_proto.h b/sys/compat/svr4/svr4_proto.h new file mode 100644 index 0000000..101d36e --- /dev/null +++ b/sys/compat/svr4/svr4_proto.h @@ -0,0 +1,472 @@ +/* + * System call prototypes. + * + * DO NOT EDIT-- this file is automatically generated. + * created from; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 + */ + +#ifndef _SVR4_SYSPROTO_H_ +#define _SVR4_SYSPROTO_H_ + +#include <sys/signal.h> + +struct proc; + +#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ + 0 : sizeof(register_t) - sizeof(t)) + +struct svr4_sys_open_args { + char * path; char path_[PAD_(char *)]; + int flags; char flags_[PAD_(int)]; + int mode; char mode_[PAD_(int)]; +}; +struct svr4_sys_wait_args { + int * status; char status_[PAD_(int *)]; +}; +struct svr4_sys_creat_args { + char * path; char path_[PAD_(char *)]; + int mode; char mode_[PAD_(int)]; +}; +struct svr4_sys_execv_args { + char * path; char path_[PAD_(char *)]; + char ** argp; char argp_[PAD_(char **)]; +}; +struct svr4_sys_time_args { + time_t * t; char t_[PAD_(time_t *)]; +}; +struct svr4_sys_mknod_args { + char * path; char path_[PAD_(char *)]; + int mode; char mode_[PAD_(int)]; + int dev; char dev_[PAD_(int)]; +}; +struct svr4_sys_break_args { + caddr_t nsize; char nsize_[PAD_(caddr_t)]; +}; +struct svr4_sys_stat_args { + char * path; char path_[PAD_(char *)]; + struct svr4_stat * ub; char ub_[PAD_(struct svr4_stat *)]; +}; +struct svr4_sys_alarm_args { + unsigned sec; char sec_[PAD_(unsigned)]; +}; +struct svr4_sys_fstat_args { + int fd; char fd_[PAD_(int)]; + struct svr4_stat * sb; char sb_[PAD_(struct svr4_stat *)]; +}; +struct svr4_sys_pause_args { + register_t dummy; +}; +struct svr4_sys_utime_args { + char * path; char path_[PAD_(char *)]; + struct svr4_utimbuf * ubuf; char ubuf_[PAD_(struct svr4_utimbuf *)]; +}; +struct svr4_sys_access_args { + char * path; char path_[PAD_(char *)]; + int flags; char flags_[PAD_(int)]; +}; +struct svr4_sys_nice_args { + int prio; char prio_[PAD_(int)]; +}; +struct svr4_sys_kill_args { + int pid; char pid_[PAD_(int)]; + int signum; char signum_[PAD_(int)]; +}; +struct svr4_sys_pgrpsys_args { + int cmd; char cmd_[PAD_(int)]; + int pid; char pid_[PAD_(int)]; + int pgid; char pgid_[PAD_(int)]; +}; +struct svr4_sys_times_args { + struct tms * tp; char tp_[PAD_(struct tms *)]; +}; +struct svr4_sys_signal_args { + int signum; char signum_[PAD_(int)]; + svr4_sig_t handler; char handler_[PAD_(svr4_sig_t)]; +}; +#if defined(NOTYET) +struct svr4_sys_msgsys_args { + int what; char what_[PAD_(int)]; + int a2; char a2_[PAD_(int)]; + int a3; char a3_[PAD_(int)]; + int a4; char a4_[PAD_(int)]; + int a5; char a5_[PAD_(int)]; +}; +#else +#endif +struct svr4_sys_sysarch_args { + int op; char op_[PAD_(int)]; + void * a1; char a1_[PAD_(void *)]; +}; +struct svr4_sys_ioctl_args { + int fd; char fd_[PAD_(int)]; + u_long com; char com_[PAD_(u_long)]; + caddr_t data; char data_[PAD_(caddr_t)]; +}; +struct svr4_sys_utssys_args { + void * a1; char a1_[PAD_(void *)]; + void * a2; char a2_[PAD_(void *)]; + int sel; char sel_[PAD_(int)]; + void * a3; char a3_[PAD_(void *)]; +}; +struct svr4_sys_execve_args { + char * path; char path_[PAD_(char *)]; + char ** argp; char argp_[PAD_(char **)]; + char ** envp; char envp_[PAD_(char **)]; +}; +struct svr4_sys_fcntl_args { + int fd; char fd_[PAD_(int)]; + int cmd; char cmd_[PAD_(int)]; + char * arg; char arg_[PAD_(char *)]; +}; +struct svr4_sys_ulimit_args { + int cmd; char cmd_[PAD_(int)]; + long newlimit; char newlimit_[PAD_(long)]; +}; +struct svr4_sys_getdents_args { + int fd; char fd_[PAD_(int)]; + char * buf; char buf_[PAD_(char *)]; + int nbytes; char nbytes_[PAD_(int)]; +}; +struct svr4_sys_getmsg_args { + int fd; char fd_[PAD_(int)]; + struct svr4_strbuf * ctl; char ctl_[PAD_(struct svr4_strbuf *)]; + struct svr4_strbuf * dat; char dat_[PAD_(struct svr4_strbuf *)]; + int * flags; char flags_[PAD_(int *)]; +}; +struct svr4_sys_putmsg_args { + int fd; char fd_[PAD_(int)]; + struct svr4_strbuf * ctl; char ctl_[PAD_(struct svr4_strbuf *)]; + struct svr4_strbuf * dat; char dat_[PAD_(struct svr4_strbuf *)]; + int flags; char flags_[PAD_(int)]; +}; +struct svr4_sys_poll_args { + struct pollfd * fds; char fds_[PAD_(struct pollfd *)]; + unsigned int nfds; char nfds_[PAD_(unsigned int)]; + int timeout; char timeout_[PAD_(int)]; +}; +struct svr4_sys_lstat_args { + char * path; char path_[PAD_(char *)]; + struct svr4_stat * ub; char ub_[PAD_(struct svr4_stat *)]; +}; +struct svr4_sys_sigprocmask_args { + int how; char how_[PAD_(int)]; + svr4_sigset_t * set; char set_[PAD_(svr4_sigset_t *)]; + svr4_sigset_t * oset; char oset_[PAD_(svr4_sigset_t *)]; +}; +struct svr4_sys_sigsuspend_args { + svr4_sigset_t * ss; char ss_[PAD_(svr4_sigset_t *)]; +}; +struct svr4_sys_sigaltstack_args { + struct svr4_sigaltstack * nss; char nss_[PAD_(struct svr4_sigaltstack *)]; + struct svr4_sigaltstack * oss; char oss_[PAD_(struct svr4_sigaltstack *)]; +}; +struct svr4_sys_sigaction_args { + int signum; char signum_[PAD_(int)]; + struct svr4_sigaction * nsa; char nsa_[PAD_(struct svr4_sigaction *)]; + struct svr4_sigaction * osa; char osa_[PAD_(struct svr4_sigaction *)]; +}; +struct svr4_sys_sigpending_args { + int what; char what_[PAD_(int)]; + svr4_sigset_t * mask; char mask_[PAD_(svr4_sigset_t *)]; +}; +struct svr4_sys_context_args { + int func; char func_[PAD_(int)]; + struct svr4_ucontext * uc; char uc_[PAD_(struct svr4_ucontext *)]; +}; +struct svr4_sys_statvfs_args { + char * path; char path_[PAD_(char *)]; + struct svr4_statvfs * fs; char fs_[PAD_(struct svr4_statvfs *)]; +}; +struct svr4_sys_fstatvfs_args { + int fd; char fd_[PAD_(int)]; + struct svr4_statvfs * fs; char fs_[PAD_(struct svr4_statvfs *)]; +}; +struct svr4_sys_waitsys_args { + int grp; char grp_[PAD_(int)]; + int id; char id_[PAD_(int)]; + union svr4_siginfo * info; char info_[PAD_(union svr4_siginfo *)]; + int options; char options_[PAD_(int)]; +}; +struct svr4_sys_hrtsys_args { + int cmd; char cmd_[PAD_(int)]; + int fun; char fun_[PAD_(int)]; + int sub; char sub_[PAD_(int)]; + void * rv1; char rv1_[PAD_(void *)]; + void * rv2; char rv2_[PAD_(void *)]; +}; +struct svr4_sys_pathconf_args { + char * path; char path_[PAD_(char *)]; + int name; char name_[PAD_(int)]; +}; +struct svr4_sys_mmap_args { + caddr_t addr; char addr_[PAD_(caddr_t)]; + svr4_size_t len; char len_[PAD_(svr4_size_t)]; + int prot; char prot_[PAD_(int)]; + int flags; char flags_[PAD_(int)]; + int fd; char fd_[PAD_(int)]; + svr4_off_t pos; char pos_[PAD_(svr4_off_t)]; +}; +struct svr4_sys_fpathconf_args { + int fd; char fd_[PAD_(int)]; + int name; char name_[PAD_(int)]; +}; +struct svr4_sys_xstat_args { + int two; char two_[PAD_(int)]; + char * path; char path_[PAD_(char *)]; + struct svr4_xstat * ub; char ub_[PAD_(struct svr4_xstat *)]; +}; +struct svr4_sys_lxstat_args { + int two; char two_[PAD_(int)]; + char * path; char path_[PAD_(char *)]; + struct svr4_xstat * ub; char ub_[PAD_(struct svr4_xstat *)]; +}; +struct svr4_sys_fxstat_args { + int two; char two_[PAD_(int)]; + int fd; char fd_[PAD_(int)]; + struct svr4_xstat * sb; char sb_[PAD_(struct svr4_xstat *)]; +}; +struct svr4_sys_xmknod_args { + int two; char two_[PAD_(int)]; + char * path; char path_[PAD_(char *)]; + svr4_mode_t mode; char mode_[PAD_(svr4_mode_t)]; + svr4_dev_t dev; char dev_[PAD_(svr4_dev_t)]; +}; +struct svr4_sys_setrlimit_args { + int which; char which_[PAD_(int)]; + const struct svr4_rlimit * rlp; char rlp_[PAD_(const struct svr4_rlimit *)]; +}; +struct svr4_sys_getrlimit_args { + int which; char which_[PAD_(int)]; + struct svr4_rlimit * rlp; char rlp_[PAD_(struct svr4_rlimit *)]; +}; +struct svr4_sys_memcntl_args { + void * addr; char addr_[PAD_(void *)]; + svr4_size_t len; char len_[PAD_(svr4_size_t)]; + int cmd; char cmd_[PAD_(int)]; + void * arg; char arg_[PAD_(void *)]; + int attr; char attr_[PAD_(int)]; + int mask; char mask_[PAD_(int)]; +}; +struct svr4_sys_uname_args { + struct svr4_utsname * name; char name_[PAD_(struct svr4_utsname *)]; + int dummy; char dummy_[PAD_(int)]; +}; +struct svr4_sys_sysconfig_args { + int name; char name_[PAD_(int)]; +}; +struct svr4_sys_systeminfo_args { + int what; char what_[PAD_(int)]; + char * buf; char buf_[PAD_(char *)]; + long len; char len_[PAD_(long)]; +}; +struct svr4_sys_fchroot_args { + int fd; char fd_[PAD_(int)]; +}; +struct svr4_sys_utimes_args { + char * path; char path_[PAD_(char *)]; + struct timeval * tptr; char tptr_[PAD_(struct timeval *)]; +}; +struct svr4_sys_vhangup_args { + register_t dummy; +}; +struct svr4_sys_gettimeofday_args { + struct timeval * tp; char tp_[PAD_(struct timeval *)]; +}; +struct svr4_sys_llseek_args { + int fd; char fd_[PAD_(int)]; + long offset1; char offset1_[PAD_(long)]; + long offset2; char offset2_[PAD_(long)]; + int whence; char whence_[PAD_(int)]; +}; +struct svr4_sys_acl_args { + char * path; char path_[PAD_(char *)]; + int cmd; char cmd_[PAD_(int)]; + int num; char num_[PAD_(int)]; + struct svr4_aclent * buf; char buf_[PAD_(struct svr4_aclent *)]; +}; +struct svr4_sys_auditsys_args { + int code; char code_[PAD_(int)]; + int a1; char a1_[PAD_(int)]; + int a2; char a2_[PAD_(int)]; + int a3; char a3_[PAD_(int)]; + int a4; char a4_[PAD_(int)]; + int a5; char a5_[PAD_(int)]; +}; +struct svr4_sys_facl_args { + int fd; char fd_[PAD_(int)]; + int cmd; char cmd_[PAD_(int)]; + int num; char num_[PAD_(int)]; + struct svr4_aclent * buf; char buf_[PAD_(struct svr4_aclent *)]; +}; +struct svr4_sys_resolvepath_args { + const char * path; char path_[PAD_(const char *)]; + char * buf; char buf_[PAD_(char *)]; + size_t bufsiz; char bufsiz_[PAD_(size_t)]; +}; +struct svr4_sys_getdents64_args { + int fd; char fd_[PAD_(int)]; + struct svr4_dirent64 * dp; char dp_[PAD_(struct svr4_dirent64 *)]; + int nbytes; char nbytes_[PAD_(int)]; +}; +struct svr4_sys_mmap64_args { + void * addr; char addr_[PAD_(void *)]; + svr4_size_t len; char len_[PAD_(svr4_size_t)]; + int prot; char prot_[PAD_(int)]; + int flags; char flags_[PAD_(int)]; + int fd; char fd_[PAD_(int)]; + svr4_off64_t pos; char pos_[PAD_(svr4_off64_t)]; +}; +struct svr4_sys_stat64_args { + char * path; char path_[PAD_(char *)]; + struct svr4_stat64 * sb; char sb_[PAD_(struct svr4_stat64 *)]; +}; +struct svr4_sys_lstat64_args { + char * path; char path_[PAD_(char *)]; + struct svr4_stat64 * sb; char sb_[PAD_(struct svr4_stat64 *)]; +}; +struct svr4_sys_fstat64_args { + int fd; char fd_[PAD_(int)]; + struct svr4_stat64 * sb; char sb_[PAD_(struct svr4_stat64 *)]; +}; +struct svr4_sys_statvfs64_args { + char * path; char path_[PAD_(char *)]; + struct svr4_statvfs64 * fs; char fs_[PAD_(struct svr4_statvfs64 *)]; +}; +struct svr4_sys_fstatvfs64_args { + int fd; char fd_[PAD_(int)]; + struct svr4_statvfs64 * fs; char fs_[PAD_(struct svr4_statvfs64 *)]; +}; +struct svr4_sys_setrlimit64_args { + int which; char which_[PAD_(int)]; + const struct svr4_rlimit64 * rlp; char rlp_[PAD_(const struct svr4_rlimit64 *)]; +}; +struct svr4_sys_getrlimit64_args { + int which; char which_[PAD_(int)]; + struct svr4_rlimit64 * rlp; char rlp_[PAD_(struct svr4_rlimit64 *)]; +}; +struct svr4_sys_creat64_args { + char * path; char path_[PAD_(char *)]; + int mode; char mode_[PAD_(int)]; +}; +struct svr4_sys_open64_args { + char * path; char path_[PAD_(char *)]; + int flags; char flags_[PAD_(int)]; + int mode; char mode_[PAD_(int)]; +}; +struct svr4_sys_socket_args { + int domain; char domain_[PAD_(int)]; + int type; char type_[PAD_(int)]; + int protocol; char protocol_[PAD_(int)]; +}; +struct svr4_sys_recv_args { + int s; char s_[PAD_(int)]; + caddr_t buf; char buf_[PAD_(caddr_t)]; + int len; char len_[PAD_(int)]; + int flags; char flags_[PAD_(int)]; +}; +struct svr4_sys_send_args { + int s; char s_[PAD_(int)]; + caddr_t buf; char buf_[PAD_(caddr_t)]; + int len; char len_[PAD_(int)]; + int flags; char flags_[PAD_(int)]; +}; +struct svr4_sys_sendto_args { + int s; char s_[PAD_(int)]; + const void * buf; char buf_[PAD_(const void *)]; + size_t len; char len_[PAD_(size_t)]; + int flags; char flags_[PAD_(int)]; + const struct sockaddr * to; char to_[PAD_(const struct sockaddr *)]; + int tolen; char tolen_[PAD_(int)]; +}; +int svr4_sys_open __P((struct proc *, struct svr4_sys_open_args *)); +int svr4_sys_wait __P((struct proc *, struct svr4_sys_wait_args *)); +int svr4_sys_creat __P((struct proc *, struct svr4_sys_creat_args *)); +int svr4_sys_execv __P((struct proc *, struct svr4_sys_execv_args *)); +int svr4_sys_time __P((struct proc *, struct svr4_sys_time_args *)); +int svr4_sys_mknod __P((struct proc *, struct svr4_sys_mknod_args *)); +int svr4_sys_break __P((struct proc *, struct svr4_sys_break_args *)); +int svr4_sys_stat __P((struct proc *, struct svr4_sys_stat_args *)); +int svr4_sys_alarm __P((struct proc *, struct svr4_sys_alarm_args *)); +int svr4_sys_fstat __P((struct proc *, struct svr4_sys_fstat_args *)); +int svr4_sys_pause __P((struct proc *, struct svr4_sys_pause_args *)); +int svr4_sys_utime __P((struct proc *, struct svr4_sys_utime_args *)); +int svr4_sys_access __P((struct proc *, struct svr4_sys_access_args *)); +int svr4_sys_nice __P((struct proc *, struct svr4_sys_nice_args *)); +int svr4_sys_kill __P((struct proc *, struct svr4_sys_kill_args *)); +int svr4_sys_pgrpsys __P((struct proc *, struct svr4_sys_pgrpsys_args *)); +int svr4_sys_times __P((struct proc *, struct svr4_sys_times_args *)); +int svr4_sys_signal __P((struct proc *, struct svr4_sys_signal_args *)); +#if defined(NOTYET) +int svr4_sys_msgsys __P((struct proc *, struct svr4_sys_msgsys_args *)); +#else +#endif +int svr4_sys_sysarch __P((struct proc *, struct svr4_sys_sysarch_args *)); +int svr4_sys_ioctl __P((struct proc *, struct svr4_sys_ioctl_args *)); +int svr4_sys_utssys __P((struct proc *, struct svr4_sys_utssys_args *)); +int svr4_sys_execve __P((struct proc *, struct svr4_sys_execve_args *)); +int svr4_sys_fcntl __P((struct proc *, struct svr4_sys_fcntl_args *)); +int svr4_sys_ulimit __P((struct proc *, struct svr4_sys_ulimit_args *)); +int svr4_sys_getdents __P((struct proc *, struct svr4_sys_getdents_args *)); +int svr4_sys_getmsg __P((struct proc *, struct svr4_sys_getmsg_args *)); +int svr4_sys_putmsg __P((struct proc *, struct svr4_sys_putmsg_args *)); +int svr4_sys_poll __P((struct proc *, struct svr4_sys_poll_args *)); +int svr4_sys_lstat __P((struct proc *, struct svr4_sys_lstat_args *)); +int svr4_sys_sigprocmask __P((struct proc *, struct svr4_sys_sigprocmask_args *)); +int svr4_sys_sigsuspend __P((struct proc *, struct svr4_sys_sigsuspend_args *)); +int svr4_sys_sigaltstack __P((struct proc *, struct svr4_sys_sigaltstack_args *)); +int svr4_sys_sigaction __P((struct proc *, struct svr4_sys_sigaction_args *)); +int svr4_sys_sigpending __P((struct proc *, struct svr4_sys_sigpending_args *)); +int svr4_sys_context __P((struct proc *, struct svr4_sys_context_args *)); +int svr4_sys_statvfs __P((struct proc *, struct svr4_sys_statvfs_args *)); +int svr4_sys_fstatvfs __P((struct proc *, struct svr4_sys_fstatvfs_args *)); +int svr4_sys_waitsys __P((struct proc *, struct svr4_sys_waitsys_args *)); +int svr4_sys_hrtsys __P((struct proc *, struct svr4_sys_hrtsys_args *)); +int svr4_sys_pathconf __P((struct proc *, struct svr4_sys_pathconf_args *)); +int svr4_sys_mmap __P((struct proc *, struct svr4_sys_mmap_args *)); +int svr4_sys_fpathconf __P((struct proc *, struct svr4_sys_fpathconf_args *)); +int svr4_sys_xstat __P((struct proc *, struct svr4_sys_xstat_args *)); +int svr4_sys_lxstat __P((struct proc *, struct svr4_sys_lxstat_args *)); +int svr4_sys_fxstat __P((struct proc *, struct svr4_sys_fxstat_args *)); +int svr4_sys_xmknod __P((struct proc *, struct svr4_sys_xmknod_args *)); +int svr4_sys_setrlimit __P((struct proc *, struct svr4_sys_setrlimit_args *)); +int svr4_sys_getrlimit __P((struct proc *, struct svr4_sys_getrlimit_args *)); +int svr4_sys_memcntl __P((struct proc *, struct svr4_sys_memcntl_args *)); +int svr4_sys_uname __P((struct proc *, struct svr4_sys_uname_args *)); +int svr4_sys_sysconfig __P((struct proc *, struct svr4_sys_sysconfig_args *)); +int svr4_sys_systeminfo __P((struct proc *, struct svr4_sys_systeminfo_args *)); +int svr4_sys_fchroot __P((struct proc *, struct svr4_sys_fchroot_args *)); +int svr4_sys_utimes __P((struct proc *, struct svr4_sys_utimes_args *)); +int svr4_sys_vhangup __P((struct proc *, struct svr4_sys_vhangup_args *)); +int svr4_sys_gettimeofday __P((struct proc *, struct svr4_sys_gettimeofday_args *)); +int svr4_sys_llseek __P((struct proc *, struct svr4_sys_llseek_args *)); +int svr4_sys_acl __P((struct proc *, struct svr4_sys_acl_args *)); +int svr4_sys_auditsys __P((struct proc *, struct svr4_sys_auditsys_args *)); +int svr4_sys_facl __P((struct proc *, struct svr4_sys_facl_args *)); +int svr4_sys_resolvepath __P((struct proc *, struct svr4_sys_resolvepath_args *)); +int svr4_sys_getdents64 __P((struct proc *, struct svr4_sys_getdents64_args *)); +int svr4_sys_mmap64 __P((struct proc *, struct svr4_sys_mmap64_args *)); +int svr4_sys_stat64 __P((struct proc *, struct svr4_sys_stat64_args *)); +int svr4_sys_lstat64 __P((struct proc *, struct svr4_sys_lstat64_args *)); +int svr4_sys_fstat64 __P((struct proc *, struct svr4_sys_fstat64_args *)); +int svr4_sys_statvfs64 __P((struct proc *, struct svr4_sys_statvfs64_args *)); +int svr4_sys_fstatvfs64 __P((struct proc *, struct svr4_sys_fstatvfs64_args *)); +int svr4_sys_setrlimit64 __P((struct proc *, struct svr4_sys_setrlimit64_args *)); +int svr4_sys_getrlimit64 __P((struct proc *, struct svr4_sys_getrlimit64_args *)); +int svr4_sys_creat64 __P((struct proc *, struct svr4_sys_creat64_args *)); +int svr4_sys_open64 __P((struct proc *, struct svr4_sys_open64_args *)); +int svr4_sys_socket __P((struct proc *, struct svr4_sys_socket_args *)); +int svr4_sys_recv __P((struct proc *, struct svr4_sys_recv_args *)); +int svr4_sys_send __P((struct proc *, struct svr4_sys_send_args *)); +int svr4_sys_sendto __P((struct proc *, struct svr4_sys_sendto_args *)); + +#ifdef COMPAT_43 + +#if defined(NOTYET) +#else +#endif + +#endif /* COMPAT_43 */ + +#undef PAD_ + +#endif /* !_SVR4_SYSPROTO_H_ */ diff --git a/sys/compat/svr4/svr4_resource.c b/sys/compat/svr4/svr4_resource.c new file mode 100644 index 0000000..083049f --- /dev/null +++ b/sys/compat/svr4/svr4_resource.c @@ -0,0 +1,311 @@ +/* Derived from: + * $NetBSD: svr4_resource.c,v 1.3 1998/12/13 18:00:52 christos Exp $ + */ + +/*- + * Original copyright: + * + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Portions of this software have been derived from software contributed + * to the FreeBSD Project by Mark Newton. + * + * Copyright (c) 1999 Mark Newton + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/proc.h> +#include <sys/file.h> +#include <sys/resource.h> +#include <sys/resourcevar.h> + +#include <svr4/svr4_types.h> +#include <svr4/svr4_resource.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_util.h> + +static __inline int svr4_to_native_rl __P((int)); + +static __inline int +svr4_to_native_rl(rl) + int rl; +{ + switch (rl) { + case SVR4_RLIMIT_CPU: + return RLIMIT_CPU; + case SVR4_RLIMIT_FSIZE: + return RLIMIT_FSIZE; + case SVR4_RLIMIT_DATA: + return RLIMIT_DATA; + case SVR4_RLIMIT_STACK: + return RLIMIT_STACK; + case SVR4_RLIMIT_CORE: + return RLIMIT_CORE; + case SVR4_RLIMIT_NOFILE: + return RLIMIT_NOFILE; + case SVR4_RLIMIT_VMEM: + return RLIMIT_RSS; + default: + return -1; + } +} + +/* + * Check if the resource limit fits within the BSD range and it is not + * one of the magic SVR4 limit values + */ +#define OKLIMIT(l) (((int32_t)(l)) >= 0 && ((int32_t)(l)) < 0x7fffffff && \ + ((svr4_rlim_t)(l)) != SVR4_RLIM_INFINITY && \ + ((svr4_rlim_t)(l)) != SVR4_RLIM_SAVED_CUR && \ + ((svr4_rlim_t)(l)) != SVR4_RLIM_SAVED_MAX) + +#define OKLIMIT64(l) (((rlim_t)(l)) >= 0 && ((rlim_t)(l)) < RLIM_INFINITY && \ + ((svr4_rlim64_t)(l)) != SVR4_RLIM64_INFINITY && \ + ((svr4_rlim64_t)(l)) != SVR4_RLIM64_SAVED_CUR && \ + ((svr4_rlim64_t)(l)) != SVR4_RLIM64_SAVED_MAX) + +int +svr4_sys_getrlimit(p, uap) + register struct proc *p; + struct svr4_sys_getrlimit_args *uap; +{ + int rl = svr4_to_native_rl(SCARG(uap, which)); + struct rlimit blim; + struct svr4_rlimit slim; + + if (rl == -1) + return EINVAL; + + blim = p->p_rlimit[rl]; + + /* + * Our infinity, is their maxfiles. + */ + if (rl == RLIMIT_NOFILE && blim.rlim_max == RLIM_INFINITY) + blim.rlim_max = maxfiles; + + /* + * If the limit can be be represented, it is returned. + * Otherwise, if rlim_cur == rlim_max, return RLIM_SAVED_MAX + * else return RLIM_SAVED_CUR + */ + if (blim.rlim_max == RLIM_INFINITY) + slim.rlim_max = SVR4_RLIM_INFINITY; + else if (OKLIMIT(blim.rlim_max)) + slim.rlim_max = (svr4_rlim_t) blim.rlim_max; + else + slim.rlim_max = SVR4_RLIM_SAVED_MAX; + + if (blim.rlim_cur == RLIM_INFINITY) + slim.rlim_cur = SVR4_RLIM_INFINITY; + else if (OKLIMIT(blim.rlim_cur)) + slim.rlim_cur = (svr4_rlim_t) blim.rlim_cur; + else if (blim.rlim_max == blim.rlim_cur) + slim.rlim_cur = SVR4_RLIM_SAVED_MAX; + else + slim.rlim_cur = SVR4_RLIM_SAVED_CUR; + + return copyout(&slim, SCARG(uap, rlp), sizeof(*SCARG(uap, rlp))); +} + + +int +svr4_sys_setrlimit(p, uap) + register struct proc *p; + struct svr4_sys_setrlimit_args *uap; +{ + int rl = svr4_to_native_rl(SCARG(uap, which)); + struct rlimit blim, *limp; + struct svr4_rlimit slim; + int error; + + if (rl == -1) + return EINVAL; + + limp = &p->p_rlimit[rl]; + + if ((error = copyin(SCARG(uap, rlp), &slim, sizeof(slim))) != 0) + return error; + + /* + * if the limit is SVR4_RLIM_INFINITY, then we set it to our + * unlimited. + * We should also: If it is SVR4_RLIM_SAVED_MAX, we should set the + * new limit to the corresponding saved hard limit, and if + * it is equal to SVR4_RLIM_SAVED_CUR, we should set it to the + * corresponding saved soft limit. + * + */ + if (slim.rlim_max == SVR4_RLIM_INFINITY) + blim.rlim_max = RLIM_INFINITY; + else if (OKLIMIT(slim.rlim_max)) + blim.rlim_max = (rlim_t) slim.rlim_max; + else if (slim.rlim_max == SVR4_RLIM_SAVED_MAX) + blim.rlim_max = limp->rlim_max; + else if (slim.rlim_max == SVR4_RLIM_SAVED_CUR) + blim.rlim_max = limp->rlim_cur; + + if (slim.rlim_cur == SVR4_RLIM_INFINITY) + blim.rlim_cur = RLIM_INFINITY; + else if (OKLIMIT(slim.rlim_cur)) + blim.rlim_cur = (rlim_t) slim.rlim_cur; + else if (slim.rlim_cur == SVR4_RLIM_SAVED_MAX) + blim.rlim_cur = limp->rlim_max; + else if (slim.rlim_cur == SVR4_RLIM_SAVED_CUR) + blim.rlim_cur = limp->rlim_cur; + + return dosetrlimit(p, rl, &blim); +} + + +int +svr4_sys_getrlimit64(p, uap) + register struct proc *p; + struct svr4_sys_getrlimit64_args *uap; +{ + int rl = svr4_to_native_rl(SCARG(uap, which)); + struct rlimit blim; + struct svr4_rlimit64 slim; + + if (rl == -1) + return EINVAL; + + blim = p->p_rlimit[rl]; + + /* + * Our infinity, is their maxfiles. + */ + if (rl == RLIMIT_NOFILE && blim.rlim_max == RLIM_INFINITY) + blim.rlim_max = maxfiles; + + /* + * If the limit can be be represented, it is returned. + * Otherwise, if rlim_cur == rlim_max, return SVR4_RLIM_SAVED_MAX + * else return SVR4_RLIM_SAVED_CUR + */ + if (blim.rlim_max == RLIM_INFINITY) + slim.rlim_max = SVR4_RLIM64_INFINITY; + else if (OKLIMIT64(blim.rlim_max)) + slim.rlim_max = (svr4_rlim64_t) blim.rlim_max; + else + slim.rlim_max = SVR4_RLIM64_SAVED_MAX; + + if (blim.rlim_cur == RLIM_INFINITY) + slim.rlim_cur = SVR4_RLIM64_INFINITY; + else if (OKLIMIT64(blim.rlim_cur)) + slim.rlim_cur = (svr4_rlim64_t) blim.rlim_cur; + else if (blim.rlim_max == blim.rlim_cur) + slim.rlim_cur = SVR4_RLIM64_SAVED_MAX; + else + slim.rlim_cur = SVR4_RLIM64_SAVED_CUR; + + return copyout(&slim, SCARG(uap, rlp), sizeof(*SCARG(uap, rlp))); +} + + +int +svr4_sys_setrlimit64(p, uap) + register struct proc *p; + struct svr4_sys_setrlimit64_args *uap; +{ + int rl = svr4_to_native_rl(SCARG(uap, which)); + struct rlimit blim, *limp; + struct svr4_rlimit64 slim; + int error; + + if (rl == -1) + return EINVAL; + + limp = &p->p_rlimit[rl]; + + if ((error = copyin(SCARG(uap, rlp), &slim, sizeof(slim))) != 0) + return error; + + /* + * if the limit is SVR4_RLIM64_INFINITY, then we set it to our + * unlimited. + * We should also: If it is SVR4_RLIM64_SAVED_MAX, we should set the + * new limit to the corresponding saved hard limit, and if + * it is equal to SVR4_RLIM64_SAVED_CUR, we should set it to the + * corresponding saved soft limit. + * + */ + if (slim.rlim_max == SVR4_RLIM64_INFINITY) + blim.rlim_max = RLIM_INFINITY; + else if (OKLIMIT64(slim.rlim_max)) + blim.rlim_max = (rlim_t) slim.rlim_max; + else if (slim.rlim_max == SVR4_RLIM64_SAVED_MAX) + blim.rlim_max = limp->rlim_max; + else if (slim.rlim_max == SVR4_RLIM64_SAVED_CUR) + blim.rlim_max = limp->rlim_cur; + + if (slim.rlim_cur == SVR4_RLIM64_INFINITY) + blim.rlim_cur = RLIM_INFINITY; + else if (OKLIMIT64(slim.rlim_cur)) + blim.rlim_cur = (rlim_t) slim.rlim_cur; + else if (slim.rlim_cur == SVR4_RLIM64_SAVED_MAX) + blim.rlim_cur = limp->rlim_max; + else if (slim.rlim_cur == SVR4_RLIM64_SAVED_CUR) + blim.rlim_cur = limp->rlim_cur; + + return dosetrlimit(p, rl, &blim); +} diff --git a/sys/compat/svr4/svr4_resource.h b/sys/compat/svr4/svr4_resource.h new file mode 100644 index 0000000..98c4fce --- /dev/null +++ b/sys/compat/svr4/svr4_resource.h @@ -0,0 +1,107 @@ +/* Derived from: + * $NetBSD: svr4_resource.h,v 1.1 1998/11/28 21:53:02 christos Exp $ */ + +/*- + * Original copyright: + * + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Portions of this code derived from software contributed to the + * FreeBSD Project by Mark Newton. + * + * Copyright (c) 1999 Mark Newton + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_RESOURCE_H_ +#define _SVR4_RESOURCE_H_ + +#define SVR4_RLIMIT_CPU 0 +#define SVR4_RLIMIT_FSIZE 1 +#define SVR4_RLIMIT_DATA 2 +#define SVR4_RLIMIT_STACK 3 +#define SVR4_RLIMIT_CORE 4 +#define SVR4_RLIMIT_NOFILE 5 +#define SVR4_RLIMIT_VMEM 6 +#define SVR4_RLIMIT_AS SVR4_RLIMIT_VMEM +#define SVR4_RLIM_NLIMITS 7 + +typedef u_int32_t svr4_rlim_t; + +#define SVR4_RLIM_SAVED_CUR 0x7ffffffd +#define SVR4_RLIM_SAVED_MAX 0x7ffffffe +#define SVR4_RLIM_INFINITY 0x7fffffff + +struct svr4_rlimit { + svr4_rlim_t rlim_cur; + svr4_rlim_t rlim_max; +}; + +typedef u_int64_t svr4_rlim64_t; + +#define SVR4_RLIM64_SAVED_CUR ((svr4_rlim64_t) -1) +#define SVR4_RLIM64_SAVED_MAX ((svr4_rlim64_t) -2) +#define SVR4_RLIM64_INFINITY ((svr4_rlim64_t) -3) + +struct svr4_rlimit64 { + svr4_rlim64_t rlim_cur; + svr4_rlim64_t rlim_max; +}; + +#endif /* !_SVR4_RESOURCE_H_ */ diff --git a/sys/compat/svr4/svr4_siginfo.h b/sys/compat/svr4/svr4_siginfo.h new file mode 100644 index 0000000..fe63e5d --- /dev/null +++ b/sys/compat/svr4/svr4_siginfo.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_SIGINFO_H_ +#define _SVR4_SIGINFO_H_ + +#define SVR4_ILL_ILLOPC 1 +#define SVR4_ILL_ILLOPN 2 +#define SVR4_ILL_ILLADR 3 +#define SVR4_ILL_ILLTRP 4 +#define SVR4_ILL_PRVOPC 5 +#define SVR4_ILL_PRVREG 6 +#define SVR4_ILL_COPROC 7 +#define SVR4_ILL_BADSTK 8 + +#define SVR4_FPE_INTDIV 1 +#define SVR4_FPE_INTOVF 2 +#define SVR4_FPE_FLTDIV 3 +#define SVR4_FPE_FLTOVF 4 +#define SVR4_FPE_FLTUND 5 +#define SVR4_FPE_FLTRES 6 +#define SVR4_FPE_FLTINV 7 +#define SVR4_FPE_FLTSUB 8 + +#define SVR4_SEGV_MAPERR 1 +#define SVR4_SEGV_ACCERR 2 + +#define SVR4_BUS_ADRALN 1 +#define SVR4_BUS_ADRERR 2 +#define SVR4_BUS_OBJERR 3 + +#define SVR4_TRAP_BRKPT 1 +#define SVR4_TRAP_TRACE 2 + +#define SVR4_POLL_IN 1 +#define SVR4_POLL_OUT 2 +#define SVR4_POLL_MSG 3 +#define SVR4_POLL_ERR 4 +#define SVR4_POLL_PRI 5 + +#define SVR4_CLD_EXITED 1 +#define SVR4_CLD_KILLED 2 +#define SVR4_CLD_DUMPED 3 +#define SVR4_CLD_TRAPPED 4 +#define SVR4_CLD_STOPPED 5 +#define SVR4_CLD_CONTINUED 6 + +#define SVR4_EMT_TAGOVF 1 + +typedef union svr4_siginfo { + char si_pad[128]; /* Total size; for future expansion */ + struct { + int _signo; + int _code; + int _errno; + union { + struct { + svr4_pid_t _pid; + svr4_clock_t _utime; + int _status; + svr4_clock_t _stime; + } _child; + + struct { + caddr_t _addr; + int _trap; + } _fault; + } _reason; + } _info; +} svr4_siginfo_t; + +#define si_signo _info._signo +#define si_code _info._code +#define si_errno _info._errno + +#define si_pid _info._reason._child._pid +#define si_stime _info._reason._child._stime +#define si_status _info._reason._child._status +#define si_utime _info._reason._child._utime + +#define si_addr _info._reason._fault._addr +#define si_trap _info._reason._fault._trap + +#endif /* !_SVR4_SIGINFO_H_ */ diff --git a/sys/compat/svr4/svr4_signal.c b/sys/compat/svr4/svr4_signal.c new file mode 100644 index 0000000..47cc6fe --- /dev/null +++ b/sys/compat/svr4/svr4_signal.c @@ -0,0 +1,623 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/namei.h> +#include <sys/proc.h> +#include <sys/filedesc.h> +#include <sys/mount.h> +#include <sys/kernel.h> +#include <sys/signal.h> +#include <sys/signalvar.h> +#include <sys/malloc.h> +#include <sys/sysproto.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_ucontext.h> + +#define sigemptyset(s) memset((s), 0, sizeof(*(s))) +#define sigismember(s, n) (*(s) & sigmask(n)) +#define sigaddset(s, n) (*(s) |= sigmask(n)) + +#define svr4_sigmask(n) (1 << (((n) - 1) & 31)) +#define svr4_sigword(n) (((n) - 1) >> 5) +#define svr4_sigemptyset(s) memset((s), 0, sizeof(*(s))) +#define svr4_sigismember(s, n) ((s)->bits[svr4_sigword(n)] & svr4_sigmask(n)) +#define svr4_sigaddset(s, n) ((s)->bits[svr4_sigword(n)] |= svr4_sigmask(n)) + +static __inline void svr4_sigfillset __P((svr4_sigset_t *)); +void svr4_to_bsd_sigaction __P((const struct svr4_sigaction *, + struct sigaction *)); +void bsd_to_svr4_sigaction __P((const struct sigaction *, + struct svr4_sigaction *)); + +int bsd_to_svr4_sig[] = { + 0, + SVR4_SIGHUP, + SVR4_SIGINT, + SVR4_SIGQUIT, + SVR4_SIGILL, + SVR4_SIGTRAP, + SVR4_SIGABRT, + SVR4_SIGEMT, + SVR4_SIGFPE, + SVR4_SIGKILL, + SVR4_SIGBUS, + SVR4_SIGSEGV, + SVR4_SIGSYS, + SVR4_SIGPIPE, + SVR4_SIGALRM, + SVR4_SIGTERM, + SVR4_SIGURG, + SVR4_SIGSTOP, + SVR4_SIGTSTP, + SVR4_SIGCONT, + SVR4_SIGCHLD, + SVR4_SIGTTIN, + SVR4_SIGTTOU, + SVR4_SIGIO, + SVR4_SIGXCPU, + SVR4_SIGXFSZ, + SVR4_SIGVTALRM, + SVR4_SIGPROF, + SVR4_SIGWINCH, + 0, /* SIGINFO */ + SVR4_SIGUSR1, + SVR4_SIGUSR2, +}; + +int svr4_to_bsd_sig[] = { + 0, + SIGHUP, + SIGINT, + SIGQUIT, + SIGILL, + SIGTRAP, + SIGABRT, + SIGEMT, + SIGFPE, + SIGKILL, + SIGBUS, + SIGSEGV, + SIGSYS, + SIGPIPE, + SIGALRM, + SIGTERM, + SIGUSR1, + SIGUSR2, + SIGCHLD, + 0, /* XXX NetBSD uses SIGPWR here, but we don't seem to have one */ + SIGWINCH, + SIGURG, + SIGIO, + SIGSTOP, + SIGTSTP, + SIGCONT, + SIGTTIN, + SIGTTOU, + SIGVTALRM, + SIGPROF, + SIGXCPU, + SIGXFSZ, +}; + +static __inline void +svr4_sigfillset(s) + svr4_sigset_t *s; +{ + int i; + + svr4_sigemptyset(s); + for (i = 1; i < SVR4_NSIG; i++) + svr4_sigaddset(s, i); +} + +void +svr4_to_bsd_sigset(sss, bss) + const svr4_sigset_t *sss; + sigset_t *bss; +{ + int i, newsig; + + sigemptyset(bss); + for (i = 1; i < SVR4_NSIG; i++) { + if (svr4_sigismember(sss, i)) { + newsig = svr4_to_bsd_sig[i]; + if (newsig) + sigaddset(bss, newsig); + } + } +} + + +void +bsd_to_svr4_sigset(bss, sss) + const sigset_t *bss; + svr4_sigset_t *sss; +{ + int i, newsig; + + svr4_sigemptyset(sss); + for (i = 1; i < NSIG; i++) { + if (sigismember(bss, i)) { + newsig = bsd_to_svr4_sig[i]; + if (newsig) + svr4_sigaddset(sss, newsig); + } + } +} + + +/* + * XXX: Only a subset of the flags is currently implemented. + */ +void +svr4_to_bsd_sigaction(ssa, bsa) + const struct svr4_sigaction *ssa; + struct sigaction *bsa; +{ + + bsa->sa_handler = (sig_t) ssa->sa_handler; + svr4_to_bsd_sigset(&ssa->sa_mask, &bsa->sa_mask); + bsa->sa_flags = 0; + if ((ssa->sa_flags & SVR4_SA_ONSTACK) != 0) + bsa->sa_flags |= SA_ONSTACK; + if ((ssa->sa_flags & SVR4_SA_RESETHAND) != 0) + bsa->sa_flags |= SA_RESETHAND; + if ((ssa->sa_flags & SVR4_SA_RESTART) != 0) + bsa->sa_flags |= SA_RESTART; + if ((ssa->sa_flags & SVR4_SA_SIGINFO) != 0) + DPRINTF(("svr4_to_bsd_sigaction: SA_SIGINFO ignored\n")); + if ((ssa->sa_flags & SVR4_SA_NOCLDSTOP) != 0) + bsa->sa_flags |= SA_NOCLDSTOP; + if ((ssa->sa_flags & SVR4_SA_NODEFER) != 0) + bsa->sa_flags |= SA_NODEFER; + if ((ssa->sa_flags & SVR4_SA_NOCLDWAIT) != 0) + bsa->sa_flags |= SA_NOCLDWAIT; + if ((ssa->sa_flags & ~SVR4_SA_ALLBITS) != 0) + DPRINTF(("svr4_to_bsd_sigaction: extra bits ignored\n")); +} + +void +bsd_to_svr4_sigaction(bsa, ssa) + const struct sigaction *bsa; + struct svr4_sigaction *ssa; +{ + + ssa->sa_handler = (svr4_sig_t) bsa->sa_handler; + bsd_to_svr4_sigset(&bsa->sa_mask, &ssa->sa_mask); + ssa->sa_flags = 0; + if ((bsa->sa_flags & SA_ONSTACK) != 0) + ssa->sa_flags |= SVR4_SA_ONSTACK; + if ((bsa->sa_flags & SA_RESETHAND) != 0) + ssa->sa_flags |= SVR4_SA_RESETHAND; + if ((bsa->sa_flags & SA_RESTART) != 0) + ssa->sa_flags |= SVR4_SA_RESTART; + if ((bsa->sa_flags & SA_NODEFER) != 0) + ssa->sa_flags |= SVR4_SA_NODEFER; + if ((bsa->sa_flags & SA_NOCLDSTOP) != 0) + ssa->sa_flags |= SVR4_SA_NOCLDSTOP; +} + +void +svr4_to_bsd_sigaltstack(sss, bss) + const struct svr4_sigaltstack *sss; + struct sigaltstack *bss; +{ + + bss->ss_sp = sss->ss_sp; + bss->ss_size = sss->ss_size; + bss->ss_flags = 0; + if ((sss->ss_flags & SVR4_SS_DISABLE) != 0) + bss->ss_flags |= SS_DISABLE; + if ((sss->ss_flags & SVR4_SS_ONSTACK) != 0) + bss->ss_flags |= SS_ONSTACK; + if ((sss->ss_flags & ~SVR4_SS_ALLBITS) != 0) + /*XXX*/ uprintf("svr4_to_bsd_sigaltstack: extra bits ignored\n"); +} + +void +bsd_to_svr4_sigaltstack(bss, sss) + const struct sigaltstack *bss; + struct svr4_sigaltstack *sss; +{ + + sss->ss_sp = bss->ss_sp; + sss->ss_size = bss->ss_size; + sss->ss_flags = 0; + if ((bss->ss_flags & SS_DISABLE) != 0) + sss->ss_flags |= SVR4_SS_DISABLE; + if ((bss->ss_flags & SS_ONSTACK) != 0) + sss->ss_flags |= SVR4_SS_ONSTACK; +} + +int +svr4_sys_sigaction(p, uap) + register struct proc *p; + struct svr4_sys_sigaction_args *uap; +{ + struct svr4_sigaction *nisa, *oisa, tmpisa; + struct sigaction *nbsa, *obsa, tmpbsa; + struct sigaction_args sa; + caddr_t sg; + int error; + + sg = stackgap_init(); + nisa = SCARG(uap, nsa); + oisa = SCARG(uap, osa); + + if (oisa != NULL) + obsa = stackgap_alloc(&sg, sizeof(struct sigaction)); + else + obsa = NULL; + + if (nisa != NULL) { + nbsa = stackgap_alloc(&sg, sizeof(struct sigaction)); + if ((error = copyin(nisa, &tmpisa, sizeof(tmpisa))) != 0) + return error; + svr4_to_bsd_sigaction(&tmpisa, &tmpbsa); + if ((error = copyout(&tmpbsa, nbsa, sizeof(tmpbsa))) != 0) + return error; + } else + nbsa = NULL; + + SCARG(&sa, signum) = svr4_to_bsd_sig[SCARG(uap, signum)]; + SCARG(&sa, nsa) = nbsa; + SCARG(&sa, osa) = obsa; + + if ((error = sigaction(p, &sa)) != 0) + return error; + + if (oisa != NULL) { + if ((error = copyin(obsa, &tmpbsa, sizeof(tmpbsa))) != 0) + return error; + bsd_to_svr4_sigaction(&tmpbsa, &tmpisa); + if ((error = copyout(&tmpisa, oisa, sizeof(tmpisa))) != 0) + return error; + } + + return 0; +} + +int +svr4_sys_sigaltstack(p, uap) + register struct proc *p; + struct svr4_sys_sigaltstack_args *uap; +{ + struct svr4_sigaltstack *nsss, *osss, tmpsss; + struct sigaltstack *nbss, *obss, tmpbss; + struct sigaltstack_args sa; + caddr_t sg; + int error, *retval; + + retval = p->p_retval; + sg = stackgap_init(); + nsss = SCARG(uap, nss); + osss = SCARG(uap, oss); + + if (osss != NULL) + obss = stackgap_alloc(&sg, sizeof(struct sigaltstack)); + else + obss = NULL; + + if (nsss != NULL) { + nbss = stackgap_alloc(&sg, sizeof(struct sigaltstack)); + if ((error = copyin(nsss, &tmpsss, sizeof(tmpsss))) != 0) + return error; + svr4_to_bsd_sigaltstack(&tmpsss, &tmpbss); + if ((error = copyout(&tmpbss, nbss, sizeof(tmpbss))) != 0) + return error; + } else + nbss = NULL; + + SCARG(&sa, nss) = nbss; + SCARG(&sa, oss) = obss; + + if ((error = sigaltstack(p, &sa)) != 0) + return error; + + if (obss != NULL) { + if ((error = copyin(obss, &tmpbss, sizeof(tmpbss))) != 0) + return error; + bsd_to_svr4_sigaltstack(&tmpbss, &tmpsss); + if ((error = copyout(&tmpsss, osss, sizeof(tmpsss))) != 0) + return error; + } + + return 0; +} + +/* + * Stolen from the ibcs2 one + */ +int +svr4_sys_signal(p, uap) + register struct proc *p; + struct svr4_sys_signal_args *uap; +{ + int signum = svr4_to_bsd_sig[SVR4_SIGNO(SCARG(uap, signum))]; + int error, *retval; + caddr_t sg = stackgap_init(); + + retval = p->p_retval; + if (signum <= 0 || signum >= SVR4_NSIG) + return (EINVAL); + + switch (SVR4_SIGCALL(SCARG(uap, signum))) { + case SVR4_SIGDEFER_MASK: + if (SCARG(uap, handler) == SVR4_SIG_HOLD) + goto sighold; + /* FALLTHROUGH */ + + case SVR4_SIGNAL_MASK: + { + struct sigaction_args sa_args; + struct sigaction *nbsa, *obsa, sa; + + nbsa = stackgap_alloc(&sg, sizeof(struct sigaction)); + obsa = stackgap_alloc(&sg, sizeof(struct sigaction)); + SCARG(&sa_args, signum) = signum; + SCARG(&sa_args, nsa) = nbsa; + SCARG(&sa_args, osa) = obsa; + + sa.sa_handler = (sig_t) SCARG(uap, handler); + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + + if (signum != SIGALRM) + sa.sa_flags = SA_RESTART; + + if ((error = copyout(&sa, nbsa, sizeof(sa))) != 0) + return error; + if ((error = sigaction(p, &sa_args)) != 0) { + DPRINTF(("signal: sigaction failed: %d\n", + error)); + *retval = (int)SVR4_SIG_ERR; + return error; + } + if ((error = copyin(obsa, &sa, sizeof(sa))) != 0) + return error; + *retval = (int)sa.sa_handler; + return 0; + } + + case SVR4_SIGHOLD_MASK: +sighold: + { + struct sigprocmask_args sa; + + SCARG(&sa, how) = SIG_BLOCK; + SCARG(&sa, mask) = sigmask(signum); + return sigprocmask(p, &sa); + } + + case SVR4_SIGRELSE_MASK: + { + struct sigprocmask_args sa; + + SCARG(&sa, how) = SIG_UNBLOCK; + SCARG(&sa, mask) = sigmask(signum); + return sigprocmask(p, &sa); + } + + case SVR4_SIGIGNORE_MASK: + { + struct sigaction_args sa_args; + struct sigaction *bsa, sa; + + bsa = stackgap_alloc(&sg, sizeof(struct sigaction)); + SCARG(&sa_args, signum) = signum; + SCARG(&sa_args, nsa) = bsa; + SCARG(&sa_args, osa) = NULL; + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if ((error = copyout(&sa, bsa, sizeof(sa))) != 0) + return error; + if ((error = sigaction(p, &sa_args)) != 0) { + DPRINTF(("sigignore: sigaction failed\n")); + return error; + } + return 0; + } + + case SVR4_SIGPAUSE_MASK: + { + struct sigsuspend_args sa; + + SCARG(&sa, mask) = p->p_sigmask & ~sigmask(signum); + return sigsuspend(p, &sa); + } + + default: + return (ENOSYS); + } +} + + +int +svr4_sys_sigprocmask(p, uap) + struct proc *p; + struct svr4_sys_sigprocmask_args *uap; +{ + svr4_sigset_t sss; + sigset_t bss; + int error = 0, *retval; + + retval = p->p_retval; + if (SCARG(uap, oset) != NULL) { + /* Fix the return value first if needed */ + bsd_to_svr4_sigset(&p->p_sigmask, &sss); + if ((error = copyout(&sss, SCARG(uap, oset), sizeof(sss))) != 0) + return error; + } + + if (SCARG(uap, set) == NULL) + /* Just examine */ + return 0; + + if ((error = copyin(SCARG(uap, set), &sss, sizeof(sss))) != 0) + return error; + + svr4_to_bsd_sigset(&sss, &bss); + + (void) splhigh(); + + switch (SCARG(uap, how)) { + case SVR4_SIG_BLOCK: + p->p_sigmask |= bss & ~sigcantmask; + break; + + case SVR4_SIG_UNBLOCK: + p->p_sigmask &= ~bss; + break; + + case SVR4_SIG_SETMASK: + p->p_sigmask = bss & ~sigcantmask; + break; + + default: + error = EINVAL; + break; + } + + (void) spl0(); + + return error; +} + +int +svr4_sys_sigpending(p, uap) + struct proc *p; + struct svr4_sys_sigpending_args *uap; +{ + sigset_t bss; + int *retval; + svr4_sigset_t sss; + + retval = p->p_retval; + switch (SCARG(uap, what)) { + case 1: /* sigpending */ + if (SCARG(uap, mask) == NULL) + return 0; + bss = p->p_siglist & p->p_sigmask; + bsd_to_svr4_sigset(&bss, &sss); + break; + + case 2: /* sigfillset */ + svr4_sigfillset(&sss); + break; + + default: + return EINVAL; + } + + return copyout(&sss, SCARG(uap, mask), sizeof(sss)); +} + +int +svr4_sys_sigsuspend(p, uap) + register struct proc *p; + struct svr4_sys_sigsuspend_args *uap; +{ + svr4_sigset_t sss; + sigset_t bss; + struct sigsuspend_args sa; + int error; + + if ((error = copyin(SCARG(uap, ss), &sss, sizeof(sss))) != 0) + return error; + + svr4_to_bsd_sigset(&sss, &bss); + + SCARG(&sa, mask) = bss; + return sigsuspend(p, &sa); +} + + +int +svr4_sys_kill(p, uap) + register struct proc *p; + struct svr4_sys_kill_args *uap; +{ + struct kill_args ka; + + SCARG(&ka, pid) = SCARG(uap, pid); + SCARG(&ka, signum) = svr4_to_bsd_sig[SCARG(uap, signum)]; + return kill(p, &ka); +} + + +int +svr4_sys_context(p, uap) + register struct proc *p; + struct svr4_sys_context_args *uap; +{ + struct svr4_ucontext uc; + int error; + + switch (uap->func) { + case 0: + DPRINTF(("getcontext(%p)\n", uap->uc)); + svr4_getcontext(p, &uc, p->p_sigmask, + p->p_sigacts->ps_sigstk.ss_flags & SS_ONSTACK); + return copyout(&uc, uap->uc, sizeof(uc)); + + case 1: + DPRINTF(("setcontext(%p)\n", uap->uc)); + if ((error = copyin(uap->uc, &uc, sizeof(uc))) != 0) + return error; + DPRINTF(("uc_flags = %x\n", uc.uc_flags)); + DPRINTF(("uc_sigmask = %x\n", uc.uc_sigmask)); + + return svr4_setcontext(p, &uc); + + default: + DPRINTF(("context(%d, %p)\n", uap->func, + uap->uc)); + return ENOSYS; + } + return 0; +} + +int +svr4_sys_pause(p, uap) + register struct proc *p; + struct svr4_sys_pause_args *uap; +{ + struct sigsuspend_args bsa; + + SCARG(&bsa, mask) = p->p_sigmask; + return sigsuspend(p, &bsa); +} diff --git a/sys/compat/svr4/svr4_signal.h b/sys/compat/svr4/svr4_signal.h new file mode 100644 index 0000000..39444a9 --- /dev/null +++ b/sys/compat/svr4/svr4_signal.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_SIGNAL_H_ +#define _SVR4_SIGNAL_H_ + +#include <i386/svr4/svr4_machdep.h> +#include <svr4/svr4_siginfo.h> + +#define SVR4_SIGHUP 1 +#define SVR4_SIGINT 2 +#define SVR4_SIGQUIT 3 +#define SVR4_SIGILL 4 +#define SVR4_SIGTRAP 5 +#define SVR4_SIGIOT 6 +#define SVR4_SIGABRT 6 +#define SVR4_SIGEMT 7 +#define SVR4_SIGFPE 8 +#define SVR4_SIGKILL 9 +#define SVR4_SIGBUS 10 +#define SVR4_SIGSEGV 11 +#define SVR4_SIGSYS 12 +#define SVR4_SIGPIPE 13 +#define SVR4_SIGALRM 14 +#define SVR4_SIGTERM 15 +#define SVR4_SIGUSR1 16 +#define SVR4_SIGUSR2 17 +#define SVR4_SIGCLD 18 +#define SVR4_SIGCHLD 18 +#define SVR4_SIGPWR 19 +#define SVR4_SIGWINCH 20 +#define SVR4_SIGURG 21 +#define SVR4_SIGPOLL 22 +#define SVR4_SIGIO 22 +#define SVR4_SIGSTOP 23 +#define SVR4_SIGTSTP 24 +#define SVR4_SIGCONT 25 +#define SVR4_SIGTTIN 26 +#define SVR4_SIGTTOU 27 +#define SVR4_SIGVTALRM 28 +#define SVR4_SIGPROF 29 +#define SVR4_SIGXCPU 30 +#define SVR4_SIGXFSZ 31 +#define SVR4_NSIG 32 + +#define SVR4_SIGNO_MASK 0x00FF +#define SVR4_SIGNAL_MASK 0x0000 +#define SVR4_SIGDEFER_MASK 0x0100 +#define SVR4_SIGHOLD_MASK 0x0200 +#define SVR4_SIGRELSE_MASK 0x0400 +#define SVR4_SIGIGNORE_MASK 0x0800 +#define SVR4_SIGPAUSE_MASK 0x1000 + +typedef void (*svr4_sig_t) __P((int, svr4_siginfo_t *, void *)); +#define SVR4_SIG_DFL (svr4_sig_t) 0 +#define SVR4_SIG_ERR (svr4_sig_t) -1 +#define SVR4_SIG_IGN (svr4_sig_t) 1 +#define SVR4_SIG_HOLD (svr4_sig_t) 2 + +#define SVR4_SIGNO(a) ((a) & SVR4_SIGNO_MASK) +#define SVR4_SIGCALL(a) ((a) & ~SVR4_SIGNO_MASK) + +#define SVR4_SIG_BLOCK 1 +#define SVR4_SIG_UNBLOCK 2 +#define SVR4_SIG_SETMASK 3 + +typedef struct { + u_long bits[4]; +} svr4_sigset_t; + +struct svr4_sigaction { + int sa_flags; + svr4_sig_t sa_handler; + svr4_sigset_t sa_mask; + int sa_reserved[2]; +}; + +struct svr4_sigaltstack { + char *ss_sp; + int ss_size; + int ss_flags; +}; + +/* sa_flags */ +#define SVR4_SA_ONSTACK 0x00000001 +#define SVR4_SA_RESETHAND 0x00000002 +#define SVR4_SA_RESTART 0x00000004 +#define SVR4_SA_SIGINFO 0x00000008 +#define SVR4_SA_NODEFER 0x00000010 +#define SVR4_SA_NOCLDWAIT 0x00010000 /* No zombies */ +#define SVR4_SA_NOCLDSTOP 0x00020000 /* No jcl */ +#define SVR4_SA_ALLBITS 0x0003001f + +/* ss_flags */ +#define SVR4_SS_ONSTACK 0x00000001 +#define SVR4_SS_DISABLE 0x00000002 +#define SVR4_SS_ALLBITS 0x00000003 + +void bsd_to_svr4_sigaltstack __P((const struct sigaltstack *, struct svr4_sigaltstack *)); +void bsd_to_svr4_sigset __P((const sigset_t *, svr4_sigset_t *)); +void svr4_to_bsd_sigaltstack __P((const struct svr4_sigaltstack *, struct sigaltstack *)); +void svr4_to_bsd_sigset __P((const svr4_sigset_t *, sigset_t *)); +void svr4_sendsig(sig_t, int, int, u_long); + +#endif /* !_SVR4_SIGNAL_H_ */ diff --git a/sys/compat/svr4/svr4_socket.c b/sys/compat/svr4/svr4_socket.c new file mode 100644 index 0000000..314e1cd --- /dev/null +++ b/sys/compat/svr4/svr4_socket.c @@ -0,0 +1,204 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1996 Christos Zoulas. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * In SVR4 unix domain sockets are referenced sometimes + * (in putmsg(2) for example) as a [device, inode] pair instead of a pathname. + * Since there is no iname() routine in the kernel, and we need access to + * a mapping from inode to pathname, we keep our own table. This is a simple + * linked list that contains the pathname, the [device, inode] pair, the + * file corresponding to that socket and the process. When the + * socket gets closed we remove the item from the list. The list gets loaded + * every time a stat(2) call finds a socket. + */ + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/systm.h> +#include <sys/queue.h> +#include <sys/mbuf.h> +#include <sys/file.h> +#include <sys/mount.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#include <sys/sysproto.h> +#include <sys/un.h> +#include <sys/stat.h> +#include <sys/proc.h> +#include <sys/malloc.h> + +#include <svr4/svr4_types.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_socket.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_sockmod.h> +#include <svr4/svr4_proto.h> + +struct svr4_sockcache_entry { + struct proc *p; /* Process for the socket */ + void *cookie; /* Internal cookie used for matching */ + struct sockaddr_un sock;/* Pathname for the socket */ + dev_t dev; /* Device where the socket lives on */ + ino_t ino; /* Inode where the socket lives on */ + TAILQ_ENTRY(svr4_sockcache_entry) entries; +}; + +extern TAILQ_HEAD(svr4_sockcache_head, svr4_sockcache_entry) svr4_head; +extern int svr4_str_initialized; + +struct sockaddr_un * +svr4_find_socket(p, fp, dev, ino) + struct proc *p; + struct file *fp; + dev_t dev; + ino_t ino; +{ + struct svr4_sockcache_entry *e; + void *cookie = ((struct socket *) fp->f_data)->so_emuldata; + + if (!svr4_str_initialized) { + DPRINTF(("svr4_find_socket: uninitialized [%p,%d,%d]\n", + p, dev, ino)); + TAILQ_INIT(&svr4_head); + svr4_str_initialized = 1; + return NULL; + } + + + DPRINTF(("svr4_find_socket: [%p,%d,%d]: ", p, dev, ino)); + for (e = svr4_head.tqh_first; e != NULL; e = e->entries.tqe_next) + if (e->p == p && e->dev == dev && e->ino == ino) { +#ifdef DIAGNOSTIC + if (e->cookie != NULL && e->cookie != cookie) + panic("svr4 socket cookie mismatch"); +#endif + e->cookie = cookie; + DPRINTF(("%s\n", e->sock.sun_path)); + return &e->sock; + } + + DPRINTF(("not found\n")); + return NULL; +} + + +void +svr4_delete_socket(p, fp) + struct proc *p; + struct file *fp; +{ + struct svr4_sockcache_entry *e; + void *cookie = ((struct socket *) fp->f_data)->so_emuldata; + + if (!svr4_str_initialized) { + TAILQ_INIT(&svr4_head); + svr4_str_initialized = 1; + return; + } + + for (e = svr4_head.tqh_first; e != NULL; e = e->entries.tqe_next) + if (e->p == p && e->cookie == cookie) { + TAILQ_REMOVE(&svr4_head, e, entries); + DPRINTF(("svr4_delete_socket: %s [%p,%d,%d]\n", + e->sock.sun_path, p, e->dev, e->ino)); + free(e, M_TEMP); + return; + } +} + + +int +svr4_add_socket(p, path, st) + struct proc *p; + const char *path; + struct stat *st; +{ + struct svr4_sockcache_entry *e; + int len, error; + + if (!svr4_str_initialized) { + TAILQ_INIT(&svr4_head); + svr4_str_initialized = 1; + } + + e = malloc(sizeof(*e), M_TEMP, M_WAITOK); + e->cookie = NULL; + e->dev = st->st_dev; + e->ino = st->st_ino; + e->p = p; + + if ((error = copyinstr(path, e->sock.sun_path, + sizeof(e->sock.sun_path), &len)) != 0) { + DPRINTF(("svr4_add_socket: copyinstr failed %d\n", error)); + free(e, M_TEMP); + return error; + } + + e->sock.sun_family = AF_LOCAL; + e->sock.sun_len = len; + + TAILQ_INSERT_HEAD(&svr4_head, e, entries); + DPRINTF(("svr4_add_socket: %s [%p,%d,%d]\n", e->sock.sun_path, + p, e->dev, e->ino)); + return 0; +} + + +int +svr4_sys_socket(p, uap) + struct proc *p; + struct svr4_sys_socket_args *uap; +{ + switch (SCARG(uap, type)) { + case SVR4_SOCK_DGRAM: + SCARG(uap, type) = SOCK_DGRAM; + break; + + case SVR4_SOCK_STREAM: + SCARG(uap, type) = SOCK_STREAM; + break; + + case SVR4_SOCK_RAW: + SCARG(uap, type) = SOCK_RAW; + break; + + case SVR4_SOCK_RDM: + SCARG(uap, type) = SOCK_RDM; + break; + + case SVR4_SOCK_SEQPACKET: + SCARG(uap, type) = SOCK_SEQPACKET; + break; + default: + return EINVAL; + } + return socket(p, (struct socket_args *)uap); +} diff --git a/sys/compat/svr4/svr4_socket.h b/sys/compat/svr4/svr4_socket.h new file mode 100644 index 0000000..8e0dc31 --- /dev/null +++ b/sys/compat/svr4/svr4_socket.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1996 Christos Zoulas. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_SOCKET_H_ +#define _SVR4_SOCKET_H_ + +#include <netinet/in.h> + +struct sockaddr_un; +struct proc; +struct file; + +struct svr4_sockaddr_in { + u_char sin_family; + u_short sin_port; + struct in_addr sin_addr; + u_char sin_zero[8]; +}; + +struct sockaddr_un *svr4_find_socket __P((struct proc *, struct file *, + dev_t, ino_t)); +void svr4_delete_socket __P((struct proc *, struct file *)); +int svr4_add_socket __P((struct proc *, const char *, struct stat *)); + +#endif /* _SVR4_SOCKET_H_ */ diff --git a/sys/compat/svr4/svr4_sockio.c b/sys/compat/svr4/svr4_sockio.c new file mode 100644 index 0000000..7b9fb1f --- /dev/null +++ b/sys/compat/svr4/svr4_sockio.c @@ -0,0 +1,174 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1995 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/file.h> +#include <sys/filedesc.h> +#include <sys/sockio.h> +#include <sys/termios.h> +#include <sys/tty.h> +#include <sys/socket.h> +#include <sys/mount.h> +#include <net/if.h> +#include <sys/malloc.h> + +#include <sys/sysproto.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_stropts.h> +#include <svr4/svr4_ioctl.h> +#include <svr4/svr4_sockio.h> + +static int bsd_to_svr4_flags __P((int)); + +#define bsd_to_svr4_flag(a) \ + if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a) + +static int +bsd_to_svr4_flags(bf) + int bf; +{ + int sf = 0; + bsd_to_svr4_flag(FF_UP); + bsd_to_svr4_flag(FF_BROADCAST); + bsd_to_svr4_flag(FF_DEBUG); + bsd_to_svr4_flag(FF_LOOPBACK); + bsd_to_svr4_flag(FF_POINTOPOINT); +#if defined(IFF_NOTRAILERS) + bsd_to_svr4_flag(FF_NOTRAILERS); +#endif + bsd_to_svr4_flag(FF_RUNNING); + bsd_to_svr4_flag(FF_NOARP); + bsd_to_svr4_flag(FF_PROMISC); + bsd_to_svr4_flag(FF_ALLMULTI); + bsd_to_svr4_flag(FF_MULTICAST); + return sf; +} + +int +svr4_sock_ioctl(fp, p, retval, fd, cmd, data) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t data; +{ + int error; + int (*ctl) __P((struct file *, u_long, caddr_t, struct proc *)) = + fp->f_ops->fo_ioctl; + + *retval = 0; + + switch (cmd) { + case SVR4_SIOCGIFNUM: + { + struct ifnet *ifp; + struct ifaddr *ifa; + int ifnum = 0; + + /* + * This does not return the number of physical + * interfaces (if_index), but the number of interfaces + * + addresses like ifconf() does, because this number + * is used by code that will call SVR4_SIOCGIFCONF to + * find the space needed for SVR4_SIOCGIFCONF. So we + * count the number of ifreq entries that the next + * SVR4_SIOCGIFCONF will return. Maybe a more correct + * fix is to make SVR4_SIOCGIFCONF return only one + * entry per physical interface? + */ + + for (ifp = ifnet.tqh_first; + ifp != 0; ifp = ifp->if_link.tqe_next) + if ((ifa = ifp->if_addrhead.tqh_first) == NULL) + ifnum++; + else + for (;ifa != NULL; + ifa = ifa->ifa_link.tqe_next) + ifnum++; + + + DPRINTF(("SIOCGIFNUM %d\n", ifnum)); + return copyout(&ifnum, data, sizeof(ifnum)); + } + + case SVR4_SIOCGIFFLAGS: + { + struct ifreq br; + struct svr4_ifreq sr; + + if ((error = copyin(data, &sr, sizeof(sr))) != 0) + return error; + + (void) strncpy(br.ifr_name, "de0", /*sr.svr4_ifr_name,*/ + sizeof(br.ifr_name)); + if ((error = (*ctl)(fp, SIOCGIFFLAGS, + (caddr_t) &br, p)) != 0) { + DPRINTF(("SIOCGIFFLAGS (%s) %s: error %d\n", + br.ifr_name, sr.svr4_ifr_name, error)); + return error; + } + + sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags); + DPRINTF(("SIOCGIFFLAGS %s = %x\n", + sr.svr4_ifr_name, sr.svr4_ifr_flags)); + return copyout(&sr, data, sizeof(sr)); + } + + case SVR4_SIOCGIFCONF: + { + struct svr4_ifconf sc; + + if ((error = copyin(data, &sc, sizeof(sc))) != 0) + return error; + + DPRINTF(("ifreq %d svr4_ifreq %d ifc_len %d\n", + sizeof(struct ifreq), sizeof(struct svr4_ifreq), + sc.svr4_ifc_len)); + + if ((error = (*ctl)(fp, OSIOCGIFCONF, + (caddr_t) &sc, p)) != 0) + return error; + + DPRINTF(("SIOCGIFCONF\n")); + return 0; + } + + + default: + DPRINTF(("Unknown svr4 sockio %lx\n", cmd)); + return 0; /* ENOSYS really */ + } +} diff --git a/sys/compat/svr4/svr4_sockio.h b/sys/compat/svr4/svr4_sockio.h new file mode 100644 index 0000000..7ddbcf7 --- /dev/null +++ b/sys/compat/svr4/svr4_sockio.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1995 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_SOCKIO_H_ +#define _SVR4_SOCKIO_H_ + +#define SVR4_IFF_UP 0x0001 +#define SVR4_IFF_BROADCAST 0x0002 +#define SVR4_IFF_DEBUG 0x0004 +#define SVR4_IFF_LOOPBACK 0x0008 +#define SVR4_IFF_POINTOPOINT 0x0010 +#define SVR4_IFF_NOTRAILERS 0x0020 +#define SVR4_IFF_RUNNING 0x0040 +#define SVR4_IFF_NOARP 0x0080 +#define SVR4_IFF_PROMISC 0x0100 +#define SVR4_IFF_ALLMULTI 0x0200 +#define SVR4_IFF_INTELLIGENT 0x0400 +#define SVR4_IFF_MULTICAST 0x0800 +#define SVR4_IFF_MULTI_BCAST 0x1000 +#define SVR4_IFF_UNNUMBERED 0x2000 +#define SVR4_IFF_PRIVATE 0x8000 + +struct svr4_ifreq { +#define SVR4_IFNAMSIZ 16 + char svr4_ifr_name[SVR4_IFNAMSIZ]; + union { + struct osockaddr ifru_addr; + struct osockaddr ifru_dstaddr; + struct osockaddr ifru_broadaddr; + short ifru_flags; + int ifru_metric; + char ifru_data; + char ifru_enaddr[6]; + int if_muxid[2]; + + } ifr_ifru; + +#define svr4_ifr_addr ifr_ifru.ifru_addr +#define svr4_ifr_dstaddr ifr_ifru.ifru_dstaddr +#define svr4_ifr_broadaddr ifr_ifru.ifru_broadaddr +#define svr4_ifr_flags ifr_ifru.ifru_flags +#define svr4_ifr_metric ifr_ifru.ifru_metric +#define svr4_ifr_data ifr_ifru.ifru_data +#define svr4_ifr_enaddr ifr_ifru.ifru_enaddr +#define svr4_ifr_muxid ifr_ifru.ifru_muxid + +}; + +struct svr4_ifconf { + int svr4_ifc_len; + union { + caddr_t ifcu_buf; + struct svr4_ifreq *ifcu_req; + } ifc_ifcu; + +#define svr4_ifc_buf ifc_ifcu.ifcu_buf +#define svr4_ifc_req ifc_ifcu.ifcu_req +}; + +#define SVR4_SIOC ('i' << 8) + +#define SVR4_SIOCGIFFLAGS SVR4_IOWR('i', 17, struct svr4_ifreq) +#define SVR4_SIOCGIFCONF SVR4_IOWR('i', 20, struct svr4_ifconf) +#define SVR4_SIOCGIFNUM SVR4_IOR('i', 87, int) + +#endif /* !_SVR4_SOCKIO_H_ */ diff --git a/sys/compat/svr4/svr4_sockmod.h b/sys/compat/svr4/svr4_sockmod.h new file mode 100644 index 0000000..e0fe451 --- /dev/null +++ b/sys/compat/svr4/svr4_sockmod.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_SOCKMOD_H_ +#define _SVR4_SOCKMOD_H_ + +#define SVR4_SIMOD ('I' << 8) + +#define SVR4_SI_OGETUDATA (SVR4_SIMOD|101) +#define SVR4_SI_SHUTDOWN (SVR4_SIMOD|102) +#define SVR4_SI_LISTEN (SVR4_SIMOD|103) +#define SVR4_SI_SETMYNAME (SVR4_SIMOD|104) +#define SVR4_SI_SETPEERNAME (SVR4_SIMOD|105) +#define SVR4_SI_GETINTRANSIT (SVR4_SIMOD|106) +#define SVR4_SI_TCL_LINK (SVR4_SIMOD|107) +#define SVR4_SI_TCL_UNLINK (SVR4_SIMOD|108) +#define SVR4_SI_SOCKPARAMS (SVR4_SIMOD|109) +#define SVR4_SI_GETUDATA (SVR4_SIMOD|110) + + +#define SVR4_SOCK_DGRAM 1 +#define SVR4_SOCK_STREAM 2 +#define SVR4_SOCK_STREAM_ORD 3 +#define SVR4_SOCK_RAW 4 +#define SVR4_SOCK_RDM 5 +#define SVR4_SOCK_SEQPACKET 6 + +struct svr4_si_sockparms { + int family; + int type; + int protocol; +}; + +struct svr4_si_oudata { + int tidusize; + int addrsize; + int optsize; + int etsdusize; + int servtype; + int so_state; + int so_options; + int tsdusize; +}; + +struct svr4_si_udata { + int tidusize; + int addrsize; + int optsize; + int etsdusize; + int servtype; + int so_state; + int so_options; + int tsdusize; + struct svr4_si_sockparms sockparms; +}; +#endif /* !_SVR4_SOCKMOD_H_ */ diff --git a/sys/compat/svr4/svr4_stat.c b/sys/compat/svr4/svr4_stat.c new file mode 100644 index 0000000..99448ba --- /dev/null +++ b/sys/compat/svr4/svr4_stat.c @@ -0,0 +1,803 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/namei.h> +#include <sys/proc.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <sys/filedesc.h> +#include <sys/kernel.h> +#include <sys/mount.h> +#include <sys/malloc.h> +#include <sys/unistd.h> + +#include <sys/time.h> +#include <sys/ucred.h> +#include <vm/vm.h> +#include <sys/sysctl.h> +#include <netinet/in.h> + +#include <sys/sysproto.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_stat.h> +#include <svr4/svr4_ustat.h> +#include <svr4/svr4_utsname.h> +#include <svr4/svr4_systeminfo.h> +#include <svr4/svr4_socket.h> +#include <svr4/svr4_time.h> +#if defined(NOTYET) +#include "svr4_fuser.h" +#endif + +#ifdef sparc +/* + * Solaris-2.4 on the sparc has the old stat call using the new + * stat data structure... + */ +# define SVR4_NO_OSTAT +#endif + +struct svr4_ustat_args { + svr4_dev_t dev; + struct svr4_ustat * name; +}; + +static void bsd_to_svr4_xstat __P((struct stat *, struct svr4_xstat *)); +static void bsd_to_svr4_stat64 __P((struct stat *, struct svr4_stat64 *)); +int svr4_ustat __P((struct proc *, struct svr4_ustat_args *)); +static int svr4_to_bsd_pathconf __P((int)); + +/* + * SVR4 uses named pipes as named sockets, so we tell programs + * that sockets are named pipes with mode 0 + */ +#define BSD_TO_SVR4_MODE(mode) (S_ISSOCK(mode) ? S_IFIFO : (mode)) + + +#ifndef SVR4_NO_OSTAT +static void bsd_to_svr4_stat __P((struct stat *, struct svr4_stat *)); + +static void +bsd_to_svr4_stat(st, st4) + struct stat *st; + struct svr4_stat *st4; +{ + memset(st4, 0, sizeof(*st4)); + st4->st_dev = bsd_to_svr4_odev_t(st->st_dev); + st4->st_ino = st->st_ino; + st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode); + st4->st_nlink = st->st_nlink; + st4->st_uid = st->st_uid; + st4->st_gid = st->st_gid; + st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev); + st4->st_size = st->st_size; + st4->st_atim = st->st_atimespec.tv_sec; + st4->st_mtim = st->st_mtimespec.tv_sec; + st4->st_ctim = st->st_ctimespec.tv_sec; +} +#endif + + +static void +bsd_to_svr4_xstat(st, st4) + struct stat *st; + struct svr4_xstat *st4; +{ + memset(st4, 0, sizeof(*st4)); + st4->st_dev = bsd_to_svr4_dev_t(st->st_dev); + st4->st_ino = st->st_ino; + st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode); + st4->st_nlink = st->st_nlink; + st4->st_uid = st->st_uid; + st4->st_gid = st->st_gid; + st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev); + st4->st_size = st->st_size; + st4->st_atim = st->st_atimespec; + st4->st_mtim = st->st_mtimespec; + st4->st_ctim = st->st_ctimespec; + st4->st_blksize = st->st_blksize; + st4->st_blocks = st->st_blocks; + strcpy(st4->st_fstype, "unknown"); +} + + +static void +bsd_to_svr4_stat64(st, st4) + struct stat *st; + struct svr4_stat64 *st4; +{ + memset(st4, 0, sizeof(*st4)); + st4->st_dev = bsd_to_svr4_dev_t(st->st_dev); + st4->st_ino = st->st_ino; + st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode); + st4->st_nlink = st->st_nlink; + st4->st_uid = st->st_uid; + st4->st_gid = st->st_gid; + st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev); + st4->st_size = st->st_size; + st4->st_atim = st->st_atimespec; + st4->st_mtim = st->st_mtimespec; + st4->st_ctim = st->st_ctimespec; + st4->st_blksize = st->st_blksize; + st4->st_blocks = st->st_blocks; + strcpy(st4->st_fstype, "unknown"); +} + +int +svr4_sys_stat(p, uap) + struct proc *p; + struct svr4_sys_stat_args *uap; +{ + int *retval; +#ifdef SVR4_NO_OSTAT + struct svr4_sys_xstat_args cup; + + retval = &(p->p_retval[0]); + SCARG(&cup, two) = 2; + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, ub) = (struct svr4_xstat *) SCARG(uap, ub); + return svr4_sys_xstat(p, &cup, retval); +#else + struct stat st; + struct svr4_stat svr4_st; + struct stat_args cup; + int error; + caddr_t sg = stackgap_init(); + + retval = p->p_retval; + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat)); + + + if ((error = stat(p, &cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_stat(&st, &svr4_st); + + if (S_ISSOCK(st.st_mode)) + (void) svr4_add_socket(p, SCARG(uap, path), &st); + + if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0) + return error; + + return 0; +#endif +} + + +int +svr4_sys_lstat(p, uap) + register struct proc *p; + struct svr4_sys_lstat_args *uap; +{ + int *retval; + struct stat st; + struct svr4_stat svr4_st; + struct lstat_args cup; + int error; + caddr_t sg = stackgap_init(); + + retval = p->p_retval; + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = lstat(p, &cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_stat(&st, &svr4_st); + + if (S_ISSOCK(st.st_mode)) + (void) svr4_add_socket(p, SCARG(uap, path), &st); + + if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0) + return error; + + return 0; +} + + +int +svr4_sys_fstat(p, uap) + register struct proc *p; + struct svr4_sys_fstat_args *uap; +{ + struct stat st; + struct svr4_stat svr4_st; + struct fstat_args cup; + int error, *retval; + caddr_t sg = stackgap_init(); + + retval = p->p_retval; + SCARG(&cup, fd) = SCARG(uap, fd); + SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = fstat(p, &cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_stat(&st, &svr4_st); + + if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0) + return error; + + return 0; +} + + +int +svr4_sys_xstat(p, uap) + register struct proc *p; + struct svr4_sys_xstat_args *uap; +{ + struct stat st; + struct svr4_xstat svr4_st; + struct stat_args cup; + int error, *retval; + + caddr_t sg = stackgap_init(); + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + retval = p->p_retval; + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = stat(p, &cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_xstat(&st, &svr4_st); + +#if defined(SOCKET_NOTYET) + if (S_ISSOCK(st.st_mode)) + (void) svr4_add_socket(p, SCARG(uap, path), &st); +#endif + + if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0) + return error; + + return 0; +} + +int +svr4_sys_lxstat(p, uap) + register struct proc *p; + struct svr4_sys_lxstat_args *uap; +{ + int *retval; + struct stat st; + struct svr4_xstat svr4_st; + struct lstat_args cup; + int error; + caddr_t sg = stackgap_init(); + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + retval = p->p_retval; + + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = lstat(p, &cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_xstat(&st, &svr4_st); + +#if defined(SOCKET_NOTYET) + if (S_ISSOCK(st.st_mode)) + (void) svr4_add_socket(p, SCARG(uap, path), &st); +#endif + if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0) + return error; + + return 0; +} + + +int +svr4_sys_fxstat(p, uap) + register struct proc *p; + struct svr4_sys_fxstat_args *uap; +{ + int *retval; + struct stat st; + struct svr4_xstat svr4_st; + struct fstat_args cup; + int error; + + caddr_t sg = stackgap_init(); + + retval = p->p_retval; + SCARG(&cup, fd) = SCARG(uap, fd); + SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = fstat(p, &cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_xstat(&st, &svr4_st); + + if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0) + return error; + + return 0; +} + +int +svr4_sys_stat64(p, uap) + register struct proc *p; + struct svr4_sys_stat64_args *uap; +{ + struct stat st; + struct svr4_stat64 svr4_st; + struct stat_args cup; + int error, *retval; + caddr_t sg = stackgap_init(); + + retval = p->p_retval; + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = stat(p, &cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_stat64(&st, &svr4_st); + + if (S_ISSOCK(st.st_mode)) + (void) svr4_add_socket(p, SCARG(uap, path), &st); + + if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0) + return error; + + return 0; +} + + +int +svr4_sys_lstat64(p, uap) + register struct proc *p; + struct svr4_sys_lstat64_args *uap; +{ + struct stat st; + struct svr4_stat64 svr4_st; + struct stat_args cup; + int error, *retval; + caddr_t sg = stackgap_init(); + + retval = p->p_retval; + + CHECKALTEXIST(p, &sg, (char *) SCARG(uap, path)); + + SCARG(&cup, path) = SCARG(uap, path); + SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = lstat(p, (struct lstat_args *)&cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_stat64(&st, &svr4_st); + + if (S_ISSOCK(st.st_mode)) + (void) svr4_add_socket(p, SCARG(uap, path), &st); + + if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0) + return error; + + return 0; +} + + +int +svr4_sys_fstat64(p, uap) + register struct proc *p; + struct svr4_sys_fstat64_args *uap; +{ + struct stat st; + struct svr4_stat64 svr4_st; + struct fstat_args cup; + int error, *retval; + caddr_t sg = stackgap_init(); + + retval = p->p_retval; + + SCARG(&cup, fd) = SCARG(uap, fd); + SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = fstat(p, &cup)) != 0) + return error; + + if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0) + return error; + + bsd_to_svr4_stat64(&st, &svr4_st); + + if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0) + return error; + + return 0; +} + + +int +svr4_ustat(p, uap) + register struct proc *p; + struct svr4_ustat_args *uap; +{ + struct svr4_ustat us; + int error; + + memset(&us, 0, sizeof us); + + /* + * XXX: should set f_tfree and f_tinode at least + * How do we translate dev -> fstat? (and then to svr4_ustat) + */ + if ((error = copyout(&us, SCARG(uap, name), sizeof us)) != 0) + return (error); + + return 0; +} + +/*extern char ostype[], hostname[], osrelease[], version[], machine[];*/ + +int +svr4_sys_uname(p, uap) + register struct proc *p; + struct svr4_sys_uname_args *uap; +{ + struct svr4_utsname sut; + + + memset(&sut, 0, sizeof(sut)); + + strncpy(sut.sysname, ostype, sizeof(sut.sysname)); + sut.sysname[sizeof(sut.sysname) - 1] = '\0'; + + strncpy(sut.nodename, hostname, sizeof(sut.nodename)); + sut.nodename[sizeof(sut.nodename) - 1] = '\0'; + + strncpy(sut.release, osrelease, sizeof(sut.release)); + sut.release[sizeof(sut.release) - 1] = '\0'; + + strncpy(sut.version, version, sizeof(sut.version)); + sut.version[sizeof(sut.version) - 1] = '\0'; + + strncpy(sut.machine, machine, sizeof(sut.machine)); + sut.machine[sizeof(sut.machine) - 1] = '\0'; + + return copyout((caddr_t) &sut, (caddr_t) SCARG(uap, name), + sizeof(struct svr4_utsname)); +} + +int +svr4_sys_systeminfo(p, uap) + struct proc *p; + struct svr4_sys_systeminfo_args *uap; +{ + char *str = NULL; + int error = 0, *retval = p->p_retval; + size_t len = 0; + char buf[1]; /* XXX NetBSD uses 256, but that seems like awfully + excessive kstack usage for an empty string... */ + u_int rlen = SCARG(uap, len); + + switch (SCARG(uap, what)) { + case SVR4_SI_SYSNAME: + str = ostype; + break; + + case SVR4_SI_HOSTNAME: + str = hostname; + break; + + case SVR4_SI_RELEASE: + str = osrelease; + break; + + case SVR4_SI_VERSION: + str = version; + break; + + case SVR4_SI_MACHINE: + str = machine; + break; + + case SVR4_SI_ARCHITECTURE: + str = machine; + break; + + case SVR4_SI_HW_SERIAL: + str = "0"; + break; + + case SVR4_SI_HW_PROVIDER: + str = ostype; + break; + + case SVR4_SI_SRPC_DOMAIN: + str = domainname; + break; + + case SVR4_SI_PLATFORM: +#ifdef __i386__ + str = "i86pc"; +#else + str = "unknown"; +#endif + break; + + case SVR4_SI_KERB_REALM: + str = "unsupported"; + break; +#if defined(WHY_DOES_AN_EMULATOR_WANT_TO_SET_HOSTNAMES) + case SVR4_SI_SET_HOSTNAME: + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) + return error; + name = KERN_HOSTNAME; + return kern_sysctl(&name, 1, 0, 0, SCARG(uap, buf), rlen, p); + + case SVR4_SI_SET_SRPC_DOMAIN: + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) + return error; + name = KERN_NISDOMAINNAME; + return kern_sysctl(&name, 1, 0, 0, SCARG(uap, buf), rlen, p); +#else + case SVR4_SI_SET_HOSTNAME: + case SVR4_SI_SET_SRPC_DOMAIN: + /* FALLTHROUGH */ +#endif + case SVR4_SI_SET_KERB_REALM: + return 0; + + default: + DPRINTF(("Bad systeminfo command %d\n", SCARG(uap, what))); + return ENOSYS; + } + + if (str) { + len = strlen(str) + 1; + if (len > rlen) + len = rlen; + + if (SCARG(uap, buf)) { + error = copyout(str, SCARG(uap, buf), len); + if (error) + return error; + /* make sure we are NULL terminated */ + buf[0] = '\0'; + error = copyout(buf, &(SCARG(uap, buf)[len - 1]), 1); + } + else + error = 0; + } + /* XXX NetBSD has hostname setting stuff here. Why would an emulator + want to do that? */ + + *retval = len; + return error; +} + +int +svr4_sys_utssys(p, uap) + register struct proc *p; + struct svr4_sys_utssys_args *uap; +{ + switch (SCARG(uap, sel)) { + case 0: /* uname(2) */ + { + struct svr4_sys_uname_args ua; + SCARG(&ua, name) = SCARG(uap, a1); + return svr4_sys_uname(p, &ua); + } + + case 2: /* ustat(2) */ + { + struct svr4_ustat_args ua; + SCARG(&ua, dev) = (svr4_dev_t) SCARG(uap, a2); + SCARG(&ua, name) = SCARG(uap, a1); + return svr4_ustat(p, &ua); + } + + case 3: /* fusers(2) */ + return ENOSYS; + + default: + return ENOSYS; + } + return ENOSYS; +} + + +int +svr4_sys_utime(p, uap) + register struct proc *p; + struct svr4_sys_utime_args *uap; +{ + struct svr4_utimbuf ub; + struct timeval tbuf[2]; + struct utimes_args ap; + int error; + caddr_t sg = stackgap_init(); + void *ttp; + + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + SCARG(&ap, path) = SCARG(uap, path); + if (SCARG(uap, ubuf) != NULL) { + if ((error = copyin(SCARG(uap, ubuf), &ub, sizeof(ub))) != 0) + return error; + tbuf[0].tv_sec = ub.actime; + tbuf[0].tv_usec = 0; + tbuf[1].tv_sec = ub.modtime; + tbuf[1].tv_usec = 0; + ttp = stackgap_alloc(&sg, sizeof(tbuf)); + error = copyout(tbuf, ttp, sizeof(tbuf)); + if (error) + return error; + SCARG(&ap, tptr) = ttp; + } + else + SCARG(&ap, tptr) = NULL; + return utimes(p, &ap); +} + + +int +svr4_sys_utimes(p, uap) + register struct proc *p; + struct svr4_sys_utimes_args *uap; +{ + caddr_t sg = stackgap_init(); + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + return utimes(p, (struct utimes_args *)uap); +} + +static int +svr4_to_bsd_pathconf(name) + int name; +{ + switch (name) { + case SVR4_PC_LINK_MAX: + return _PC_LINK_MAX; + + case SVR4_PC_MAX_CANON: + return _PC_MAX_CANON; + + case SVR4_PC_MAX_INPUT: + return _PC_MAX_INPUT; + + case SVR4_PC_NAME_MAX: + return _PC_NAME_MAX; + + case SVR4_PC_PATH_MAX: + return _PC_PATH_MAX; + + case SVR4_PC_PIPE_BUF: + return _PC_PIPE_BUF; + + case SVR4_PC_NO_TRUNC: + return _PC_NO_TRUNC; + + case SVR4_PC_VDISABLE: + return _PC_VDISABLE; + + case SVR4_PC_CHOWN_RESTRICTED: + return _PC_CHOWN_RESTRICTED; + case SVR4_PC_SYNC_IO: +#if defined(_PC_SYNC_IO) + return _PC_SYNC_IO; +#else + return 0; +#endif + case SVR4_PC_ASYNC_IO: + case SVR4_PC_PRIO_IO: + /* Not supported */ + return 0; + + default: + /* Invalid */ + return -1; + } +} + + +int +svr4_sys_pathconf(p, uap) + register struct proc *p; + struct svr4_sys_pathconf_args *uap; +{ + caddr_t sg = stackgap_init(); + int *retval = p->p_retval; + + CHECKALTEXIST(p, &sg, SCARG(uap, path)); + + SCARG(uap, name) = svr4_to_bsd_pathconf(SCARG(uap, name)); + + switch (SCARG(uap, name)) { + case -1: + *retval = -1; + return EINVAL; + case 0: + *retval = 0; + return 0; + default: + return pathconf(p, (struct pathconf_args *)uap); + } +} + + +int +svr4_sys_fpathconf(p, uap) + register struct proc *p; + struct svr4_sys_fpathconf_args *uap; +{ + int *retval = p->p_retval; + + SCARG(uap, name) = svr4_to_bsd_pathconf(SCARG(uap, name)); + + switch (SCARG(uap, name)) { + case -1: + *retval = -1; + return EINVAL; + case 0: + *retval = 0; + return 0; + default: + return fpathconf(p, (struct fpathconf_args *)uap); + } +} diff --git a/sys/compat/svr4/svr4_stat.h b/sys/compat/svr4/svr4_stat.h new file mode 100644 index 0000000..dea7d1f --- /dev/null +++ b/sys/compat/svr4/svr4_stat.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_STAT_H_ +#define _SVR4_STAT_H_ + +#include <svr4/svr4_types.h> +#include <sys/stat.h> + +struct svr4_stat { + svr4_o_dev_t st_dev; + svr4_o_ino_t st_ino; + svr4_o_mode_t st_mode; + svr4_o_nlink_t st_nlink; + svr4_o_uid_t st_uid; + svr4_o_gid_t st_gid; + svr4_o_dev_t st_rdev; + svr4_off_t st_size; + svr4_time_t st_atim; + svr4_time_t st_mtim; + svr4_time_t st_ctim; +}; + +struct svr4_xstat { + svr4_dev_t st_dev; + long st_pad1[3]; + svr4_ino_t st_ino; + svr4_mode_t st_mode; + svr4_nlink_t st_nlink; + svr4_uid_t st_uid; + svr4_gid_t st_gid; + svr4_dev_t st_rdev; + long st_pad2[2]; + svr4_off_t st_size; + long st_pad3; + svr4_timestruc_t st_atim; + svr4_timestruc_t st_mtim; + svr4_timestruc_t st_ctim; + long st_blksize; + svr4_blkcnt_t st_blocks; + char st_fstype[16]; + long st_pad4[8]; +}; + +struct svr4_stat64 { + svr4_dev_t st_dev; + long st_pad1[3]; + svr4_ino64_t st_ino; + svr4_mode_t st_mode; + svr4_nlink_t st_nlink; + svr4_uid_t st_uid; + svr4_gid_t st_gid; + svr4_dev_t st_rdev; + long st_pad2[2]; + svr4_off64_t st_size; + svr4_timestruc_t st_atim; + svr4_timestruc_t st_mtim; + svr4_timestruc_t st_ctim; + long st_blksize; + svr4_blkcnt64_t st_blocks; + char st_fstype[16]; + long st_pad4[8]; +}; + +#define SVR4_PC_LINK_MAX 1 +#define SVR4_PC_MAX_CANON 2 +#define SVR4_PC_MAX_INPUT 3 +#define SVR4_PC_NAME_MAX 4 +#define SVR4_PC_PATH_MAX 5 +#define SVR4_PC_PIPE_BUF 6 +#define SVR4_PC_NO_TRUNC 7 +#define SVR4_PC_VDISABLE 8 +#define SVR4_PC_CHOWN_RESTRICTED 9 +#define SVR4_PC_ASYNC_IO 10 +#define SVR4_PC_PRIO_IO 11 +#define SVR4_PC_SYNC_IO 12 + +#endif /* !_SVR4_STAT_H_ */ diff --git a/sys/compat/svr4/svr4_statvfs.h b/sys/compat/svr4/svr4_statvfs.h new file mode 100644 index 0000000..30ae808 --- /dev/null +++ b/sys/compat/svr4/svr4_statvfs.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_STATVFS_H_ +#define _SVR4_STATVFS_H_ + +typedef struct svr4_statvfs { + u_long f_bsize; + u_long f_frsize; + svr4_fsblkcnt_t f_blocks; + svr4_fsblkcnt_t f_bfree; + svr4_fsblkcnt_t f_bavail; + svr4_fsblkcnt_t f_files; + svr4_fsblkcnt_t f_ffree; + svr4_fsblkcnt_t f_favail; + u_long f_fsid; + char f_basetype[16]; + u_long f_flag; + u_long f_namemax; + char f_fstr[32]; + u_long f_filler[16]; +} svr4_statvfs_t; + +typedef struct svr4_statvfs64 { + u_long f_bsize; + u_long f_frsize; + svr4_fsblkcnt64_t f_blocks; + svr4_fsblkcnt64_t f_bfree; + svr4_fsblkcnt64_t f_bavail; + svr4_fsblkcnt64_t f_files; + svr4_fsblkcnt64_t f_ffree; + svr4_fsblkcnt64_t f_favail; + u_long f_fsid; + char f_basetype[16]; + u_long f_flag; + u_long f_namemax; + char f_fstr[32]; + u_long f_filler[16]; +} svr4_statvfs64_t; + +#define SVR4_ST_RDONLY 0x01 +#define SVR4_ST_NOSUID 0x02 +#define SVR4_ST_NOTRUNC 0x04 + +#endif /* !_SVR4_STATVFS_H_ */ diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c new file mode 100644 index 0000000..a656d33 --- /dev/null +++ b/sys/compat/svr4/svr4_stream.c @@ -0,0 +1,2264 @@ +/* + * Copyright (c) 1998 Mark Newton. All rights reserved. + * Copyright (c) 1994, 1996 Christos Zoulas. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Pretend that we have streams... + * Yes, this is gross. + * + * ToDo: The state machine for getmsg needs re-thinking + */ + +#define COMPAT_43 1 + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/systm.h> +#include <sys/buf.h> +#include <sys/malloc.h> +#include <sys/tty.h> +#include <sys/file.h> +#include <sys/filedesc.h> +#include <sys/unistd.h> +#include <sys/fcntl.h> +#include <sys/filio.h> +#include <sys/select.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#include <sys/un.h> +#include <net/if.h> +#include <netinet/in.h> +#include <sys/mount.h> +#include <sys/mbuf.h> +#include <sys/protosw.h> +#include <sys/signal.h> +#include <sys/signalvar.h> +#include <sys/uio.h> +#include <sys/ktrace.h> +#include <sys/proc.h> +#include <sys/vnode.h> +#include <sys/device.h> +#include <sys/stat.h> + +#include <sys/sysproto.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_stropts.h> +#include <svr4/svr4_timod.h> +#include <svr4/svr4_sockmod.h> +#include <svr4/svr4_ioctl.h> +#include <svr4/svr4_socket.h> + +/* Utils */ +static int clean_pipe __P((struct proc *, const char *)); +static void getparm __P((struct file *, struct svr4_si_sockparms *)); + +/* Address Conversions */ +static void sockaddr_to_netaddr_in __P((struct svr4_strmcmd *, + const struct sockaddr_in *)); +static void sockaddr_to_netaddr_un __P((struct svr4_strmcmd *, + const struct sockaddr_un *)); +static void netaddr_to_sockaddr_in __P((struct sockaddr_in *, + const struct svr4_strmcmd *)); +static void netaddr_to_sockaddr_un __P((struct sockaddr_un *, + const struct svr4_strmcmd *)); + +/* stream ioctls */ +static int i_nread __P((struct file *, struct proc *, register_t *, int, + u_long, caddr_t)); +static int i_fdinsert __P((struct file *, struct proc *, register_t *, int, + u_long, caddr_t)); +static int i_str __P((struct file *, struct proc *, register_t *, int, + u_long, caddr_t)); +static int i_setsig __P((struct file *, struct proc *, register_t *, int, + u_long, caddr_t)); +static int i_getsig __P((struct file *, struct proc *, register_t *, int, + u_long, caddr_t)); +static int _i_bind_rsvd __P((struct file *, struct proc *, register_t *, int, + u_long, caddr_t)); +static int _i_rele_rsvd __P((struct file *, struct proc *, register_t *, int, + u_long, caddr_t)); + +/* i_str sockmod calls */ +static int sockmod __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); +static int si_listen __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); +static int si_ogetudata __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); +static int si_sockparams __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); +static int si_shutdown __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); +static int si_getudata __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); + +/* i_str timod calls */ +static int timod __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); +static int ti_getinfo __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); +static int ti_bind __P((struct file *, int, struct svr4_strioctl *, + struct proc *)); + +/* infrastructure */ +static int svr4_sendit __P((struct proc *p, int s, struct msghdr *mp, + int flags)); + +static int svr4_recvit __P((struct proc *p, int s, struct msghdr *mp, + caddr_t namelenp)); + +/* <sigh> Ok, so we shouldn't use sendit() in uipc_syscalls.c because + * it isn't part of a "public" interface; We're supposed to use + * pru_sosend instead. Same goes for recvit()/pru_soreceive() for + * that matter. Solution: Suck sendit()/recvit() into here where we + * can do what we like. + * + * I hate code duplication. + * + * I will take out all the #ifdef COMPAT_OLDSOCK gumph, though. + */ +static int +svr4_sendit(p, s, mp, flags) + register struct proc *p; + int s; + register struct msghdr *mp; + int flags; +{ + struct file *fp; + struct uio auio; + register struct iovec *iov; + register int i; + struct mbuf *control; + struct sockaddr *to; + int len, error; + struct socket *so; +#ifdef KTRACE + struct iovec *ktriov = NULL; +#endif + + error = getsock(p->p_fd, s, &fp); + if (error) + return (error); + auio.uio_iov = mp->msg_iov; + auio.uio_iovcnt = mp->msg_iovlen; + auio.uio_segflg = UIO_USERSPACE; + auio.uio_rw = UIO_WRITE; + auio.uio_procp = p; + auio.uio_offset = 0; /* XXX */ + auio.uio_resid = 0; + iov = mp->msg_iov; + for (i = 0; i < mp->msg_iovlen; i++, iov++) { + if ((auio.uio_resid += iov->iov_len) < 0) + return (EINVAL); + } + if (mp->msg_name) { + error = getsockaddr(&to, mp->msg_name, mp->msg_namelen); + if (error) + return (error); + } else + to = 0; + if (mp->msg_control) { + if (mp->msg_controllen < sizeof(struct cmsghdr)) { + error = EINVAL; + goto bad; + } + error = sockargs(&control, mp->msg_control, + mp->msg_controllen, MT_CONTROL); + if (error) + goto bad; + } else + control = 0; +#ifdef KTRACE + if (KTRPOINT(p, KTR_GENIO)) { + int iovlen = auio.uio_iovcnt * sizeof (struct iovec); + + MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK); + bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen); + } +#endif + len = auio.uio_resid; + so = (struct socket *)fp->f_data; + error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control, + flags, p); + if (error) { + if (auio.uio_resid != len && (error == ERESTART || + error == EINTR || error == EWOULDBLOCK)) + error = 0; + if (error == EPIPE) + psignal(p, SIGPIPE); + } + if (error == 0) + p->p_retval[0] = len - auio.uio_resid; +#ifdef KTRACE + if (ktriov != NULL) { + if (error == 0) + ktrgenio(p->p_tracep, s, UIO_WRITE, + ktriov, p->p_retval[0], error); + FREE(ktriov, M_TEMP); + } +#endif +bad: + if (to) + FREE(to, M_SONAME); + return (error); +} + +static int +svr4_recvit(p, s, mp, namelenp) + register struct proc *p; + int s; + register struct msghdr *mp; + caddr_t namelenp; +{ + struct file *fp; + struct uio auio; + register struct iovec *iov; + register int i; + int len, error; + struct mbuf *m, *control = 0; + caddr_t ctlbuf; + struct socket *so; + struct sockaddr *fromsa = 0; +#ifdef KTRACE + struct iovec *ktriov = NULL; +#endif + + error = getsock(p->p_fd, s, &fp); + if (error) + return (error); + auio.uio_iov = mp->msg_iov; + auio.uio_iovcnt = mp->msg_iovlen; + auio.uio_segflg = UIO_USERSPACE; + auio.uio_rw = UIO_READ; + auio.uio_procp = p; + auio.uio_offset = 0; /* XXX */ + auio.uio_resid = 0; + iov = mp->msg_iov; + for (i = 0; i < mp->msg_iovlen; i++, iov++) { + if ((auio.uio_resid += iov->iov_len) < 0) + return (EINVAL); + } +#ifdef KTRACE + if (KTRPOINT(p, KTR_GENIO)) { + int iovlen = auio.uio_iovcnt * sizeof (struct iovec); + + MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK); + bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen); + } +#endif + len = auio.uio_resid; + so = (struct socket *)fp->f_data; + error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio, + (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0, + &mp->msg_flags); + if (error) { + if (auio.uio_resid != len && (error == ERESTART || + error == EINTR || error == EWOULDBLOCK)) + error = 0; + } +#ifdef KTRACE + if (ktriov != NULL) { + if (error == 0) + ktrgenio(p->p_tracep, s, UIO_READ, + ktriov, len - auio.uio_resid, error); + FREE(ktriov, M_TEMP); + } +#endif + if (error) + goto out; + p->p_retval[0] = len - auio.uio_resid; + if (mp->msg_name) { + len = mp->msg_namelen; + if (len <= 0 || fromsa == 0) + len = 0; + else { +#ifndef MIN +#define MIN(a,b) ((a)>(b)?(b):(a)) +#endif + /* save sa_len before it is destroyed by MSG_COMPAT */ + len = MIN(len, fromsa->sa_len); + error = copyout(fromsa, + (caddr_t)mp->msg_name, (unsigned)len); + if (error) + goto out; + } + mp->msg_namelen = len; + if (namelenp && + (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) { + goto out; + } + } + if (mp->msg_control) { + len = mp->msg_controllen; + m = control; + mp->msg_controllen = 0; + ctlbuf = (caddr_t) mp->msg_control; + + while (m && len > 0) { + unsigned int tocopy; + + if (len >= m->m_len) + tocopy = m->m_len; + else { + mp->msg_flags |= MSG_CTRUNC; + tocopy = len; + } + + if (error = copyout((caddr_t)mtod(m, caddr_t), + ctlbuf, tocopy)) + goto out; + + ctlbuf += tocopy; + len -= tocopy; + m = m->m_next; + } + mp->msg_controllen = ctlbuf - mp->msg_control; + } +out: + if (fromsa) + FREE(fromsa, M_SONAME); + if (control) + m_freem(control); + return (error); +} + +#ifdef DEBUG_SVR4 +static void bufprint __P((u_char *, size_t)); +static int show_ioc __P((const char *, struct svr4_strioctl *)); +static int show_strbuf __P((struct svr4_strbuf *)); +static void show_msg __P((const char *, int, struct svr4_strbuf *, + struct svr4_strbuf *, int)); + +static void +bufprint(buf, len) + u_char *buf; + size_t len; +{ + size_t i; + + uprintf("\n\t"); + for (i = 0; i < len; i++) { + uprintf("%x ", buf[i]); + if (i && (i % 16) == 0) + uprintf("\n\t"); + } +} + +static int +show_ioc(str, ioc) + const char *str; + struct svr4_strioctl *ioc; +{ + u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK); + int error; + + uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ", + str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf); + + if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) { + free((char *) ptr, M_TEMP); + return error; + } + + bufprint(ptr, ioc->len); + + uprintf("}\n"); + + free((char *) ptr, M_TEMP); + return 0; +} + + +static int +show_strbuf(str) + struct svr4_strbuf *str; +{ + int error; + u_char *ptr = NULL; + int maxlen = str->maxlen; + int len = str->len; + + if (maxlen < 0) + maxlen = 0; + + if (len >= maxlen) + len = maxlen; + + if (len > 0) { + ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK); + + if ((error = copyin(str->buf, ptr, len)) != 0) { + free((char *) ptr, M_TEMP); + return error; + } + } + + uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf); + + if (ptr) + bufprint(ptr, len); + + uprintf("]}"); + + if (ptr) + free((char *) ptr, M_TEMP); + + return 0; +} + + +static void +show_msg(str, fd, ctl, dat, flags) + const char *str; + int fd; + struct svr4_strbuf *ctl; + struct svr4_strbuf *dat; + int flags; +{ + struct svr4_strbuf buf; + int error; + + uprintf("%s(%d", str, fd); + if (ctl != NULL) { + if ((error = copyin(ctl, &buf, sizeof(buf))) != 0) + return; + show_strbuf(&buf); + } + else + uprintf(", NULL"); + + if (dat != NULL) { + if ((error = copyin(dat, &buf, sizeof(buf))) != 0) + return; + show_strbuf(&buf); + } + else + uprintf(", NULL"); + + uprintf(", %x);\n", flags); +} + +#endif /* DEBUG_SVR4 */ + +/* + * We are faced with an interesting situation. On svr4 unix sockets + * are really pipes. But we really have sockets, and we might as + * well use them. At the point where svr4 calls TI_BIND, it has + * already created a named pipe for the socket using mknod(2). + * We need to create a socket with the same name when we bind, + * so we need to remove the pipe before, otherwise we'll get address + * already in use. So we *carefully* remove the pipe, to avoid + * using this as a random file removal tool. We use system calls + * to avoid code duplication. + */ +static int +clean_pipe(p, path) + struct proc *p; + const char *path; +{ + struct lstat_args la; + struct unlink_args ua; + struct stat st; + int error; + caddr_t sg = stackgap_init(); + size_t l = strlen(path) + 1; + void *tpath; + + tpath = stackgap_alloc(&sg, l); + SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat)); + + if ((error = copyout(path, tpath, l)) != 0) + return error; + + SCARG(&la, path) = tpath; + + if ((error = lstat(p, &la)) != 0) + return 0; + + if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0) + return 0; + + /* + * Make sure we are dealing with a mode 0 named pipe. + */ + if ((st.st_mode & S_IFMT) != S_IFIFO) + return 0; + + if ((st.st_mode & ALLPERMS) != 0) + return 0; + + SCARG(&ua, path) = SCARG(&la, path); + + if ((error = unlink(p, &ua)) != 0) { + DPRINTF(("clean_pipe: unlink failed %d\n", error)); + return error; + } + + return 0; +} + + +static void +sockaddr_to_netaddr_in(sc, sain) + struct svr4_strmcmd *sc; + const struct sockaddr_in *sain; +{ + struct svr4_netaddr_in *na; + na = SVR4_ADDROF(sc); + + na->family = sain->sin_family; + na->port = sain->sin_port; + na->addr = sain->sin_addr.s_addr; + DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port, + na->addr)); +} + + +static void +sockaddr_to_netaddr_un(sc, saun) + struct svr4_strmcmd *sc; + const struct sockaddr_un *saun; +{ + struct svr4_netaddr_un *na; + char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 - + sizeof(*sc); + const char *src; + + na = SVR4_ADDROF(sc); + na->family = saun->sun_family; + for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; ) + if (dst == edst) + break; + DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path)); +} + + +static void +netaddr_to_sockaddr_in(sain, sc) + struct sockaddr_in *sain; + const struct svr4_strmcmd *sc; +{ + const struct svr4_netaddr_in *na; + + + na = SVR4_C_ADDROF(sc); + memset(sain, 0, sizeof(*sain)); + sain->sin_len = sizeof(*sain); + sain->sin_family = na->family; + sain->sin_port = na->port; + sain->sin_addr.s_addr = na->addr; + DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family, + sain->sin_port, sain->sin_addr.s_addr)); +} + + +static void +netaddr_to_sockaddr_un(saun, sc) + struct sockaddr_un *saun; + const struct svr4_strmcmd *sc; +{ + const struct svr4_netaddr_un *na; + char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1]; + const char *src; + + na = SVR4_C_ADDROF(sc); + memset(saun, 0, sizeof(*saun)); + saun->sun_family = na->family; + for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; ) + if (dst == edst) + break; + saun->sun_len = dst - saun->sun_path; + DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family, + saun->sun_path)); +} + + +static void +getparm(fp, pa) + struct file *fp; + struct svr4_si_sockparms *pa; +{ + struct svr4_strm *st = svr4_stream_get(fp); + struct socket *so = (struct socket *) fp->f_data; + + if (st == NULL) + return; + + pa->family = st->s_family; + + switch (so->so_type) { + case SOCK_DGRAM: + pa->type = SVR4_T_CLTS; + pa->protocol = IPPROTO_UDP; + DPRINTF(("getparm(dgram)\n")); + return; + + case SOCK_STREAM: + pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */ + pa->protocol = IPPROTO_IP; + DPRINTF(("getparm(stream)\n")); + return; + + case SOCK_RAW: + pa->type = SVR4_T_CLTS; + pa->protocol = IPPROTO_RAW; + DPRINTF(("getparm(raw)\n")); + return; + + default: + pa->type = 0; + pa->protocol = 0; + DPRINTF(("getparm(type %d?)\n", so->so_type)); + return; + } +} + + +static int +si_ogetudata(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + int error; + struct svr4_si_oudata ud; + struct svr4_si_sockparms pa; + + if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) { + DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n", + sizeof(ud), ioc->len)); + return EINVAL; + } + + if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0) + return error; + + getparm(fp, &pa); + + switch (pa.family) { + case AF_INET: + ud.tidusize = 16384; + ud.addrsize = sizeof(struct svr4_sockaddr_in); + if (pa.type == SVR4_SOCK_STREAM) + ud.etsdusize = 1; + else + ud.etsdusize = 0; + break; + + case AF_LOCAL: + ud.tidusize = 65536; + ud.addrsize = 128; + ud.etsdusize = 128; + break; + + default: + DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n", + pa.family)); + return ENOSYS; + } + + /* I have no idea what these should be! */ + ud.optsize = 128; + ud.tsdusize = 128; + + ud.servtype = pa.type; + + /* XXX: Fixme */ + ud.so_state = 0; + ud.so_options = 0; + return copyout(&ud, ioc->buf, ioc->len); +} + + +static int +si_sockparams(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + struct svr4_si_sockparms pa; + + getparm(fp, &pa); + return copyout(&pa, ioc->buf, sizeof(pa)); +} + + +static int +si_listen(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + int error; + struct svr4_strm *st = svr4_stream_get(fp); + struct svr4_strmcmd lst; + struct listen_args la; + + if (st == NULL) + return EINVAL; + + if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0) + return error; + + if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) { + DPRINTF(("si_listen: bad request %ld\n", lst.cmd)); + return EINVAL; + } + + /* + * We are making assumptions again... + */ + SCARG(&la, s) = fd; + DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5)); + SCARG(&la, backlog) = 5; + + if ((error = listen(p, &la)) != 0) { + DPRINTF(("SI_LISTEN: listen failed %d\n", error)); + return error; + } + + st->s_cmd = SVR4_TI__ACCEPT_WAIT; + lst.cmd = SVR4_TI_BIND_REPLY; + + switch (st->s_family) { + case AF_INET: + /* XXX: Fill the length here */ + break; + + case AF_LOCAL: + lst.len = 140; + lst.pad[28] = 0x00000000; /* magic again */ + lst.pad[29] = 0x00000800; /* magic again */ + lst.pad[30] = 0x80001400; /* magic again */ + break; + + default: + DPRINTF(("SI_LISTEN: Unsupported address family %d\n", + st->s_family)); + return ENOSYS; + } + + + if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0) + return error; + + return 0; +} + + +static int +si_getudata(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + int error; + struct svr4_si_udata ud; + + if (sizeof(ud) != ioc->len) { + DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n", + sizeof(ud), ioc->len)); + return EINVAL; + } + + if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0) + return error; + + getparm(fp, &ud.sockparms); + + switch (ud.sockparms.family) { + case AF_INET: + DPRINTF(("getudata_inet\n")); + ud.tidusize = 16384; + ud.tsdusize = 16384; + ud.addrsize = sizeof(struct svr4_sockaddr_in); + if (ud.sockparms.type == SVR4_SOCK_STREAM) + ud.etsdusize = 1; + else + ud.etsdusize = 0; + ud.optsize = 0; + break; + + case AF_LOCAL: + DPRINTF(("getudata_local\n")); + ud.tidusize = 65536; + ud.tsdusize = 128; + ud.addrsize = 128; + ud.etsdusize = 128; + ud.optsize = 128; + break; + + default: + DPRINTF(("SI_GETUDATA: Unsupported address family %d\n", + ud.sockparms.family)); + return ENOSYS; + } + + + ud.servtype = ud.sockparms.type; + DPRINTF(("ud.servtype = %d\n", ud.servtype)); + /* XXX: Fixme */ + ud.so_state = 0; + ud.so_options = 0; + return copyout(&ud, ioc->buf, sizeof(ud)); +} + + +static int +si_shutdown(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + int error; + struct shutdown_args ap; + + if (ioc->len != sizeof(SCARG(&ap, how))) { + DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n", + sizeof(SCARG(&ap, how)), ioc->len)); + return EINVAL; + } + + if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0) + return error; + + SCARG(&ap, s) = fd; + + return shutdown(p, &ap); +} + + +static int +sockmod(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + switch (ioc->cmd) { + case SVR4_SI_OGETUDATA: + DPRINTF(("SI_OGETUDATA\n")); + return si_ogetudata(fp, fd, ioc, p); + + case SVR4_SI_SHUTDOWN: + DPRINTF(("SI_SHUTDOWN\n")); + return si_shutdown(fp, fd, ioc, p); + + case SVR4_SI_LISTEN: + DPRINTF(("SI_LISTEN\n")); + return si_listen(fp, fd, ioc, p); + + case SVR4_SI_SETMYNAME: + DPRINTF(("SI_SETMYNAME\n")); + return 0; + + case SVR4_SI_SETPEERNAME: + DPRINTF(("SI_SETPEERNAME\n")); + return 0; + + case SVR4_SI_GETINTRANSIT: + DPRINTF(("SI_GETINTRANSIT\n")); + return 0; + + case SVR4_SI_TCL_LINK: + DPRINTF(("SI_TCL_LINK\n")); + return 0; + + case SVR4_SI_TCL_UNLINK: + DPRINTF(("SI_TCL_UNLINK\n")); + return 0; + + case SVR4_SI_SOCKPARAMS: + DPRINTF(("SI_SOCKPARAMS\n")); + return si_sockparams(fp, fd, ioc, p); + + case SVR4_SI_GETUDATA: + DPRINTF(("SI_GETUDATA\n")); + return si_getudata(fp, fd, ioc, p); + + default: + DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd)); + return 0; + + } +} + + +static int +ti_getinfo(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + int error; + struct svr4_infocmd info; + + memset(&info, 0, sizeof(info)); + + if ((error = copyin(ioc->buf, &info, ioc->len)) != 0) + return error; + + if (info.cmd != SVR4_TI_INFO_REQUEST) + return EINVAL; + + info.cmd = SVR4_TI_INFO_REPLY; + info.tsdu = 0; + info.etsdu = 1; + info.cdata = -2; + info.ddata = -2; + info.addr = 16; + info.opt = -1; + info.tidu = 16384; + info.serv = 2; + info.current = 0; + info.provider = 2; + + ioc->len = sizeof(info); + if ((error = copyout(&info, ioc->buf, ioc->len)) != 0) + return error; + + return 0; +} + + +static int +ti_bind(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + int error; + struct svr4_strm *st = svr4_stream_get(fp); + struct sockaddr_in sain; + struct sockaddr_un saun; + caddr_t sg; + void *skp, *sup = NULL; + int sasize; + struct svr4_strmcmd bnd; + struct bind_args ba; + + if (st == NULL) { + DPRINTF(("ti_bind: bad file descriptor\n")); + return EINVAL; + } + + if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0) + return error; + + if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) { + DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd)); + return EINVAL; + } + + switch (st->s_family) { + case AF_INET: + skp = &sain; + sasize = sizeof(sain); + + if (bnd.offs == 0) + goto reply; + + netaddr_to_sockaddr_in(&sain, &bnd); + + DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n", + sain.sin_family, sain.sin_port, + sain.sin_addr.s_addr)); + break; + + case AF_LOCAL: + skp = &saun; + sasize = sizeof(saun); + if (bnd.offs == 0) + goto reply; + + netaddr_to_sockaddr_un(&saun, &bnd); + + if (saun.sun_path[0] == '\0') + goto reply; + + DPRINTF(("TI_BIND: fam %d, path %s\n", + saun.sun_family, saun.sun_path)); + + if ((error = clean_pipe(p, saun.sun_path)) != 0) + return error; + + bnd.pad[28] = 0x00001000; /* magic again */ + break; + + default: + DPRINTF(("TI_BIND: Unsupported address family %d\n", + st->s_family)); + return ENOSYS; + } + + sg = stackgap_init(); + sup = stackgap_alloc(&sg, sasize); + + if ((error = copyout(skp, sup, sasize)) != 0) + return error; + + SCARG(&ba, s) = fd; + DPRINTF(("TI_BIND: fileno %d\n", fd)); + SCARG(&ba, name) = (void *) sup; + SCARG(&ba, namelen) = sasize; + + if ((error = bind(p, &ba)) != 0) { + DPRINTF(("TI_BIND: bind failed %d\n", error)); + return error; + } + +reply: + if (sup == NULL) { + memset(&bnd, 0, sizeof(bnd)); + bnd.len = sasize + 4; + bnd.offs = 0x10; /* XXX */ + } + + bnd.cmd = SVR4_TI_BIND_REPLY; + + if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0) + return error; + + return 0; +} + + +static int +timod(fp, fd, ioc, p) + struct file *fp; + int fd; + struct svr4_strioctl *ioc; + struct proc *p; +{ + switch (ioc->cmd) { + case SVR4_TI_GETINFO: + DPRINTF(("TI_GETINFO\n")); + return ti_getinfo(fp, fd, ioc, p); + + case SVR4_TI_OPTMGMT: + DPRINTF(("TI_OPTMGMT\n")); + return 0; + + case SVR4_TI_BIND: + DPRINTF(("TI_BIND\n")); + return ti_bind(fp, fd, ioc, p); + + case SVR4_TI_UNBIND: + DPRINTF(("TI_UNBIND\n")); + return 0; + + default: + DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd)); + return 0; + } +} + + +int +svr4_stream_ti_ioctl(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat; + struct svr4_strm *st = svr4_stream_get(fp); + int error; + void *skp, *sup; + struct sockaddr_in sain; + struct sockaddr_un saun; + struct svr4_strmcmd sc; + int sasize; + caddr_t sg; + int *lenp; + + DPRINTF(("svr4_stream_ti_ioctl\n")); + + if (st == NULL) + return EINVAL; + + sc.offs = 0x10; + + if ((error = copyin(sub, &skb, sizeof(skb))) != 0) { + DPRINTF(("ti_ioctl: error copying in strbuf\n")); + return error; + } + + switch (st->s_family) { + case AF_INET: + skp = &sain; + sasize = sizeof(sain); + break; + + case AF_LOCAL: + skp = &saun; + sasize = sizeof(saun); + break; + + default: + DPRINTF(("ti_ioctl: Unsupported address family %d\n", + st->s_family)); + return ENOSYS; + } + + sg = stackgap_init(); + sup = stackgap_alloc(&sg, sasize); + lenp = stackgap_alloc(&sg, sizeof(*lenp)); + + if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) { + DPRINTF(("ti_ioctl: error copying out lenp\n")); + return error; + } + + switch (cmd) { + case SVR4_TI_GETMYNAME: + DPRINTF(("TI_GETMYNAME\n")); + { + struct getsockname_args ap; + SCARG(&ap, fdes) = fd; + SCARG(&ap, asa) = sup; + SCARG(&ap, alen) = lenp; + if ((error = getsockname(p, &ap)) != 0) { + DPRINTF(("ti_ioctl: getsockname error\n")); + return error; + } + } + break; + + case SVR4_TI_GETPEERNAME: + DPRINTF(("TI_GETPEERNAME\n")); + { + struct getpeername_args ap; + SCARG(&ap, fdes) = fd; + SCARG(&ap, asa) = sup; + SCARG(&ap, alen) = lenp; + if ((error = getpeername(p, &ap)) != 0) { + DPRINTF(("ti_ioctl: getpeername error\n")); + return error; + } + } + break; + + case SVR4_TI_SETMYNAME: + DPRINTF(("TI_SETMYNAME\n")); + return 0; + + case SVR4_TI_SETPEERNAME: + DPRINTF(("TI_SETPEERNAME\n")); + return 0; + default: + DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd)); + return ENOSYS; + } + + if ((error = copyin(sup, skp, sasize)) != 0) { + DPRINTF(("ti_ioctl: error copying in socket data\n")); + return error; + } + + if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) { + DPRINTF(("ti_ioctl: error copying in socket size\n")); + return error; + } + + switch (st->s_family) { + case AF_INET: + sockaddr_to_netaddr_in(&sc, &sain); + skb.len = sasize; + break; + + case AF_LOCAL: + sockaddr_to_netaddr_un(&sc, &saun); + skb.len = sasize + 4; + break; + + default: + return ENOSYS; + } + + + if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) { + DPRINTF(("ti_ioctl: error copying out socket data\n")); + return error; + } + + + if ((error = copyout(&skb, sub, sizeof(skb))) != 0) { + DPRINTF(("ti_ioctl: error copying out strbuf\n")); + return error; + } + + return error; +} + + + + +static int +i_nread(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + int error; + int nread = 0; + + /* + * We are supposed to return the message length in nread, and the + * number of messages in retval. We don't have the notion of number + * of stream messages, so we just find out if we have any bytes waiting + * for us, and if we do, then we assume that we have at least one + * message waiting for us. + */ + if ((error = (*fp->f_ops->fo_ioctl)(fp, FIONREAD, + (caddr_t) &nread, p)) != 0) + return error; + + if (nread != 0) + *retval = 1; + else + *retval = 0; + + return copyout(&nread, dat, sizeof(nread)); +} + +static int +i_fdinsert(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + /* + * Major hack again here. We assume that we are using this to + * implement accept(2). If that is the case, we have already + * called accept, and we have stored the file descriptor in + * afd. We find the file descriptor that the code wants to use + * in fd insert, and then we dup2() our accepted file descriptor + * to it. + */ + int error; + struct svr4_strm *st = svr4_stream_get(fp); + struct svr4_strfdinsert fdi; + struct dup2_args d2p; + struct close_args clp; + + if (st == NULL) { + DPRINTF(("fdinsert: bad file type\n")); + return EINVAL; + } + + if (st->s_afd == -1) { + DPRINTF(("fdinsert: accept fd not found\n")); + return ENOENT; + } + + if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) { + DPRINTF(("fdinsert: copyin failed %d\n", error)); + return error; + } + + SCARG(&d2p, from) = st->s_afd; + SCARG(&d2p, to) = fdi.fd; + + if ((error = dup2(p, &d2p)) != 0) { + DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n", + st->s_afd, fdi.fd, error)); + return error; + } + + SCARG(&clp, fd) = st->s_afd; + + if ((error = close(p, &clp)) != 0) { + DPRINTF(("fdinsert: close(%d) failed %d\n", + st->s_afd, error)); + return error; + } + + st->s_afd = -1; + + *retval = 0; + return 0; +} + + +static int +_i_bind_rsvd(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + struct mkfifo_args ap; + + /* + * This is a supposed to be a kernel and library only ioctl. + * It gets called before ti_bind, when we have a unix + * socket, to physically create the socket transport and + * ``reserve'' it. I don't know how this get reserved inside + * the kernel, but we are going to create it nevertheless. + */ + SCARG(&ap, path) = dat; + SCARG(&ap, mode) = S_IFIFO; + + return mkfifo(p, &ap); +} + +static int +_i_rele_rsvd(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + struct unlink_args ap; + + /* + * This is a supposed to be a kernel and library only ioctl. + * I guess it is supposed to release the socket. + */ + SCARG(&ap, path) = dat; + + return unlink(p, &ap); +} + +static int +i_str(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + int error; + struct svr4_strioctl ioc; + + if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0) + return error; + +#ifdef DEBUG_SVR4 + if ((error = show_ioc(">", &ioc)) != 0) + return error; +#endif /* DEBUG_SVR4 */ + + switch (ioc.cmd & 0xff00) { + case SVR4_SIMOD: + if ((error = sockmod(fp, fd, &ioc, p)) != 0) + return error; + break; + + case SVR4_TIMOD: + if ((error = timod(fp, fd, &ioc, p)) != 0) + return error; + break; + + default: + DPRINTF(("Unimplemented module %c %ld\n", + (char) (cmd >> 8), cmd & 0xff)); + return 0; + } + +#ifdef DEBUG_SVR4 + if ((error = show_ioc("<", &ioc)) != 0) + return error; +#endif /* DEBUG_SVR4 */ + return copyout(&ioc, dat, sizeof(ioc)); +} + +static int +i_setsig(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + /* + * This is the best we can do for now; we cannot generate + * signals only for specific events so the signal mask gets + * ignored; we save it just to pass it to a possible I_GETSIG... + * + * We alse have to fix the O_ASYNC fcntl bit, so the + * process will get SIGPOLLs. + */ + struct fcntl_args fa; + int error; + register_t oflags, flags; + struct svr4_strm *st = svr4_stream_get(fp); + + if (st == NULL) { + DPRINTF(("i_setsig: bad file descriptor\n")); + return EINVAL; + } + /* get old status flags */ + SCARG(&fa, fd) = fd; + SCARG(&fa, cmd) = F_GETFL; + if ((error = fcntl(p, &fa)) != 0) + return error; + + oflags = p->p_retval[0]; + + /* update the flags */ + if (dat != NULL) { + int mask; + + flags = oflags | O_ASYNC; + if ((error = copyin(dat, &mask, sizeof(mask))) != 0) { + DPRINTF(("i_setsig: bad eventmask pointer\n")); + return error; + } + if (mask & SVR4_S_ALLMASK) { + DPRINTF(("i_setsig: bad eventmask data %x\n", mask)); + return EINVAL; + } + st->s_eventmask = mask; + } + else { + flags = oflags & ~O_ASYNC; + st->s_eventmask = 0; + } + + /* set the new flags, if changed */ + if (flags != oflags) { + SCARG(&fa, cmd) = F_SETFL; + SCARG(&fa, arg) = (long) flags; + if ((error = fcntl(p, &fa)) != 0) + return error; + flags = p->p_retval[0]; + } + + /* set up SIGIO receiver if needed */ + if (dat != NULL) { + SCARG(&fa, cmd) = F_SETOWN; + SCARG(&fa, arg) = (long) p->p_pid; + return fcntl(p, &fa); + } + return 0; +} + +static int +i_getsig(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + int error; + + if (dat != NULL) { + struct svr4_strm *st = svr4_stream_get(fp); + + if (st == NULL) { + DPRINTF(("i_getsig: bad file descriptor\n")); + return EINVAL; + } + if ((error = copyout(&st->s_eventmask, dat, + sizeof(st->s_eventmask))) != 0) { + DPRINTF(("i_getsig: bad eventmask pointer\n")); + return error; + } + } + return 0; +} + +int +svr4_stream_ioctl(fp, p, retval, fd, cmd, dat) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t dat; +{ + *retval = 0; + + /* + * All the following stuff assumes "sockmod" is pushed... + */ + switch (cmd) { + case SVR4_I_NREAD: + DPRINTF(("I_NREAD\n")); + return i_nread(fp, p, retval, fd, cmd, dat); + + case SVR4_I_PUSH: + DPRINTF(("I_PUSH %x\n", dat)); +#if defined(DEBUG_SVR4) + show_strbuf(dat); +#endif + return 0; + + case SVR4_I_POP: + DPRINTF(("I_POP\n")); + return 0; + + case SVR4_I_LOOK: + DPRINTF(("I_LOOK\n")); + return 0; + + case SVR4_I_FLUSH: + DPRINTF(("I_FLUSH\n")); + return 0; + + case SVR4_I_SRDOPT: + DPRINTF(("I_SRDOPT\n")); + return 0; + + case SVR4_I_GRDOPT: + DPRINTF(("I_GRDOPT\n")); + return 0; + + case SVR4_I_STR: + DPRINTF(("I_STR\n")); + return i_str(fp, p, retval, fd, cmd, dat); + + case SVR4_I_SETSIG: + DPRINTF(("I_SETSIG\n")); + return i_setsig(fp, p, retval, fd, cmd, dat); + + case SVR4_I_GETSIG: + DPRINTF(("I_GETSIG\n")); + return i_getsig(fp, p, retval, fd, cmd, dat); + + case SVR4_I_FIND: + DPRINTF(("I_FIND\n")); + /* + * Here we are not pushing modules really, we just + * pretend all are present + */ + *retval = 0; + return 0; + + case SVR4_I_LINK: + DPRINTF(("I_LINK\n")); + return 0; + + case SVR4_I_UNLINK: + DPRINTF(("I_UNLINK\n")); + return 0; + + case SVR4_I_ERECVFD: + DPRINTF(("I_ERECVFD\n")); + return 0; + + case SVR4_I_PEEK: + DPRINTF(("I_PEEK\n")); + return 0; + + case SVR4_I_FDINSERT: + DPRINTF(("I_FDINSERT\n")); + return i_fdinsert(fp, p, retval, fd, cmd, dat); + + case SVR4_I_SENDFD: + DPRINTF(("I_SENDFD\n")); + return 0; + + case SVR4_I_RECVFD: + DPRINTF(("I_RECVFD\n")); + return 0; + + case SVR4_I_SWROPT: + DPRINTF(("I_SWROPT\n")); + return 0; + + case SVR4_I_GWROPT: + DPRINTF(("I_GWROPT\n")); + return 0; + + case SVR4_I_LIST: + DPRINTF(("I_LIST\n")); + return 0; + + case SVR4_I_PLINK: + DPRINTF(("I_PLINK\n")); + return 0; + + case SVR4_I_PUNLINK: + DPRINTF(("I_PUNLINK\n")); + return 0; + + case SVR4_I_SETEV: + DPRINTF(("I_SETEV\n")); + return 0; + + case SVR4_I_GETEV: + DPRINTF(("I_GETEV\n")); + return 0; + + case SVR4_I_STREV: + DPRINTF(("I_STREV\n")); + return 0; + + case SVR4_I_UNSTREV: + DPRINTF(("I_UNSTREV\n")); + return 0; + + case SVR4_I_FLUSHBAND: + DPRINTF(("I_FLUSHBAND\n")); + return 0; + + case SVR4_I_CKBAND: + DPRINTF(("I_CKBAND\n")); + return 0; + + case SVR4_I_GETBAND: + DPRINTF(("I_GETBANK\n")); + return 0; + + case SVR4_I_ATMARK: + DPRINTF(("I_ATMARK\n")); + return 0; + + case SVR4_I_SETCLTIME: + DPRINTF(("I_SETCLTIME\n")); + return 0; + + case SVR4_I_GETCLTIME: + DPRINTF(("I_GETCLTIME\n")); + return 0; + + case SVR4_I_CANPUT: + DPRINTF(("I_CANPUT\n")); + return 0; + + case SVR4__I_BIND_RSVD: + DPRINTF(("_I_BIND_RSVD\n")); + return _i_bind_rsvd(fp, p, retval, fd, cmd, dat); + + case SVR4__I_RELE_RSVD: + DPRINTF(("_I_RELE_RSVD\n")); + return _i_rele_rsvd(fp, p, retval, fd, cmd, dat); + + default: + DPRINTF(("unimpl cmd = %lx\n", cmd)); + break; + } + + return 0; +} + + + +int +svr4_sys_putmsg(p, uap) + register struct proc *p; + struct svr4_sys_putmsg_args *uap; +{ + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct svr4_strbuf dat, ctl; + struct svr4_strmcmd sc; + struct sockaddr_in sain; + struct sockaddr_un saun; + void *skp, *sup; + int sasize, *retval; + struct svr4_strm *st; + int error; + caddr_t sg; + + retval = p->p_retval; + if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) { +#ifdef DEBUG_SVR4 + uprintf("putmsg: bad fp\n"); +#endif + return EBADF; + } + +#ifdef DEBUG_SVR4 + show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl), + SCARG(uap, dat), SCARG(uap, flags)); +#endif /* DEBUG_SVR4 */ + + if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) { +#ifdef DEBUG_SVR4 + uprintf("putmsg: bad fp(2)\n"); +#endif + return EBADF; + } + + if (SCARG(uap, ctl) != NULL) { + if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) { +#ifdef DEBUG_SVR4 + uprintf("putmsg: copyin(): %d\n", error); +#endif + return error; + } + } + else + ctl.len = -1; + + if (SCARG(uap, dat) != NULL) { + if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) { +#ifdef DEBUG_SVR4 + uprintf("putmsg: copyin(): %d (2)\n", error); +#endif + return error; + } + } + else + dat.len = -1; + + /* + * Only for sockets for now. + */ + if ((st = svr4_stream_get(fp)) == NULL) { + DPRINTF(("putmsg: bad file type\n")); + return EINVAL; + } + + if (ctl.len > sizeof(sc)) { + DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len, + sizeof(struct svr4_strmcmd))); + return EINVAL; + } + + if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0) + return error; + + switch (st->s_family) { + case AF_INET: + if (sc.len != sizeof(sain)) { + if (sc.cmd == SVR4_TI_DATA_REQUEST) { + struct write_args wa; + + /* Solaris seems to use sc.cmd = 3 to + * send "expedited" data. telnet uses + * this for options processing, sending EOF, + * etc. I'm sure other things use it too. + * I don't have any documentation + * on it, so I'm making a guess that this + * is how it works. newton@atdot.dotat.org XXX + */ + DPRINTF(("sending expedited data (???)\n")); + SCARG(&wa, fd) = SCARG(uap, fd); + SCARG(&wa, buf) = dat.buf; + SCARG(&wa, nbyte) = dat.len; + return write(p, &wa); + } + DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len)); + return EINVAL; + } + netaddr_to_sockaddr_in(&sain, &sc); + skp = &sain; + sasize = sizeof(sain); + error = sain.sin_family != st->s_family; + break; + + case AF_LOCAL: + if (ctl.len == 8) { + /* We are doing an accept; succeed */ + DPRINTF(("putmsg: Do nothing\n")); + *retval = 0; + return 0; + } + else { + /* Maybe we've been given a device/inode pair */ + dev_t *dev = SVR4_ADDROF(&sc); + ino_t *ino = (ino_t *) &dev[1]; + skp = svr4_find_socket(p, fp, *dev, *ino); + if (skp == NULL) { + skp = &saun; + /* I guess we have it by name */ + netaddr_to_sockaddr_un(skp, &sc); + } + sasize = sizeof(saun); + } + break; + + default: + DPRINTF(("putmsg: Unsupported address family %d\n", + st->s_family)); + return ENOSYS; + } + + sg = stackgap_init(); + sup = stackgap_alloc(&sg, sasize); + + if ((error = copyout(skp, sup, sasize)) != 0) + return error; + + switch (st->s_cmd = sc.cmd) { + case SVR4_TI_CONNECT_REQUEST: /* connect */ + { + struct connect_args co; + + SCARG(&co, s) = SCARG(uap, fd); + SCARG(&co, name) = (void *) sup; + SCARG(&co, namelen) = (int) sasize; + + return connect(p, &co); + } + + case SVR4_TI_SENDTO_REQUEST: /* sendto */ + { + struct msghdr msg; + struct iovec aiov; + + msg.msg_name = (caddr_t) sup; + msg.msg_namelen = sasize; + msg.msg_iov = &aiov; + msg.msg_iovlen = 1; + msg.msg_control = 0; + msg.msg_flags = 0; + aiov.iov_base = dat.buf; + aiov.iov_len = dat.len; +#if 0 + error = so->so_proto->pr_usrreqs->pru_sosend(so, 0, + uio, 0, 0, 0, uio->uio_procp); +#endif + error = svr4_sendit(p, SCARG(uap, fd), &msg, + SCARG(uap, flags)); + DPRINTF(("sendto_request error: %d\n", error)); + *retval = 0; + return error; + } + + default: + DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd)); + return ENOSYS; + } +} + +int +svr4_sys_getmsg(p, uap) + register struct proc *p; + struct svr4_sys_getmsg_args *uap; +{ + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct getpeername_args ga; + struct accept_args aa; + struct svr4_strbuf dat, ctl; + struct svr4_strmcmd sc; + int error, *retval; + struct msghdr msg; + struct iovec aiov; + struct sockaddr_in sain; + struct sockaddr_un saun; + void *skp, *sup; + int sasize; + struct svr4_strm *st; + int *flen; + int fl; + caddr_t sg; + + retval = p->p_retval; + if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) + return EBADF; + + memset(&sc, 0, sizeof(sc)); + +#ifdef DEBUG_SVR4 + show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl), + SCARG(uap, dat), 0); +#endif /* DEBUG_SVR4 */ + + if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) + return EBADF; + + if (SCARG(uap, ctl) != NULL) { + if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) + return error; + } + else { + ctl.len = -1; + ctl.maxlen = 0; + } + + if (SCARG(uap, dat) != NULL) { + if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) + return error; + } + else { + dat.len = -1; + dat.maxlen = 0; + } + + /* + * Only for sockets for now. + */ + if ((st = svr4_stream_get(fp)) == NULL) { + DPRINTF(("getmsg: bad file type\n")); + return EINVAL; + } + + if (ctl.maxlen == -1 || dat.maxlen == -1) { + DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n")); + return ENOSYS; + } + + switch (st->s_family) { + case AF_INET: + skp = &sain; + sasize = sizeof(sain); + break; + + case AF_LOCAL: + skp = &saun; + sasize = sizeof(saun); + break; + + default: + DPRINTF(("getmsg: Unsupported address family %d\n", + st->s_family)); + return ENOSYS; + } + + sg = stackgap_init(); + sup = stackgap_alloc(&sg, sasize); + flen = (int *) stackgap_alloc(&sg, sizeof(*flen)); + + fl = sasize; + if ((error = copyout(&fl, flen, sizeof(fl))) != 0) + return error; + + switch (st->s_cmd) { + case SVR4_TI_CONNECT_REQUEST: + DPRINTF(("getmsg: TI_CONNECT_REQUEST\n")); + /* + * We do the connect in one step, so the putmsg should + * have gotten the error. + */ + sc.cmd = SVR4_TI_OK_REPLY; + sc.len = 0; + + ctl.len = 8; + dat.len = -1; + fl = 1; + st->s_cmd = sc.cmd; + break; + + case SVR4_TI_OK_REPLY: + DPRINTF(("getmsg: TI_OK_REPLY\n")); + /* + * We are immediately after a connect reply, so we send + * a connect verification. + */ + + SCARG(&ga, fdes) = SCARG(uap, fd); + SCARG(&ga, asa) = (void *) sup; + SCARG(&ga, alen) = flen; + + if ((error = getpeername(p, &ga)) != 0) { + DPRINTF(("getmsg: getpeername failed %d\n", error)); + return error; + } + + if ((error = copyin(sup, skp, sasize)) != 0) + return error; + + sc.cmd = SVR4_TI_CONNECT_REPLY; + sc.pad[0] = 0x4; + sc.offs = 0x18; + sc.pad[1] = 0x14; + sc.pad[2] = 0x04000402; + + switch (st->s_family) { + case AF_INET: + sc.len = sasize; + sockaddr_to_netaddr_in(&sc, &sain); + break; + + case AF_LOCAL: + sc.len = sasize + 4; + sockaddr_to_netaddr_un(&sc, &saun); + break; + + default: + return ENOSYS; + } + + ctl.len = 40; + dat.len = -1; + fl = 0; + st->s_cmd = sc.cmd; + break; + + case SVR4_TI__ACCEPT_OK: + DPRINTF(("getmsg: TI__ACCEPT_OK\n")); + /* + * We do the connect in one step, so the putmsg should + * have gotten the error. + */ + sc.cmd = SVR4_TI_OK_REPLY; + sc.len = 1; + + ctl.len = 8; + dat.len = -1; + fl = 1; + st->s_cmd = SVR4_TI__ACCEPT_WAIT; + break; + + case SVR4_TI__ACCEPT_WAIT: + DPRINTF(("getmsg: TI__ACCEPT_WAIT\n")); + /* + * We are after a listen, so we try to accept... + */ + SCARG(&aa, s) = SCARG(uap, fd); + SCARG(&aa, name) = (void *) sup; + SCARG(&aa, anamelen) = flen; + + if ((error = accept(p, &aa)) != 0) { + DPRINTF(("getmsg: accept failed %d\n", error)); + return error; + } + + st->s_afd = *retval; + + DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd)); + + if ((error = copyin(sup, skp, sasize)) != 0) + return error; + + sc.cmd = SVR4_TI_ACCEPT_REPLY; + sc.offs = 0x18; + sc.pad[0] = 0x0; + + switch (st->s_family) { + case AF_INET: + sc.pad[1] = 0x28; + sockaddr_to_netaddr_in(&sc, &sain); + ctl.len = 40; + sc.len = sasize; + break; + + case AF_LOCAL: + sc.pad[1] = 0x00010000; + sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */ + sc.pad[3] = 0x00010000; + ctl.len = 134; + sc.len = sasize + 4; + break; + + default: + return ENOSYS; + } + + dat.len = -1; + fl = 0; + st->s_cmd = SVR4_TI__ACCEPT_OK; + break; + + case SVR4_TI_SENDTO_REQUEST: + DPRINTF(("getmsg: TI_SENDTO_REQUEST\n")); + if (ctl.maxlen > 36 && ctl.len < 36) + ctl.len = 36; + + if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0) + return error; + + switch (st->s_family) { + case AF_INET: + sockaddr_to_netaddr_in(&sc, &sain); + break; + + case AF_LOCAL: + sockaddr_to_netaddr_un(&sc, &saun); + break; + + default: + return ENOSYS; + } + + msg.msg_name = (caddr_t) sup; + msg.msg_namelen = sasize; + msg.msg_iov = &aiov; + msg.msg_iovlen = 1; + msg.msg_control = 0; + aiov.iov_base = dat.buf; + aiov.iov_len = dat.maxlen; + msg.msg_flags = 0; + + error = svr4_recvit(p, SCARG(uap, fd), &msg, (caddr_t) flen); + + if (error) { + DPRINTF(("getmsg: recvit failed %d\n", error)); + return error; + } + + if ((error = copyin(msg.msg_name, skp, sasize)) != 0) + return error; + + sc.cmd = SVR4_TI_RECVFROM_IND; + + switch (st->s_family) { + case AF_INET: + sc.len = sasize; + sockaddr_to_netaddr_in(&sc, &sain); + break; + + case AF_LOCAL: + sc.len = sasize + 4; + sockaddr_to_netaddr_un(&sc, &saun); + break; + + default: + return ENOSYS; + } + + dat.len = *retval; + fl = 0; + st->s_cmd = sc.cmd; + break; + + default: + st->s_cmd = sc.cmd; + if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) { + struct read_args ra; + + /* More wierdness: Again, I can't find documentation + * to back this up, but when a process does a generic + * "getmsg()" call it seems that the command field is + * zero and the length of the data area is zero. I + * think processes expect getmsg() to fill in dat.len + * after reading at most dat.maxlen octets from the + * stream. Since we're using sockets I can let + * read() look after it and frob return values + * appropriately (or inappropriately :-) + * -- newton@atdot.dotat.org XXX + */ + SCARG(&ra, fd) = SCARG(uap, fd); + SCARG(&ra, buf) = dat.buf; + SCARG(&ra, nbyte) = dat.maxlen; + if ((error = read(p, &ra)) != 0) { + return error; + } + dat.len = *retval; + *retval = 0; + st->s_cmd = SVR4_TI_SENDTO_REQUEST; + break; + } + DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd)); + return EINVAL; + } + + if (SCARG(uap, ctl)) { + if (ctl.len != -1) + if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0) + return error; + + if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0) + return error; + } + + if (SCARG(uap, dat)) { + if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0) + return error; + } + + if (SCARG(uap, flags)) { /* XXX: Need translation */ + if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0) + return error; + } + + *retval = 0; + +#ifdef DEBUG_SVR4 + show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl), + SCARG(uap, dat), fl); +#endif /* DEBUG_SVR4 */ + return error; +} + +int svr4_sys_send(p, uap) + struct proc *p; + struct svr4_sys_send_args *uap; +{ + struct osend_args osa; + SCARG(&osa, s) = SCARG(uap, s); + SCARG(&osa, buf) = SCARG(uap, buf); + SCARG(&osa, len) = SCARG(uap, len); + SCARG(&osa, flags) = SCARG(uap, flags); + return osend(p, &osa); +} + +int svr4_sys_recv(p, uap) + struct proc *p; + struct svr4_sys_recv_args *uap; +{ + struct orecv_args ora; + SCARG(&ora, s) = SCARG(uap, s); + SCARG(&ora, buf) = SCARG(uap, buf); + SCARG(&ora, len) = SCARG(uap, len); + SCARG(&ora, flags) = SCARG(uap, flags); + return orecv(p, &ora); +} + +/* + * XXX This isn't necessary, but it's handy for inserting debug code into + * sendto(). Let's leave it here for now... + */ +int +svr4_sys_sendto(p, uap) + struct proc *p; + struct svr4_sys_sendto_args *uap; +{ + struct sendto_args sa; + + SCARG(&sa, s) = SCARG(uap, s); + SCARG(&sa, buf) = SCARG(uap, buf); + SCARG(&sa, len) = SCARG(uap, len); + SCARG(&sa, flags) = SCARG(uap, flags); + SCARG(&sa, to) = SCARG(uap, to); + SCARG(&sa, tolen) = SCARG(uap, tolen); + + DPRINTF(("calling sendto()\n")); + return sendto(p, &sa); +} + diff --git a/sys/compat/svr4/svr4_stropts.h b/sys/compat/svr4/svr4_stropts.h new file mode 100644 index 0000000..75a33b3 --- /dev/null +++ b/sys/compat/svr4/svr4_stropts.h @@ -0,0 +1,173 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_STROPTS_H_ +#define _SVR4_STROPTS_H_ + + +struct svr4_strbuf { + int maxlen; + int len; + char *buf; +}; + +#define SVR4_STR ('S' << 8) +#define SVR4_I_NREAD (SVR4_STR| 1) +#define SVR4_I_PUSH (SVR4_STR| 2) +#define SVR4_I_POP (SVR4_STR| 3) +#define SVR4_I_LOOK (SVR4_STR| 4) +#define SVR4_I_FLUSH (SVR4_STR| 5) +#define SVR4_I_SRDOPT (SVR4_STR| 6) +#define SVR4_I_GRDOPT (SVR4_STR| 7) +#define SVR4_I_STR (SVR4_STR| 8) +#define SVR4_I_SETSIG (SVR4_STR| 9) +#define SVR4_I_GETSIG (SVR4_STR|10) +#define SVR4_I_FIND (SVR4_STR|11) +#define SVR4_I_LINK (SVR4_STR|12) +#define SVR4_I_UNLINK (SVR4_STR|13) +#define SVR4_I_ERECVFD (SVR4_STR|14) +#define SVR4_I_PEEK (SVR4_STR|15) +#define SVR4_I_FDINSERT (SVR4_STR|16) +#define SVR4_I_SENDFD (SVR4_STR|17) +#define SVR4_I_RECVFD (SVR4_STR|18) +#define SVR4_I_SWROPT (SVR4_STR|19) +#define SVR4_I_GWROPT (SVR4_STR|20) +#define SVR4_I_LIST (SVR4_STR|21) +#define SVR4_I_PLINK (SVR4_STR|22) +#define SVR4_I_PUNLINK (SVR4_STR|23) +#define SVR4_I_SETEV (SVR4_STR|24) +#define SVR4_I_GETEV (SVR4_STR|25) +#define SVR4_I_STREV (SVR4_STR|26) +#define SVR4_I_UNSTREV (SVR4_STR|27) +#define SVR4_I_FLUSHBAND (SVR4_STR|28) +#define SVR4_I_CKBAND (SVR4_STR|29) +#define SVR4_I_GETBAND (SVR4_STR|30) +#define SVR4_I_ATMARK (SVR4_STR|31) +#define SVR4_I_SETCLTIME (SVR4_STR|32) +#define SVR4_I_GETCLTIME (SVR4_STR|33) +#define SVR4_I_CANPUT (SVR4_STR|34) + +/* + * The following two ioctls are OS specific and + * undocumented. + */ +#define SVR4__I_BIND_RSVD (SVR4_STR|242) +#define SVR4__I_RELE_RSVD (SVR4_STR|243) + +/* + * Service type definitions + */ +#define SVR4_T_COTS 1 /* Connection-orieted */ +#define SVR4_T_COTS_ORD 2 /* Local connection-oriented */ +#define SVR4_T_CLTS 3 /* Connectionless */ + +/* Struct passed for SVR4_I_STR */ +struct svr4_strioctl { + u_long cmd; + int timeout; + int len; + char *buf; +}; + +/* + * Bits for I_{G,S}ETSIG + */ +#define SVR4_S_INPUT 0x0001 /* any message on read queue no HIPRI */ +#define SVR4_S_HIPRI 0x0002 /* high prio message on read queue */ +#define SVR4_S_OUTPUT 0x0004 /* write queue has free space */ +#define SVR4_S_MSG 0x0008 /* signal message in read queue head */ +#define SVR4_S_ERROR 0x0010 /* error message in read queue head */ +#define SVR4_S_HANGUP 0x0020 /* hangup message in read queue head */ +#define SVR4_S_RDNORM 0x0040 /* normal message on read queue */ +#define SVR4_S_WRNORM S_OUTPUT /* write queue has free space */ +#define SVR4_S_RDBAND 0x0080 /* out of band message on read queue */ +#define SVR4_S_WRBAND 0x0100 /* write queue has free space for oob */ +#define SVR4_S_BANDURG 0x0200 /* generate SIGURG instead of SIGPOLL */ +#define SVR4_S_ALLMASK 0x03ff /* all events mask */ + +/* + * Our internal state for the stream + * For now we keep almost nothing... In the future we can keep more + * streams state. + */ +struct svr4_strm { + int s_family; /* socket family */ + int s_cmd; /* last getmsg reply or putmsg request */ + int s_afd; /* last accepted fd; [for fd_insert] */ + int s_eventmask; /* state info from I_SETSIG et al */ +}; + +/* + * The following structures are determined empirically. + */ +struct svr4_strmcmd { + long cmd; /* command ? */ + long len; /* Address len */ + long offs; /* Address offset */ + long pad[61]; +}; + +struct svr4_infocmd { + long cmd; + long tsdu; + long etsdu; + long cdata; + long ddata; + long addr; + long opt; + long tidu; + long serv; + long current; + long provider; +}; + +struct svr4_strfdinsert { + struct svr4_strbuf ctl; + struct svr4_strbuf data; + long flags; + int fd; + int offset; +}; + +struct svr4_netaddr_in { + u_short family; + u_short port; + u_long addr; +}; + +struct svr4_netaddr_un { + u_short family; + char path[1]; +}; + +#define SVR4_ADDROF(sc) (void *) (((char *) (sc)) + (sc)->offs) +#define SVR4_C_ADDROF(sc) (const void *) (((const char *) (sc)) + (sc)->offs) + +struct svr4_strm *svr4_stream_get __P((struct file *fp)); + +#endif /* !_SVR4_STROPTS */ diff --git a/sys/compat/svr4/svr4_syscall.h b/sys/compat/svr4/svr4_syscall.h new file mode 100644 index 0000000..1489740 --- /dev/null +++ b/sys/compat/svr4/svr4_syscall.h @@ -0,0 +1,144 @@ +/* + * System call numbers. + * + * DO NOT EDIT-- this file is automatically generated. + * created from; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 + */ + +#define SVR4_SYS_exit 1 +#define SVR4_SYS_fork 2 +#define SVR4_SYS_read 3 +#define SVR4_SYS_write 4 +#define SVR4_SYS_svr4_sys_open 5 +#define SVR4_SYS_close 6 +#define SVR4_SYS_svr4_sys_wait 7 +#define SVR4_SYS_svr4_sys_creat 8 +#define SVR4_SYS_link 9 +#define SVR4_SYS_unlink 10 +#define SVR4_SYS_svr4_sys_execv 11 +#define SVR4_SYS_chdir 12 +#define SVR4_SYS_svr4_sys_time 13 +#define SVR4_SYS_svr4_sys_mknod 14 +#define SVR4_SYS_chmod 15 +#define SVR4_SYS_chown 16 +#define SVR4_SYS_svr4_sys_break 17 +#define SVR4_SYS_svr4_sys_stat 18 +#define SVR4_SYS_lseek 19 +#define SVR4_SYS_getpid 20 +#define SVR4_SYS_setuid 23 +#define SVR4_SYS_getuid 24 +#define SVR4_SYS_svr4_sys_alarm 27 +#define SVR4_SYS_svr4_sys_fstat 28 +#define SVR4_SYS_svr4_sys_pause 29 +#define SVR4_SYS_svr4_sys_utime 30 +#define SVR4_SYS_svr4_sys_access 33 +#define SVR4_SYS_svr4_sys_nice 34 +#define SVR4_SYS_sync 36 +#define SVR4_SYS_svr4_sys_kill 37 +#define SVR4_SYS_svr4_sys_pgrpsys 39 +#define SVR4_SYS_dup 41 +#define SVR4_SYS_pipe 42 +#define SVR4_SYS_svr4_sys_times 43 +#define SVR4_SYS_setgid 46 +#define SVR4_SYS_getgid 47 +#define SVR4_SYS_svr4_sys_signal 48 +#define SVR4_SYS_svr4_sys_msgsys 49 +#define SVR4_SYS_svr4_sys_sysarch 50 +#define SVR4_SYS_svr4_sys_ioctl 54 +#define SVR4_SYS_svr4_sys_utssys 57 +#define SVR4_SYS_fsync 58 +#define SVR4_SYS_svr4_sys_execve 59 +#define SVR4_SYS_umask 60 +#define SVR4_SYS_chroot 61 +#define SVR4_SYS_svr4_sys_fcntl 62 +#define SVR4_SYS_svr4_sys_ulimit 63 +#define SVR4_SYS_rmdir 79 +#define SVR4_SYS_mkdir 80 +#define SVR4_SYS_svr4_sys_getdents 81 +#define SVR4_SYS_svr4_sys_getmsg 85 +#define SVR4_SYS_svr4_sys_putmsg 86 +#define SVR4_SYS_svr4_sys_poll 87 +#define SVR4_SYS_svr4_sys_lstat 88 +#define SVR4_SYS_symlink 89 +#define SVR4_SYS_readlink 90 +#define SVR4_SYS_getgroups 91 +#define SVR4_SYS_setgroups 92 +#define SVR4_SYS_fchmod 93 +#define SVR4_SYS_fchown 94 +#define SVR4_SYS_svr4_sys_sigprocmask 95 +#define SVR4_SYS_svr4_sys_sigsuspend 96 +#define SVR4_SYS_svr4_sys_sigaltstack 97 +#define SVR4_SYS_svr4_sys_sigaction 98 +#define SVR4_SYS_svr4_sys_sigpending 99 +#define SVR4_SYS_svr4_sys_context 100 +#define SVR4_SYS_svr4_sys_statvfs 103 +#define SVR4_SYS_svr4_sys_fstatvfs 104 +#define SVR4_SYS_svr4_sys_waitsys 107 +#define SVR4_SYS_svr4_sys_hrtsys 109 +#define SVR4_SYS_svr4_sys_pathconf 113 +#define SVR4_SYS_svr4_sys_mmap 115 +#define SVR4_SYS_mprotect 116 +#define SVR4_SYS_munmap 117 +#define SVR4_SYS_svr4_sys_fpathconf 118 +#define SVR4_SYS_vfork 119 +#define SVR4_SYS_fchdir 120 +#define SVR4_SYS_readv 121 +#define SVR4_SYS_writev 122 +#define SVR4_SYS_svr4_sys_xstat 123 +#define SVR4_SYS_svr4_sys_lxstat 124 +#define SVR4_SYS_svr4_sys_fxstat 125 +#define SVR4_SYS_svr4_sys_xmknod 126 +#define SVR4_SYS_svr4_sys_setrlimit 128 +#define SVR4_SYS_svr4_sys_getrlimit 129 +#define SVR4_SYS_lchown 130 +#define SVR4_SYS_svr4_sys_memcntl 131 +#define SVR4_SYS_rename 134 +#define SVR4_SYS_svr4_sys_uname 135 +#define SVR4_SYS_setegid 136 +#define SVR4_SYS_svr4_sys_sysconfig 137 +#define SVR4_SYS_adjtime 138 +#define SVR4_SYS_svr4_sys_systeminfo 139 +#define SVR4_SYS_seteuid 141 +#define SVR4_SYS_svr4_sys_fchroot 153 +#define SVR4_SYS_svr4_sys_utimes 154 +#define SVR4_SYS_svr4_sys_vhangup 155 +#define SVR4_SYS_svr4_sys_gettimeofday 156 +#define SVR4_SYS_getitimer 157 +#define SVR4_SYS_setitimer 158 +#define SVR4_SYS_svr4_sys_llseek 175 +#define SVR4_SYS_svr4_sys_acl 185 +#define SVR4_SYS_svr4_sys_auditsys 186 +#define SVR4_SYS_nanosleep 199 +#define SVR4_SYS_svr4_sys_facl 200 +#define SVR4_SYS_setreuid 202 +#define SVR4_SYS_setregid 203 +#define SVR4_SYS_svr4_sys_resolvepath 209 +#define SVR4_SYS_svr4_sys_getdents64 213 +#define SVR4_SYS_svr4_sys_mmap64 214 +#define SVR4_SYS_svr4_sys_stat64 215 +#define SVR4_SYS_svr4_sys_lstat64 216 +#define SVR4_SYS_svr4_sys_fstat64 217 +#define SVR4_SYS_svr4_sys_statvfs64 218 +#define SVR4_SYS_svr4_sys_fstatvfs64 219 +#define SVR4_SYS_svr4_sys_setrlimit64 220 +#define SVR4_SYS_svr4_sys_getrlimit64 221 +#define SVR4_SYS_svr4_sys_creat64 224 +#define SVR4_SYS_svr4_sys_open64 225 +#define SVR4_SYS_svr4_sys_socket 230 +#define SVR4_SYS_socketpair 231 +#define SVR4_SYS_bind 232 +#define SVR4_SYS_listen 233 +#define SVR4_SYS_accept 234 +#define SVR4_SYS_connect 235 +#define SVR4_SYS_shutdown 236 +#define SVR4_SYS_svr4_sys_recv 237 +#define SVR4_SYS_recvfrom 238 +#define SVR4_SYS_recvmsg 239 +#define SVR4_SYS_svr4_sys_send 240 +#define SVR4_SYS_sendmsg 241 +#define SVR4_SYS_svr4_sys_sendto 242 +#define SVR4_SYS_getpeername 243 +#define SVR4_SYS_getsockname 244 +#define SVR4_SYS_getsockopt 245 +#define SVR4_SYS_setsockopt 246 +#define SVR4_SYS_MAXSYSCALL 250 diff --git a/sys/compat/svr4/svr4_syscallnames.c b/sys/compat/svr4/svr4_syscallnames.c new file mode 100644 index 0000000..bb715b0 --- /dev/null +++ b/sys/compat/svr4/svr4_syscallnames.c @@ -0,0 +1,263 @@ +/* + * System call names. + * + * DO NOT EDIT-- this file is automatically generated. + * created from; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 + */ + +char *svr4_syscallnames[] = { + "#0", /* 0 = unused */ + "exit", /* 1 = exit */ + "fork", /* 2 = fork */ + "read", /* 3 = read */ + "write", /* 4 = write */ + "svr4_sys_open", /* 5 = svr4_sys_open */ + "close", /* 6 = close */ + "svr4_sys_wait", /* 7 = svr4_sys_wait */ + "svr4_sys_creat", /* 8 = svr4_sys_creat */ + "link", /* 9 = link */ + "unlink", /* 10 = unlink */ + "svr4_sys_execv", /* 11 = svr4_sys_execv */ + "chdir", /* 12 = chdir */ + "svr4_sys_time", /* 13 = svr4_sys_time */ + "svr4_sys_mknod", /* 14 = svr4_sys_mknod */ + "chmod", /* 15 = chmod */ + "chown", /* 16 = chown */ + "svr4_sys_break", /* 17 = svr4_sys_break */ + "svr4_sys_stat", /* 18 = svr4_sys_stat */ + "lseek", /* 19 = lseek */ + "getpid", /* 20 = getpid */ + "#21", /* 21 = old_mount */ + "#22", /* 22 = sysv_umount */ + "setuid", /* 23 = setuid */ + "getuid", /* 24 = getuid */ + "#25", /* 25 = stime */ + "#26", /* 26 = ptrace */ + "svr4_sys_alarm", /* 27 = svr4_sys_alarm */ + "svr4_sys_fstat", /* 28 = svr4_sys_fstat */ + "svr4_sys_pause", /* 29 = svr4_sys_pause */ + "svr4_sys_utime", /* 30 = svr4_sys_utime */ + "#31", /* 31 = stty */ + "#32", /* 32 = gtty */ + "svr4_sys_access", /* 33 = svr4_sys_access */ + "svr4_sys_nice", /* 34 = svr4_sys_nice */ + "#35", /* 35 = statfs */ + "sync", /* 36 = sync */ + "svr4_sys_kill", /* 37 = svr4_sys_kill */ + "#38", /* 38 = fstatfs */ + "svr4_sys_pgrpsys", /* 39 = svr4_sys_pgrpsys */ + "#40", /* 40 = xenix */ + "dup", /* 41 = dup */ + "pipe", /* 42 = pipe */ + "svr4_sys_times", /* 43 = svr4_sys_times */ + "#44", /* 44 = profil */ + "#45", /* 45 = plock */ + "setgid", /* 46 = setgid */ + "getgid", /* 47 = getgid */ + "svr4_sys_signal", /* 48 = svr4_sys_signal */ +#if defined(NOTYET) + "svr4_sys_msgsys", /* 49 = svr4_sys_msgsys */ +#else + "#49", /* 49 = msgsys */ +#endif + "svr4_sys_sysarch", /* 50 = svr4_sys_sysarch */ + "#51", /* 51 = acct */ + "#52", /* 52 = shmsys */ + "#53", /* 53 = semsys */ + "svr4_sys_ioctl", /* 54 = svr4_sys_ioctl */ + "#55", /* 55 = uadmin */ + "#56", /* 56 = exch */ + "svr4_sys_utssys", /* 57 = svr4_sys_utssys */ + "fsync", /* 58 = fsync */ + "svr4_sys_execve", /* 59 = svr4_sys_execve */ + "umask", /* 60 = umask */ + "chroot", /* 61 = chroot */ + "svr4_sys_fcntl", /* 62 = svr4_sys_fcntl */ + "svr4_sys_ulimit", /* 63 = svr4_sys_ulimit */ + "#64", /* 64 = reserved */ + "#65", /* 65 = reserved */ + "#66", /* 66 = reserved */ + "#67", /* 67 = reserved */ + "#68", /* 68 = reserved */ + "#69", /* 69 = reserved */ + "#70", /* 70 = advfs */ + "#71", /* 71 = unadvfs */ + "#72", /* 72 = rmount */ + "#73", /* 73 = rumount */ + "#74", /* 74 = rfstart */ + "#75", /* 75 = sigret */ + "#76", /* 76 = rdebug */ + "#77", /* 77 = rfstop */ + "#78", /* 78 = rfsys */ + "rmdir", /* 79 = rmdir */ + "mkdir", /* 80 = mkdir */ + "svr4_sys_getdents", /* 81 = svr4_sys_getdents */ + "#82", /* 82 = libattach */ + "#83", /* 83 = libdetach */ + "#84", /* 84 = sysfs */ + "svr4_sys_getmsg", /* 85 = svr4_sys_getmsg */ + "svr4_sys_putmsg", /* 86 = svr4_sys_putmsg */ + "svr4_sys_poll", /* 87 = svr4_sys_poll */ + "svr4_sys_lstat", /* 88 = svr4_sys_lstat */ + "symlink", /* 89 = symlink */ + "readlink", /* 90 = readlink */ + "getgroups", /* 91 = getgroups */ + "setgroups", /* 92 = setgroups */ + "fchmod", /* 93 = fchmod */ + "fchown", /* 94 = fchown */ + "svr4_sys_sigprocmask", /* 95 = svr4_sys_sigprocmask */ + "svr4_sys_sigsuspend", /* 96 = svr4_sys_sigsuspend */ + "svr4_sys_sigaltstack", /* 97 = svr4_sys_sigaltstack */ + "svr4_sys_sigaction", /* 98 = svr4_sys_sigaction */ + "svr4_sys_sigpending", /* 99 = svr4_sys_sigpending */ + "svr4_sys_context", /* 100 = svr4_sys_context */ + "#101", /* 101 = evsys */ + "#102", /* 102 = evtrapret */ + "svr4_sys_statvfs", /* 103 = svr4_sys_statvfs */ + "svr4_sys_fstatvfs", /* 104 = svr4_sys_fstatvfs */ + "#105", /* 105 = whoknows */ + "#106", /* 106 = nfssvc */ + "svr4_sys_waitsys", /* 107 = svr4_sys_waitsys */ + "#108", /* 108 = sigsendsys */ + "svr4_sys_hrtsys", /* 109 = svr4_sys_hrtsys */ + "#110", /* 110 = acancel */ + "#111", /* 111 = async */ + "#112", /* 112 = priocntlsys */ + "svr4_sys_pathconf", /* 113 = svr4_sys_pathconf */ + "#114", /* 114 = mincore */ + "svr4_sys_mmap", /* 115 = svr4_sys_mmap */ + "mprotect", /* 116 = mprotect */ + "munmap", /* 117 = munmap */ + "svr4_sys_fpathconf", /* 118 = svr4_sys_fpathconf */ + "vfork", /* 119 = vfork */ + "fchdir", /* 120 = fchdir */ + "readv", /* 121 = readv */ + "writev", /* 122 = writev */ + "svr4_sys_xstat", /* 123 = svr4_sys_xstat */ + "svr4_sys_lxstat", /* 124 = svr4_sys_lxstat */ + "svr4_sys_fxstat", /* 125 = svr4_sys_fxstat */ + "svr4_sys_xmknod", /* 126 = svr4_sys_xmknod */ + "#127", /* 127 = clocal */ + "svr4_sys_setrlimit", /* 128 = svr4_sys_setrlimit */ + "svr4_sys_getrlimit", /* 129 = svr4_sys_getrlimit */ + "lchown", /* 130 = lchown */ + "svr4_sys_memcntl", /* 131 = svr4_sys_memcntl */ + "#132", /* 132 = getpmsg */ + "#133", /* 133 = putpmsg */ + "rename", /* 134 = rename */ + "svr4_sys_uname", /* 135 = svr4_sys_uname */ + "setegid", /* 136 = setegid */ + "svr4_sys_sysconfig", /* 137 = svr4_sys_sysconfig */ + "adjtime", /* 138 = adjtime */ + "svr4_sys_systeminfo", /* 139 = svr4_sys_systeminfo */ + "#140", /* 140 = notused */ + "seteuid", /* 141 = seteuid */ + "#142", /* 142 = vtrace */ + "#143", /* 143 = { */ + "#144", /* 144 = sigtimedwait */ + "#145", /* 145 = lwp_info */ + "#146", /* 146 = yield */ + "#147", /* 147 = lwp_sema_wait */ + "#148", /* 148 = lwp_sema_post */ + "#149", /* 149 = lwp_sema_trywait */ + "#150", /* 150 = notused */ + "#151", /* 151 = notused */ + "#152", /* 152 = modctl */ + "svr4_sys_fchroot", /* 153 = svr4_sys_fchroot */ + "svr4_sys_utimes", /* 154 = svr4_sys_utimes */ + "svr4_sys_vhangup", /* 155 = svr4_sys_vhangup */ + "svr4_sys_gettimeofday", /* 156 = svr4_sys_gettimeofday */ + "getitimer", /* 157 = getitimer */ + "setitimer", /* 158 = setitimer */ + "#159", /* 159 = lwp_create */ + "#160", /* 160 = lwp_exit */ + "#161", /* 161 = lwp_suspend */ + "#162", /* 162 = lwp_continue */ + "#163", /* 163 = lwp_kill */ + "#164", /* 164 = lwp_self */ + "#165", /* 165 = lwp_getprivate */ + "#166", /* 166 = lwp_setprivate */ + "#167", /* 167 = lwp_wait */ + "#168", /* 168 = lwp_mutex_unlock */ + "#169", /* 169 = lwp_mutex_lock */ + "#170", /* 170 = lwp_cond_wait */ + "#171", /* 171 = lwp_cond_signal */ + "#172", /* 172 = lwp_cond_broadcast */ + "#173", /* 173 = { */ + "#174", /* 174 = { */ + "svr4_sys_llseek", /* 175 = svr4_sys_llseek */ + "#176", /* 176 = inst_sync */ + "#177", /* 177 = whoknows */ + "#178", /* 178 = kaio */ + "#179", /* 179 = whoknows */ + "#180", /* 180 = whoknows */ + "#181", /* 181 = whoknows */ + "#182", /* 182 = whoknows */ + "#183", /* 183 = whoknows */ + "#184", /* 184 = tsolsys */ + "svr4_sys_acl", /* 185 = svr4_sys_acl */ + "svr4_sys_auditsys", /* 186 = svr4_sys_auditsys */ + "#187", /* 187 = processor_bind */ + "#188", /* 188 = processor_info */ + "#189", /* 189 = p_online */ + "#190", /* 190 = sigqueue */ + "#191", /* 191 = clock_gettime */ + "#192", /* 192 = clock_settime */ + "#193", /* 193 = clock_getres */ + "#194", /* 194 = timer_create */ + "#195", /* 195 = timer_delete */ + "#196", /* 196 = timer_settime */ + "#197", /* 197 = timer_gettime */ + "#198", /* 198 = timer_overrun */ + "nanosleep", /* 199 = nanosleep */ + "svr4_sys_facl", /* 200 = svr4_sys_facl */ + "#201", /* 201 = door */ + "setreuid", /* 202 = setreuid */ + "setregid", /* 203 = setregid */ + "#204", /* 204 = install_utrap */ + "#205", /* 205 = signotify */ + "#206", /* 206 = schedctl */ + "#207", /* 207 = pset */ + "#208", /* 208 = whoknows */ + "svr4_sys_resolvepath", /* 209 = svr4_sys_resolvepath */ + "#210", /* 210 = signotifywait */ + "#211", /* 211 = lwp_sigredirect */ + "#212", /* 212 = lwp_alarm */ + "svr4_sys_getdents64", /* 213 = svr4_sys_getdents64 */ + "svr4_sys_mmap64", /* 214 = svr4_sys_mmap64 */ + "svr4_sys_stat64", /* 215 = svr4_sys_stat64 */ + "svr4_sys_lstat64", /* 216 = svr4_sys_lstat64 */ + "svr4_sys_fstat64", /* 217 = svr4_sys_fstat64 */ + "svr4_sys_statvfs64", /* 218 = svr4_sys_statvfs64 */ + "svr4_sys_fstatvfs64", /* 219 = svr4_sys_fstatvfs64 */ + "svr4_sys_setrlimit64", /* 220 = svr4_sys_setrlimit64 */ + "svr4_sys_getrlimit64", /* 221 = svr4_sys_getrlimit64 */ + "#222", /* 222 = pread64 */ + "#223", /* 223 = pwrite64 */ + "svr4_sys_creat64", /* 224 = svr4_sys_creat64 */ + "svr4_sys_open64", /* 225 = svr4_sys_open64 */ + "#226", /* 226 = rpcsys */ + "#227", /* 227 = whoknows */ + "#228", /* 228 = whoknows */ + "#229", /* 229 = whoknows */ + "svr4_sys_socket", /* 230 = svr4_sys_socket */ + "socketpair", /* 231 = socketpair */ + "bind", /* 232 = bind */ + "listen", /* 233 = listen */ + "accept", /* 234 = accept */ + "connect", /* 235 = connect */ + "shutdown", /* 236 = shutdown */ + "svr4_sys_recv", /* 237 = svr4_sys_recv */ + "recvfrom", /* 238 = recvfrom */ + "recvmsg", /* 239 = recvmsg */ + "svr4_sys_send", /* 240 = svr4_sys_send */ + "sendmsg", /* 241 = sendmsg */ + "svr4_sys_sendto", /* 242 = svr4_sys_sendto */ + "getpeername", /* 243 = getpeername */ + "getsockname", /* 244 = getsockname */ + "getsockopt", /* 245 = getsockopt */ + "setsockopt", /* 246 = setsockopt */ + "#247", /* 247 = sockconfig */ + "#248", /* 248 = { */ + "#249", /* 249 = { */ +}; diff --git a/sys/compat/svr4/svr4_sysconfig.h b/sys/compat/svr4/svr4_sysconfig.h new file mode 100644 index 0000000..bb1000a --- /dev/null +++ b/sys/compat/svr4/svr4_sysconfig.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1995 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_SYSCONFIG_H_ +#define _SVR4_SYSCONFIG_H_ + +#define SVR4_CONFIG_UNUSED 0x01 +#define SVR4_CONFIG_NGROUPS 0x02 +#define SVR4_CONFIG_CHILD_MAX 0x03 +#define SVR4_CONFIG_OPEN_FILES 0x04 +#define SVR4_CONFIG_POSIX_VER 0x05 +#define SVR4_CONFIG_PAGESIZE 0x06 +#define SVR4_CONFIG_CLK_TCK 0x07 +#define SVR4_CONFIG_XOPEN_VER 0x08 +#define SVR4_CONFIG_UNUSED_9 0x09 +#define SVR4_CONFIG_PROF_TCK 0x0a +#define SVR4_CONFIG_NPROC_CONF 0x0b +#define SVR4_CONFIG_NPROC_ONLN 0x0c +#define SVR4_CONFIG_AIO_LISTIO_MAX 0x0e +#define SVR4_CONFIG_AIO_MAX 0x0f +#define SVR4_CONFIG_AIO_PRIO_DELTA_MAX 0x10 +#define SVR4_CONFIG_DELAYTIMER_MAX 0x11 +#define SVR4_CONFIG_MQ_OPEN_MAX 0x12 +#define SVR4_CONFIG_MQ_PRIO_MAX 0x13 +#define SVR4_CONFIG_RTSIG_MAX 0x14 +#define SVR4_CONFIG_SEM_NSEMS_MAX 0x15 +#define SVR4_CONFIG_SEM_VALUE_MAX 0x16 +#define SVR4_CONFIG_SIGQUEUE_MAX 0x17 +#define SVR4_CONFIG_SIGRT_MIN 0x18 +#define SVR4_CONFIG_SIGRT_MAX 0x19 +#define SVR4_CONFIG_TIMER_MAX 0x20 +#define SVR4_CONFIG_PHYS_PAGES 0x21 +#define SVR4_CONFIG_AVPHYS_PAGES 0x22 + +#endif /* !_SVR4_SYSCONFIG_H_ */ diff --git a/sys/compat/svr4/svr4_sysent.c b/sys/compat/svr4/svr4_sysent.c new file mode 100644 index 0000000..3b1415d --- /dev/null +++ b/sys/compat/svr4/svr4_sysent.c @@ -0,0 +1,282 @@ +/* + * System call switch table. + * + * DO NOT EDIT-- this file is automatically generated. + * created from; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/param.h> +#include <sys/file.h> +#include <sys/filio.h> +#include <sys/sysent.h> +#include <sys/sysproto.h> +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_stropts.h> +#include <svr4/svr4_socket.h> +#include <svr4/svr4_sockio.h> +#include <svr4/svr4_timod.h> +#include <svr4/svr4_proto.h> + +/* The casts are bogus but will do for now. */ +struct sysent svr4_sysent[] = { + { 0, (sy_call_t *)nosys }, /* 0 = unused */ + { 1, (sy_call_t *)exit }, /* 1 = exit */ + { 0, (sy_call_t *)fork }, /* 2 = fork */ + { 3, (sy_call_t *)read }, /* 3 = read */ + { 3, (sy_call_t *)write }, /* 4 = write */ + { 3, (sy_call_t *)svr4_sys_open }, /* 5 = svr4_sys_open */ + { 1, (sy_call_t *)close }, /* 6 = close */ + { 1, (sy_call_t *)svr4_sys_wait }, /* 7 = svr4_sys_wait */ + { 2, (sy_call_t *)svr4_sys_creat }, /* 8 = svr4_sys_creat */ + { 2, (sy_call_t *)link }, /* 9 = link */ + { 1, (sy_call_t *)unlink }, /* 10 = unlink */ + { 2, (sy_call_t *)svr4_sys_execv }, /* 11 = svr4_sys_execv */ + { 1, (sy_call_t *)chdir }, /* 12 = chdir */ + { 1, (sy_call_t *)svr4_sys_time }, /* 13 = svr4_sys_time */ + { 3, (sy_call_t *)svr4_sys_mknod }, /* 14 = svr4_sys_mknod */ + { 2, (sy_call_t *)chmod }, /* 15 = chmod */ + { 3, (sy_call_t *)chown }, /* 16 = chown */ + { 1, (sy_call_t *)svr4_sys_break }, /* 17 = svr4_sys_break */ + { 2, (sy_call_t *)svr4_sys_stat }, /* 18 = svr4_sys_stat */ + { 3, (sy_call_t *)lseek }, /* 19 = lseek */ + { 0, (sy_call_t *)getpid }, /* 20 = getpid */ + { 0, (sy_call_t *)nosys }, /* 21 = old_mount */ + { 0, (sy_call_t *)nosys }, /* 22 = sysv_umount */ + { 1, (sy_call_t *)setuid }, /* 23 = setuid */ + { 0, (sy_call_t *)getuid }, /* 24 = getuid */ + { 0, (sy_call_t *)nosys }, /* 25 = stime */ + { 0, (sy_call_t *)nosys }, /* 26 = ptrace */ + { 1, (sy_call_t *)svr4_sys_alarm }, /* 27 = svr4_sys_alarm */ + { 2, (sy_call_t *)svr4_sys_fstat }, /* 28 = svr4_sys_fstat */ + { 0, (sy_call_t *)svr4_sys_pause }, /* 29 = svr4_sys_pause */ + { 2, (sy_call_t *)svr4_sys_utime }, /* 30 = svr4_sys_utime */ + { 0, (sy_call_t *)nosys }, /* 31 = stty */ + { 0, (sy_call_t *)nosys }, /* 32 = gtty */ + { 2, (sy_call_t *)svr4_sys_access }, /* 33 = svr4_sys_access */ + { 1, (sy_call_t *)svr4_sys_nice }, /* 34 = svr4_sys_nice */ + { 0, (sy_call_t *)nosys }, /* 35 = statfs */ + { 0, (sy_call_t *)sync }, /* 36 = sync */ + { 2, (sy_call_t *)svr4_sys_kill }, /* 37 = svr4_sys_kill */ + { 0, (sy_call_t *)nosys }, /* 38 = fstatfs */ + { 3, (sy_call_t *)svr4_sys_pgrpsys }, /* 39 = svr4_sys_pgrpsys */ + { 0, (sy_call_t *)nosys }, /* 40 = xenix */ + { 1, (sy_call_t *)dup }, /* 41 = dup */ + { 0, (sy_call_t *)pipe }, /* 42 = pipe */ + { 1, (sy_call_t *)svr4_sys_times }, /* 43 = svr4_sys_times */ + { 0, (sy_call_t *)nosys }, /* 44 = profil */ + { 0, (sy_call_t *)nosys }, /* 45 = plock */ + { 1, (sy_call_t *)setgid }, /* 46 = setgid */ + { 0, (sy_call_t *)getgid }, /* 47 = getgid */ + { 2, (sy_call_t *)svr4_sys_signal }, /* 48 = svr4_sys_signal */ +#if defined(NOTYET) + { 5, (sy_call_t *)svr4_sys_msgsys }, /* 49 = svr4_sys_msgsys */ +#else + { 0, (sy_call_t *)nosys }, /* 49 = msgsys */ +#endif + { 2, (sy_call_t *)svr4_sys_sysarch }, /* 50 = svr4_sys_sysarch */ + { 0, (sy_call_t *)nosys }, /* 51 = acct */ + { 0, (sy_call_t *)nosys }, /* 52 = shmsys */ + { 0, (sy_call_t *)nosys }, /* 53 = semsys */ + { 3, (sy_call_t *)svr4_sys_ioctl }, /* 54 = svr4_sys_ioctl */ + { 0, (sy_call_t *)nosys }, /* 55 = uadmin */ + { 0, (sy_call_t *)nosys }, /* 56 = exch */ + { 4, (sy_call_t *)svr4_sys_utssys }, /* 57 = svr4_sys_utssys */ + { 1, (sy_call_t *)fsync }, /* 58 = fsync */ + { 3, (sy_call_t *)svr4_sys_execve }, /* 59 = svr4_sys_execve */ + { 1, (sy_call_t *)umask }, /* 60 = umask */ + { 1, (sy_call_t *)chroot }, /* 61 = chroot */ + { 3, (sy_call_t *)svr4_sys_fcntl }, /* 62 = svr4_sys_fcntl */ + { 2, (sy_call_t *)svr4_sys_ulimit }, /* 63 = svr4_sys_ulimit */ + { 0, (sy_call_t *)nosys }, /* 64 = reserved */ + { 0, (sy_call_t *)nosys }, /* 65 = reserved */ + { 0, (sy_call_t *)nosys }, /* 66 = reserved */ + { 0, (sy_call_t *)nosys }, /* 67 = reserved */ + { 0, (sy_call_t *)nosys }, /* 68 = reserved */ + { 0, (sy_call_t *)nosys }, /* 69 = reserved */ + { 0, (sy_call_t *)nosys }, /* 70 = advfs */ + { 0, (sy_call_t *)nosys }, /* 71 = unadvfs */ + { 0, (sy_call_t *)nosys }, /* 72 = rmount */ + { 0, (sy_call_t *)nosys }, /* 73 = rumount */ + { 0, (sy_call_t *)nosys }, /* 74 = rfstart */ + { 0, (sy_call_t *)nosys }, /* 75 = sigret */ + { 0, (sy_call_t *)nosys }, /* 76 = rdebug */ + { 0, (sy_call_t *)nosys }, /* 77 = rfstop */ + { 0, (sy_call_t *)nosys }, /* 78 = rfsys */ + { 1, (sy_call_t *)rmdir }, /* 79 = rmdir */ + { 2, (sy_call_t *)mkdir }, /* 80 = mkdir */ + { 3, (sy_call_t *)svr4_sys_getdents }, /* 81 = svr4_sys_getdents */ + { 0, (sy_call_t *)nosys }, /* 82 = libattach */ + { 0, (sy_call_t *)nosys }, /* 83 = libdetach */ + { 0, (sy_call_t *)nosys }, /* 84 = sysfs */ + { 4, (sy_call_t *)svr4_sys_getmsg }, /* 85 = svr4_sys_getmsg */ + { 4, (sy_call_t *)svr4_sys_putmsg }, /* 86 = svr4_sys_putmsg */ + { 3, (sy_call_t *)svr4_sys_poll }, /* 87 = svr4_sys_poll */ + { 2, (sy_call_t *)svr4_sys_lstat }, /* 88 = svr4_sys_lstat */ + { 2, (sy_call_t *)symlink }, /* 89 = symlink */ + { 3, (sy_call_t *)readlink }, /* 90 = readlink */ + { 2, (sy_call_t *)getgroups }, /* 91 = getgroups */ + { 2, (sy_call_t *)setgroups }, /* 92 = setgroups */ + { 2, (sy_call_t *)fchmod }, /* 93 = fchmod */ + { 3, (sy_call_t *)fchown }, /* 94 = fchown */ + { 3, (sy_call_t *)svr4_sys_sigprocmask }, /* 95 = svr4_sys_sigprocmask */ + { 1, (sy_call_t *)svr4_sys_sigsuspend }, /* 96 = svr4_sys_sigsuspend */ + { 2, (sy_call_t *)svr4_sys_sigaltstack }, /* 97 = svr4_sys_sigaltstack */ + { 3, (sy_call_t *)svr4_sys_sigaction }, /* 98 = svr4_sys_sigaction */ + { 2, (sy_call_t *)svr4_sys_sigpending }, /* 99 = svr4_sys_sigpending */ + { 2, (sy_call_t *)svr4_sys_context }, /* 100 = svr4_sys_context */ + { 0, (sy_call_t *)nosys }, /* 101 = evsys */ + { 0, (sy_call_t *)nosys }, /* 102 = evtrapret */ + { 2, (sy_call_t *)svr4_sys_statvfs }, /* 103 = svr4_sys_statvfs */ + { 2, (sy_call_t *)svr4_sys_fstatvfs }, /* 104 = svr4_sys_fstatvfs */ + { 0, (sy_call_t *)nosys }, /* 105 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 106 = nfssvc */ + { 4, (sy_call_t *)svr4_sys_waitsys }, /* 107 = svr4_sys_waitsys */ + { 0, (sy_call_t *)nosys }, /* 108 = sigsendsys */ + { 5, (sy_call_t *)svr4_sys_hrtsys }, /* 109 = svr4_sys_hrtsys */ + { 0, (sy_call_t *)nosys }, /* 110 = acancel */ + { 0, (sy_call_t *)nosys }, /* 111 = async */ + { 0, (sy_call_t *)nosys }, /* 112 = priocntlsys */ + { 2, (sy_call_t *)svr4_sys_pathconf }, /* 113 = svr4_sys_pathconf */ + { 0, (sy_call_t *)nosys }, /* 114 = mincore */ + { 6, (sy_call_t *)svr4_sys_mmap }, /* 115 = svr4_sys_mmap */ + { 3, (sy_call_t *)mprotect }, /* 116 = mprotect */ + { 2, (sy_call_t *)munmap }, /* 117 = munmap */ + { 2, (sy_call_t *)svr4_sys_fpathconf }, /* 118 = svr4_sys_fpathconf */ + { 0, (sy_call_t *)vfork }, /* 119 = vfork */ + { 1, (sy_call_t *)fchdir }, /* 120 = fchdir */ + { 3, (sy_call_t *)readv }, /* 121 = readv */ + { 3, (sy_call_t *)writev }, /* 122 = writev */ + { 3, (sy_call_t *)svr4_sys_xstat }, /* 123 = svr4_sys_xstat */ + { 3, (sy_call_t *)svr4_sys_lxstat }, /* 124 = svr4_sys_lxstat */ + { 3, (sy_call_t *)svr4_sys_fxstat }, /* 125 = svr4_sys_fxstat */ + { 4, (sy_call_t *)svr4_sys_xmknod }, /* 126 = svr4_sys_xmknod */ + { 0, (sy_call_t *)nosys }, /* 127 = clocal */ + { 2, (sy_call_t *)svr4_sys_setrlimit }, /* 128 = svr4_sys_setrlimit */ + { 2, (sy_call_t *)svr4_sys_getrlimit }, /* 129 = svr4_sys_getrlimit */ + { 3, (sy_call_t *)lchown }, /* 130 = lchown */ + { 6, (sy_call_t *)svr4_sys_memcntl }, /* 131 = svr4_sys_memcntl */ + { 0, (sy_call_t *)nosys }, /* 132 = getpmsg */ + { 0, (sy_call_t *)nosys }, /* 133 = putpmsg */ + { 2, (sy_call_t *)rename }, /* 134 = rename */ + { 2, (sy_call_t *)svr4_sys_uname }, /* 135 = svr4_sys_uname */ + { 1, (sy_call_t *)setegid }, /* 136 = setegid */ + { 1, (sy_call_t *)svr4_sys_sysconfig }, /* 137 = svr4_sys_sysconfig */ + { 2, (sy_call_t *)adjtime }, /* 138 = adjtime */ + { 3, (sy_call_t *)svr4_sys_systeminfo }, /* 139 = svr4_sys_systeminfo */ + { 0, (sy_call_t *)nosys }, /* 140 = notused */ + { 1, (sy_call_t *)seteuid }, /* 141 = seteuid */ + { 0, (sy_call_t *)nosys }, /* 142 = vtrace */ + { 0, (sy_call_t *)nosys }, /* 143 = { */ + { 0, (sy_call_t *)nosys }, /* 144 = sigtimedwait */ + { 0, (sy_call_t *)nosys }, /* 145 = lwp_info */ + { 0, (sy_call_t *)nosys }, /* 146 = yield */ + { 0, (sy_call_t *)nosys }, /* 147 = lwp_sema_wait */ + { 0, (sy_call_t *)nosys }, /* 148 = lwp_sema_post */ + { 0, (sy_call_t *)nosys }, /* 149 = lwp_sema_trywait */ + { 0, (sy_call_t *)nosys }, /* 150 = notused */ + { 0, (sy_call_t *)nosys }, /* 151 = notused */ + { 0, (sy_call_t *)nosys }, /* 152 = modctl */ + { 1, (sy_call_t *)svr4_sys_fchroot }, /* 153 = svr4_sys_fchroot */ + { 2, (sy_call_t *)svr4_sys_utimes }, /* 154 = svr4_sys_utimes */ + { 0, (sy_call_t *)svr4_sys_vhangup }, /* 155 = svr4_sys_vhangup */ + { 1, (sy_call_t *)svr4_sys_gettimeofday }, /* 156 = svr4_sys_gettimeofday */ + { 2, (sy_call_t *)getitimer }, /* 157 = getitimer */ + { 3, (sy_call_t *)setitimer }, /* 158 = setitimer */ + { 0, (sy_call_t *)nosys }, /* 159 = lwp_create */ + { 0, (sy_call_t *)nosys }, /* 160 = lwp_exit */ + { 0, (sy_call_t *)nosys }, /* 161 = lwp_suspend */ + { 0, (sy_call_t *)nosys }, /* 162 = lwp_continue */ + { 0, (sy_call_t *)nosys }, /* 163 = lwp_kill */ + { 0, (sy_call_t *)nosys }, /* 164 = lwp_self */ + { 0, (sy_call_t *)nosys }, /* 165 = lwp_getprivate */ + { 0, (sy_call_t *)nosys }, /* 166 = lwp_setprivate */ + { 0, (sy_call_t *)nosys }, /* 167 = lwp_wait */ + { 0, (sy_call_t *)nosys }, /* 168 = lwp_mutex_unlock */ + { 0, (sy_call_t *)nosys }, /* 169 = lwp_mutex_lock */ + { 0, (sy_call_t *)nosys }, /* 170 = lwp_cond_wait */ + { 0, (sy_call_t *)nosys }, /* 171 = lwp_cond_signal */ + { 0, (sy_call_t *)nosys }, /* 172 = lwp_cond_broadcast */ + { 0, (sy_call_t *)nosys }, /* 173 = { */ + { 0, (sy_call_t *)nosys }, /* 174 = { */ + { 4, (sy_call_t *)svr4_sys_llseek }, /* 175 = svr4_sys_llseek */ + { 0, (sy_call_t *)nosys }, /* 176 = inst_sync */ + { 0, (sy_call_t *)nosys }, /* 177 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 178 = kaio */ + { 0, (sy_call_t *)nosys }, /* 179 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 180 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 181 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 182 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 183 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 184 = tsolsys */ + { 4, (sy_call_t *)svr4_sys_acl }, /* 185 = svr4_sys_acl */ + { 6, (sy_call_t *)svr4_sys_auditsys }, /* 186 = svr4_sys_auditsys */ + { 0, (sy_call_t *)nosys }, /* 187 = processor_bind */ + { 0, (sy_call_t *)nosys }, /* 188 = processor_info */ + { 0, (sy_call_t *)nosys }, /* 189 = p_online */ + { 0, (sy_call_t *)nosys }, /* 190 = sigqueue */ + { 0, (sy_call_t *)nosys }, /* 191 = clock_gettime */ + { 0, (sy_call_t *)nosys }, /* 192 = clock_settime */ + { 0, (sy_call_t *)nosys }, /* 193 = clock_getres */ + { 0, (sy_call_t *)nosys }, /* 194 = timer_create */ + { 0, (sy_call_t *)nosys }, /* 195 = timer_delete */ + { 0, (sy_call_t *)nosys }, /* 196 = timer_settime */ + { 0, (sy_call_t *)nosys }, /* 197 = timer_gettime */ + { 0, (sy_call_t *)nosys }, /* 198 = timer_overrun */ + { 2, (sy_call_t *)nanosleep }, /* 199 = nanosleep */ + { 4, (sy_call_t *)svr4_sys_facl }, /* 200 = svr4_sys_facl */ + { 0, (sy_call_t *)nosys }, /* 201 = door */ + { 2, (sy_call_t *)setreuid }, /* 202 = setreuid */ + { 2, (sy_call_t *)setregid }, /* 203 = setregid */ + { 0, (sy_call_t *)nosys }, /* 204 = install_utrap */ + { 0, (sy_call_t *)nosys }, /* 205 = signotify */ + { 0, (sy_call_t *)nosys }, /* 206 = schedctl */ + { 0, (sy_call_t *)nosys }, /* 207 = pset */ + { 0, (sy_call_t *)nosys }, /* 208 = whoknows */ + { 3, (sy_call_t *)svr4_sys_resolvepath }, /* 209 = svr4_sys_resolvepath */ + { 0, (sy_call_t *)nosys }, /* 210 = signotifywait */ + { 0, (sy_call_t *)nosys }, /* 211 = lwp_sigredirect */ + { 0, (sy_call_t *)nosys }, /* 212 = lwp_alarm */ + { 3, (sy_call_t *)svr4_sys_getdents64 }, /* 213 = svr4_sys_getdents64 */ + { 6, (sy_call_t *)svr4_sys_mmap64 }, /* 214 = svr4_sys_mmap64 */ + { 2, (sy_call_t *)svr4_sys_stat64 }, /* 215 = svr4_sys_stat64 */ + { 2, (sy_call_t *)svr4_sys_lstat64 }, /* 216 = svr4_sys_lstat64 */ + { 2, (sy_call_t *)svr4_sys_fstat64 }, /* 217 = svr4_sys_fstat64 */ + { 2, (sy_call_t *)svr4_sys_statvfs64 }, /* 218 = svr4_sys_statvfs64 */ + { 2, (sy_call_t *)svr4_sys_fstatvfs64 }, /* 219 = svr4_sys_fstatvfs64 */ + { 2, (sy_call_t *)svr4_sys_setrlimit64 }, /* 220 = svr4_sys_setrlimit64 */ + { 2, (sy_call_t *)svr4_sys_getrlimit64 }, /* 221 = svr4_sys_getrlimit64 */ + { 0, (sy_call_t *)nosys }, /* 222 = pread64 */ + { 0, (sy_call_t *)nosys }, /* 223 = pwrite64 */ + { 2, (sy_call_t *)svr4_sys_creat64 }, /* 224 = svr4_sys_creat64 */ + { 3, (sy_call_t *)svr4_sys_open64 }, /* 225 = svr4_sys_open64 */ + { 0, (sy_call_t *)nosys }, /* 226 = rpcsys */ + { 0, (sy_call_t *)nosys }, /* 227 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 228 = whoknows */ + { 0, (sy_call_t *)nosys }, /* 229 = whoknows */ + { 3, (sy_call_t *)svr4_sys_socket }, /* 230 = svr4_sys_socket */ + { 4, (sy_call_t *)socketpair }, /* 231 = socketpair */ + { 3, (sy_call_t *)bind }, /* 232 = bind */ + { 2, (sy_call_t *)listen }, /* 233 = listen */ + { 3, (sy_call_t *)accept }, /* 234 = accept */ + { 3, (sy_call_t *)connect }, /* 235 = connect */ + { 2, (sy_call_t *)shutdown }, /* 236 = shutdown */ + { 4, (sy_call_t *)svr4_sys_recv }, /* 237 = svr4_sys_recv */ + { 6, (sy_call_t *)recvfrom }, /* 238 = recvfrom */ + { 3, (sy_call_t *)recvmsg }, /* 239 = recvmsg */ + { 4, (sy_call_t *)svr4_sys_send }, /* 240 = svr4_sys_send */ + { 3, (sy_call_t *)sendmsg }, /* 241 = sendmsg */ + { 6, (sy_call_t *)svr4_sys_sendto }, /* 242 = svr4_sys_sendto */ + { 3, (sy_call_t *)getpeername }, /* 243 = getpeername */ + { 3, (sy_call_t *)getsockname }, /* 244 = getsockname */ + { 5, (sy_call_t *)getsockopt }, /* 245 = getsockopt */ + { 5, (sy_call_t *)setsockopt }, /* 246 = setsockopt */ + { 0, (sy_call_t *)nosys }, /* 247 = sockconfig */ + { 0, (sy_call_t *)nosys }, /* 248 = { */ + { 0, (sy_call_t *)nosys }, /* 249 = { */ +}; diff --git a/sys/compat/svr4/svr4_systeminfo.h b/sys/compat/svr4/svr4_systeminfo.h new file mode 100644 index 0000000..520c6fa --- /dev/null +++ b/sys/compat/svr4/svr4_systeminfo.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_SYSTEMINFO_H_ +#define _SVR4_SYSTEMINFO_H_ + +#define SVR4_SI_SYSNAME 1 +#define SVR4_SI_HOSTNAME 2 +#define SVR4_SI_RELEASE 3 +#define SVR4_SI_VERSION 4 +#define SVR4_SI_MACHINE 5 +#define SVR4_SI_ARCHITECTURE 6 +#define SVR4_SI_HW_SERIAL 7 +#define SVR4_SI_HW_PROVIDER 8 +#define SVR4_SI_SRPC_DOMAIN 9 +#define SVR4_SI_SET_HOSTNAME 258 +#define SVR4_SI_SET_SRPC_DOMAIN 265 +#define SVR4_SI_SET_KERB_REALM 266 +#define SVR4_SI_KERB_REALM 267 +#define SVR4_SI_PLATFORM 513 +#define SVR4_SI_ISALIST 514 + +#endif /* !_SVR4_SYSTEMINFO_H_ */ diff --git a/sys/compat/svr4/svr4_sysvec.c b/sys/compat/svr4/svr4_sysvec.c new file mode 100644 index 0000000..8b0997d --- /dev/null +++ b/sys/compat/svr4/svr4_sysvec.c @@ -0,0 +1,383 @@ +/* XXX we use functions that might not exist. */ +#include "opt_compat.h" + +#ifndef COMPAT_43 +#error "Unable to compile SVR4-emulator due to missing COMPAT_43 option!" +#endif + +#include <sys/param.h> +#include <sys/buf.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/sysent.h> +#include <sys/imgact.h> +#include <sys/imgact_elf.h> +#include <sys/socket.h> +#include <sys/sockio.h> +#include <sys/signalvar.h> +#include <sys/malloc.h> +#include <sys/namei.h> +#include <sys/vnode.h> +#include <sys/module.h> +#include <vm/vm.h> +#include <vm/vm_param.h> +#include <vm/vm_prot.h> +#include <vm/vm_page.h> +#include <vm/vm_extern.h> +#include <sys/exec.h> +#include <sys/kernel.h> +#include <machine/cpu.h> +#include <netinet/in.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_syscall.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_sockio.h> +#include <svr4/svr4_socket.h> +#include <svr4/svr4_errno.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_siginfo.h> +#include <svr4/svr4_util.h> + +extern int bsd_to_svr4_sig[]; +extern int svr4_to_bsd_sig[]; + +int bsd_to_svr4_errno[ELAST+1] = { + 0, + SVR4_EPERM, + SVR4_ENOENT, + SVR4_ESRCH, + SVR4_EINTR, + SVR4_EIO, + SVR4_ENXIO, + SVR4_E2BIG, + SVR4_ENOEXEC, + SVR4_EBADF, + SVR4_ECHILD, + SVR4_EDEADLK, + SVR4_ENOMEM, + SVR4_EACCES, + SVR4_EFAULT, + SVR4_ENOTBLK, + SVR4_EBUSY, + SVR4_EEXIST, + SVR4_EXDEV, + SVR4_ENODEV, + SVR4_ENOTDIR, + SVR4_EISDIR, + SVR4_EINVAL, + SVR4_ENFILE, + SVR4_EMFILE, + SVR4_ENOTTY, + SVR4_ETXTBSY, + SVR4_EFBIG, + SVR4_ENOSPC, + SVR4_ESPIPE, + SVR4_EROFS, + SVR4_EMLINK, + SVR4_EPIPE, + SVR4_EDOM, + SVR4_ERANGE, + SVR4_EAGAIN, + SVR4_EINPROGRESS, + SVR4_EALREADY, + SVR4_ENOTSOCK, + SVR4_EDESTADDRREQ, + SVR4_EMSGSIZE, + SVR4_EPROTOTYPE, + SVR4_ENOPROTOOPT, + SVR4_EPROTONOSUPPORT, + SVR4_ESOCKTNOSUPPORT, + SVR4_EOPNOTSUPP, + SVR4_EPFNOSUPPORT, + SVR4_EAFNOSUPPORT, + SVR4_EADDRINUSE, + SVR4_EADDRNOTAVAIL, + SVR4_ENETDOWN, + SVR4_ENETUNREACH, + SVR4_ENETRESET, + SVR4_ECONNABORTED, + SVR4_ECONNRESET, + SVR4_ENOBUFS, + SVR4_EISCONN, + SVR4_ENOTCONN, + SVR4_ESHUTDOWN, + SVR4_ETOOMANYREFS, + SVR4_ETIMEDOUT, + SVR4_ECONNREFUSED, + SVR4_ELOOP, + SVR4_ENAMETOOLONG, + SVR4_EHOSTDOWN, + SVR4_EHOSTUNREACH, + SVR4_ENOTEMPTY, + SVR4_EPROCLIM, + SVR4_EUSERS, + SVR4_EDQUOT, + SVR4_ESTALE, + SVR4_EREMOTE, + SVR4_EBADRPC, + SVR4_ERPCMISMATCH, + SVR4_EPROGUNAVAIL, + SVR4_EPROGMISMATCH, + SVR4_EPROCUNAVAIL, + SVR4_ENOLCK, + SVR4_ENOSYS, + SVR4_EFTYPE, + SVR4_EAUTH, + SVR4_ENEEDAUTH, + SVR4_EIDRM, + SVR4_ENOMSG, +}; + + +static int svr4_fixup(long **stack_base, struct image_params *imgp); + +extern struct sysent svr4_sysent[]; +#undef szsigcode +#undef sigcode + +extern int svr4_szsigcode; +extern char svr4_sigcode[]; + +struct sysentvec svr4_sysvec = { + SVR4_SYS_MAXSYSCALL, + svr4_sysent, + 0xff, + NSIG, + bsd_to_svr4_sig, + ELAST, /* ELAST */ + bsd_to_svr4_errno, + 0, + svr4_fixup, + svr4_sendsig, + svr4_sigcode, + &svr4_szsigcode, + 0, + "SVR4" +}; + +Elf32_Brandinfo svr4_brand = { + "SVR4", + "/compat/svr4", + "/lib/libc.so.1", + &svr4_sysvec +}; + +const char svr4_emul_path[] = "/compat/svr4"; + +static int +svr4_fixup(long **stack_base, struct image_params *imgp) +{ + Elf32_Auxargs *args = (Elf32_Auxargs *)imgp->auxargs; + long *pos; + + pos = *stack_base + (imgp->argc + imgp->envc + 2); + + if (args->trace) { + AUXARGS_ENTRY(pos, AT_DEBUG, 1); + } + if (args->execfd != -1) { + AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd); + } + AUXARGS_ENTRY(pos, AT_PHDR, args->phdr); + AUXARGS_ENTRY(pos, AT_PHENT, args->phent); + AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum); + AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz); + AUXARGS_ENTRY(pos, AT_FLAGS, args->flags); + AUXARGS_ENTRY(pos, AT_ENTRY, args->entry); + AUXARGS_ENTRY(pos, AT_BASE, args->base); + AUXARGS_ENTRY(pos, AT_UID, imgp->proc->p_cred->p_ruid); + AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_cred->p_svuid); + AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_cred->p_rgid); + AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_cred->p_svgid); + AUXARGS_ENTRY(pos, AT_NULL, 0); + + free(imgp->auxargs, M_TEMP); + imgp->auxargs = NULL; + + (*stack_base)--; + **stack_base = (int)imgp->argc; + return 0; +} + +/* + * Search an alternate path before passing pathname arguments on + * to system calls. Useful for keeping a seperate 'emulation tree'. + * + * If cflag is set, we check if an attempt can be made to create + * the named file, i.e. we check if the directory it should + * be in exists. + * + * Code shamelessly stolen by Mark Newton from IBCS2 emulation code. + */ +int +svr4_emul_find(p, sgp, prefix, path, pbuf, cflag) + struct proc *p; + caddr_t *sgp; /* Pointer to stackgap memory */ + const char *prefix; + char *path; + char **pbuf; + int cflag; +{ + struct nameidata nd; + struct nameidata ndroot; + struct vattr vat; + struct vattr vatroot; + int error; + char *ptr, *buf, *cp; + size_t sz, len; + + buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK); + *pbuf = path; + + for (ptr = buf; (*ptr = *prefix) != '\0'; ptr++, prefix++) + continue; + + sz = MAXPATHLEN - (ptr - buf); + + /* + * If sgp is not given then the path is already in kernel space + */ + if (sgp == NULL) + error = copystr(path, ptr, sz, &len); + else + error = copyinstr(path, ptr, sz, &len); + + if (error) { + free(buf, M_TEMP); + return error; + } + + if (*ptr != '/') { + free(buf, M_TEMP); + return EINVAL; + } + + /* + * We know that there is a / somewhere in this pathname. + * Search backwards for it, to find the file's parent dir + * to see if it exists in the alternate tree. If it does, + * and we want to create a file (cflag is set). We don't + * need to worry about the root comparison in this case. + */ + + if (cflag) { + for (cp = &ptr[len] - 1; *cp != '/'; cp--); + *cp = '\0'; + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p); + + if ((error = namei(&nd)) != 0) { + free(buf, M_TEMP); + return error; + } + + *cp = '/'; + } + else { + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p); + + if ((error = namei(&nd)) != 0) { + free(buf, M_TEMP); + return error; + } + + /* + * We now compare the vnode of the svr4_root to the one + * vnode asked. If they resolve to be the same, then we + * ignore the match so that the real root gets used. + * This avoids the problem of traversing "../.." to find the + * root directory and never finding it, because "/" resolves + * to the emulation root directory. This is expensive :-( + */ + NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, svr4_emul_path, + p); + + if ((error = namei(&ndroot)) != 0) { + /* Cannot happen! */ + free(buf, M_TEMP); + vrele(nd.ni_vp); + return error; + } + + if ((error = VOP_GETATTR(nd.ni_vp, &vat, p->p_ucred, p)) != 0) { + goto done; + } + + if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, p->p_ucred, p)) + != 0) { + goto done; + } + + if (vat.va_fsid == vatroot.va_fsid && + vat.va_fileid == vatroot.va_fileid) { + error = ENOENT; + goto done; + } + + } + if (sgp == NULL) + *pbuf = buf; + else { + sz = &ptr[len] - buf; + *pbuf = stackgap_alloc(sgp, sz + 1); + error = copyout(buf, *pbuf, sz); + free(buf, M_TEMP); + } + + +done: + vrele(nd.ni_vp); + if (!cflag) + vrele(ndroot.ni_vp); + return error; +} + +/* + * XXX: wrong, for the same reason described in linux_sysvec.c + */ +static int svr4_elf_modevent __P((module_t mod, int type, void *data)); + +static int +svr4_elf_modevent(module_t mod, int type, void *data) +{ + int error; + + error = 0; + + switch(type) { + case MOD_LOAD: + if (elf_insert_brand_entry(&svr4_brand) < 0) + error = EINVAL; + if (error) + printf("cannot insert svr4 elf brand handler\n"); + else if (bootverbose) + printf("svr4 ELF exec handler installed\n"); + break; + case MOD_UNLOAD: + /* XXX There needs to be a generic function that any + * emulator can call to say, "Are any currently-running + * executables using me?" so we can fail to unload the + * module if it's in use. Locking up because you forgot + * to shut down a program prior to a kldunload isn't fun. + */ + if (elf_remove_brand_entry(&svr4_brand) < 0) + error = EINVAL; + if (error) + printf("Could not deinstall ELF interpreter entry\n"); + else if (bootverbose) + printf("svr4 ELF exec handler removed\n"); + break; + default: + break; + } + return error; +} + +static moduledata_t svr4_elf_mod = { + "svr4elf", + svr4_elf_modevent, + 0 +}; +DECLARE_MODULE(svr4elf, svr4_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY); diff --git a/sys/compat/svr4/svr4_termios.c b/sys/compat/svr4/svr4_termios.c new file mode 100644 index 0000000..fd5db71 --- /dev/null +++ b/sys/compat/svr4/svr4_termios.c @@ -0,0 +1,619 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/file.h> +#include <sys/filedesc.h> +#include <sys/fcntl.h> +#include <sys/unistd.h> +#include <sys/termios.h> +#include <sys/tty.h> +#include <sys/socket.h> +#include <sys/mount.h> +#include <net/if.h> +#include <sys/malloc.h> + +#include <sys/sysproto.h> + +#include <svr4/svr4.h> +#include <svr4/svr4_types.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_ioctl.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_stropts.h> +#include <svr4/svr4_termios.h> + + +#ifndef __CONCAT3 +# if __STDC__ +# define __CONCAT3(a,b,c) a ## b ## c +# else +# define __CONCAT3(a,b,c) a/**/b/**/c +# endif +#endif + +static u_long bsd_to_svr4_speed __P((u_long, u_long)); +static u_long svr4_to_bsd_speed __P((u_long, u_long)); +static void svr4_to_bsd_termios __P((const struct svr4_termios *, + struct termios *, int)); +static void bsd_to_svr4_termios __P((const struct termios *, + struct svr4_termios *)); +static void svr4_termio_to_termios __P((const struct svr4_termio *, + struct svr4_termios *)); +static void svr4_termios_to_termio __P((const struct svr4_termios *, + struct svr4_termio *)); +#ifdef DEBUG_SVR4 +static void print_svr4_termios __P((const struct svr4_termios *)); +static void print_bsd_termios __P((const struct termios *)); +#endif /* DEBUG_SVR4 */ + +#define undefined_char(a,b) /**/ +#define undefined_flag1(f,a,b) /**/ +#define undefined_flag2(f,a,b,c1,t1,c2,t2) /**/ +#define undefined_flag4(f,a,b,c1,t1,c2,t2,c3,t3,c4,t4) /**/ + +#define svr4_to_bsd_char(a,b) \ + if (new || __CONCAT3(SVR4_,a,b) < SVR4_NCC) { \ + if (st->c_cc[__CONCAT3(SVR4_,a,b)] == SVR4_POSIX_VDISABLE) \ + bt->c_cc[__CONCAT(a,b)] = _POSIX_VDISABLE; \ + else \ + bt->c_cc[__CONCAT(a,b)] = st->c_cc[__CONCAT3(SVR4_,a,b)]; \ + } + +#define svr4_to_bsd_flag1(f,a,b) \ + if (new || __CONCAT3(SVR4_,a,b) < 0200000) { \ + if (st->f & __CONCAT3(SVR4_,a,b)) \ + bt->f |= __CONCAT(a,b); \ + else \ + bt->f &= ~__CONCAT(a,b); \ + } + +#define svr4_to_bsd_flag2(f,a,b,c1,t1,c2,t2) \ + if (new || __CONCAT3(SVR4_,a,b) < 0200000) { \ + bt->f &= ~__CONCAT(a,b); \ + switch (st->f & __CONCAT3(SVR4_,a,b)) { \ + case __CONCAT3(SVR4_,c1,t1): bt->f |= __CONCAT(c1,t1); break; \ + case __CONCAT3(SVR4_,c2,t2): bt->f |= __CONCAT(c2,t2); break; \ + } \ + } + +#define svr4_to_bsd_flag4(f,a,b,c1,t1,c2,t2,c3,t3,c4,t4) \ + if (new || __CONCAT3(SVR4_,a,b) < 0200000) { \ + bt->f &= ~__CONCAT(a,b); \ + switch (st->f & __CONCAT3(SVR4_,a,b)) { \ + case __CONCAT3(SVR4_,c1,t1): bt->f |= __CONCAT(c1,t1); break; \ + case __CONCAT3(SVR4_,c2,t2): bt->f |= __CONCAT(c2,t2); break; \ + case __CONCAT3(SVR4_,c3,t3): bt->f |= __CONCAT(c3,t3); break; \ + case __CONCAT3(SVR4_,c4,t4): bt->f |= __CONCAT(c4,t4); break; \ + } \ + } + + +#define bsd_to_svr4_char(a,b) \ + if (bt->c_cc[__CONCAT(a,b)] == _POSIX_VDISABLE) \ + st->c_cc[__CONCAT3(SVR4_,a,b)] = SVR4_POSIX_VDISABLE; \ + else \ + st->c_cc[__CONCAT3(SVR4_,a,b)] = bt->c_cc[__CONCAT(a,b)] + +#define bsd_to_svr4_flag1(f,a,b) \ + if (bt->f & __CONCAT(a,b)) \ + st->f |= __CONCAT3(SVR4_,a,b); \ + else \ + st->f &= ~__CONCAT3(SVR4_,a,b) + +#define bsd_to_svr4_flag2(f,a,b,c1,t1,c2,t2) \ + st->f &= ~__CONCAT(a,b); \ + switch (bt->f & __CONCAT(a,b)) { \ + case __CONCAT(c1,t1): st->f |= __CONCAT3(SVR4_,c1,t1); break; \ + case __CONCAT(c2,t2): st->f |= __CONCAT3(SVR4_,c2,t2); break; \ + } + +#define bsd_to_svr4_flag4(f,a,b,c1,t1,c2,t2,c3,t3,c4,t4) \ + st->f &= ~__CONCAT(a,b); \ + switch (bt->f & __CONCAT(a,b)) { \ + case __CONCAT(c1,t1): st->f |= __CONCAT3(SVR4_,c1,t1); break; \ + case __CONCAT(c2,t2): st->f |= __CONCAT3(SVR4_,c2,t2); break; \ + case __CONCAT(c3,t3): st->f |= __CONCAT3(SVR4_,c3,t3); break; \ + case __CONCAT(c4,t4): st->f |= __CONCAT3(SVR4_,c4,t4); break; \ + } + +#ifdef DEBUG_SVR4 +static void +print_svr4_termios(st) + const struct svr4_termios *st; +{ + int i; + DPRINTF(("SVR4\niflag=%lo oflag=%lo cflag=%lo lflag=%lo\n", + st->c_iflag, st->c_oflag, st->c_cflag, st->c_lflag)); + DPRINTF(("cc: ")); + for (i = 0; i < SVR4_NCCS; i++) + DPRINTF(("%o ", st->c_cc[i])); + DPRINTF(("\n")); +} + + +static void +print_bsd_termios(bt) + const struct termios *bt; +{ + int i; + uprintf("BSD\niflag=%o oflag=%o cflag=%o lflag=%o\n", + bt->c_iflag, bt->c_oflag, bt->c_cflag, bt->c_lflag); + uprintf("cc: "); + for (i = 0; i < NCCS; i++) + uprintf("%o ", bt->c_cc[i]); + uprintf("\n"); +} +#endif /* DEBUG_SVR4 */ + +static u_long +bsd_to_svr4_speed(sp, mask) + u_long sp; + u_long mask; +{ + switch (sp) { +#undef getval +#define getval(a,b) case __CONCAT(a,b): sp = __CONCAT3(SVR4_,a,b) + getval(B,0); + getval(B,50); + getval(B,75); + getval(B,110); + getval(B,134); + getval(B,150); + getval(B,200); + getval(B,300); + getval(B,600); + getval(B,1200); + getval(B,1800); + getval(B,2400); + getval(B,4800); + getval(B,9600); + getval(B,19200); + getval(B,38400); + getval(B,57600); + getval(B,115200); + default: sp = SVR4_B9600; /* XXX */ + } + + while ((mask & 1) == 0) { + mask >>= 1; + sp <<= 1; + } + + return sp; +} + + +static u_long +svr4_to_bsd_speed(sp, mask) + u_long sp; + u_long mask; +{ + while ((mask & 1) == 0) { + mask >>= 1; + sp >>= 1; + } + + switch (sp & mask) { +#undef getval +#define getval(a,b) case __CONCAT3(SVR4_,a,b): return __CONCAT(a,b) + getval(B,0); + getval(B,50); + getval(B,75); + getval(B,110); + getval(B,134); + getval(B,150); + getval(B,200); + getval(B,300); + getval(B,600); + getval(B,1200); + getval(B,1800); + getval(B,2400); + getval(B,4800); + getval(B,9600); + getval(B,19200); + getval(B,38400); + getval(B,57600); + getval(B,115200); + default: return B9600; /* XXX */ + } +} + + +static void +svr4_to_bsd_termios(st, bt, new) + const struct svr4_termios *st; + struct termios *bt; + int new; +{ + /* control characters */ + /* + * We process VMIN and VTIME first, + * because they are shared with VEOF and VEOL + */ + svr4_to_bsd_char(V,MIN); + svr4_to_bsd_char(V,TIME); + + svr4_to_bsd_char(V,INTR); + svr4_to_bsd_char(V,QUIT); + svr4_to_bsd_char(V,ERASE); + svr4_to_bsd_char(V,KILL); + svr4_to_bsd_char(V,EOF); + svr4_to_bsd_char(V,EOL); + svr4_to_bsd_char(V,EOL2); + undefined_char(V,SWTCH); + svr4_to_bsd_char(V,START); + svr4_to_bsd_char(V,STOP); + svr4_to_bsd_char(V,SUSP); + svr4_to_bsd_char(V,DSUSP); + svr4_to_bsd_char(V,REPRINT); + svr4_to_bsd_char(V,DISCARD); + svr4_to_bsd_char(V,WERASE); + svr4_to_bsd_char(V,LNEXT); + + /* Input modes */ + svr4_to_bsd_flag1(c_iflag,I,GNBRK); + svr4_to_bsd_flag1(c_iflag,B,RKINT); + svr4_to_bsd_flag1(c_iflag,I,GNPAR); + svr4_to_bsd_flag1(c_iflag,P,ARMRK); + svr4_to_bsd_flag1(c_iflag,I,NPCK); + svr4_to_bsd_flag1(c_iflag,I,STRIP); + svr4_to_bsd_flag1(c_iflag,I,NLCR); + svr4_to_bsd_flag1(c_iflag,I,GNCR); + svr4_to_bsd_flag1(c_iflag,I,CRNL); + undefined_flag1(c_iflag,I,UCLC); + svr4_to_bsd_flag1(c_iflag,I,XON); + svr4_to_bsd_flag1(c_iflag,I,XANY); + svr4_to_bsd_flag1(c_iflag,I,XOFF); + svr4_to_bsd_flag1(c_iflag,I,MAXBEL); + undefined_flag1(c_iflag,D,OSMODE); + + /* Output modes */ + svr4_to_bsd_flag1(c_oflag,O,POST); + undefined_flag1(c_oflag,O,LCUC); + svr4_to_bsd_flag1(c_oflag,O,NLCR); + undefined_flag1(c_oflag,O,CRNL); + undefined_flag1(c_oflag,O,NOCR); + undefined_flag1(c_oflag,O,NLRET); + undefined_flag1(c_oflag,O,FILL); + undefined_flag1(c_oflag,O,FDEL); + undefined_flag2(c_oflag,N,LDLY,N,L0,N,L1); + undefined_flag4(c_oflag,C,RDLY,C,R0,C,R1,C,R2,C,R3); + undefined_flag4(c_oflag,T,ABDLY,T,AB0,T,AB1,T,AB2,T,AB3); + undefined_flag2(c_oflag,B,SDLY,B,S0,B,S1); + undefined_flag2(c_oflag,V,TDLY,V,T0,V,T1); + undefined_flag2(c_oflag,F,FDLY,F,F0,F,F1); + undefined_flag1(c_oflag,P,AGEOUT); + undefined_flag1(c_oflag,W,RAP); + + /* Control modes */ + bt->c_ospeed = svr4_to_bsd_speed(st->c_cflag, SVR4_CBAUD); + svr4_to_bsd_flag4(c_cflag,C,SIZE,C,S5,C,S6,C,S7,C,S8) + svr4_to_bsd_flag1(c_cflag,C,STOPB); + svr4_to_bsd_flag1(c_cflag,C,READ); + svr4_to_bsd_flag1(c_cflag,P,ARENB); + svr4_to_bsd_flag1(c_cflag,P,ARODD); + svr4_to_bsd_flag1(c_cflag,H,UPCL); + svr4_to_bsd_flag1(c_cflag,C,LOCAL); + undefined_flag1(c_cflag,R,CV1EN); + undefined_flag1(c_cflag,X,MT1EN); + undefined_flag1(c_cflag,L,OBLK); + undefined_flag1(c_cflag,X,CLUDE); + bt->c_ispeed = svr4_to_bsd_speed(st->c_cflag, SVR4_CIBAUD); + undefined_flag1(c_cflag,P,AREXT); + + /* line discipline modes */ + svr4_to_bsd_flag1(c_lflag,I,SIG); + svr4_to_bsd_flag1(c_lflag,I,CANON); + undefined_flag1(c_lflag,X,CASE); + svr4_to_bsd_flag1(c_lflag,E,CHO); + svr4_to_bsd_flag1(c_lflag,E,CHOE); + svr4_to_bsd_flag1(c_lflag,E,CHOK); + svr4_to_bsd_flag1(c_lflag,E,CHONL); + svr4_to_bsd_flag1(c_lflag,N,OFLSH); + svr4_to_bsd_flag1(c_lflag,T,OSTOP); + svr4_to_bsd_flag1(c_lflag,E,CHOCTL); + svr4_to_bsd_flag1(c_lflag,E,CHOPRT); + svr4_to_bsd_flag1(c_lflag,E,CHOKE); + undefined_flag1(c_lflag,D,EFECHO); + svr4_to_bsd_flag1(c_lflag,F,LUSHO); + svr4_to_bsd_flag1(c_lflag,P,ENDIN); + svr4_to_bsd_flag1(c_lflag,I,EXTEN); +} + + +static void +bsd_to_svr4_termios(bt, st) + const struct termios *bt; + struct svr4_termios *st; +{ + /* control characters */ + /* + * We process VMIN and VTIME first, + * because they are shared with VEOF and VEOL + */ + bsd_to_svr4_char(V,MIN); + bsd_to_svr4_char(V,TIME); + bsd_to_svr4_char(V,INTR); + bsd_to_svr4_char(V,QUIT); + bsd_to_svr4_char(V,ERASE); + bsd_to_svr4_char(V,KILL); + bsd_to_svr4_char(V,EOF); + bsd_to_svr4_char(V,EOL); + bsd_to_svr4_char(V,EOL2); + undefined_char(V,SWTCH); + bsd_to_svr4_char(V,START); + bsd_to_svr4_char(V,STOP); + bsd_to_svr4_char(V,SUSP); + bsd_to_svr4_char(V,DSUSP); + bsd_to_svr4_char(V,REPRINT); + bsd_to_svr4_char(V,DISCARD); + bsd_to_svr4_char(V,WERASE); + bsd_to_svr4_char(V,LNEXT); + + /* Input modes */ + bsd_to_svr4_flag1(c_iflag,I,GNBRK); + bsd_to_svr4_flag1(c_iflag,B,RKINT); + bsd_to_svr4_flag1(c_iflag,I,GNPAR); + bsd_to_svr4_flag1(c_iflag,P,ARMRK); + bsd_to_svr4_flag1(c_iflag,I,NPCK); + bsd_to_svr4_flag1(c_iflag,I,STRIP); + bsd_to_svr4_flag1(c_iflag,I,NLCR); + bsd_to_svr4_flag1(c_iflag,I,GNCR); + bsd_to_svr4_flag1(c_iflag,I,CRNL); + undefined_flag1(c_iflag,I,UCLC); + bsd_to_svr4_flag1(c_iflag,I,XON); + bsd_to_svr4_flag1(c_iflag,I,XANY); + bsd_to_svr4_flag1(c_iflag,I,XOFF); + bsd_to_svr4_flag1(c_iflag,I,MAXBEL); + undefined_flag1(c_iflag,D,OSMODE); + + /* Output modes */ + bsd_to_svr4_flag1(c_oflag,O,POST); + undefined_flag1(c_oflag,O,LCUC); + bsd_to_svr4_flag1(c_oflag,O,NLCR); + undefined_flag1(c_oflag,O,CRNL); + undefined_flag1(c_oflag,O,NOCR); + undefined_flag1(c_oflag,O,NLRET); + undefined_flag1(c_oflag,O,FILL); + undefined_flag1(c_oflag,O,FDEL); + undefined_flag2(c_oflag,N,LDLY,N,L0,N,L1); + undefined_flag4(c_oflag,C,RDLY,C,R0,C,R1,C,R2,C,R3); + undefined_flag4(c_oflag,T,ABDLY,T,AB0,T,AB1,T,AB2,T,AB3); + undefined_flag2(c_oflag,B,SDLY,B,S0,B,S1); + undefined_flag2(c_oflag,V,TDLY,V,T0,V,T1); + undefined_flag2(c_oflag,F,FDLY,F,F0,F,F1); + undefined_flag1(c_oflag,P,AGEOUT); + undefined_flag1(c_oflag,W,RAP); + + /* Control modes */ + st->c_cflag &= ~SVR4_CBAUD; + st->c_cflag |= bsd_to_svr4_speed(bt->c_ospeed, SVR4_CBAUD); + bsd_to_svr4_flag4(c_cflag,C,SIZE,C,S5,C,S6,C,S7,C,S8) + bsd_to_svr4_flag1(c_cflag,C,STOPB); + bsd_to_svr4_flag1(c_cflag,C,READ); + bsd_to_svr4_flag1(c_cflag,P,ARENB); + bsd_to_svr4_flag1(c_cflag,P,ARODD); + bsd_to_svr4_flag1(c_cflag,H,UPCL); + bsd_to_svr4_flag1(c_cflag,C,LOCAL); + undefined_flag1(c_cflag,R,CV1EN); + undefined_flag1(c_cflag,X,MT1EN); + undefined_flag1(c_cflag,L,OBLK); + undefined_flag1(c_cflag,X,CLUDE); + st->c_cflag &= ~SVR4_CIBAUD; + st->c_cflag |= bsd_to_svr4_speed(bt->c_ispeed, SVR4_CIBAUD); + + undefined_flag1(c_oflag,P,AREXT); + + /* line discipline modes */ + bsd_to_svr4_flag1(c_lflag,I,SIG); + bsd_to_svr4_flag1(c_lflag,I,CANON); + undefined_flag1(c_lflag,X,CASE); + bsd_to_svr4_flag1(c_lflag,E,CHO); + bsd_to_svr4_flag1(c_lflag,E,CHOE); + bsd_to_svr4_flag1(c_lflag,E,CHOK); + bsd_to_svr4_flag1(c_lflag,E,CHONL); + bsd_to_svr4_flag1(c_lflag,N,OFLSH); + bsd_to_svr4_flag1(c_lflag,T,OSTOP); + bsd_to_svr4_flag1(c_lflag,E,CHOCTL); + bsd_to_svr4_flag1(c_lflag,E,CHOPRT); + bsd_to_svr4_flag1(c_lflag,E,CHOKE); + undefined_flag1(c_lflag,D,EFECHO); + bsd_to_svr4_flag1(c_lflag,F,LUSHO); + bsd_to_svr4_flag1(c_lflag,P,ENDIN); + bsd_to_svr4_flag1(c_lflag,I,EXTEN); +} + + +static void +svr4_termio_to_termios(t, ts) + const struct svr4_termio *t; + struct svr4_termios *ts; +{ + int i; + + ts->c_iflag = (svr4_tcflag_t) t->c_iflag; + ts->c_oflag = (svr4_tcflag_t) t->c_oflag; + ts->c_cflag = (svr4_tcflag_t) t->c_cflag; + ts->c_lflag = (svr4_tcflag_t) t->c_lflag; + + for (i = 0; i < SVR4_NCC; i++) + ts->c_cc[i] = (svr4_cc_t) t->c_cc[i]; +} + + +static void +svr4_termios_to_termio(ts, t) + const struct svr4_termios *ts; + struct svr4_termio *t; +{ + int i; + + t->c_iflag = (u_short) ts->c_iflag; + t->c_oflag = (u_short) ts->c_oflag; + t->c_cflag = (u_short) ts->c_cflag; + t->c_lflag = (u_short) ts->c_lflag; + t->c_line = 0; /* XXX */ + + for (i = 0; i < SVR4_NCC; i++) + t->c_cc[i] = (u_char) ts->c_cc[i]; +} + +int +svr4_term_ioctl(fp, p, retval, fd, cmd, data) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t data; +{ + struct termios bt; + struct svr4_termios st; + struct svr4_termio t; + int error, new; + int (*ctl) __P((struct file *, u_long, caddr_t, struct proc *)) = + fp->f_ops->fo_ioctl; + + *retval = 0; + + DPRINTF(("TERM ioctl %x\n", cmd)); + + switch (cmd) { + case SVR4_TCGETA: + case SVR4_TCGETS: + DPRINTF(("ioctl(TCGET%c);\n", cmd == SVR4_TCGETA ? 'A' : 'S')); + if ((error = (*ctl)(fp, TIOCGETA, (caddr_t) &bt, p)) != 0) + return error; + + memset(&st, 0, sizeof(st)); + bsd_to_svr4_termios(&bt, &st); + +#ifdef DEBUG_SVR4 + print_bsd_termios(&bt); + print_svr4_termios(&st); +#endif /* DEBUG_SVR4 */ + + if (cmd == SVR4_TCGETA) { + svr4_termios_to_termio(&st, &t); + return copyout(&t, data, sizeof(t)); + } + else { + return copyout(&st, data, sizeof(st)); + } + + case SVR4_TCSETA: + case SVR4_TCSETS: + case SVR4_TCSETAW: + case SVR4_TCSETSW: + case SVR4_TCSETAF: + case SVR4_TCSETSF: + DPRINTF(("TCSET{A,S,AW,SW,AF,SF}\n")); + /* get full BSD termios so we don't lose information */ + if ((error = (*ctl)(fp, TIOCGETA, (caddr_t) &bt, p)) != 0) + return error; + + switch (cmd) { + case SVR4_TCSETS: + case SVR4_TCSETSW: + case SVR4_TCSETSF: + if ((error = copyin(data, &st, sizeof(st))) != 0) + return error; + new = 1; + break; + + case SVR4_TCSETA: + case SVR4_TCSETAW: + case SVR4_TCSETAF: + if ((error = copyin(data, &t, sizeof(t))) != 0) + return error; + + svr4_termio_to_termios(&t, &st); + new = 0; + break; + + default: + return EINVAL; + } + + svr4_to_bsd_termios(&st, &bt, new); + + switch (cmd) { + case SVR4_TCSETA: + case SVR4_TCSETS: + DPRINTF(("ioctl(TCSET[A|S]);\n")); + cmd = TIOCSETA; + break; + case SVR4_TCSETAW: + case SVR4_TCSETSW: + DPRINTF(("ioctl(TCSET[A|S]W);\n")); + cmd = TIOCSETAW; + break; + case SVR4_TCSETAF: + case SVR4_TCSETSF: + DPRINTF(("ioctl(TCSET[A|S]F);\n")); + cmd = TIOCSETAF; + break; + } + +#ifdef DEBUG_SVR4 + print_bsd_termios(&bt); + print_svr4_termios(&st); +#endif /* DEBUG_SVR4 */ + + return (*ctl)(fp, cmd, (caddr_t) &bt, p); + + case SVR4_TIOCGWINSZ: + DPRINTF(("TIOCGWINSZ\n")); + { + struct svr4_winsize ws; + + error = (*ctl)(fp, TIOCGWINSZ, (caddr_t) &ws, p); + if (error) + return error; + return copyout(&ws, data, sizeof(ws)); + } + + case SVR4_TIOCSWINSZ: + DPRINTF(("TIOCSWINSZ\n")); + { + struct svr4_winsize ws; + + if ((error = copyin(data, &ws, sizeof(ws))) != 0) + return error; + return (*ctl)(fp, TIOCSWINSZ, (caddr_t) &ws, p); + } + + default: + DPRINTF(("teleport to STREAMS ioctls...\n")); + return svr4_stream_ti_ioctl(fp, p, retval, fd, cmd, data); + } +} diff --git a/sys/compat/svr4/svr4_termios.h b/sys/compat/svr4/svr4_termios.h new file mode 100644 index 0000000..a8f40ad --- /dev/null +++ b/sys/compat/svr4/svr4_termios.h @@ -0,0 +1,222 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_TERMIOS_H_ +#define _SVR4_TERMIOS_H_ + +#define SVR4_POSIX_VDISABLE 0 +#define SVR4_NCC 8 +#define SVR4_NCCS 19 + +typedef u_long svr4_tcflag_t; +typedef u_char svr4_cc_t; +typedef u_long svr4_speed_t; + +struct svr4_termios { + svr4_tcflag_t c_iflag; + svr4_tcflag_t c_oflag; + svr4_tcflag_t c_cflag; + svr4_tcflag_t c_lflag; + svr4_cc_t c_cc[SVR4_NCCS]; +}; + +struct svr4_termio { + u_short c_iflag; + u_short c_oflag; + u_short c_cflag; + u_short c_lflag; + char c_line; + u_char c_cc[SVR4_NCC]; +}; + +/* control characters */ +#define SVR4_VINTR 0 +#define SVR4_VQUIT 1 +#define SVR4_VERASE 2 +#define SVR4_VKILL 3 +#define SVR4_VEOF 4 +#define SVR4_VEOL 5 +#define SVR4_VEOL2 6 +#define SVR4_VMIN 4 +#define SVR4_VTIME 5 +#define SVR4_VSWTCH 7 +#define SVR4_VSTART 8 +#define SVR4_VSTOP 9 +#define SVR4_VSUSP 10 +#define SVR4_VDSUSP 11 +#define SVR4_VREPRINT 12 +#define SVR4_VDISCARD 13 +#define SVR4_VWERASE 14 +#define SVR4_VLNEXT 15 + +/* Input modes */ +#define SVR4_IGNBRK 00000001 +#define SVR4_BRKINT 00000002 +#define SVR4_IGNPAR 00000004 +#define SVR4_PARMRK 00000010 +#define SVR4_INPCK 00000020 +#define SVR4_ISTRIP 00000040 +#define SVR4_INLCR 00000100 +#define SVR4_IGNCR 00000200 +#define SVR4_ICRNL 00000400 +#define SVR4_IUCLC 00001000 +#define SVR4_IXON 00002000 +#define SVR4_IXANY 00004000 +#define SVR4_IXOFF 00010000 +#define SVR4_IMAXBEL 00020000 +#define SVR4_DOSMODE 00100000 + +/* Output modes */ +#define SVR4_OPOST 00000001 +#define SVR4_OLCUC 00000002 +#define SVR4_ONLCR 00000004 +#define SVR4_OCRNL 00000010 +#define SVR4_ONOCR 00000020 +#define SVR4_ONLRET 00000040 +#define SVR4_OFILL 00000100 +#define SVR4_OFDEL 00000200 +#define SVR4_NLDLY 00000400 +#define SVR4_NL0 00000000 +#define SVR4_NL1 00000400 +#define SVR4_CRDLY 00003000 +#define SVR4_CR0 00000000 +#define SVR4_CR1 00001000 +#define SVR4_CR2 00002000 +#define SVR4_CR3 00003000 +#define SVR4_TABDLY 00014000 +#define SVR4_TAB0 00000000 +#define SVR4_TAB1 00004000 +#define SVR4_TAB2 00010000 +#define SVR4_TAB3 00014000 +#define SVR4_XTABS 00014000 +#define SVR4_BSDLY 00020000 +#define SVR4_BS0 00000000 +#define SVR4_BS1 00020000 +#define SVR4_VTDLY 00040000 +#define SVR4_VT0 00000000 +#define SVR4_VT1 00040000 +#define SVR4_FFDLY 00100000 +#define SVR4_FF0 00000000 +#define SVR4_FF1 00100000 +#define SVR4_PAGEOUT 00200000 +#define SVR4_WRAP 00400000 + +/* Control modes */ +#define SVR4_CBAUD 00000017 +#define SVR4_CSIZE 00000060 +#define SVR4_CS5 00000000 +#define SVR4_CS6 00000200 +#define SVR4_CS7 00000040 +#define SVR4_CS8 00000006 +#define SVR4_CSTOPB 00000100 +#define SVR4_CREAD 00000200 +#define SVR4_PARENB 00000400 +#define SVR4_PARODD 00001000 +#define SVR4_HUPCL 00002000 +#define SVR4_CLOCAL 00004000 +#define SVR4_RCV1EN 00010000 +#define SVR4_XMT1EN 00020000 +#define SVR4_LOBLK 00040000 +#define SVR4_XCLUDE 00100000 +#define SVR4_CIBAUD 03600000 +#define SVR4_PAREXT 04000000 + +/* line discipline modes */ +#define SVR4_ISIG 00000001 +#define SVR4_ICANON 00000002 +#define SVR4_XCASE 00000004 +#define SVR4_ECHO 00000010 +#define SVR4_ECHOE 00000020 +#define SVR4_ECHOK 00000040 +#define SVR4_ECHONL 00000100 +#define SVR4_NOFLSH 00000200 +#define SVR4_TOSTOP 00000400 +#define SVR4_ECHOCTL 00001000 +#define SVR4_ECHOPRT 00002000 +#define SVR4_ECHOKE 00004000 +#define SVR4_DEFECHO 00010000 +#define SVR4_FLUSHO 00020000 +#define SVR4_PENDIN 00040000 +#define SVR4_IEXTEN 00100000 + +#define SVR4_TIOC ('T' << 8) + +#define SVR4_TCGETA (SVR4_TIOC| 1) +#define SVR4_TCSETA (SVR4_TIOC| 2) +#define SVR4_TCSETAW (SVR4_TIOC| 3) +#define SVR4_TCSETAF (SVR4_TIOC| 4) +#define SVR4_TCSBRK (SVR4_TIOC| 5) +#define SVR4_TCXONC (SVR4_TIOC| 6) +#define SVR4_TCFLSH (SVR4_TIOC| 7) +#define SVR4_TIOCKBON (SVR4_TIOC| 8) +#define SVR4_TIOCKBOF (SVR4_TIOC| 9) +#define SVR4_KBENABLED (SVR4_TIOC|10) +#define SVR4_TCGETS (SVR4_TIOC|13) +#define SVR4_TCSETS (SVR4_TIOC|14) +#define SVR4_TCSETSW (SVR4_TIOC|15) +#define SVR4_TCSETSF (SVR4_TIOC|16) +#define SVR4_TCDSET (SVR4_TIOC|32) +#define SVR4_RTS_TOG (SVR4_TIOC|33) +#define SVR4_TCGETSC (SVR4_TIOC|34) +#define SVR4_TCSETSC (SVR4_TIOC|35) +#define SVR4_TCMOUSE (SVR4_TIOC|36) +#define SVR4_TIOCGWINSZ (SVR4_TIOC|104) +#define SVR4_TIOCSWINSZ (SVR4_TIOC|103) + +struct svr4_winsize { + u_short ws_row; + u_short ws_col; + u_short ws_xpixel; + u_short ws_ypixel; +}; + +#define SVR4_B0 0 +#define SVR4_B50 1 +#define SVR4_B75 2 +#define SVR4_B110 3 +#define SVR4_B134 4 +#define SVR4_B150 5 +#define SVR4_B200 6 +#define SVR4_B300 7 +#define SVR4_B600 8 +#define SVR4_B1200 9 +#define SVR4_B1800 10 +#define SVR4_B2400 11 +#define SVR4_B4800 12 +#define SVR4_B9600 13 +#define SVR4_B19200 14 +#define SVR4_B38400 15 +#define SVR4_B57600 16 +#define SVR4_B76800 17 +#define SVR4_B115200 18 +#define SVR4_B153600 19 +#define SVR4_B230400 20 +#define SVR4_B307200 21 +#define SVR4_B460800 22 + +#endif /* !_SVR4_TERMIOS_H_ */ diff --git a/sys/compat/svr4/svr4_time.h b/sys/compat/svr4/svr4_time.h new file mode 100644 index 0000000..c92f4f4 --- /dev/null +++ b/sys/compat/svr4/svr4_time.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_TIME_H_ +#define _SVR4_TIME_H_ + +#include <sys/time.h> + +struct svr4_utimbuf { + time_t actime; + time_t modtime; +}; + +#endif /* !_SVR4_TIME_H_ */ diff --git a/sys/compat/svr4/svr4_timod.h b/sys/compat/svr4/svr4_timod.h new file mode 100644 index 0000000..277f1f4 --- /dev/null +++ b/sys/compat/svr4/svr4_timod.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_TIMOD_H_ +#define _SVR4_TIMOD_H_ + +#define SVR4_TIMOD ('T' << 8) +#define SVR4_TI_GETINFO (SVR4_TIMOD|140) +#define SVR4_TI_OPTMGMT (SVR4_TIMOD|141) +#define SVR4_TI_BIND (SVR4_TIMOD|142) +#define SVR4_TI_UNBIND (SVR4_TIMOD|143) +#define SVR4_TI_GETMYNAME (SVR4_TIMOD|144) +#define SVR4_TI_GETPEERNAME (SVR4_TIMOD|145) +#define SVR4_TI_SETMYNAME (SVR4_TIMOD|146) +#define SVR4_TI_SETPEERNAME (SVR4_TIMOD|147) +#define SVR4_TI_SYNC (SVR4_TIMOD|148) +#define SVR4_TI_GETADDRS (SVR4_TIMOD|149) + +#define SVR4_TI_CONNECT_REQUEST 0x00 +#define SVR4_TI_CONNECT_RESPONSE 0x01 +#define SVR4_TI_DISCONNECT_REQUEST 0x02 +#define SVR4_TI_DATA_REQUEST 0x03 +#define SVR4_TI_EXPDATA_REQUEST 0x04 +#define SVR4_TI_INFO_REQUEST 0x05 +#define SVR4_TI_OLD_BIND_REQUEST 0x06 +#define SVR4_TI_UNBIND_REQUEST 0x07 +#define SVR4_TI_SENDTO_REQUEST 0x08 +#define SVR4_TI_OLD_OPTMGMT_REQUEST 0x09 +#define SVR4_TI_ORDREL_REQUEST 0x0a + +#define SVR4_TI_ACCEPT_REPLY 0x0b +#define SVR4_TI_CONNECT_REPLY 0x0c +#define SVR4_TI_DISCONNECT_IND 0x0d +#define SVR4_TI_DATA_IND 0x0e +#define SVR4_TI_EXPDATA_IND 0x0f +#define SVR4_TI_INFO_REPLY 0x10 +#define SVR4_TI_BIND_REPLY 0x11 +#define SVR4_TI_ERROR_REPLY 0x12 +#define SVR4_TI_OK_REPLY 0x13 +#define SVR4_TI_RECVFROM_IND 0x14 +#define SVR4_TI_RECVFROM_ERROR_IND 0x15 +#define SVR4_TI_OPTMGMT_REPLY 0x16 +#define SVR4_TI_ORDREL_IND 0x17 + +#define SVR4_TI_ADDRESS_REQUEST 0x18 +#define SVR4_TI_ADDRESS_REPLY 0x19 + +#define SVR4_TI_BIND_REQUEST 0x20 +#define SVR4_TI_OPTMGMT_REQUEST 0x21 + +#define SVR4_TI__ACCEPT_WAIT 0x10000001 +#define SVR4_TI__ACCEPT_OK 0x10000002 + +struct svr4_netbuf { + u_int maxlen; + u_int len; + char *buf; +}; + +#endif /* !_SVR4_TIMOD_H_ */ diff --git a/sys/compat/svr4/svr4_ttold.c b/sys/compat/svr4/svr4_ttold.c new file mode 100644 index 0000000..691f1d6 --- /dev/null +++ b/sys/compat/svr4/svr4_ttold.c @@ -0,0 +1,381 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/file.h> +#include <sys/filedesc.h> +#include <sys/fcntl.h> +#include <sys/ioctl_compat.h> +#include <sys/unistd.h> +#include <sys/termios.h> +#include <sys/tty.h> +#include <sys/socket.h> +#include <sys/mount.h> +#include <net/if.h> +#include <sys/malloc.h> + +#include <sys/sysproto.h> + +#include <svr4/svr4_types.h> +#include <svr4/svr4_util.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_proto.h> +#include <svr4/svr4_stropts.h> +#include <svr4/svr4_ttold.h> +#include <svr4/svr4_ioctl.h> + + +static void svr4_tchars_to_bsd_tchars __P((const struct svr4_tchars *st, + struct tchars *bt)); +static void bsd_tchars_to_svr4_tchars __P((const struct tchars *bt, + struct svr4_tchars *st)); +static void svr4_sgttyb_to_bsd_sgttyb __P((const struct svr4_sgttyb *ss, + struct sgttyb *bs)); +static void bsd_sgttyb_to_svr4_sgttyb __P((const struct sgttyb *bs, + struct svr4_sgttyb *ss)); +static void svr4_ltchars_to_bsd_ltchars __P((const struct svr4_ltchars *sl, + struct ltchars *bl)); +static void bsd_ltchars_to_svr4_ltchars __P((const struct ltchars *bl, + struct svr4_ltchars *sl)); + +#ifdef DEBUG_SVR4 +static void print_svr4_sgttyb __P((const char *, struct svr4_sgttyb *)); +static void print_svr4_tchars __P((const char *, struct svr4_tchars *)); +static void print_svr4_ltchars __P((const char *, struct svr4_ltchars *)); + +static void +print_svr4_sgttyb(str, ss) + const char *str; + struct svr4_sgttyb *ss; +{ + + uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed); + uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill, + ss->sg_flags); +} + +static void +print_svr4_tchars(str, st) + const char *str; + struct svr4_tchars *st; +{ + uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc); + uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc, + st->t_stopc, st->t_eofc, st->t_brkc); +} + +static void +print_svr4_ltchars(str, sl) + const char *str; + struct svr4_ltchars *sl; +{ + uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc); + uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc, + sl->t_flushc, sl->t_werasc, sl->t_lnextc); +} +#endif /* DEBUG_SVR4 */ + +static void +svr4_tchars_to_bsd_tchars(st, bt) + const struct svr4_tchars *st; + struct tchars *bt; +{ + bt->t_intrc = st->t_intrc; + bt->t_quitc = st->t_quitc; + bt->t_startc = st->t_startc; + bt->t_stopc = st->t_stopc; + bt->t_eofc = st->t_eofc; + bt->t_brkc = st->t_brkc; +} + + +static void +bsd_tchars_to_svr4_tchars(bt, st) + const struct tchars *bt; + struct svr4_tchars *st; +{ + st->t_intrc = bt->t_intrc; + st->t_quitc = bt->t_quitc; + st->t_startc = bt->t_startc; + st->t_stopc = bt->t_stopc; + st->t_eofc = bt->t_eofc; + st->t_brkc = bt->t_brkc; +} + + +static void +svr4_sgttyb_to_bsd_sgttyb(ss, bs) + const struct svr4_sgttyb *ss; + struct sgttyb *bs; +{ + bs->sg_ispeed = ss->sg_ispeed; + bs->sg_ospeed = ss->sg_ospeed; + bs->sg_erase = ss->sg_erase; + bs->sg_kill = ss->sg_kill; + bs->sg_flags = ss->sg_flags; +}; + + +static void +bsd_sgttyb_to_svr4_sgttyb(bs, ss) + const struct sgttyb *bs; + struct svr4_sgttyb *ss; +{ + ss->sg_ispeed = bs->sg_ispeed; + ss->sg_ospeed = bs->sg_ospeed; + ss->sg_erase = bs->sg_erase; + ss->sg_kill = bs->sg_kill; + ss->sg_flags = bs->sg_flags; +} + + +static void +svr4_ltchars_to_bsd_ltchars(sl, bl) + const struct svr4_ltchars *sl; + struct ltchars *bl; +{ + bl->t_suspc = sl->t_suspc; + bl->t_dsuspc = sl->t_dsuspc; + bl->t_rprntc = sl->t_rprntc; + bl->t_flushc = sl->t_flushc; + bl->t_werasc = sl->t_werasc; + bl->t_lnextc = sl->t_lnextc; +} + + +static void +bsd_ltchars_to_svr4_ltchars(bl, sl) + const struct ltchars *bl; + struct svr4_ltchars *sl; +{ + sl->t_suspc = bl->t_suspc; + sl->t_dsuspc = bl->t_dsuspc; + sl->t_rprntc = bl->t_rprntc; + sl->t_flushc = bl->t_flushc; + sl->t_werasc = bl->t_werasc; + sl->t_lnextc = bl->t_lnextc; +} + + +int +svr4_ttold_ioctl(fp, p, retval, fd, cmd, data) + struct file *fp; + struct proc *p; + register_t *retval; + int fd; + u_long cmd; + caddr_t data; +{ + int error; + int (*ctl) __P((struct file *, u_long, caddr_t, struct proc *)) = + fp->f_ops->fo_ioctl; + + *retval = 0; + + switch (cmd) { + case SVR4_TIOCGPGRP: + { + pid_t pid; + + if ((error = (*ctl)(fp, TIOCGPGRP, + (caddr_t) &pid, p)) != 0) + return error; + + DPRINTF(("TIOCGPGRP %d\n", pid)); + + if ((error = copyout(&pid, data, sizeof(pid))) != 0) + return error; + + } + + case SVR4_TIOCSPGRP: + { + pid_t pid; + + if ((error = copyin(data, &pid, sizeof(pid))) != 0) + return error; + + DPRINTF(("TIOCSPGRP %d\n", pid)); + + return (*ctl)(fp, TIOCSPGRP, (caddr_t) &pid, p); + } + + case SVR4_TIOCGSID: + { +#if defined(TIOCGSID) + pid_t pid; + if ((error = (*ctl)(fp, TIOCGSID, + (caddr_t) &pid, p)) != 0) + return error; + + DPRINTF(("TIOCGSID %d\n", pid)); + + return copyout(&pid, data, sizeof(pid)); +#else + uprintf("ioctl(TIOCGSID) for pid %d unsupported\n", p->p_pid); + return EINVAL; +#endif + } + + case SVR4_TIOCGETP: + { + struct sgttyb bs; + struct svr4_sgttyb ss; + + error = (*ctl)(fp, TIOCGETP, (caddr_t) &bs, p); + if (error) + return error; + + bsd_sgttyb_to_svr4_sgttyb(&bs, &ss); +#ifdef DEBUG_SVR4 + print_svr4_sgttyb("SVR4_TIOCGETP", &ss); +#endif /* DEBUG_SVR4 */ + return copyout(&ss, data, sizeof(ss)); + } + + case SVR4_TIOCSETP: + case SVR4_TIOCSETN: + { + struct sgttyb bs; + struct svr4_sgttyb ss; + + if ((error = copyin(data, &ss, sizeof(ss))) != 0) + return error; + + svr4_sgttyb_to_bsd_sgttyb(&ss, &bs); +#ifdef DEBUG_SVR4 + print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss); +#endif /* DEBUG_SVR4 */ + cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN; + return (*ctl)(fp, cmd, (caddr_t) &bs, p); + } + + case SVR4_TIOCGETC: + { + struct tchars bt; + struct svr4_tchars st; + + error = (*ctl)(fp, TIOCGETC, (caddr_t) &bt, p); + if (error) + return error; + + bsd_tchars_to_svr4_tchars(&bt, &st); +#ifdef DEBUG_SVR4 + print_svr4_tchars("SVR4_TIOCGETC", &st); +#endif /* DEBUG_SVR4 */ + return copyout(&st, data, sizeof(st)); + } + + case SVR4_TIOCSETC: + { + struct tchars bt; + struct svr4_tchars st; + + if ((error = copyin(data, &st, sizeof(st))) != 0) + return error; + + svr4_tchars_to_bsd_tchars(&st, &bt); +#ifdef DEBUG_SVR4 + print_svr4_tchars("SVR4_TIOCSETC", &st); +#endif /* DEBUG_SVR4 */ + return (*ctl)(fp, TIOCSETC, (caddr_t) &bt, p); + } + + case SVR4_TIOCGLTC: + { + struct ltchars bl; + struct svr4_ltchars sl; + + error = (*ctl)(fp, TIOCGLTC, (caddr_t) &bl, p); + if (error) + return error; + + bsd_ltchars_to_svr4_ltchars(&bl, &sl); +#ifdef DEBUG_SVR4 + print_svr4_ltchars("SVR4_TIOCGLTC", &sl); +#endif /* DEBUG_SVR4 */ + return copyout(&sl, data, sizeof(sl)); + } + + case SVR4_TIOCSLTC: + { + struct ltchars bl; + struct svr4_ltchars sl; + + if ((error = copyin(data, &sl, sizeof(sl))) != 0) + return error; + + svr4_ltchars_to_bsd_ltchars(&sl, &bl); +#ifdef DEBUG_SVR4 + print_svr4_ltchars("SVR4_TIOCSLTC", &sl); +#endif /* DEBUG_SVR4 */ + return (*ctl)(fp, TIOCSLTC, (caddr_t) &bl, p); + } + + case SVR4_TIOCLGET: + { + int flags; + if ((error = (*ctl)(fp, TIOCLGET, + (caddr_t) &flags, p)) != 0) + return error; + DPRINTF(("SVR4_TIOCLGET %o\n", flags)); + return copyout(&flags, data, sizeof(flags)); + } + + case SVR4_TIOCLSET: + case SVR4_TIOCLBIS: + case SVR4_TIOCLBIC: + { + int flags; + + if ((error = copyin(data, &flags, sizeof(flags))) != 0) + return error; + + switch (cmd) { + case SVR4_TIOCLSET: + cmd = TIOCLSET; + break; + case SVR4_TIOCLBIS: + cmd = TIOCLBIS; + break; + case SVR4_TIOCLBIC: + cmd = TIOCLBIC; + break; + } + + DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags)); + return (*ctl)(fp, cmd, (caddr_t) &flags, p); + } + + default: + DPRINTF(("Unknown svr4 ttold %lx\n", cmd)); + return 0; /* ENOSYS really */ + } +} diff --git a/sys/compat/svr4/svr4_ttold.h b/sys/compat/svr4/svr4_ttold.h new file mode 100644 index 0000000..edc0762 --- /dev/null +++ b/sys/compat/svr4/svr4_ttold.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_TTOLD_H_ +#define _SVR4_TTOLD_H_ + +struct svr4_tchars { + char t_intrc; + char t_quitc; + char t_startc; + char t_stopc; + char t_eofc; + char t_brkc; +}; + +struct svr4_sgttyb { + u_char sg_ispeed; + u_char sg_ospeed; + u_char sg_erase; + u_char sg_kill; + int sg_flags; +}; + +struct svr4_ltchars { + char t_suspc; + char t_dsuspc; + char t_rprntc; + char t_flushc; + char t_werasc; + char t_lnextc; +}; + +#ifndef SVR4_tIOC +#define SVR4_tIOC ('t' << 8) +#endif + +#define SVR4_TIOCGETD (SVR4_tIOC | 0) +#define SVR4_TIOCSETD (SVR4_tIOC | 1) +#define SVR4_TIOCHPCL (SVR4_tIOC | 2) +#define SVR4_TIOCGETP (SVR4_tIOC | 8) +#define SVR4_TIOCSETP (SVR4_tIOC | 9) +#define SVR4_TIOCSETN (SVR4_tIOC | 10) +#define SVR4_TIOCEXCL (SVR4_tIOC | 13) +#define SVR4_TIOCNXCL (SVR4_tIOC | 14) +#define SVR4_TIOCFLUSH (SVR4_tIOC | 16) +#define SVR4_TIOCSETC (SVR4_tIOC | 17) +#define SVR4_TIOCGETC (SVR4_tIOC | 18) +#define SVR4_TIOCGPGRP (SVR4_tIOC | 20) +#define SVR4_TIOCSPGRP (SVR4_tIOC | 21) +#define SVR4_TIOCGSID (SVR4_tIOC | 22) +#define SVR4_TIOCSTI (SVR4_tIOC | 23) +#define SVR4_TIOCSSID (SVR4_tIOC | 24) +#define SVR4_TIOCMSET (SVR4_tIOC | 26) +#define SVR4_TIOCMBIS (SVR4_tIOC | 27) +#define SVR4_TIOCMBIC (SVR4_tIOC | 28) +#define SVR4_TIOCMGET (SVR4_tIOC | 29) +#define SVR4_TIOCREMOTE (SVR4_tIOC | 30) +#define SVR4_TIOCSIGNAL (SVR4_tIOC | 31) + +#define SVR4_TIOCSTART (SVR4_tIOC | 110) +#define SVR4_TIOCSTOP (SVR4_tIOC | 111) +#define SVR4_TIOCNOTTY (SVR4_tIOC | 113) +#define SVR4_TIOCOUTQ (SVR4_tIOC | 115) +#define SVR4_TIOCGLTC (SVR4_tIOC | 116) +#define SVR4_TIOCSLTC (SVR4_tIOC | 117) +#define SVR4_TIOCCDTR (SVR4_tIOC | 120) +#define SVR4_TIOCSDTR (SVR4_tIOC | 121) +#define SVR4_TIOCCBRK (SVR4_tIOC | 122) +#define SVR4_TIOCSBRK (SVR4_tIOC | 123) +#define SVR4_TIOCLGET (SVR4_tIOC | 124) +#define SVR4_TIOCLSET (SVR4_tIOC | 125) +#define SVR4_TIOCLBIC (SVR4_tIOC | 126) +#define SVR4_TIOCLBIS (SVR4_tIOC | 127) + +#define SVR4_TIOCM_LE 0001 +#define SVR4_TIOCM_DTR 0002 +#define SVR4_TIOCM_RTS 0004 +#define SVR4_TIOCM_ST 0010 +#define SVR4_TIOCM_SR 0020 +#define SVR4_TIOCM_CTS 0040 +#define SVR4_TIOCM_CAR 0100 +#define SVR4_TIOCM_CD SVR4_TIOCM_CAR +#define SVR4_TIOCM_RNG 0200 +#define SVR4_TIOCM_RI SVR4_TIOCM_RNG +#define SVR4_TIOCM_DSR 0400 + +#define SVR4_OTTYDISC 0 +#define SVR4_NETLDISC 1 +#define SVR4_NTTYDISC 2 +#define SVR4_TABLDISC 3 +#define SVR4_NTABLDISC 4 +#define SVR4_MOUSELDISC 5 +#define SVR4_KBDLDISC 6 + +#endif /* !_SVR4_TTOLD_H_ */ diff --git a/sys/compat/svr4/svr4_types.h b/sys/compat/svr4/svr4_types.h new file mode 100644 index 0000000..406e0da --- /dev/null +++ b/sys/compat/svr4/svr4_types.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_TYPES_H_ +#define _SVR4_TYPES_H_ + +typedef u_quad_t svr4_ino64_t; +typedef quad_t svr4_off64_t; +typedef quad_t svr4_blkcnt64_t; +typedef u_quad_t svr4_fsblkcnt64_t; + +typedef long svr4_off_t; +typedef u_long svr4_dev_t; +typedef u_long svr4_ino_t; +typedef u_long svr4_mode_t; +typedef u_long svr4_nlink_t; +typedef long svr4_uid_t; +typedef long svr4_gid_t; +typedef long svr4_daddr_t; +typedef long svr4_pid_t; +typedef long svr4_time_t; +typedef long svr4_blkcnt_t; +typedef u_long svr4_fsblkcnt_t; +typedef char *svr4_caddr_t; +typedef u_int svr4_size_t; + +typedef short svr4_o_dev_t; +typedef short svr4_o_pid_t; +typedef u_short svr4_o_ino_t; +typedef u_short svr4_o_mode_t; +typedef short svr4_o_nlink_t; +typedef u_short svr4_o_uid_t; +typedef u_short svr4_o_gid_t; +typedef long svr4_clock_t; +typedef int svr4_key_t; + +typedef struct timespec svr4_timestruc_t; + +#define svr4_omajor(x) ((int32_t)((((x) & 0x7f00) >> 8))) +#define svr4_ominor(x) ((int32_t)((((x) & 0x00ff) >> 0))) +#define svr4_omakedev(x,y) ((svr4_o_dev_t)((((x) << 8) & 0x7f00) | \ + (((y) << 0) & 0x00ff))) + +#define svr4_to_bsd_odev_t(d) makedev(svr4_omajor(d), svr4_ominor(d)) +#define bsd_to_svr4_odev_t(d) svr4_omakedev(major(d), minor(d)) + +#define svr4_major(x) ((int32_t)((((x) & 0xfffc0000) >> 18))) +#define svr4_minor(x) ((int32_t)((((x) & 0x0003ffff) >> 0))) +#define svr4_makedev(x,y) ((svr4_dev_t)((((x) << 18) & 0xfffc0000) | \ + (((y) << 0) & 0x0003ffff))) +#define svr4_to_bsd_dev_t(d) makedev(svr4_major(d), svr4_minor(d)) +#define bsd_to_svr4_dev_t(d) svr4_makedev(major(d), minor(d)) + +#endif /* !_SVR4_TYPES_H_ */ diff --git a/sys/compat/svr4/svr4_ucontext.h b/sys/compat/svr4/svr4_ucontext.h new file mode 100644 index 0000000..e2bdb82 --- /dev/null +++ b/sys/compat/svr4/svr4_ucontext.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_UCONTEXT_H_ +#define _SVR4_UCONTEXT_H_ + +/* + * Machine context + */ + +#define SVR4_UC_SIGMASK 0x01 +#define SVR4_UC_STACK 0x02 + +#define SVR4_UC_CPU 0x04 +#define SVR4_UC_FPU 0x08 +#define SVR4_UC_WEITEK 0x10 + +#define SVR4_UC_MCONTEXT (SVR4_UC_CPU|SVR4_UC_FPU|SVR4_UC_WEITEK) + +#define SVR4_UC_ALL (SVR4_UC_SIGMASK|SVR4_UC_STACK|SVR4_UC_MCONTEXT) + +typedef struct svr4_ucontext { + u_long uc_flags; + /* struct svr4_ucontext *uc_link;*/ + void *uc_link; + svr4_sigset_t uc_sigmask; + struct svr4_sigaltstack uc_stack; + svr4_mcontext_t uc_mcontext; + long uc_pad[5]; +} svr4_ucontext_t; + +#define SVR4_UC_GETREGSET 0 +#define SVR4_UC_SETREGSET 1 + +/* + * Signal frame + */ +struct svr4_sigframe { + int sf_signum; + union svr4_siginfo *sf_sip; + struct svr4_ucontext *sf_ucp; + sig_t sf_handler; + struct svr4_ucontext sf_uc; + union svr4_siginfo sf_si; +}; + +#endif /* !_SVR4_UCONTEXT_H_ */ diff --git a/sys/compat/svr4/svr4_ulimit.h b/sys/compat/svr4/svr4_ulimit.h new file mode 100644 index 0000000..c151da1 --- /dev/null +++ b/sys/compat/svr4/svr4_ulimit.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_ULIMIT_H_ +#define _SVR4_ULIMIT_H_ + +#define SVR4_GFILLIM 1 +#define SVR4_SFILLIM 2 +#define SVR4_GMEMLIM 3 +#define SVR4_GDESLIM 4 +#define SVR4_GTXTOFF 64 + + +#endif /* !_SVR4_ULIMIT_H_ */ diff --git a/sys/compat/svr4/svr4_ustat.h b/sys/compat/svr4/svr4_ustat.h new file mode 100644 index 0000000..89712d5 --- /dev/null +++ b/sys/compat/svr4/svr4_ustat.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_USTAT_H_ +#define _SVR4_USTAT_H_ + +#include <svr4/svr4_types.h> + +struct svr4_ustat { + svr4_daddr_t f_tfree; + svr4_ino_t f_tinode; + char f_fname[6]; + char f_fpack[6]; +}; + +#endif /* !_SVR4_USTAT_H_ */ diff --git a/sys/compat/svr4/svr4_util.h b/sys/compat/svr4/svr4_util.h new file mode 100644 index 0000000..8bbb980 --- /dev/null +++ b/sys/compat/svr4/svr4_util.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_UTIL_H_ +#define _SVR4_UTIL_H_ + +/*#include <compat/common/compat_util.h>*/ +#include <vm/vm.h> +#include <vm/vm_param.h> +#include <vm/pmap.h> +#include <machine/vmparam.h> +#include <sys/exec.h> +#include <sys/sysent.h> +#include <sys/cdefs.h> + +#ifdef DEBUG_SVR4 +#define DPRINTF(a) uprintf a; +#else +#define DPRINTF(a) +#endif + + +static __inline caddr_t stackgap_init(void); +static __inline void *stackgap_alloc(caddr_t *, size_t); + +static __inline caddr_t +stackgap_init() +{ +#define szsigcode (*(curproc->p_sysent->sv_szsigcode)) + return (caddr_t)(((caddr_t)PS_STRINGS) - szsigcode - SPARE_USRSPACE); +} + +static __inline void * +stackgap_alloc(sgp, sz) + caddr_t *sgp; + size_t sz; +{ + void *p = (void *) *sgp; + *sgp += ALIGN(sz); + return p; +} + +extern const char svr4_emul_path[]; +int svr4_emul_find __P((struct proc *, caddr_t *, const char *, char *, + char **, int)); + +#define CHECKALTEXIST(p, sgp, path) \ + svr4_emul_find(p, sgp, svr4_emul_path, path, &(path), 0) + +#define CHECKALTCREAT(p, sgp, path) \ + svr4_emul_find(p, sgp, svr4_emul_path, path, &(path), 1) + +#endif /* !_SVR4_UTIL_H_ */ diff --git a/sys/compat/svr4/svr4_utsname.h b/sys/compat/svr4/svr4_utsname.h new file mode 100644 index 0000000..c3afa1d --- /dev/null +++ b/sys/compat/svr4/svr4_utsname.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_UTSNAME_H_ +#define _SVR4_UTSNAME_H_ + +#include <svr4/svr4_types.h> + +struct svr4_utsname { + char sysname[257]; + char nodename[257]; + char release[257]; + char version[257]; + char machine[257]; +}; + +#endif /* !_SVR4_UTSNAME_H_ */ diff --git a/sys/compat/svr4/svr4_wait.h b/sys/compat/svr4/svr4_wait.h new file mode 100644 index 0000000..1935163 --- /dev/null +++ b/sys/compat/svr4/svr4_wait.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1998 Mark Newton + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SVR4_WAIT_H_ +#define _SVR4_WAIT_H_ + + +#define SVR4_P_PID 0 +#define SVR4_P_PPID 1 +#define SVR4_P_PGID 2 +#define SVR4_P_SID 3 +#define SVR4_P_CID 4 +#define SVR4_P_UID 5 +#define SVR4_P_GID 6 +#define SVR4_P_ALL 7 + +#define SVR4_WEXITED 0x01 +#define SVR4_WTRAPPED 0x02 +#define SVR4_WSTOPPED 0x04 +#define SVR4_WCONTINUED 0x08 +#define SVR4_WUNDEF1 0x10 +#define SVR4_WUNDEF2 0x20 +#define SVR4_WNOHANG 0x40 +#define SVR4_WNOWAIT 0x80 + +#define SVR4_WOPTMASK (SVR4_WEXITED|SVR4_WTRAPPED|SVR4_WSTOPPED|\ + SVR4_WCONTINUED|SVR4_WNOHANG|SVR4_WNOWAIT) + +#endif /* !_SVR4_WAIT_H_ */ diff --git a/sys/compat/svr4/syscalls.conf b/sys/compat/svr4/syscalls.conf new file mode 100644 index 0000000..5c01a85 --- /dev/null +++ b/sys/compat/svr4/syscalls.conf @@ -0,0 +1,12 @@ +# $Id: syscalls.conf,v 1.4 1998/03/13 19:13:54 jb Exp $ +sysnames="svr4_syscallnames.c" +sysproto="svr4_proto.h" +sysproto_h=_SVR4_SYSPROTO_H_ +syshdr="svr4_syscall.h" +syssw="svr4_sysent.c" +sysmk="/dev/null" +syshide="/dev/null" +syscallprefix="SVR4_SYS_" +switchname="svr4_sysent" +namesname="svr4_syscallnames" +sysvec="\n" diff --git a/sys/compat/svr4/syscalls.master b/sys/compat/svr4/syscalls.master new file mode 100644 index 0000000..1420318 --- /dev/null +++ b/sys/compat/svr4/syscalls.master @@ -0,0 +1,373 @@ +; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 +; System call name/number master file (or rather, slave, from SVR4). +; Processed to create svr4_sysent.c, svr4_syscalls.c and svr4_syscall.h. + +; Columns: number type nargs namespc name alt{name,tag,rtyp}/comments +; number system call number, must be in order +; type one of STD, OBSOL, UNIMPL, COMPAT +; namespc one of POSIX, BSD, STD, NOHIDE (I dont care :-) -Peter +; name psuedo-prototype of syscall routine +; If one of the following alts is different, then all appear: +; altname name of system call if different +; alttag name of args struct tag if different from [o]`name'"_args" +; altrtyp return type if not int (bogus - syscalls always return int) +; for UNIMPL/OBSOL, name continues with comments + +; types: +; STD always included +; COMPAT included on COMPAT #ifdef +; LIBCOMPAT included on COMPAT #ifdef, and placed in syscall.h +; OBSOL obsolete, not included in system, only specifies name +; UNIMPL not implemented, placeholder only + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/param.h> +#include <sys/file.h> +#include <sys/filio.h> +#include <sys/sysent.h> +#include <sys/sysproto.h> +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> + +#include <svr4/svr4_types.h> +#include <svr4/svr4_signal.h> +#include <svr4/svr4_stropts.h> +#include <svr4/svr4_socket.h> +#include <svr4/svr4_sockio.h> +#include <svr4/svr4_timod.h> +#include <svr4/svr4_proto.h> + +; #ifdef's, etc. may be included, and are copied to the output files. + +0 UNIMPL SVR4 unused +1 NOPROTO POSIX { int exit(int rval); } +2 NOPROTO POSIX { int fork(void); } +3 NOPROTO POSIX { int read(int fd, char *buf, u_int nbyte); } +4 NOPROTO SVR4 { int write(int fd, char *buf, u_int nbyte); } +5 STD SVR4 { int svr4_sys_open(char *path, int flags, int mode); } +6 NOPROTO SVR4 { int close(int fd); } +7 STD SVR4 { int svr4_sys_wait(int *status); } +8 STD SVR4 { int svr4_sys_creat(char *path, int mode); } +9 NOPROTO SVR4 { int link(char *path, char *link); } +10 NOPROTO SVR4 { int unlink(char *path); } +11 STD SVR4 { int svr4_sys_execv(char *path, char **argp); } +12 NOPROTO SVR4 { int chdir(char *path); } +13 STD SVR4 { int svr4_sys_time(time_t *t); } +14 STD SVR4 { int svr4_sys_mknod(char* path, int mode, int dev); } +15 NOPROTO SVR4 { int chmod(char *path, int mode); } +16 NOPROTO SVR4 { int chown(char *path, uid_t uid, gid_t gid); } +17 STD SVR4 { int svr4_sys_break(caddr_t nsize); } +18 STD SVR4 { int svr4_sys_stat(char* path, \ + struct svr4_stat* ub); } +19 NOPROTO SVR4 { int lseek(int filedes, off_t *offset, int whence); } +20 NOPROTO SVR4 { pid_t getpid(void); } +21 UNIMPL SVR4 old_mount +22 UNIMPL SVR4 sysv_umount +23 NOPROTO SVR4 { int setuid(uid_t uid); } +24 NOPROTO SVR4 { uid_t getuid(void); } +25 UNIMPL SVR4 stime +26 UNIMPL SVR4 ptrace +27 STD SVR4 { int svr4_sys_alarm(unsigned sec); } +28 STD SVR4 { int svr4_sys_fstat(int fd, struct svr4_stat *sb); } +29 STD SVR4 { int svr4_sys_pause(void); } +30 STD SVR4 { int svr4_sys_utime(char *path, \ + struct svr4_utimbuf *ubuf); } +31 UNIMPL SVR4 stty +32 UNIMPL SVR4 gtty +33 STD SVR4 { int svr4_sys_access(char *path, int flags); } +34 STD SVR4 { int svr4_sys_nice(int prio); } +35 UNIMPL SVR4 statfs +36 NOPROTO SVR4 { int sync(void); } +37 STD SVR4 { int svr4_sys_kill(int pid, int signum); } +38 UNIMPL SVR4 fstatfs +39 STD SVR4 { int svr4_sys_pgrpsys(int cmd, int pid, int pgid); } +40 UNIMPL SVR4 xenix +41 NOPROTO SVR4 { int dup(u_int fd); } +42 NOPROTO SVR4 { int pipe(void); } +43 STD SVR4 { int svr4_sys_times(struct tms *tp); } +44 UNIMPL SVR4 profil +45 UNIMPL SVR4 plock +46 NOPROTO SVR4 { int setgid(gid_t gid); } +47 NOPROTO SVR4 { gid_t getgid(void); } +48 STD SVR4 { int svr4_sys_signal(int signum, \ + svr4_sig_t handler); } +#if defined(NOTYET) +49 STD SVR4 { int svr4_sys_msgsys(int what, int a2, int a3, \ + int a4, int a5); } +#else +49 UNIMPL SVR4 msgsys +#endif +50 STD SVR4 { int svr4_sys_sysarch(int op, void *a1); } +51 UNIMPL SVR4 acct +52 UNIMPL SVR4 shmsys +53 UNIMPL SVR4 semsys +54 STD SVR4 { int svr4_sys_ioctl(int fd, u_long com, \ + caddr_t data); } +55 UNIMPL SVR4 uadmin +56 UNIMPL SVR4 exch +57 STD SVR4 { int svr4_sys_utssys(void *a1, void *a2, int sel, \ + void *a3); } +58 NOPROTO SVR4 { int fsync(int fd); } +59 STD SVR4 { int svr4_sys_execve(char *path, char **argp, \ + char **envp); } +60 NOPROTO SVR4 { int umask(int newmask); } +61 NOPROTO SVR4 { int chroot(char *path); } +62 STD SVR4 { int svr4_sys_fcntl(int fd, int cmd, char *arg); } +63 STD SVR4 { int svr4_sys_ulimit(int cmd, long newlimit); } +64 UNIMPL SVR4 reserved +65 UNIMPL SVR4 reserved +66 UNIMPL SVR4 reserved +67 UNIMPL SVR4 reserved +68 UNIMPL SVR4 reserved +69 UNIMPL SVR4 reserved +70 UNIMPL SVR4 advfs +71 UNIMPL SVR4 unadvfs +72 UNIMPL SVR4 rmount +73 UNIMPL SVR4 rumount +74 UNIMPL SVR4 rfstart +75 UNIMPL SVR4 sigret +76 UNIMPL SVR4 rdebug +77 UNIMPL SVR4 rfstop +78 UNIMPL SVR4 rfsys +79 NOPROTO SVR4 { int rmdir(char *path); } +80 NOPROTO SVR4 { int mkdir(char *path, int mode); } +81 STD SVR4 { int svr4_sys_getdents(int fd, char *buf, \ + int nbytes); } +82 UNIMPL SVR4 libattach +83 UNIMPL SVR4 libdetach +84 UNIMPL SVR4 sysfs +85 STD SVR4 { int svr4_sys_getmsg(int fd, struct svr4_strbuf *ctl, \ + struct svr4_strbuf *dat, int *flags); } +86 STD SVR4 { int svr4_sys_putmsg(int fd, struct svr4_strbuf *ctl, \ + struct svr4_strbuf *dat, int flags); } +87 STD SVR4 { int svr4_sys_poll(struct pollfd *fds, unsigned int nfds, \ + int timeout); } +88 STD SVR4 { int svr4_sys_lstat(char *path, \ + struct svr4_stat *ub); } +89 NOPROTO SVR4 { int symlink(char *path, char *link); } +90 NOPROTO SVR4 { int readlink(char *path, char *buf, int count); } +91 NOPROTO SVR4 { int getgroups(u_int gidsetsize, gid_t *gidset); } +92 NOPROTO SVR4 { int setgroups(u_int gidsetsize, gid_t *gidset); } +93 NOPROTO SVR4 { int fchmod(int fd, int mode); } +94 NOPROTO SVR4 { int fchown(int fd, int uid, int gid); } +95 STD SVR4 { int svr4_sys_sigprocmask(int how, \ + svr4_sigset_t *set, svr4_sigset_t *oset); } +96 STD SVR4 { int svr4_sys_sigsuspend(svr4_sigset_t *ss); } +97 STD SVR4 { int svr4_sys_sigaltstack( \ + struct svr4_sigaltstack *nss, \ + struct svr4_sigaltstack *oss); } +98 STD SVR4 { int svr4_sys_sigaction(int signum, \ + struct svr4_sigaction *nsa, \ + struct svr4_sigaction *osa); } +99 STD SVR4 { int svr4_sys_sigpending(int what, \ + svr4_sigset_t *mask); } +100 STD SVR4 { int svr4_sys_context(int func, \ + struct svr4_ucontext *uc); } +101 UNIMPL SVR4 evsys +102 UNIMPL SVR4 evtrapret +103 STD SVR4 { int svr4_sys_statvfs(char *path, \ + struct svr4_statvfs *fs); } +104 STD SVR4 { int svr4_sys_fstatvfs(int fd, \ + struct svr4_statvfs *fs); } +105 UNIMPL SVR4 whoknows +106 UNIMPL SVR4 nfssvc +107 STD SVR4 { int svr4_sys_waitsys(int grp, int id, \ + union svr4_siginfo *info, int options); } +108 UNIMPL SVR4 sigsendsys +109 STD SVR4 { int svr4_sys_hrtsys(int cmd, int fun, int sub, \ + void *rv1, void *rv2); } +110 UNIMPL SVR4 acancel +111 UNIMPL SVR4 async +112 UNIMPL SVR4 priocntlsys +113 STD SVR4 { int svr4_sys_pathconf(char *path, int name); } +114 UNIMPL SVR4 mincore +115 STD SVR4 { caddr_t svr4_sys_mmap( caddr_t addr, svr4_size_t len, \ + int prot, int flags, int fd, svr4_off_t pos); } +116 NOPROTO SVR4 { int mprotect(void *addr, int len, int prot); } +117 NOPROTO SVR4 { int munmap(void *addr, int len); } +118 STD SVR4 { int svr4_sys_fpathconf(int fd, int name); } +119 NOPROTO SVR4 { int vfork(void); } +120 NOPROTO SVR4 { int fchdir(int fd); } +121 NOPROTO SVR4 { int readv(int fd, struct iovec *iovp, \ + u_int iovcnt); } +122 NOPROTO SVR4 { int writev(int fd, struct iovec *iovp, \ + u_int iovcnt); } +123 STD SVR4 { int svr4_sys_xstat(int two, char *path, \ + struct svr4_xstat *ub); } +124 STD SVR4 { int svr4_sys_lxstat(int two, char *path, \ + struct svr4_xstat *ub); } +125 STD SVR4 { int svr4_sys_fxstat(int two, int fd, \ + struct svr4_xstat *sb); } +126 STD SVR4 { int svr4_sys_xmknod(int two, char *path, \ + svr4_mode_t mode, svr4_dev_t dev); } +127 UNIMPL SVR4 clocal +128 STD SVR4 { int svr4_sys_setrlimit(int which, \ + const struct svr4_rlimit *rlp); } +129 STD SVR4 { int svr4_sys_getrlimit(int which, \ + struct svr4_rlimit *rlp); } +130 NOPROTO SVR4 { int lchown(char *path, uid_t uid, gid_t gid); } +131 STD SVR4 { int svr4_sys_memcntl(void * addr, \ + svr4_size_t len, int cmd, void * arg, \ + int attr, int mask); } +132 UNIMPL SVR4 getpmsg +133 UNIMPL SVR4 putpmsg +134 NOPROTO SVR4 { int rename(char *from, char *to); } +135 STD SVR4 { int svr4_sys_uname(struct svr4_utsname* name, \ + int dummy); } +136 NOPROTO SVR4 { int setegid(gid_t egid); } +137 STD SVR4 { int svr4_sys_sysconfig(int name); } +138 NOPROTO SVR4 { int adjtime(struct timeval *delta, \ + struct timeval *olddelta); } +139 STD SVR4 { long svr4_sys_systeminfo(int what, char *buf, \ + long len); } +140 UNIMPL SVR4 notused +141 NOPROTO SVR4 { int seteuid(uid_t euid); } +142 UNIMPL SVR4 vtrace +; fork1 +143 UNIMPL SVR4 { int fork(void); } +144 UNIMPL SVR4 sigtimedwait +145 UNIMPL SVR4 lwp_info +146 UNIMPL SVR4 yield +147 UNIMPL SVR4 lwp_sema_wait +148 UNIMPL SVR4 lwp_sema_post +149 UNIMPL SVR4 lwp_sema_trywait +150 UNIMPL SVR4 notused +151 UNIMPL SVR4 notused +152 UNIMPL SVR4 modctl +153 STD SVR4 { int svr4_sys_fchroot(int fd); } +154 STD SVR4 { int svr4_sys_utimes(char *path, \ + struct timeval *tptr); } +155 STD SVR4 { int svr4_sys_vhangup(void); } +156 STD SVR4 { int svr4_sys_gettimeofday(struct timeval *tp); } +157 NOPROTO SVR4 { int getitimer(u_int which, struct itimerval *itv); } +158 NOPROTO SVR4 { int setitimer(u_int which, struct itimerval *itv, \ + struct itimerval *oitv); } +159 UNIMPL SVR4 lwp_create +160 UNIMPL SVR4 lwp_exit +161 UNIMPL SVR4 lwp_suspend +162 UNIMPL SVR4 lwp_continue +163 UNIMPL SVR4 lwp_kill +164 UNIMPL SVR4 lwp_self +165 UNIMPL SVR4 lwp_getprivate +166 UNIMPL SVR4 lwp_setprivate +167 UNIMPL SVR4 lwp_wait +168 UNIMPL SVR4 lwp_mutex_unlock +169 UNIMPL SVR4 lwp_mutex_lock +170 UNIMPL SVR4 lwp_cond_wait +171 UNIMPL SVR4 lwp_cond_signal +172 UNIMPL SVR4 lwp_cond_broadcast +173 UNIMPL SVR4 { ssize_t svr4_sys_pread(int fd, void *buf, \ + size_t nbyte, svr4_off_t off); } +174 UNIMPL SVR4 { ssize_t svr4_sys_pwrite(int fd, const void *buf, \ + size_t nbyte, svr4_off_t off); } +175 STD SVR4 { svr4_off64_t svr4_sys_llseek(int fd, long offset1, \ + long offset2, int whence); } +176 UNIMPL SVR4 inst_sync +177 UNIMPL SVR4 whoknows +178 UNIMPL SVR4 kaio +179 UNIMPL SVR4 whoknows +180 UNIMPL SVR4 whoknows +181 UNIMPL SVR4 whoknows +182 UNIMPL SVR4 whoknows +183 UNIMPL SVR4 whoknows +184 UNIMPL SVR4 tsolsys +185 STD SVR4 { int svr4_sys_acl(char *path, int cmd, int num, \ + struct svr4_aclent *buf); } +186 STD SVR4 { int svr4_sys_auditsys(int code, int a1, int a2, \ + int a3, int a4, int a5); } +187 UNIMPL SVR4 processor_bind +188 UNIMPL SVR4 processor_info +189 UNIMPL SVR4 p_online +190 UNIMPL SVR4 sigqueue +191 UNIMPL SVR4 clock_gettime +192 UNIMPL SVR4 clock_settime +193 UNIMPL SVR4 clock_getres +194 UNIMPL SVR4 timer_create +195 UNIMPL SVR4 timer_delete +196 UNIMPL SVR4 timer_settime +197 UNIMPL SVR4 timer_gettime +198 UNIMPL SVR4 timer_overrun +199 NOPROTO SVR4 { int nanosleep(const struct timespec *rqtp, \ + struct timespec *rmtp); } +200 STD SVR4 { int svr4_sys_facl(int fd, int cmd, int num, \ + struct svr4_aclent *buf); } +201 UNIMPL SVR4 door +202 NOPROTO SVR4 { int setreuid(int ruid, int euid); } +203 NOPROTO SVR4 { int setregid(int rgid, int egid); } +204 UNIMPL SVR4 install_utrap +205 UNIMPL SVR4 signotify +206 UNIMPL SVR4 schedctl +207 UNIMPL SVR4 pset +208 UNIMPL SVR4 whoknows +209 STD SVR4 { int svr4_sys_resolvepath(const char *path, \ + char *buf, size_t bufsiz); } +210 UNIMPL SVR4 signotifywait +211 UNIMPL SVR4 lwp_sigredirect +212 UNIMPL SVR4 lwp_alarm +213 STD SVR4 { int svr4_sys_getdents64(int fd, \ + struct svr4_dirent64 *dp, \ + int nbytes); } +;213 UNIMPL SVR4 getdents64 +214 STD SVR4 { caddr_t svr4_sys_mmap64(void *addr, \ + svr4_size_t len, int prot, int flags, int fd, \ + svr4_off64_t pos); } +215 STD SVR4 { int svr4_sys_stat64(char *path, \ + struct svr4_stat64 *sb); } +216 STD SVR4 { int svr4_sys_lstat64(char *path, \ + struct svr4_stat64 *sb); } +217 STD SVR4 { int svr4_sys_fstat64(int fd, \ + struct svr4_stat64 *sb); } +218 STD SVR4 { int svr4_sys_statvfs64(char *path, \ + struct svr4_statvfs64 *fs); } +219 STD SVR4 { int svr4_sys_fstatvfs64(int fd, \ + struct svr4_statvfs64 *fs); } +220 STD SVR4 { int svr4_sys_setrlimit64(int which, \ + const struct svr4_rlimit64 *rlp); } +221 STD SVR4 { int svr4_sys_getrlimit64(int which, \ + struct svr4_rlimit64 *rlp); } +222 UNIMPL SVR4 pread64 +223 UNIMPL SVR4 pwrite64 +224 STD SVR4 { int svr4_sys_creat64(char *path, int mode); } +225 STD SVR4 { int svr4_sys_open64(char *path, int flags, \ + int mode); } +226 UNIMPL SVR4 rpcsys +227 UNIMPL SVR4 whoknows +228 UNIMPL SVR4 whoknows +229 UNIMPL SVR4 whoknows +230 STD SVR4 { int svr4_sys_socket(int domain, int type, \ + int protocol); } +231 NOPROTO SVR4 { int socketpair(int domain, int type, \ + int protocol, int *rsv); } +232 NOPROTO SVR4 { int bind(int s, const struct sockaddr *name, \ + int namelen); } +233 NOPROTO SVR4 { int listen(int s, int backlog); } +234 NOPROTO SVR4 { int accept(int s, struct sockaddr *name, \ + int *anamelen); } +235 NOPROTO SVR4 { int connect(int s, const struct sockaddr *name, \ + int namelen); } +236 NOPROTO SVR4 { int shutdown(int s, int how); } +237 STD SVR4 { int svr4_sys_recv(int s, caddr_t buf, int len, int flags); } +238 NOPROTO SVR4 { ssize_t recvfrom(int s, void *buf, size_t len, \ + int flags, struct sockaddr *from, \ + int *fromlenaddr); } +239 NOPROTO SVR4 { ssize_t recvmsg(int s, struct msghdr *msg, \ + int flags); } +240 STD SVR4 { int svr4_sys_send(int s, caddr_t buf, int len, int flags); } +241 NOPROTO SVR4 { ssize_t sendmsg(int s, const struct msghdr *msg, \ + int flags); } +242 STD SVR4 { ssize_t svr4_sys_sendto(int s, const void *buf, \ + size_t len, int flags, \ + const struct sockaddr *to, int tolen); } +243 NOPROTO SVR4 { int getpeername(int fdes, struct sockaddr *asa, \ + int *alen); } +244 NOPROTO SVR4 { int getsockname(int fdes, struct sockaddr *asa, \ + int *alen); } +245 NOPROTO SVR4 { int getsockopt(int s, int level, int name, \ + void *val, int *avalsize); } +246 NOPROTO SVR4 { int setsockopt(int s, int level, int name, \ + const void *val, int valsize); } +247 UNIMPL SVR4 sockconfig +248 UNIMPL SVR4 { int ntp_gettime(struct ntptimeval *ntvp); } +249 UNIMPL SVR4 { int ntp_adjtime(struct timex *tp); } |