summaryrefslogtreecommitdiffstats
path: root/bsd-user/mmap.c
Commit message (Collapse)AuthorAgeFilesLines
* bsd-user/mmap.c: assert that target_mprotect cannot failWarner Losh2021-10-181-4/+1Star
| | | | | | | | | | | | | | | | | Similar to the equivalent linux-user change 86abac06c14. All error conditions that target_mprotect checks are also checked by target_mmap. EACCESS cannot happen because we are just removing PROT_WRITE. ENOMEM should not happen because we are modifying a whole VMA (and we have bigger problems anyway if it happens). Fixes a Coverity false positive, where Coverity complains about target_mprotect's return value being passed to tb_invalidate_phys_range. Signed-off-by: Mikaël Urankar <mikael.urankar@gmail.com> Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user/mmap.c: Implement MAP_EXCL, required by jemalloc in headKyle Evans2021-10-181-3/+7
| | | | | | | | | | | jemalloc requires a working MAP_EXCL. Ensure that no page is double mapped when specified. In addition, use guest_range_valid_untagged to test for valid ranges of pages rather than an incomplete inlined version of the test that might be wrong. Signed-off-by: Kyle Evans <kevans@FreeBSD.org> Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
* bsd-user/mmap.c: Don't mmap fd == -1 independently from MAP_ANON flagWarner Losh2021-10-181-5/+25
| | | | | | | | | | | | | Switch checks for !(flags & MAP_ANONYMOUS) with checks for fd != -1. MAP_STACK and MAP_GUARD both require fd == -1 and don't require mapping the fd either. Add analysis from Guy Yur detailing the different cases for MAP_GUARD and MAP_STACK. Signed-off-by: Guy Yur <guyyur@gmail.com> [ partially merged before, finishing the job and documenting origin] Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user/mmap.c: Convert to qemu_log logging for mmap debuggingWarner Losh2021-10-181-30/+23Star
| | | | | | | | | Convert DEBUG_MMAP to qemu_log CPU_LOG_PAGE. Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user/mmap.c: mmap prefer MAP_ANON for BSDWarner Losh2021-10-181-6/+5Star
| | | | | | | | | | MAP_ANON and MAP_ANONYMOUS are identical. Prefer MAP_ANON for BSD since the file is now a confusing mix of the two. Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user/mmap.c: mmap return ENOMEM on overflowWarner Losh2021-10-181-1/+8
| | | | | | | | | | | mmap should return ENOMEM on len overflow rather than EINVAL. Return EINVAL when len == 0 and ENOMEM when the rounded to a page length is 0. Found by make check-tcg. Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user/mmap.c: MAP_ symbols are defined, so no need for ifdefsWarner Losh2021-10-181-14/+0Star
| | | | | | | | | | All these MAP_ symbols are always defined on supported FreeBSD versions (12.2 and newer), so remove the #ifdefs since they aren't needed. Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Acked-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user/mmap.c: check pread's return value to fix warnings with _FORTIFY_SOURCEMikaël Urankar2021-10-181-2/+6
| | | | | | | | | | | | Simmilar to the equivalent linux-user: commit fb7e378cf9c, which added checking to pread's return value. Update to current qemu standards with {} around the if statement. Signed-off-by: Mikaël Urankar <mikael.urankar@gmail.com> Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user/mmap.c: Always zero MAP_ANONYMOUS memory in mmap_frag()Mikaël Urankar2021-10-181-1/+3
| | | | | | | | | | | | Similar to the equivalent linux-user commit e6deac9cf99 When mapping MAP_ANONYMOUS memory fragments, still need notice about to set it zero, or it will cause issues. Signed-off-by: Mikaël Urankar <mikael.urankar@gmail.com> Signed-off-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user: Update mapping to handle reserved and starting conditionsWarner Losh2021-09-101-68/+347
| | | | | | | | | | | | | | | | | | Update the reserved base based on what platform we're on, as well as the start of the mmap range. Update routines that find va ranges to interact with the reserved ranges as well as properly align the mapping (this is especially important for targets whose page size does not match the host's). Loop where appropriate when the initial address space offered by mmap does not meet the contraints. This has 18e80c55bb6 from linux-user folded in to the upstream bsd-user code as well. Signed-off-by: Mikaël Urankar <mikael.urankar@gmail.com> Signed-off-by: Stacey Son <sson@FreeBSD.org> Signed-off-by: Warner Losh <imp@bsdimp.com> Acked-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user: update debugging in mmap.cWarner Losh2021-09-101-17/+38
| | | | | | | | | | | Update the debugging code for new features and different targets. Signed-off-by: Mikaël Urankar <mikael.urankar@gmail.com> Signed-off-by: Sean Bruno <sbruno@FreeBSD.org> Signed-off-by: Kyle Evans <kevans@FreeBSD.org> Signed-off-by: Warner Losh <imp@bsdimp.com> Acked-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user: Rewrite target system call definintion glueWarner Losh2021-09-101-2/+0Star
| | | | | | | | | | | | Rewrite target definnitions to interface with the FreeBSD system calls. This covers basic types (time_t, iovec, umtx_time, timespec, timeval, rusage, rwusage) and basic defines (mmap, rusage). Also included are FreeBSD version-specific variations. Signed-off-by: Stacey Son <sson@FreeBSD.org> Signed-off-by: Warner Losh <imp@bsdimp.com> Acked-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
* bsd-user: style tweak: keyword space (Warner Losh2021-05-111-11/+11
| | | | | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Warner Losh <imp@bsdimp.com>
* exec: Use cpu_untagged_addr in g2h; split out g2h_untaggedRichard Henderson2021-02-161-11/+12
| | | | | | | | | | | | | | | | | | | | | | | Use g2h_untagged in contexts that have no cpu, e.g. the binary loaders that operate before the primary cpu is created. As a colollary, target_mmap and friends must use untagged addresses, since they are used by the loaders. Use g2h_untagged on values returned from target_mmap, as the kernel never applies a tag itself. Use g2h_untagged on all pc values. The only current user of tags, aarch64, removes tags from code addresses upon branch, so "pc" is always untagged. Use g2h with the cpu context on hand wherever possible. Use g2h_untagged in lock_user, which will be updated soon. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20210212184902.1251044-13-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* bsd-user: include "exec/exec-all.h" which provides mmap_lock/unlock"Paolo Bonzini2018-06-011-0/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* bsd-user/mmap.c: Move __thread attribute to right placePeter Maydell2017-07-211-1/+1
| | | | | | | | | | Avoid a compiler warning on OpenBSD: bsd-user/mmap.c:28:1: warning: '__thread' is not at beginning of declaration [-Wold-style-declaration] by moving the __thread attribute to its proper place. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-id: 1500395194-21455-2-git-send-email-peter.maydell@linaro.org
* bsd-user: align use of mmap_lock to that of linux-userAlex Bennée2017-03-281-12/+1Star
| | | | | | | | | | | | | | The introduction of stricter mmap_lock checking in translate-all broke the BSD user build. The working mmap_lock functions were hidden behind CONFIG_USE_NPTL which is never defined. This patch brings them inline with linux-user. Despite the disapearence of the comment "We aren't threadsafe to start with..." this doesn't make bsd-user so. It will still need the rest of the fixes that have been done in linux-user ported over. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
* configure: remove CygwinPaolo Bonzini2017-03-201-5/+0Star
| | | | | | | | | | | | | The Cygwin target is really compiling for native Win32 with -mno-cygwin. Except, GCC 4.7.0 has finally removed the long deprecated -mno-cygwin option, and that happened about five years ago. Let it rest in peace. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Stefan Weil <sw@weilnetz.de> Message-id: 20170317160811.28370-1-pbonzini@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* translate-all: add DEBUG_LOCKING assertsAlex Bennée2016-10-311-0/+5
| | | | | | | | | | | | | | | | | | | | | This adds asserts to check the locking on the various translation engines structures. There are two sets of structures that are protected by locks. The first the l1map and PageDesc structures used to track which translation blocks are associated with which physical addresses. In user-mode this is covered by the mmap_lock. The second case are TB context related structures which are protected by tb_lock which is also user-mode only. Currently the asserts do nothing in SoftMMU mode but this will change for MTTCG. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <rth@twiddle.net> Message-Id: <20161027151030.20863-4-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* os-posix: include sys/mman.hPaolo Bonzini2016-06-161-1/+0Star
| | | | | | | | | qemu/osdep.h checks whether MAP_ANONYMOUS is defined, but this check is bogus without a previous inclusion of sys/mman.h. Include it in sysemu/os-posix.h and remove it from everywhere else. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* bsd-user: Clean up includesPeter Maydell2016-02-041-6/+1Star
| | | | | | | | | | Clean up includes so that osdep.h is included first and headers which it implies are not included manually. This commit was created with scripts/clean-includes. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 1454089805-5470-4-git-send-email-peter.maydell@linaro.org
* bsd-user/mmap.c: Don't try to override g_malloc/g_freePeter Maydell2014-06-111-60/+0Star
| | | | | | | | | | | | | | | | | | Trying to override the implementations of g_malloc and g_free is a really bad idea -- it means statically linked builds fail to link (because of the multiple definitions provided by this file and by glib), and non-statically linked builds segfault as soon as they try to do anything more complicated than printing the usage message. Remove these overridden versions and just use the glib ones. This is sufficient that bsd-user can run basic x86-64 binaries on OpenBSD again; FreeBSD and NetBSD seem to have further issues. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Sean Bruno <sbruno@freebsd.org> Reviewed-by: Ed Maste <emaste@freebsd.org>
* bsd-user: avoid conflict with qemu_vmallocBlue Swirl2013-01-261-2/+2
| | | | | | | | | Rename qemu_vmalloc() to bsd_vmalloc(), adjust the only user. Remove #ifdeffery in oslib-posix.c. Tested-by: Andreas Färber <andreas.faerber@web.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Use glib memory allocation and free functionsAnthony Liguori2011-08-211-8/+8
| | | | | | qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Fix bsd-user qemu_vmalloc() host page protection codeJuergen Lock2010-03-301-3/+2Star
| | | | | | | Just do the same as linux-user does. Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* bsd/darwin-user: mmap_frag() users only check for -1 errorBlue Swirl2010-01-311-1/+1
| | | | | | See also ee636500d6eab44b83f09cb730b67226b70423b1. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* rename USE_NPTL to CONFIG_USE_NPTLJuan Quintela2009-07-271-1/+1
| | | | | Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Update to a hopefully more future proof FSF addressBlue Swirl2009-07-161-3/+1Star
| | | | Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Fix qemu_malloc.malc2009-01-281-0/+2
| | | | | | | make {linux,bsd}-user qemu_realloc handle ptr == NULL correctly. spotted by malc. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6466 c046a42c-6fe2-441c-8c8c-71466251a162
* Fix bsd-user compile like r6412blueswir12009-01-241-0/+13
| | | | git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6434 c046a42c-6fe2-441c-8c8c-71466251a162
* Fix more FSF addressesblueswir12009-01-051-1/+2
| | | | git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6192 c046a42c-6fe2-441c-8c8c-71466251a162
* Prepare for handling different BSD mmap() flagsblueswir12008-11-291-4/+5
| | | | git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5809 c046a42c-6fe2-441c-8c8c-71466251a162
* Preliminary BSD user emulator supportblueswir12008-10-261-0/+545
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5544 c046a42c-6fe2-441c-8c8c-71466251a162