[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 15/17] bsd-user: target_mprotect: use helper host_page_size local
|
From: |
Warner Losh |
|
Subject: |
[PATCH 15/17] bsd-user: target_mprotect: use helper host_page_size local |
|
Date: |
Fri, 2 Aug 2024 17:56:15 -0600 |
Use helper variable for host_page_size. Linux-user uses a similar helper
to make the code smaller after the multi-page-size migration.
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
bsd-user/mmap.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 2118972f073..ffecf52a72a 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -63,6 +63,7 @@ void mmap_fork_end(int child)
/* NOTE: all the constants are the HOST ones, but addresses are target. */
int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
{
+ int host_page_size = qemu_real_host_page_size();
abi_ulong end, host_start, host_end, addr;
int prot1, ret;
@@ -83,7 +84,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int
target_prot)
return 0;
mmap_lock();
- host_start = start & qemu_host_page_mask;
+ host_start = start & -host_page_size;
host_end = HOST_PAGE_ALIGN(end);
if (start > host_start) {
/* handle host page containing start */
@@ -91,28 +92,28 @@ int target_mprotect(abi_ulong start, abi_ulong len, int
target_prot)
for (addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
prot1 |= page_get_flags(addr);
}
- if (host_end == host_start + qemu_host_page_size) {
+ if (host_end == host_start + host_page_size) {
for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
prot1 |= page_get_flags(addr);
}
end = host_end;
}
ret = mprotect(g2h_untagged(host_start),
- qemu_host_page_size, prot1 & PAGE_RWX);
+ host_page_size, prot1 & PAGE_RWX);
if (ret != 0)
goto error;
- host_start += qemu_host_page_size;
+ host_start += host_page_size;
}
if (end < host_end) {
prot1 = target_prot;
for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
prot1 |= page_get_flags(addr);
}
- ret = mprotect(g2h_untagged(host_end - qemu_host_page_size),
- qemu_host_page_size, prot1 & PAGE_RWX);
+ ret = mprotect(g2h_untagged(host_end - host_page_size),
+ host_page_size, prot1 & PAGE_RWX);
if (ret != 0)
goto error;
- host_end -= qemu_host_page_size;
+ host_end -= host_page_size;
}
/* handle the pages in the middle */
--
2.45.1
- [PATCH 11/17] bsd-user: Replace set_brk and padzero with zerobss from linux-user, (continued)
- [PATCH 11/17] bsd-user: Replace set_brk and padzero with zerobss from linux-user, Warner Losh, 2024/08/02
- [PATCH 13/17] bsd-user: target_mprotect: rename prot to target_prot, Warner Losh, 2024/08/02
- [PATCH 09/17] bsd-user: target_msync unused, remove it, Warner Losh, 2024/08/02
- [PATCH 16/17] bsd-user: Define validate_prot_to_pageflags and use in mprotect, Warner Losh, 2024/08/02
- [PATCH 14/17] bsd-user: target_mmap*: change prot to target_prot, Warner Losh, 2024/08/02
- [PATCH 15/17] bsd-user: target_mprotect: use helper host_page_size local,
Warner Losh <=
- [PATCH 10/17] bsd-user: Pass image name down the stack, Warner Losh, 2024/08/02
- [PATCH 17/17] bsd-user: copy linux-user target_mprotect impl, Warner Losh, 2024/08/02