The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/svr4_32/svr4_32_socket.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: svr4_32_socket.c,v 1.8 2006/06/27 09:09:40 pavel Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Christos Zoulas.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 /*
   40  * In SVR4 unix domain sockets are referenced sometimes
   41  * (in putmsg(2) for example) as a [device, inode] pair instead of a pathname.
   42  * Since there is no iname() routine in the kernel, and we need access to
   43  * a mapping from inode to pathname, we keep our own table. This is a simple
   44  * linked list that contains the pathname, the [device, inode] pair, the
   45  * file corresponding to that socket and the process. When the
   46  * socket gets closed we remove the item from the list. The list gets loaded
   47  * every time a stat(2) call finds a socket.
   48  */
   49 
   50 #include <sys/cdefs.h>
   51 __KERNEL_RCSID(0, "$NetBSD: svr4_32_socket.c,v 1.8 2006/06/27 09:09:40 pavel Exp $");
   52 
   53 #include <sys/param.h>
   54 #include <sys/kernel.h>
   55 #include <sys/systm.h>
   56 #include <sys/queue.h>
   57 #include <sys/mbuf.h>
   58 #include <sys/file.h>
   59 #include <sys/mount.h>
   60 #include <sys/socket.h>
   61 #include <sys/socketvar.h>
   62 #include <sys/sa.h>
   63 #include <sys/syscallargs.h>
   64 #include <sys/un.h>
   65 #include <sys/stat.h>
   66 
   67 #include <compat/svr4_32/svr4_32_types.h>
   68 #include <compat/svr4_32/svr4_32_util.h>
   69 #include <compat/svr4_32/svr4_32_socket.h>
   70 #include <compat/svr4_32/svr4_32_signal.h>
   71 #include <compat/svr4/svr4_sockmod.h>
   72 #include <compat/svr4_32/svr4_32_lwp.h>
   73 #include <compat/svr4_32/svr4_32_ucontext.h>
   74 #include <compat/svr4_32/svr4_32_syscallargs.h>
   75 
   76 struct svr4_sockcache_entry {
   77         struct proc *p;         /* Process for the socket               */
   78         void *cookie;           /* Internal cookie used for matching    */
   79         struct sockaddr_un sock;/* Pathname for the socket              */
   80         dev_t dev;              /* Device where the socket lives on     */
   81         svr4_ino_t ino;         /* Inode where the socket lives on      */
   82         TAILQ_ENTRY(svr4_sockcache_entry) entries;
   83 };
   84 
   85 #if 0
   86 static TAILQ_HEAD(svr4_sockcache_head, svr4_sockcache_entry) svr4_head;
   87 static int initialized = 0;
   88 
   89 struct sockaddr_un *
   90 svr4_32_find_socket(p, fp, dev, ino)
   91         struct proc *p;
   92         struct file *fp;
   93         dev_t dev;
   94         svr4_ino_t ino;
   95 {
   96         struct svr4_sockcache_entry *e;
   97         void *cookie = ((struct socket *) fp->f_data)->so_internal;
   98 
   99         if (!initialized) {
  100                 DPRINTF(("svr4_32_find_socket: uninitialized [%p,%d,%d]\n",
  101                     p, dev, ino));
  102                 TAILQ_INIT(&svr4_head);
  103                 initialized = 1;
  104                 return NULL;
  105         }
  106 
  107 
  108         DPRINTF(("svr4_32_find_socket: [%p,%d,%d]: ", p, dev, ino));
  109         for (e = svr4_head.tqh_first; e != NULL; e = e->entries.tqe_next)
  110                 if (e->p == p && e->dev == dev && e->ino == ino) {
  111 #ifdef DIAGNOSTIC
  112                         if (e->cookie != NULL && e->cookie != cookie)
  113                                 panic("svr4_32 socket cookie mismatch");
  114 #endif
  115                         e->cookie = cookie;
  116                         DPRINTF(("%s\n", e->sock.sun_path));
  117                         return &e->sock;
  118                 }
  119 
  120         DPRINTF(("not found\n"));
  121         return NULL;
  122 }
  123 #endif
  124 
  125 #if 0
  126 void
  127 svr4_32_delete_socket(p, fp)
  128         struct proc *p;
  129         struct file *fp;
  130 {
  131         struct svr4_sockcache_entry *e;
  132         void *cookie = ((struct socket *) fp->f_data)->so_internal;
  133 
  134         if (!initialized) {
  135                 TAILQ_INIT(&svr4_head);
  136                 initialized = 1;
  137                 return;
  138         }
  139 
  140         for (e = svr4_head.tqh_first; e != NULL; e = e->entries.tqe_next)
  141                 if (e->p == p && e->cookie == cookie) {
  142                         TAILQ_REMOVE(&svr4_head, e, entries);
  143                         DPRINTF(("svr4_delete_socket: %s [%p,%d,%d]\n",
  144                                  e->sock.sun_path, p, e->dev, e->ino));
  145                         free(e, M_TEMP);
  146                         return;
  147                 }
  148 }
  149 #endif
  150 
  151 #if 0
  152 int
  153 svr4_32_add_socket(p, path, st)
  154         struct proc *p;
  155         const char *path;
  156         struct stat *st;
  157 {
  158         struct svr4_sockcache_entry *e;
  159         size_t len;
  160         int error;
  161 
  162         if (!initialized) {
  163                 TAILQ_INIT(&svr4_head);
  164                 initialized = 1;
  165         }
  166 
  167         e = malloc(sizeof(*e), M_TEMP, M_WAITOK);
  168         e->cookie = NULL;
  169         e->dev = st->st_dev;
  170         e->ino = st->st_ino;
  171         e->p = p;
  172 
  173         if ((error = copyinstr(path, e->sock.sun_path,
  174             sizeof(e->sock.sun_path), &len)) != 0) {
  175                 DPRINTF(("svr4_32_add_socket: copyinstr failed %d\n", error));
  176                 free(e, M_TEMP);
  177                 return error;
  178         }
  179 
  180         e->sock.sun_family = AF_LOCAL;
  181         e->sock.sun_len = len;
  182 
  183         TAILQ_INSERT_HEAD(&svr4_head, e, entries);
  184         DPRINTF(("svr4_32_add_socket: %s [%p,%d,%d]\n", e->sock.sun_path,
  185                  p, e->dev, e->ino));
  186         return 0;
  187 }
  188 #endif
  189 
  190 int
  191 svr4_32_sys_socket(l, v, retval)
  192         struct lwp *l;
  193         void *v;
  194         register_t *retval;
  195 {
  196         struct svr4_32_sys_socket_args *uap = v;
  197         struct compat_30_sys_socket_args uap0;
  198 
  199         /*
  200          * We need to use a separate args since native has a different
  201          * padding.
  202          */
  203         SCARG(&uap0, domain) = SCARG(uap, domain);
  204         SCARG(&uap0, protocol) = SCARG(uap, protocol);
  205         switch (SCARG(uap, type)) {
  206         case SVR4_SOCK_DGRAM:
  207                 SCARG(&uap0, type) = SOCK_DGRAM;
  208                 break;
  209 
  210         case SVR4_SOCK_STREAM:
  211                 SCARG(&uap0, type) = SOCK_STREAM;
  212                 break;
  213 
  214         case SVR4_SOCK_RAW:
  215                 SCARG(&uap0, type) = SOCK_RAW;
  216                 break;
  217 
  218         case SVR4_SOCK_RDM:
  219                 SCARG(&uap0, type) = SOCK_RDM;
  220                 break;
  221 
  222         case SVR4_SOCK_SEQPACKET:
  223                 SCARG(&uap0, type) = SOCK_SEQPACKET;
  224                 break;
  225         default:
  226                 return EINVAL;
  227         }
  228         return sys___socket30(l, &uap0, retval);
  229 }

Cache object: 10f7a1f6a2d598ba5736e24f3128e5c1


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.