From: Warner Losh <imp@bsdimp.com>
To: qemu-devel@nongnu.org
Cc: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>,
Jessica Clarke <jrtc27@jrtc27.com>
Subject: [PATCH 14/17] bsd-user: target_mmap*: change prot to target_prot
Date: Fri, 2 Aug 2024 17:56:14 -0600 [thread overview]
Message-ID: <20240802235617.7971-15-imp@bsdimp.com> (raw)
In-Reply-To: <20240802235617.7971-1-imp@bsdimp.com>
Adopt the linux-user convention of using target_prot for passed in
protections. no functional change.
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
bsd-user/mmap.c | 47 ++++++++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index d34075c5c64..2118972f073 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -152,7 +152,7 @@ error:
*/
static int mmap_frag(abi_ulong real_start,
abi_ulong start, abi_ulong end,
- int prot, int flags, int fd, abi_ulong offset)
+ int target_prot, int flags, int fd, abi_ulong offset)
{
abi_ulong real_end, addr;
void *host_start;
@@ -170,20 +170,20 @@ static int mmap_frag(abi_ulong real_start,
if (prot1 == 0) {
/* no page was there, so we allocate one. See also above. */
- void *p = mmap(host_start, qemu_host_page_size, prot,
+ void *p = mmap(host_start, qemu_host_page_size, target_prot,
flags | ((fd != -1) ? MAP_ANON : 0), -1, 0);
if (p == MAP_FAILED)
return -1;
- prot1 = prot;
+ prot1 = target_prot;
}
prot1 &= PAGE_RWX;
- prot_new = prot | prot1;
+ prot_new = target_prot | prot1;
if (fd != -1) {
/* msync() won't work here, so we return an error if write is
possible while it is a shared mapping */
if ((flags & TARGET_BSD_MAP_FLAGMASK) == MAP_SHARED &&
- (prot & PROT_WRITE))
+ (target_prot & PROT_WRITE))
return -1;
/* adjust protection to be able to read */
@@ -367,7 +367,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
}
/* NOTE: all the constants are the HOST ones */
-abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
+abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
int flags, int fd, off_t offset)
{
abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len;
@@ -377,9 +377,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
qemu_log("mmap: start=0x" TARGET_ABI_FMT_lx
" len=0x" TARGET_ABI_FMT_lx " prot=%c%c%c flags=",
start, len,
- prot & PROT_READ ? 'r' : '-',
- prot & PROT_WRITE ? 'w' : '-',
- prot & PROT_EXEC ? 'x' : '-');
+ target_prot & PROT_READ ? 'r' : '-',
+ target_prot & PROT_WRITE ? 'w' : '-',
+ target_prot & PROT_EXEC ? 'x' : '-');
if (flags & MAP_ALIGNMENT_MASK) {
qemu_log("MAP_ALIGNED(%u) ",
(flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT);
@@ -416,13 +416,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
goto fail;
}
if (flags & MAP_STACK) {
- if ((fd != -1) || ((prot & (PROT_READ | PROT_WRITE)) !=
- (PROT_READ | PROT_WRITE))) {
+ if (fd != -1 ||
+ ((target_prot & (PROT_READ | PROT_WRITE)) !=
+ (PROT_READ | PROT_WRITE))) {
errno = EINVAL;
goto fail;
}
}
- if ((flags & MAP_GUARD) && (prot != PROT_NONE || fd != -1 ||
+ if ((flags & MAP_GUARD) && (target_prot != PROT_NONE || fd != -1 ||
offset != 0 || (flags & (MAP_SHARED | MAP_PRIVATE |
/* MAP_PREFAULT | */ /* MAP_PREFAULT not in mman.h */
MAP_PREFAULT_READ | MAP_ANON | MAP_STACK)) != 0)) {
@@ -512,14 +513,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
* especially important if qemu_host_page_size >
* qemu_real_host_page_size
*/
- p = mmap(g2h_untagged(start), host_len, prot,
+ p = mmap(g2h_untagged(start), host_len, target_prot,
flags | MAP_FIXED | ((fd != -1) ? MAP_ANON : 0), -1, 0);
if (p == MAP_FAILED)
goto fail;
/* update start so that it points to the file position at 'offset' */
host_start = (unsigned long)p;
if (fd != -1) {
- p = mmap(g2h_untagged(start), len, prot,
+ p = mmap(g2h_untagged(start), len, target_prot,
flags | MAP_FIXED, fd, host_offset);
if (p == MAP_FAILED) {
munmap(g2h_untagged(start), host_len);
@@ -557,11 +558,11 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
* possible while it is a shared mapping
*/
if ((flags & TARGET_BSD_MAP_FLAGMASK) == MAP_SHARED &&
- (prot & PROT_WRITE)) {
+ (target_prot & PROT_WRITE)) {
errno = EINVAL;
goto fail;
}
- retaddr = target_mmap(start, len, prot | PROT_WRITE,
+ retaddr = target_mmap(start, len, target_prot | PROT_WRITE,
MAP_FIXED | MAP_PRIVATE | MAP_ANON,
-1, 0);
if (retaddr == -1)
@@ -569,8 +570,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
if (pread(fd, g2h_untagged(start), len, offset) == -1) {
goto fail;
}
- if (!(prot & PROT_WRITE)) {
- ret = target_mprotect(start, len, prot);
+ if (!(target_prot & PROT_WRITE)) {
+ ret = target_mprotect(start, len, target_prot);
assert(ret == 0);
}
goto the_end;
@@ -587,13 +588,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
if (real_end == real_start + qemu_host_page_size) {
/* one single host page */
ret = mmap_frag(real_start, start, end,
- prot, flags, fd, offset);
+ target_prot, flags, fd, offset);
if (ret == -1)
goto fail;
goto the_end1;
}
ret = mmap_frag(real_start, start, real_start + qemu_host_page_size,
- prot, flags, fd, offset);
+ target_prot, flags, fd, offset);
if (ret == -1)
goto fail;
real_start += qemu_host_page_size;
@@ -602,7 +603,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
if (end < real_end) {
ret = mmap_frag(real_end - qemu_host_page_size,
real_end - qemu_host_page_size, end,
- prot, flags, fd,
+ target_prot, flags, fd,
offset + real_end - qemu_host_page_size - start);
if (ret == -1)
goto fail;
@@ -618,13 +619,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
else
offset1 = offset + real_start - start;
p = mmap(g2h_untagged(real_start), real_end - real_start,
- prot, flags, fd, offset1);
+ target_prot, flags, fd, offset1);
if (p == MAP_FAILED)
goto fail;
}
}
the_end1:
- page_set_flags(start, start + len - 1, prot | PAGE_VALID);
+ page_set_flags(start, start + len - 1, target_prot | PAGE_VALID);
the_end:
#ifdef DEBUG_MMAP
printf("ret=0x" TARGET_ABI_FMT_lx "\n", start);
--
2.45.1
next prev parent reply other threads:[~2024-08-02 23:59 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 23:56 [PATCH 00/17] For 9.2: A bunch of cleanups and work towards variable pagesize support Warner Losh
2024-08-02 23:56 ` [PATCH 01/17] bsd-user: Delete TaskState next member Warner Losh
2024-08-04 7:07 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 02/17] bsd-user: Make init_task_state global Warner Losh
2024-08-04 7:08 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 03/17] bsd-user: Make cpu_model and cpu_type file scope Warner Losh
2024-08-04 7:22 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 04/17] bsd-user: Implement cpu_copy() Warner Losh
2024-08-04 7:24 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 05/17] bsd-user: Eliminate unused regs arg in load_elf_binary Warner Losh
2024-08-04 7:26 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 06/17] bsd-user: Remove load_flt_binary prototype Warner Losh
2024-08-04 7:26 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 07/17] bsd-user: Remove deprecated -p argument Warner Losh
2024-08-04 7:26 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 08/17] bsd-user: Eliminate unused qemu_uname_release Warner Losh
2024-08-04 7:27 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 09/17] bsd-user: target_msync unused, remove it Warner Losh
2024-08-04 7:28 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 10/17] bsd-user: Pass image name down the stack Warner Losh
2024-08-04 7:29 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 11/17] bsd-user: Replace set_brk and padzero with zerobss from linux-user Warner Losh
2024-08-04 11:38 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 12/17] bsd-user: Use guest_range_valid_untagged to validate range Warner Losh
2024-08-04 21:30 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 13/17] bsd-user: target_mprotect: rename prot to target_prot Warner Losh
2024-08-04 21:31 ` Richard Henderson
2024-08-02 23:56 ` Warner Losh [this message]
2024-08-04 21:32 ` [PATCH 14/17] bsd-user: target_mmap*: change " Richard Henderson
2024-08-02 23:56 ` [PATCH 15/17] bsd-user: target_mprotect: use helper host_page_size local Warner Losh
2024-08-04 21:33 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 16/17] bsd-user: Define validate_prot_to_pageflags and use in mprotect Warner Losh
2024-08-04 21:44 ` Richard Henderson
2024-08-02 23:56 ` [PATCH 17/17] bsd-user: copy linux-user target_mprotect impl Warner Losh
2024-08-04 21:47 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240802235617.7971-15-imp@bsdimp.com \
--to=imp@bsdimp.com \
--cc=jrtc27@jrtc27.com \
--cc=kevans@freebsd.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.