aboutsummaryrefslogtreecommitdiff
path: root/bsd-user/mmap.c
AgeCommit message (Collapse)AuthorFilesLines
2024-08-21bsd-user: Handle short reads in mmap_h_gt_gRichard Henderson1-2/+36
In particular, if an image has a large bss, we can hit EOF before reading all bytes of the mapping. Mirror the similar change to linux-user. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20240820050848.165253-3-richard.henderson@linaro.org>
2024-05-06exec/cpu: Extract page-protection definitions to page-protection.hPhilippe Mathieu-Daudé1-0/+1
Extract page-protection definitions from "exec/cpu-all.h" to "exec/page-protection.h". The list of files requiring the new header was generated using: $ git grep -wE \ 'PAGE_(READ|WRITE|EXEC|RWX|VALID|ANON|RESERVED|TARGET_.|PASSTHROUGH)' Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Acked-by: Nicholas Piggin <npiggin@gmail.com> Acked-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20240427155714.53669-3-philmd@linaro.org>
2024-05-06exec/cpu: Rename PAGE_BITS macro to PAGE_RWXBALATON Zoltan1-3/+3
This macro can be used to abbreviate PAGE_READ | PAGE_WRITE | PAGE_EXEC for which PAGE_RWX is a better name and renaming it also shows it is not related to TARGET_PAGE_BITS. Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240505121008.44A0D4E602D@zero.eik.bme.hu> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
2023-10-03bsd-user: Implement shmat(2) and shmdt(2)Stacey Son1-1/+1
Use `WITH_MMAP_LOCK_GUARD` instead of mmap_lock() and mmap_unlock(), to match linux-user implementation, according to the following commits: 69fa2708a216df715ba5102a0f98468b540a464e linux-user: Use WITH_MMAP_LOCK_GUARD in target_{shmat,shmdt} ceda5688b650646248f269a992c06b11148c5759 linux-user: Fix shmdt Signed-off-by: Stacey Son <sson@FreeBSD.org> Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com> Message-Id: <20230925182709.4834-23-kariem.taha2.7@gmail.com>
2023-08-06bsd-user: Remove last_brkRichard Henderson1-2/+0
This variable is unused. Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2023-07-31bsd-user: Specify host page alignment if none specifiedWarner Losh1-1/+2
We're hitting an assert when we pass in alignment == 0 since that's not a power of two. so pass in the ideal page size. Signed-off-by: Warner Losh <imp@bsdimp.com> Message-Id: <20230728162927.5009-1-imp@bsdimp.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2023-07-23include/exec: Add WITH_MMAP_LOCK_GUARDRichard Henderson1-0/+1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2023-07-15bsd-user: Use page_find_range_empty for mmap_find_vma_reservedRichard Henderson1-41/+7
Use the interval tree to find empty space, rather than probing each page in turn. Cc: Warner Losh <imp@bsdimp.com> Cc: Kyle Evans <kevans@freebsd.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-bt: Warner Losh <imp@bsdimp.com> Message-Id: <20230707204054.8792-18-richard.henderson@linaro.org>
2023-07-15bsd-user: Use page_check_range_empty for MAP_EXCLRichard Henderson1-1/+1
The previous check returned -1 when any page within [start, start+len) is unmapped, not when all are unmapped. Cc: Warner Losh <imp@bsdimp.com> Cc: Kyle Evans <kevans@freebsd.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Warner Losh <imp@bsdimp.com> Message-Id: <20230707204054.8792-11-richard.henderson@linaro.org>
2023-03-28include/exec: Change reserved_va semantics to last byteRichard Henderson1-2/+2
Change the semantics to be the last byte of the guest va, rather than the following byte. This avoids some overflow conditions. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2023-03-28accel/tcg: Pass last not end to page_set_flagsRichard Henderson1-3/+3
Pass the address of the last byte to be changed, rather than the first address past the last byte. This avoids overflow when the last page of the address space is involved. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1528 Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2022-10-26accel/tcg: Call tb_invalidate_phys_page for PAGE_RESETRichard Henderson1-2/+0
When PAGE_RESET is set, we are replacing pages with new content, which means that we need to invalidate existing cached data, such as TranslationBlocks. Perform the reset invalidate while we're doing other invalidates, which allows us to remove the separate invalidates from the user-only mmap/munmap/mprotect routines. In addition, restrict invalidation to PAGE_EXEC pages. Since cdf713085131, we have validated PAGE_EXEC is present before translation, which means we can assume that if the bit is not present, there are no translations to invalidate. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2022-04-06Remove qemu-common.h include from most unitsMarc-André Lureau1-1/+0
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20220323155743.1585078-33-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-04-06Replace qemu_real_host_page variables with inlined functionsMarc-André Lureau1-1/+1
Replace the global variables with inlined helper functions. getpagesize() is very likely annotated with a "const" function attribute (at least with glibc), and thus optimization should apply even better. This avoids the need for a constructor initialization too. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20220323155743.1585078-12-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-10-18bsd-user/mmap.c: assert that target_mprotect cannot failWarner Losh1-4/+1
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>
2021-10-18bsd-user/mmap.c: Implement MAP_EXCL, required by jemalloc in headKyle Evans1-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>
2021-10-18bsd-user/mmap.c: Don't mmap fd == -1 independently from MAP_ANON flagWarner Losh1-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>
2021-10-18bsd-user/mmap.c: Convert to qemu_log logging for mmap debuggingWarner Losh1-30/+23
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>
2021-10-17bsd-user/mmap.c: mmap prefer MAP_ANON for BSDWarner Losh1-6/+5
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>
2021-10-17bsd-user/mmap.c: mmap return ENOMEM on overflowWarner Losh1-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>
2021-10-17bsd-user/mmap.c: MAP_ symbols are defined, so no need for ifdefsWarner Losh1-14/+0
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>
2021-10-17bsd-user/mmap.c: check pread's return value to fix warnings with _FORTIFY_SOURCEMikaël Urankar1-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>
2021-10-17bsd-user/mmap.c: Always zero MAP_ANONYMOUS memory in mmap_frag()Mikaël Urankar1-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>
2021-09-10bsd-user: Update mapping to handle reserved and starting conditionsWarner Losh1-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>
2021-09-10bsd-user: update debugging in mmap.cWarner Losh1-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>
2021-09-10bsd-user: Rewrite target system call definintion glueWarner Losh1-2/+0
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>
2021-05-11bsd-user: style tweak: keyword space (Warner Losh1-11/+11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Warner Losh <imp@bsdimp.com>
2021-02-16exec: Use cpu_untagged_addr in g2h; split out g2h_untaggedRichard Henderson1-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>
2018-06-01bsd-user: include "exec/exec-all.h" which provides mmap_lock/unlock"Paolo Bonzini1-0/+1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-07-21bsd-user/mmap.c: Move __thread attribute to right placePeter Maydell1-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
2017-03-28bsd-user: align use of mmap_lock to that of linux-userAlex Bennée1-12/+1
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>
2017-03-20configure: remove CygwinPaolo Bonzini1-5/+0
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>
2016-10-31translate-all: add DEBUG_LOCKING assertsAlex Bennée1-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>
2016-06-16os-posix: include sys/mman.hPaolo Bonzini1-1/+0
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>
2016-02-04bsd-user: Clean up includesPeter Maydell1-6/+1
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
2014-06-11bsd-user/mmap.c: Don't try to override g_malloc/g_freePeter Maydell1-60/+0
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>
2013-01-26bsd-user: avoid conflict with qemu_vmallocBlue Swirl1-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>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-8/+8
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-30Fix bsd-user qemu_vmalloc() host page protection codeJuergen Lock1-3/+2
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>
2010-01-31bsd/darwin-user: mmap_frag() users only check for -1 errorBlue Swirl1-1/+1
See also ee636500d6eab44b83f09cb730b67226b70423b1. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-07-27rename USE_NPTL to CONFIG_USE_NPTLJuan Quintela1-1/+1
Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-16Update to a hopefully more future proof FSF addressBlue Swirl1-3/+1
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-01-28Fix qemu_malloc.malc1-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
2009-01-24Fix bsd-user compile like r6412blueswir11-0/+13
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6434 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-05Fix more FSF addressesblueswir11-1/+2
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6192 c046a42c-6fe2-441c-8c8c-71466251a162
2008-11-29Prepare for handling different BSD mmap() flagsblueswir11-4/+5
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5809 c046a42c-6fe2-441c-8c8c-71466251a162
2008-10-26Preliminary BSD user emulator supportblueswir11-0/+545
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5544 c046a42c-6fe2-441c-8c8c-71466251a162