<p dir="ltr">It makes sense to me. Chris identified some mmap capabilities that could be implemented on normal Barr metal RTEMS but when paravirtualized, we can use kernel or hypervisor services to support the actual dirty work. But our code still needs to properly track mmaps and shm_open regions so the unmap or close is error checked correctly </p>
<p dir="ltr">On Jul 29, 2016 8:07 PM, "Gedare Bloom" <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br>
><br>
> On Wed, Nov 19, 2014 at 5:04 PM, Joel Sherrill<br>
> <<a href="mailto:joel.sherrill@oarcorp.com">joel.sherrill@oarcorp.com</a>> wrote:<br>
> ><br>
> > On 11/19/2014 2:55 PM, Gedare Bloom wrote:<br>
> >> Is this the same one that Chris has had in use before? (I think that<br>
> >> is who had one in use..)<br>
> > Yes. You wanted it in rtems to avoid me having to add a prototype to a file<br>
> > to avoid a warning.<br>
> ><br>
> I'm looking at implementing/stubbing some more mman functions. While I<br>
> do this, does it make sense to relocate this mman.h into<br>
> newlib/libc/sys/rtems/include/sys/mman.h?<br>
><br>
> > I didn't integrate his implementation but only his .h file and stubs. His<br>
> > implementation will need the addition of tests and code in confdefs.h.<br>
> ><br>
> I may integrate his implementation as part of my effort.<br>
><br>
> > --joel<br>
> ><br>
> >> -Gedare<br>
> >><br>
> >> On Wed, Nov 19, 2014 at 2:59 PM, Joel Sherrill<br>
> >> <<a href="mailto:joel.sherrill@oarcorp.com">joel.sherrill@oarcorp.com</a>> wrote:<br>
> >>> * Makefile.am updated and <a href="http://preinstall.am">preinstall.am</a> regenerated.<br>
> >>> * mprotect.c had a prototype removed now that we have mman.h<br>
> >>> * mmap.c, munmap.c: New stub files.<br>
> >>> ---<br>
> >>> cpukit/posix/Makefile.am | 5 ++<br>
> >>> cpukit/posix/include/sys/mman.h | 189 ++++++++++++++++++++++++++++++++++++++++<br>
> >>> cpukit/posix/<a href="http://preinstall.am">preinstall.am</a> | 9 ++<br>
> >>> cpukit/posix/src/mmap.c | 26 ++++++<br>
> >>> cpukit/posix/src/mprotect.c | 10 +--<br>
> >>> cpukit/posix/src/munmap.c | 30 +++++++<br>
> >>> 6 files changed, 261 insertions(+), 8 deletions(-)<br>
> >>> create mode 100644 cpukit/posix/include/sys/mman.h<br>
> >>> create mode 100644 cpukit/posix/src/mmap.c<br>
> >>> create mode 100644 cpukit/posix/src/munmap.c<br>
> >>><br>
> >>> diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am<br>
> >>> index 346b65a..b3be07c 100644<br>
> >>> --- a/cpukit/posix/Makefile.am<br>
> >>> +++ b/cpukit/posix/Makefile.am<br>
> >>> @@ -21,6 +21,9 @@ include_rtems_posix_HEADERS += include/rtems/posix/keyimpl.h<br>
> >>> include_rtems_posix_HEADERS += include/rtems/posix/config.h<br>
> >>> include_rtems_posix_HEADERS += include/rtems/posix/posixapi.h<br>
> >>><br>
> >>> +include_sysdir = $(includedir)/sys<br>
> >>> +include_sys_HEADERS = include/sys/mman.h<br>
> >>> +<br>
> >>> if HAS_PTHREADS<br>
> >>> # include<br>
> >>> include_HEADERS = include/aio.h<br>
> >>> @@ -91,7 +94,9 @@ libposix_a_SOURCES += src/cond.c src/condattrdestroy.c \<br>
> >>> src/condtimedwait.c src/condwait.c src/condwaitsupp.c src/condget.c<br>
> >>><br>
> >>> ## MEMORY_C_FILES<br>
> >>> +libposix_a_SOURCES += src/mmap.c<br>
> >>> libposix_a_SOURCES += src/mprotect.c<br>
> >>> +libposix_a_SOURCES += src/munmap.c<br>
> >>><br>
> >>> ## MESSAGE_QUEUE_C_FILES<br>
> >>> libposix_a_SOURCES += src/mqueue.c src/mqueueclose.c \<br>
> >>> diff --git a/cpukit/posix/include/sys/mman.h b/cpukit/posix/include/sys/mman.h<br>
> >>> new file mode 100644<br>
> >>> index 0000000..ddf34cc<br>
> >>> --- /dev/null<br>
> >>> +++ b/cpukit/posix/include/sys/mman.h<br>
> >>> @@ -0,0 +1,189 @@<br>
> >>> +/* $NetBSD: mman.h,v 1.36 2005/09/13 01:42:51 christos Exp $ */<br>
> >>> +<br>
> >>> +/*-<br>
> >>> + * Copyright (c) 1982, 1986, 1993<br>
> >>> + * The Regents of the University of California. All rights reserved.<br>
> >>> + *<br>
> >>> + * Redistribution and use in source and binary forms, with or without<br>
> >>> + * modification, are permitted provided that the following conditions<br>
> >>> + * are met:<br>
> >>> + * 1. Redistributions of source code must retain the above copyright<br>
> >>> + * notice, this list of conditions and the following disclaimer.<br>
> >>> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> >>> + * notice, this list of conditions and the following disclaimer in the<br>
> >>> + * documentation and/or other materials provided with the distribution.<br>
> >>> + * 3. Neither the name of the University nor the names of its contributors<br>
> >>> + * may be used to endorse or promote products derived from this software<br>
> >>> + * without specific prior written permission.<br>
> >>> + *<br>
> >>> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND<br>
> >>> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> >>> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> >>> + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE<br>
> >>> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br>
> >>> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br>
> >>> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br>
> >>> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br>
> >>> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br>
> >>> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>
> >>> + * SUCH DAMAGE.<br>
> >>> + *<br>
> >>> + * @(#)mman.h 8.2 (Berkeley) 1/9/95<br>
> >>> + */<br>
> >>> +<br>
> >>> +#ifndef _SYS_MMAN_H_<br>
> >>> +#define _SYS_MMAN_H_<br>
> >>> +<br>
> >>> +#ifdef __rtems__<br>
> >>> +<br>
> >>> +#include <inttypes.h><br>
> >>> +#include <stddef.h><br>
> >>> +#include <sys/types.h><br>
> >>> +<br>
> >>> +#else /* __rtems__ */<br>
> >>> +#include <sys/featuretest.h><br>
> >>> +<br>
> >>> +#include <machine/ansi.h><br>
> >>> +<br>
> >>> +#ifdef _BSD_SIZE_T_<br>
> >>> +typedef _BSD_SIZE_T_ size_t;<br>
> >>> +#undef _BSD_SIZE_T_<br>
> >>> +#endif<br>
> >>> +<br>
> >>> +#include <sys/ansi.h><br>
> >>> +<br>
> >>> +#ifndef mode_t<br>
> >>> +typedef __mode_t mode_t;<br>
> >>> +#define mode_t __mode_t<br>
> >>> +#endif<br>
> >>> +<br>
> >>> +#ifndef off_t<br>
> >>> +typedef __off_t off_t; /* file offset */<br>
> >>> +#define off_t __off_t<br>
> >>> +#endif<br>
> >>> +#endif /* __rtems__ */<br>
> >>> +<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * Protections are chosen from these bits, or-ed together<br>
> >>> + */<br>
> >>> +#define PROT_NONE 0x00 /* no permissions */<br>
> >>> +#define PROT_READ 0x01 /* pages can be read */<br>
> >>> +#define PROT_WRITE 0x02 /* pages can be written */<br>
> >>> +#define PROT_EXEC 0x04 /* pages can be executed */<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * Flags contain sharing type and options.<br>
> >>> + * Sharing types; choose one.<br>
> >>> + */<br>
> >>> +#define MAP_SHARED 0x0001 /* share changes */<br>
> >>> +#define MAP_PRIVATE 0x0002 /* changes are private */<br>
> >>> +<br>
> >>> +#ifdef _KERNEL<br>
> >>> +/*<br>
> >>> + * Deprecated flag; these are treated as MAP_PRIVATE internally by<br>
> >>> + * the kernel.<br>
> >>> + */<br>
> >>> +#define MAP_COPY 0x0004 /* "copy" region at mmap time */<br>
> >>> +#endif<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * Other flags<br>
> >>> + */<br>
> >>> +#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */<br>
> >>> +#define MAP_RENAME 0x0020 /* Sun: rename private pages to file */<br>
> >>> +#define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */<br>
> >>> +#define MAP_INHERIT 0x0080 /* region is retained after exec */<br>
> >>> +#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */<br>
> >>> +#define MAP_TRYFIXED 0x0400 /* attempt hint address, even within break */<br>
> >>> +#define MAP_WIRED 0x0800 /* mlock() mapping when it is established */<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * Mapping type<br>
> >>> + */<br>
> >>> +#define MAP_FILE 0x0000 /* map from file (default) */<br>
> >>> +#define MAP_ANON 0x1000 /* allocated from memory, swap space */<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * Alignment (expressed in log2). Must be >= log2(PAGE_SIZE) and<br>
> >>> + * < # bits in a pointer (26 (acorn26), 32 or 64).<br>
> >>> + */<br>
> >>> +#define MAP_ALIGNED(n) ((n) << MAP_ALIGNMENT_SHIFT)<br>
> >>> +#define MAP_ALIGNMENT_SHIFT 24<br>
> >>> +#define MAP_ALIGNMENT_MASK MAP_ALIGNED(0xff)<br>
> >>> +#define MAP_ALIGNMENT_64KB MAP_ALIGNED(16) /* 2^16 */<br>
> >>> +#define MAP_ALIGNMENT_16MB MAP_ALIGNED(24) /* 2^24 */<br>
> >>> +#define MAP_ALIGNMENT_4GB MAP_ALIGNED(32) /* 2^32 */<br>
> >>> +#define MAP_ALIGNMENT_1TB MAP_ALIGNED(40) /* 2^40 */<br>
> >>> +#define MAP_ALIGNMENT_256TB MAP_ALIGNED(48) /* 2^48 */<br>
> >>> +#define MAP_ALIGNMENT_64PB MAP_ALIGNED(56) /* 2^56 */<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * Error indicator returned by mmap(2)<br>
> >>> + */<br>
> >>> +#define MAP_FAILED ((void *) -1) /* mmap() failed */<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * Flags to msync<br>
> >>> + */<br>
> >>> +#define MS_ASYNC 0x01 /* perform asynchronous writes */<br>
> >>> +#define MS_INVALIDATE 0x02 /* invalidate cached data */<br>
> >>> +#define MS_SYNC 0x04 /* perform synchronous writes */<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * Flags to mlockall<br>
> >>> + */<br>
> >>> +#define MCL_CURRENT 0x01 /* lock all pages currently mapped */<br>
> >>> +#define MCL_FUTURE 0x02 /* lock all pages mapped in the future */<br>
> >>> +<br>
> >>> +#if defined(_NETBSD_SOURCE)<br>
> >>> +/*<br>
> >>> + * Advice to madvise<br>
> >>> + */<br>
> >>> +#define MADV_NORMAL 0 /* no further special treatment */<br>
> >>> +#define MADV_RANDOM 1 /* expect random page references */<br>
> >>> +#define MADV_SEQUENTIAL 2 /* expect sequential page references */<br>
> >>> +#define MADV_WILLNEED 3 /* will need these pages */<br>
> >>> +#define MADV_DONTNEED 4 /* dont need these pages */<br>
> >>> +#define MADV_SPACEAVAIL 5 /* insure that resources are reserved */<br>
> >>> +#define MADV_FREE 6 /* pages are empty, free them */<br>
> >>> +/*<br>
> >>> + * Flags to minherit<br>
> >>> + */<br>
> >>> +#define MAP_INHERIT_SHARE 0 /* share with child */<br>
> >>> +#define MAP_INHERIT_COPY 1 /* copy into child */<br>
> >>> +#define MAP_INHERIT_NONE 2 /* absent from child */<br>
> >>> +#define MAP_INHERIT_DONATE_COPY 3 /* copy and delete -- not<br>
> >>> + implemented in UVM */<br>
> >>> +#define MAP_INHERIT_DEFAULT MAP_INHERIT_COPY<br>
> >>> +#endif<br>
> >>> +<br>
> >>> +#ifndef _KERNEL<br>
> >>> +<br>
> >>> +#include <sys/cdefs.h><br>
> >>> +<br>
> >>> +__BEGIN_DECLS<br>
> >>> +void *mmap(void *, size_t, int, int, int, off_t);<br>
> >>> +int munmap(void *, size_t);<br>
> >>> +int mprotect(void *, size_t, int);<br>
> >>> +#ifndef __LIBC12_SOURCE__<br>
> >>> +#if defined(__rtems__)<br>
> >>> +int msync(void *, size_t, int);<br>
> >>> +#else<br>
> >>> +int msync(void *, size_t, int) __RENAME(__msync13);<br>
> >>> +#endif<br>
> >>> +#endif<br>
> >>> +int mlock(const void *, size_t);<br>
> >>> +int munlock(const void *, size_t);<br>
> >>> +int mlockall(int);<br>
> >>> +int munlockall(void);<br>
> >>> +#if defined(_NETBSD_SOURCE)<br>
> >>> +int madvise(void *, size_t, int);<br>
> >>> +int mincore(void *, size_t, char *);<br>
> >>> +int minherit(void *, size_t, int);<br>
> >>> +#endif<br>
> >>> +__END_DECLS<br>
> >>> +<br>
> >>> +#endif /* !_KERNEL */<br>
> >>> +<br>
> >>> +#endif /* !_SYS_MMAN_H_ */<br>
> >>> diff --git a/cpukit/posix/<a href="http://preinstall.am">preinstall.am</a> b/cpukit/posix/<a href="http://preinstall.am">preinstall.am</a><br>
> >>> index 6e3f2a2..1b65213 100644<br>
> >>> --- a/cpukit/posix/<a href="http://preinstall.am">preinstall.am</a><br>
> >>> +++ b/cpukit/posix/<a href="http://preinstall.am">preinstall.am</a><br>
> >>> @@ -43,6 +43,15 @@ $(PROJECT_INCLUDE)/rtems/posix/posixapi.h: include/rtems/posix/posixapi.h $(PROJ<br>
> >>> $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/posixapi.h<br>
> >>> PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/posixapi.h<br>
> >>><br>
> >>> +$(PROJECT_INCLUDE)/sys/$(dirstamp):<br>
> >>> + @$(MKDIR_P) $(PROJECT_INCLUDE)/sys<br>
> >>> + @: > $(PROJECT_INCLUDE)/sys/$(dirstamp)<br>
> >>> +PREINSTALL_DIRS += $(PROJECT_INCLUDE)/sys/$(dirstamp)<br>
> >>> +<br>
> >>> +$(PROJECT_INCLUDE)/sys/mman.h: include/sys/mman.h $(PROJECT_INCLUDE)/sys/$(dirstamp)<br>
> >>> + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/mman.h<br>
> >>> +PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/mman.h<br>
> >>> +<br>
> >>> if HAS_PTHREADS<br>
> >>> $(PROJECT_INCLUDE)/aio.h: include/aio.h $(PROJECT_INCLUDE)/$(dirstamp)<br>
> >>> $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/aio.h<br>
> >>> diff --git a/cpukit/posix/src/mmap.c b/cpukit/posix/src/mmap.c<br>
> >>> new file mode 100644<br>
> >>> index 0000000..2798326<br>
> >>> --- /dev/null<br>
> >>> +++ b/cpukit/posix/src/mmap.c<br>
> >>> @@ -0,0 +1,26 @@<br>
> >>> +/**<br>
> >>> + * @file<br>
> >>> + */<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * COPYRIGHT (c) 2014.<br>
> >>> + * On-Line Applications Research Corporation (OAR).<br>
> >>> + *<br>
> >>> + * The license and distribution terms for this file may be<br>
> >>> + * found in the file LICENSE in this distribution or at<br>
> >>> + * <a href="http://www.rtems.org/license/LICENSE">http://www.rtems.org/license/LICENSE</a>.<br>
> >>> + */<br>
> >>> +<br>
> >>> +#if HAVE_CONFIG_H<br>
> >>> +#include "config.h"<br>
> >>> +#endif<br>
> >>> +<br>
> >>> +#include <sys/mman.h><br>
> >>> +<br>
> >>> +int munmap(<br>
> >>> + void *addr __attribute__((unused)),<br>
> >>> + size_t length __attribute__((unused))<br>
> >>> +)<br>
> >>> +{<br>
> >>> + return -1;<br>
> >>> +}<br>
> >>> diff --git a/cpukit/posix/src/mprotect.c b/cpukit/posix/src/mprotect.c<br>
> >>> index 51b565e..94bd316 100644<br>
> >>> --- a/cpukit/posix/src/mprotect.c<br>
> >>> +++ b/cpukit/posix/src/mprotect.c<br>
> >>> @@ -28,16 +28,10 @@<br>
> >>> #endif<br>
> >>><br>
> >>> #include <unistd.h><br>
> >>> -<br>
> >>> -/*<br>
> >>> - * RTEMS does not have <sys/mman.h> so we need a prototype here to<br>
> >>> - * avoid warnings.<br>
> >>> - */<br>
> >>> -<br>
> >>> -int mprotect( const void *, size_t, int );<br>
> >>> +#include <sys/mman.h><br>
> >>><br>
> >>> int mprotect(<br>
> >>> - const void *addr __attribute__((unused)),<br>
> >>> + void *addr __attribute__((unused)),<br>
> >>> size_t len __attribute__((unused)),<br>
> >>> int prot __attribute__((unused)) )<br>
> >>> {<br>
> >>> diff --git a/cpukit/posix/src/munmap.c b/cpukit/posix/src/munmap.c<br>
> >>> new file mode 100644<br>
> >>> index 0000000..3ebb2f4<br>
> >>> --- /dev/null<br>
> >>> +++ b/cpukit/posix/src/munmap.c<br>
> >>> @@ -0,0 +1,30 @@<br>
> >>> +/**<br>
> >>> + * @file<br>
> >>> + */<br>
> >>> +<br>
> >>> +/*<br>
> >>> + * COPYRIGHT (c) 2014.<br>
> >>> + * On-Line Applications Research Corporation (OAR).<br>
> >>> + *<br>
> >>> + * The license and distribution terms for this file may be<br>
> >>> + * found in the file LICENSE in this distribution or at<br>
> >>> + * <a href="http://www.rtems.org/license/LICENSE">http://www.rtems.org/license/LICENSE</a>.<br>
> >>> + */<br>
> >>> +<br>
> >>> +#if HAVE_CONFIG_H<br>
> >>> +#include "config.h"<br>
> >>> +#endif<br>
> >>> +<br>
> >>> +#include <sys/mman.h><br>
> >>> +<br>
> >>> +void *mmap(<br>
> >>> + void *addr __attribute__((unused)),<br>
> >>> + size_t lenhth __attribute__((unused)),<br>
> >>> + int prot __attribute__((unused)),<br>
> >>> + int flags __attribute__((unused)),<br>
> >>> + int fildes __attribute__((unused)),<br>
> >>> + off_t off<br>
> >>> +)<br>
> >>> +{<br>
> >>> + return NULL;<br>
> >>> +}<br>
> >>> --<br>
> >>> 1.9.3<br>
> >>><br>
> >>> _______________________________________________<br>
> >>> devel mailing list<br>
> >>> <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
> >>> <a href="http://lists.rtems.org/mailman/listinfo/devel">http://lists.rtems.org/mailman/listinfo/devel</a><br>
> ><br>
> > --<br>
> > Joel Sherrill, Ph.D. Director of Research & Development<br>
> > joel.sherrill@OARcorp.com On-Line Applications Research<br>
> > Ask me about RTEMS: a free RTOS Huntsville AL 35805<br>
> > Support Available (256) 722-9985<br>
> ><br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel">http://lists.rtems.org/mailman/listinfo/devel</a><br></p>