Index: head/sys/compat/svr4/svr4_socket.c =================================================================== --- head/sys/compat/svr4/svr4_socket.c (revision 298518) +++ head/sys/compat/svr4/svr4_socket.c (revision 298519) @@ -1,245 +1,259 @@ /*- * 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 __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include 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; }; static TAILQ_HEAD(, svr4_sockcache_entry) svr4_head; static struct mtx svr4_sockcache_lock; static eventhandler_tag svr4_sockcache_exit_tag, svr4_sockcache_exec_tag; static void svr4_purge_sockcache(void *arg, struct proc *p); int svr4_find_socket(td, fp, dev, ino, saun) struct thread *td; struct file *fp; dev_t dev; ino_t ino; struct sockaddr_un *saun; { struct svr4_sockcache_entry *e; void *cookie = ((struct socket *)fp->f_data)->so_emuldata; DPRINTF(("svr4_find_socket: [%p,%ju,%ju]: ", td, (uintmax_t)dev, (uintmax_t)ino)); mtx_lock(&svr4_sockcache_lock); TAILQ_FOREACH(e, &svr4_head, entries) if (e->p == td->td_proc && 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)); *saun = e->sock; mtx_unlock(&svr4_sockcache_lock); return (0); } mtx_unlock(&svr4_sockcache_lock); DPRINTF(("not found\n")); return (ENOENT); } int svr4_add_socket(td, path, st) struct thread *td; const char *path; struct stat *st; { struct svr4_sockcache_entry *e; size_t len; int error; e = malloc(sizeof(*e), M_TEMP, M_WAITOK); e->cookie = NULL; e->dev = st->st_dev; e->ino = st->st_ino; e->p = td->td_proc; 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; mtx_lock(&svr4_sockcache_lock); TAILQ_INSERT_HEAD(&svr4_head, e, entries); mtx_unlock(&svr4_sockcache_lock); DPRINTF(("svr4_add_socket: %s [%p,%ju,%ju]\n", e->sock.sun_path, td->td_proc, (uintmax_t)e->dev, (uintmax_t)e->ino)); return 0; } 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; mtx_lock(&svr4_sockcache_lock); TAILQ_FOREACH(e, &svr4_head, entries) if (e->p == p && e->cookie == cookie) { TAILQ_REMOVE(&svr4_head, e, entries); mtx_unlock(&svr4_sockcache_lock); DPRINTF(("svr4_delete_socket: %s [%p,%ju,%ju]\n", e->sock.sun_path, p, (uintmax_t)e->dev, (uintmax_t)e->ino)); free(e, M_TEMP); return; } mtx_unlock(&svr4_sockcache_lock); +} + +struct svr4_strm * +svr4_stream_get(fp) + struct file *fp; +{ + struct socket *so; + + if (fp == NULL || fp->f_type != DTYPE_SOCKET) + return NULL; + + so = fp->f_data; + return so->so_emuldata; } void svr4_purge_sockcache(arg, p) void *arg; struct proc *p; { struct svr4_sockcache_entry *e, *ne; mtx_lock(&svr4_sockcache_lock); TAILQ_FOREACH_SAFE(e, &svr4_head, entries, ne) { if (e->p == p) { TAILQ_REMOVE(&svr4_head, e, entries); DPRINTF(("svr4_purge_sockcache: %s [%p,%ju,%ju]\n", e->sock.sun_path, p, (uintmax_t)e->dev, (uintmax_t)e->ino)); free(e, M_TEMP); } } mtx_unlock(&svr4_sockcache_lock); } void svr4_sockcache_init(void) { TAILQ_INIT(&svr4_head); mtx_init(&svr4_sockcache_lock, "svr4 socket cache", NULL, MTX_DEF); svr4_sockcache_exit_tag = EVENTHANDLER_REGISTER(process_exit, svr4_purge_sockcache, NULL, EVENTHANDLER_PRI_ANY); svr4_sockcache_exec_tag = EVENTHANDLER_REGISTER(process_exec, svr4_purge_sockcache, NULL, EVENTHANDLER_PRI_ANY); } void svr4_sockcache_destroy(void) { KASSERT(TAILQ_EMPTY(&svr4_head), ("%s: sockcache entries still around", __func__)); EVENTHANDLER_DEREGISTER(process_exec, svr4_sockcache_exec_tag); EVENTHANDLER_DEREGISTER(process_exit, svr4_sockcache_exit_tag); mtx_destroy(&svr4_sockcache_lock); } int svr4_sys_socket(td, uap) struct thread *td; struct svr4_sys_socket_args *uap; { switch (uap->type) { case SVR4_SOCK_DGRAM: uap->type = SOCK_DGRAM; break; case SVR4_SOCK_STREAM: uap->type = SOCK_STREAM; break; case SVR4_SOCK_RAW: uap->type = SOCK_RAW; break; case SVR4_SOCK_RDM: uap->type = SOCK_RDM; break; case SVR4_SOCK_SEQPACKET: uap->type = SOCK_SEQPACKET; break; default: return EINVAL; } return sys_socket(td, (struct socket_args *)uap); } Index: head/sys/compat/svr4/svr4_sysvec.c =================================================================== --- head/sys/compat/svr4/svr4_sysvec.c (revision 298518) +++ head/sys/compat/svr4/svr4_sysvec.c (revision 298519) @@ -1,313 +1,313 @@ /*- * 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. 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 __FBSDID("$FreeBSD$"); /* XXX we use functions that might not exist. */ #include "opt_compat.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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(register_t **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 = { .sv_size = SVR4_SYS_MAXSYSCALL, .sv_table = svr4_sysent, .sv_mask = 0xff, .sv_errsize = ELAST, /* ELAST */ .sv_errtbl = bsd_to_svr4_errno, .sv_transtrap = NULL, .sv_fixup = svr4_fixup, .sv_sendsig = svr4_sendsig, .sv_sigcode = svr4_sigcode, .sv_szsigcode = &svr4_szsigcode, .sv_name = "SVR4", .sv_coredump = elf32_coredump, .sv_imgact_try = NULL, .sv_minsigstksz = SVR4_MINSIGSTKSZ, .sv_pagesize = PAGE_SIZE, .sv_minuser = VM_MIN_ADDRESS, .sv_maxuser = VM_MAXUSER_ADDRESS, .sv_usrstack = USRSTACK, .sv_psstrings = PS_STRINGS, .sv_stackprot = VM_PROT_ALL, .sv_copyout_strings = exec_copyout_strings, .sv_setregs = exec_setregs, .sv_fixlimit = NULL, .sv_maxssiz = NULL, .sv_flags = SV_ABI_UNDEF | SV_IA32 | SV_ILP32, .sv_set_syscall_retval = cpu_set_syscall_retval, .sv_fetch_syscall_args = cpu_fetch_syscall_args, .sv_syscallnames = NULL, .sv_schedtail = NULL, .sv_thread_detach = NULL, .sv_trap = NULL, }; const char svr4_emul_path[] = "/compat/svr4"; Elf32_Brandinfo svr4_brand = { .brand = ELFOSABI_SYSV, .machine = EM_386, /* XXX only implemented for x86 so far. */ .compat_3_brand = "SVR4", .emul_path = svr4_emul_path, .interp_path = "/lib/libc.so.1", .sysvec = &svr4_sysvec, .interp_newpath = NULL, .brand_note = NULL, .flags = 0 }; static int svr4_fixup(register_t **stack_base, struct image_params *imgp) { Elf32_Auxargs *args; register_t *pos; KASSERT(curthread->td_proc == imgp->proc, ("unsafe svr4_fixup(), should be curproc")); args = (Elf32_Auxargs *)imgp->auxargs; pos = *stack_base + (imgp->args->argc + imgp->args->envc + 2); 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_ucred->cr_ruid); AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_ucred->cr_svuid); AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_ucred->cr_rgid); AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_ucred->cr_svgid); AUXARGS_ENTRY(pos, AT_NULL, 0); free(imgp->auxargs, M_TEMP); imgp->auxargs = NULL; (*stack_base)--; **stack_base = (register_t)imgp->args->argc; return 0; } /* * Search an alternate path before passing pathname arguments on * to system calls. Useful for keeping a separate '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. */ int svr4_emul_find(struct thread *td, char *path, enum uio_seg pathseg, char **pbuf, int create) { return (kern_alternate_path(td, svr4_emul_path, path, pathseg, pbuf, create, AT_FDCWD)); } static int svr4_elf_modevent(module_t mod, int type, void *data) { int error; error = 0; switch(type) { case MOD_LOAD: if (elf32_insert_brand_entry(&svr4_brand) < 0) { printf("cannot insert svr4 elf brand handler\n"); error = EINVAL; break; } if (bootverbose) printf("svr4 ELF exec handler installed\n"); svr4_sockcache_init(); break; case MOD_UNLOAD: /* Only allow the emulator to be removed if it isn't in use. */ if (elf32_brand_inuse(&svr4_brand) != 0) { error = EBUSY; } else if (elf32_remove_brand_entry(&svr4_brand) < 0) { error = EINVAL; } if (error) { printf("Could not deinstall ELF interpreter entry (error %d)\n", error); break; } if (bootverbose) printf("svr4 ELF exec handler removed\n"); svr4_sockcache_destroy(); break; default: return (EOPNOTSUPP); break; } return error; } static moduledata_t svr4_elf_mod = { "svr4elf", svr4_elf_modevent, 0 }; DECLARE_MODULE_TIED(svr4elf, svr4_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY); -MODULE_DEPEND(svr4elf, streams, 1, 1, 1); +MODULE_VERSION(svr4elf, 1); Index: head/sys/dev/streams/streams.c =================================================================== --- head/sys/dev/streams/streams.c (revision 298518) +++ head/sys/dev/streams/streams.c (revision 298519) @@ -1,351 +1,339 @@ /*- * Copyright (c) 1998 Mark Newton * Copyright (c) 1994 Christos Zoulas * 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 names of the authors 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. * * Stolen from NetBSD /sys/compat/svr4/svr4_net.c. Pseudo-device driver * skeleton produced from /usr/share/examples/drivers/make_pseudo_driver.sh * in 3.0-980524-SNAP then hacked a bit (but probably not enough :-). * */ #include __FBSDID("$FreeBSD$"); #include #include #include /* SYSINIT stuff */ #include /* cdevsw stuff */ #include /* malloc region definitions */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int svr4_soo_close(struct file *, struct thread *); static int svr4_ptm_alloc(struct thread *); static d_open_t streamsopen; /* * Device minor numbers */ enum { dev_ptm = 10, dev_arp = 26, dev_icmp = 27, dev_ip = 28, dev_tcp = 35, dev_udp = 36, dev_rawip = 37, dev_unix_dgram = 38, dev_unix_stream = 39, dev_unix_ord_stream = 40 }; static struct cdev *dt_ptm, *dt_arp, *dt_icmp, *dt_ip, *dt_tcp, *dt_udp, *dt_rawip, *dt_unix_dgram, *dt_unix_stream, *dt_unix_ord_stream; static struct fileops svr4_netops; static struct cdevsw streams_cdevsw = { .d_version = D_VERSION, .d_open = streamsopen, .d_name = "streams", }; struct streams_softc { struct isa_device *dev; } ; #define UNIT(dev) dev2unit(dev) /* assume one minor number per unit */ typedef struct streams_softc *sc_p; static int streams_modevent(module_t mod, int type, void *unused) { switch (type) { case MOD_LOAD: dt_ptm = make_dev(&streams_cdevsw, dev_ptm, 0, 0, 0666, "ptm"); dt_arp = make_dev(&streams_cdevsw, dev_arp, 0, 0, 0666, "arp"); dt_icmp = make_dev(&streams_cdevsw, dev_icmp, 0, 0, 0666, "icmp"); dt_ip = make_dev(&streams_cdevsw, dev_ip, 0, 0, 0666, "ip"); dt_tcp = make_dev(&streams_cdevsw, dev_tcp, 0, 0, 0666, "tcp"); dt_udp = make_dev(&streams_cdevsw, dev_udp, 0, 0, 0666, "udp"); dt_rawip = make_dev(&streams_cdevsw, dev_rawip, 0, 0, 0666, "rawip"); dt_unix_dgram = make_dev(&streams_cdevsw, dev_unix_dgram, 0, 0, 0666, "ticlts"); dt_unix_stream = make_dev(&streams_cdevsw, dev_unix_stream, 0, 0, 0666, "ticots"); dt_unix_ord_stream = make_dev(&streams_cdevsw, dev_unix_ord_stream, 0, 0, 0666, "ticotsord"); if (! (dt_ptm && dt_arp && dt_icmp && dt_ip && dt_tcp && dt_udp && dt_rawip && dt_unix_dgram && dt_unix_stream && dt_unix_ord_stream)) { printf("WARNING: device config for STREAMS failed\n"); printf("Suggest unloading streams KLD\n"); } /* Inherit generic socket file operations, except close(2). */ bcopy(&socketops, &svr4_netops, sizeof(struct fileops)); svr4_netops.fo_close = svr4_soo_close; return 0; case MOD_UNLOAD: /* XXX should check to see if it's busy first */ destroy_dev(dt_ptm); destroy_dev(dt_arp); destroy_dev(dt_icmp); destroy_dev(dt_ip); destroy_dev(dt_tcp); destroy_dev(dt_udp); destroy_dev(dt_rawip); destroy_dev(dt_unix_dgram); destroy_dev(dt_unix_stream); destroy_dev(dt_unix_ord_stream); return 0; default: return EOPNOTSUPP; break; } return 0; } static moduledata_t streams_mod = { "streams", streams_modevent, 0 }; DECLARE_MODULE(streams, streams_mod, SI_SUB_DRIVERS, SI_ORDER_ANY); MODULE_VERSION(streams, 1); +MODULE_DEPEND(streams, svr4elf, 1, 1, 1); /* * We only need open() and close() routines. open() calls socreate() * to allocate a "real" object behind the stream and mallocs some state * info for use by the svr4 emulator; close() deallocates the state * information and passes the underlying object to the normal socket close * routine. */ static int streamsopen(struct cdev *dev, int oflags, int devtype, struct thread *td) { struct svr4_strm *st; struct socket *so; struct file *fp; int family, type, protocol; int error, fd; if (td->td_dupfd >= 0) return ENODEV; switch (dev2unit(dev)) { case dev_udp: family = AF_INET; type = SOCK_DGRAM; protocol = IPPROTO_UDP; break; case dev_tcp: family = AF_INET; type = SOCK_STREAM; protocol = IPPROTO_TCP; break; case dev_ip: case dev_rawip: family = AF_INET; type = SOCK_RAW; protocol = IPPROTO_IP; break; case dev_icmp: family = AF_INET; type = SOCK_RAW; protocol = IPPROTO_ICMP; break; case dev_unix_dgram: family = AF_LOCAL; type = SOCK_DGRAM; protocol = 0; break; case dev_unix_stream: case dev_unix_ord_stream: family = AF_LOCAL; type = SOCK_STREAM; protocol = 0; break; case dev_ptm: return svr4_ptm_alloc(td); default: return EOPNOTSUPP; } if ((error = falloc(td, &fp, &fd, 0)) != 0) return error; /* An extra reference on `fp' has been held for us by falloc(). */ error = socreate(family, &so, type, protocol, td->td_ucred, td); if (error) { fdclose(td, fp, fd); fdrop(fp, td); return error; } finit(fp, FREAD | FWRITE, DTYPE_SOCKET, so, &svr4_netops); /* * Allocate a stream structure and attach it to this socket. * We don't bother locking so_emuldata for SVR4 stream sockets as * its value is constant for the lifetime of the stream once it * is initialized here. */ st = malloc(sizeof(struct svr4_strm), M_TEMP, M_WAITOK); st->s_family = so->so_proto->pr_domain->dom_family; st->s_cmd = ~0; st->s_afd = -1; st->s_eventmask = 0; so->so_emuldata = st; fdrop(fp, td); td->td_dupfd = fd; return ENXIO; } static int svr4_ptm_alloc(td) struct thread *td; { /* * XXX this is very, very ugly. But I can't find a better * way that won't duplicate a big amount of code from * sys_open(). Ho hum... * * Fortunately for us, Solaris (at least 2.5.1) makes the * /dev/ptmx open automatically just open a pty, that (after * STREAMS I_PUSHes), is just a plain pty. fstat() is used * to get the minor device number to map to a tty. * * Cycle through the names. If sys_open() returns ENOENT (or * ENXIO), short circuit the cycle and exit. * * XXX: Maybe this can now be implemented by posix_openpt()? */ static char ptyname[] = "/dev/ptyXX"; static char ttyletters[] = "pqrstuwxyzPQRST"; static char ttynumbers[] = "0123456789abcdef"; struct proc *p; register_t fd; int error, l, n; fd = -1; n = 0; l = 0; p = td->td_proc; while (fd == -1) { ptyname[8] = ttyletters[l]; ptyname[9] = ttynumbers[n]; error = kern_openat(td, AT_FDCWD, ptyname, UIO_SYSSPACE, O_RDWR, 0); switch (error) { case ENOENT: case ENXIO: return error; case 0: td->td_dupfd = td->td_retval[0]; return ENXIO; default: if (ttynumbers[++n] == '\0') { if (ttyletters[++l] == '\0') break; n = 0; } } } return ENOENT; } - -struct svr4_strm * -svr4_stream_get(fp) - struct file *fp; -{ - struct socket *so; - - if (fp == NULL || fp->f_type != DTYPE_SOCKET) - return NULL; - - so = fp->f_data; - return so->so_emuldata; -} static int svr4_soo_close(struct file *fp, struct thread *td) { struct socket *so = fp->f_data; /* CHECKUNIT_DIAG(ENXIO);*/ svr4_delete_socket(td->td_proc, fp); free(so->so_emuldata, M_TEMP); fp->f_ops = &badfileops; fp->f_data = NULL; return soclose(so); } Index: head/sys/modules/streams/Makefile =================================================================== --- head/sys/modules/streams/Makefile (revision 298518) +++ head/sys/modules/streams/Makefile (revision 298519) @@ -1,17 +1,13 @@ # $FreeBSD$ .PATH: ${.CURDIR}/../../dev/streams KMOD= streams SRCS= streams.c -EXPORT_SYMS= svr4_str_initialized \ - svr4_stream_get \ - svr4_delete_socket - .if defined(DEBUG) CFLAGS+= -DDEBUG_SVR4 .endif CFLAGS+= -O .include Index: head/sys/modules/svr4/Makefile =================================================================== --- head/sys/modules/svr4/Makefile (revision 298518) +++ head/sys/modules/svr4/Makefile (revision 298519) @@ -1,31 +1,32 @@ # $FreeBSD$ .PATH: ${.CURDIR}/../../${MACHINE_CPUARCH}/svr4 ${.CURDIR}/../../compat/svr4 KMOD= svr4 SRCS= svr4_sysent.c svr4_sysvec.c opt_compat.h opt_svr4.h \ vnode_if.h imgact_svr4.c svr4_signal.c svr4_fcntl.c \ svr4_misc.c svr4_ioctl.c svr4_stat.c svr4_filio.c \ svr4_termios.c svr4_stream.c svr4_socket.c svr4_sockio.c \ svr4_machdep.c svr4_resource.c svr4_ipc.c OBJS= svr4_locore.o +EXPORT_SYMS= svr4_delete_socket SRCS+= opt_ktrace.h opt_sysvipc.h CLEANFILES= svr4_assym.h svr4_genassym.o svr4_assym.h: svr4_genassym.o sh ${SYSDIR}/kern/genassym.sh svr4_genassym.o > ${.TARGET} svr4_locore.o: svr4_locore.s svr4_assym.h ${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \ ${.IMPSRC} -o ${.TARGET} svr4_genassym.o: svr4_genassym.c svr4.h ${CC} -c ${CFLAGS:N-fno-common} ${.IMPSRC} .if !defined(KERNBUILDDIR) && defined(DEBUG) opt_svr4.h: echo "#define DEBUG_SVR4 1" > ${.TARGET} .endif .include