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/irix/irix_mman.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: irix_mman.c,v 1.22 2008/04/28 20:23:41 martin Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Emmanuel Dreyfus.
    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  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: irix_mman.c,v 1.22 2008/04/28 20:23:41 martin Exp $");
   34 
   35 #if defined(_KERNEL_OPT)
   36 #include "opt_sysv.h"
   37 #endif
   38 
   39 #include <sys/types.h>
   40 #include <sys/param.h>
   41 #include <sys/signal.h>
   42 #include <sys/proc.h>
   43 #include <sys/exec.h>
   44 #include <sys/filedesc.h>
   45 #include <sys/file.h>
   46 #include <sys/vnode.h>
   47 #include <sys/vnode_if.h>
   48 #include <sys/mount.h>
   49 #include <sys/rwlock.h>
   50 #include <sys/systm.h>
   51 #include <sys/syscallargs.h>
   52 
   53 #include <compat/svr4/svr4_types.h>
   54 #include <compat/svr4/svr4_lwp.h>
   55 #include <compat/svr4/svr4_ucontext.h>
   56 #include <compat/svr4/svr4_signal.h>
   57 #include <compat/svr4/svr4_syscallargs.h>
   58 
   59 #include <compat/irix/irix_types.h>
   60 #include <compat/irix/irix_signal.h>
   61 #include <compat/irix/irix_mman.h>
   62 #include <compat/irix/irix_prctl.h>
   63 #include <compat/irix/irix_exec.h>
   64 #include <compat/irix/irix_syscallargs.h>
   65 
   66 static int irix_mmap(struct lwp *, void *, size_t, int ,
   67                 int, int, off_t, register_t *);
   68 
   69 int
   70 irix_sys_mmap(struct lwp *l, const struct irix_sys_mmap_args *uap, register_t *retval)
   71 {
   72         /* {
   73                 syscallarg(void *) addr;
   74                 syscallarg(irix_size_t) len;
   75                 syscallarg(int) prot;
   76                 syscallarg(int) flags;
   77                 syscallarg(int) fd;
   78                 syscallarg(irix_off_t) pos;
   79         } */
   80 
   81         return irix_mmap(l, SCARG(uap, addr), SCARG(uap, len),
   82             SCARG(uap, prot), SCARG(uap, flags), SCARG(uap, fd),
   83             SCARG(uap, pos), retval);
   84 }
   85 
   86 int
   87 irix_sys_mmap64(struct lwp *l, const struct irix_sys_mmap64_args *uap, register_t *retval)
   88 {
   89         /* {
   90                 syscallarg(void *) addr;
   91                 syscallarg(irix_size_t) len;
   92                 syscallarg(int) prot;
   93                 syscallarg(int) flags;
   94                 syscallarg(int) fd;
   95                 syscallarg(int) pad1;
   96                 syscallarg(irix_off64_t) pos;
   97         } */
   98 
   99         return irix_mmap(l, SCARG(uap, addr), SCARG(uap, len),
  100             SCARG(uap, prot), SCARG(uap, flags), SCARG(uap, fd),
  101             SCARG(uap, pos), retval);
  102 }
  103 
  104 static int
  105 irix_mmap(struct lwp *l, void *addr, size_t len, int prot, int flags, int fd, off_t pos, register_t *retval)
  106 {
  107         struct proc *p = l->l_proc;
  108         struct sys_mmap_args cup;
  109         int bsd_flags = 0;
  110         int error = 0;
  111 
  112 #ifdef DEBUG_IRIX
  113         printf("irix_sys_mmap(): addr = %p, len = 0x%x, prot = 0x%x ",
  114             addr, len, prot);
  115         printf("flags = 0x%x, fd = %d, pos = 0x%lx\n", flags, fd, (long)pos);
  116 
  117 #endif
  118         if (flags & IRIX_MAP_SHARED)
  119                 bsd_flags |= MAP_SHARED;
  120         if (flags & IRIX_MAP_PRIVATE)
  121                 bsd_flags |= MAP_PRIVATE;
  122         if (flags & IRIX_MAP_COPY)
  123                 bsd_flags |= MAP_PRIVATE;
  124 
  125         /*
  126          * Note about MAP_FIXED: IRIX's mmap(2) states that
  127          * when MAP_FIXED is unset, range 0x30000000 to 0x40000000
  128          * will not be used except if MAP_SGI_ANYADDR is set
  129          * or if syssgi(SGI_UNSUPPORTED_MAP_RESERVED_RANGE) was
  130          * enabled. We do not emulate this behavior for now.
  131          */
  132         if (flags & IRIX_MAP_FIXED)
  133                 bsd_flags |= MAP_FIXED;
  134         if (flags & IRIX_MAP_RENAME)
  135                 bsd_flags |= MAP_RENAME;
  136 
  137         if (flags & IRIX_MAP_AUTORESRV)
  138                 printf("Warning: unsupported IRIX mmap() flag MAP_AUTORESV\n");
  139         if (flags & IRIX_MAP_TEXT)
  140                 printf("Warning: unsupported IRIX mmap() flag MAP_TEXT\n");
  141         if (flags & IRIX_MAP_BRK)
  142                 printf("Warning: unsupported IRIX mmap() flag MAP_BRK\n");
  143         if (flags & IRIX_MAP_PRIMARY)
  144                 printf("Warning: unsupported IRIX mmap() flag MAP_PRIMARY\n");
  145         if (flags & IRIX_MAP_SGI_ANYADDR)
  146                 printf("Warning: unsupported IRIX mmap() flag IRIX_MAP_SGI_ANYADDR\n");
  147 
  148         /*
  149          * When AUTOGROW is set and the mapping is bigger than
  150          * the file, if pages beyond the end of file are touched,
  151          * IRIX will increase the file size accordingly. We are
  152          * not able to emulate this (yet), hence we immediatly
  153          * grow the file to fit the mapping, before mapping it.
  154          */
  155         if (flags & IRIX_MAP_AUTOGROW) {
  156                 file_t *fp;
  157                 struct vnode *vp;
  158                 struct vattr vattr;
  159 
  160                 if ((error = fd_getvnode(fd, &fp)) != 0)
  161                         return error;
  162 
  163                 if ((fp->f_flag & FWRITE) == 0) {
  164                         error = EINVAL;
  165                         goto out;
  166                 }
  167 
  168                 vp = fp->f_data;
  169                 if (vp->v_type == VFIFO) {
  170                         error = ESPIPE;
  171                         goto out;
  172                 }
  173 
  174                 if (vp->v_type == VDIR) {
  175                         error = EISDIR;
  176                         goto out;
  177                 }
  178 
  179                 if ((error = VOP_GETATTR(vp, &vattr, l->l_cred)) != 0)
  180                         goto out;
  181 
  182                 if (pos + len > vattr.va_size) {
  183                         VATTR_NULL(&vattr);
  184                         vattr.va_size = round_page(pos + len);
  185 
  186                         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
  187 
  188                         error = VOP_SETATTR(vp, &vattr, l->l_cred);
  189 
  190                         VOP_UNLOCK(vp, 0);
  191                 }
  192 out:
  193                 fd_putfile(fd);
  194                 if (error)
  195                         return error;
  196 
  197         }
  198 
  199         SCARG(&cup, addr) = addr;
  200         SCARG(&cup, len) = len;
  201         SCARG(&cup, prot) = prot;
  202         SCARG(&cup, flags) = bsd_flags;
  203         SCARG(&cup, fd) = fd;
  204         SCARG(&cup, pos) = pos;
  205 
  206         /* A private mapping that should not be visible to the share group */
  207         if (flags & IRIX_MAP_LOCAL) {
  208                 if ((error = sys_mmap(l, &cup, retval)) != 0)
  209                         return error;
  210                 addr = (void *)*retval;
  211                 irix_isrr_insert((vaddr_t)addr, len, IRIX_ISRR_PRIVATE, p);
  212                 return 0;
  213         }
  214 
  215         IRIX_VM_SYNC(p, error = sys_mmap(l, &cup, retval));
  216         return error;
  217 }
  218 
  219 
  220 int
  221 irix_sys_munmap(struct lwp *l, const struct irix_sys_munmap_args *uap, register_t *retval)
  222 {
  223         /* {
  224                 syscallarg(void *) addr;
  225                 syscallarg(size_t) len;
  226         } */
  227         struct proc *p = l->l_proc;
  228         int error;
  229 
  230         IRIX_VM_SYNC(p, error = sys_munmap(l, (const void *)uap, retval));
  231         if (error == 0)
  232                 irix_isrr_insert((vaddr_t)SCARG(uap, addr),
  233                     SCARG(uap, len), IRIX_ISRR_SHARED, p);
  234 
  235         return error;
  236 }
  237 
  238 int
  239 irix_sys_break(struct lwp *l, const struct irix_sys_break_args *uap, register_t *retval)
  240 {
  241         struct proc *p = l->l_proc;
  242         int error;
  243 
  244         IRIX_VM_SYNC(p, error = svr4_sys_break(l, (const void *)uap, retval));
  245         return error;
  246 }
  247 
  248 #ifdef SYSVSHM
  249 int
  250 irix_sys_shmsys(struct lwp *l, const struct irix_sys_shmsys_args *uap, register_t *retval)
  251 {
  252         struct proc *p = l->l_proc;
  253         int error;
  254 
  255         IRIX_VM_SYNC(p, error = svr4_sys_shmsys(l, (const void *)uap, retval));
  256         return error;
  257 }
  258 #endif
  259 
  260 int
  261 irix_sys_mprotect(struct lwp *l, const struct irix_sys_mprotect_args *uap, register_t *retval)
  262 {
  263         struct proc *p = l->l_proc;
  264         int error;
  265 
  266         IRIX_VM_SYNC(p, error = sys_mprotect(l, (const void *)uap, retval));
  267         return error;
  268 }

Cache object: ba0d445063fa9f7a5177e32512c4d0a9


[ 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.