@samitouri / QOSamiQemu / commits / fb13afb1c6

linux-user: Introduce PGBRange

Create a structure to hold a beginning/end range for guest virtual addresses, for use by probe_guest_base. Use vaddr for clarity. Reviewed-by: Warner Losh <imp@bsdimp.com> Reviewed-by: Helge Deller <deller@gmx.de> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Richard Henderson committed May 29, 2026 at 15:16 UTC fb13afb1c625738691f2cc5e1f5f47e7522af2d2
2 files changed +23 -18
linux-user/elfload.c
+18 -18
@@ -828,15 +828,15 @@ static int pgb_try_mmap_skip_brk(uintptr_t addr, uintptr_t addr_last,
828 */
829
830 typedef struct PGBAddrs {
831 - uintptr_t bounds[3][2]; /* start/last pairs */
831 + PGBRange bounds[3];
832 int nbounds;
833 } PGBAddrs;
834
835 static bool pgb_try_mmap_set(const PGBAddrs *ga, uintptr_t base, uintptr_t brk)
836 {
837 for (int i = ga->nbounds - 1; i >= 0; --i) {
838 - if (pgb_try_mmap_skip_brk(ga->bounds[i][0] + base,
839 - ga->bounds[i][1] + base,
838 + if (pgb_try_mmap_skip_brk(ga->bounds[i].lo + base,
839 + ga->bounds[i].hi + base,
840 brk, i == 0 && reserved_va) <= 0) {
841 return false;
842 }
@@ -875,26 +875,26 @@ static bool pgb_addr_set(PGBAddrs *ga, abi_ulong guest_loaddr,
875 n = 0;
876
877 if (reserved_va) {
878 - ga->bounds[n][0] = try_identity ? mmap_min_addr : 0;
879 - ga->bounds[n][1] = reserved_va;
878 + ga->bounds[n].lo = try_identity ? mmap_min_addr : 0;
879 + ga->bounds[n].hi = reserved_va;
880 n++;
881 /* LO_COMMPAGE and NULL handled by reserving from 0. */
882 } else {
883 /* Add any LO_COMMPAGE or NULL page. */
884 if (LO_COMMPAGE != -1) {
885 - ga->bounds[n][0] = 0;
886 - ga->bounds[n][1] = LO_COMMPAGE + TARGET_PAGE_SIZE - 1;
885 + ga->bounds[n].lo = 0;
886 + ga->bounds[n].hi = LO_COMMPAGE + TARGET_PAGE_SIZE - 1;
887 n++;
888 } else if (!try_identity) {
889 - ga->bounds[n][0] = 0;
890 - ga->bounds[n][1] = TARGET_PAGE_SIZE - 1;
889 + ga->bounds[n].lo = 0;
890 + ga->bounds[n].hi = TARGET_PAGE_SIZE - 1;
891 n++;
892 }
893
894 /* Add the guest image for ET_EXEC. */
895 if (guest_loaddr) {
896 - ga->bounds[n][0] = guest_loaddr;
897 - ga->bounds[n][1] = guest_hiaddr;
896 + ga->bounds[n].lo = guest_loaddr;
897 + ga->bounds[n].hi = guest_hiaddr;
898 n++;
899 }
900 }
@@ -909,8 +909,8 @@ static bool pgb_addr_set(PGBAddrs *ga, abi_ulong guest_loaddr,
909
910 /* Add any HI_COMMPAGE not covered by reserved_va. */
911 if (reserved_va < HI_COMMPAGE) {
912 - ga->bounds[n][0] = HI_COMMPAGE & qemu_real_host_page_mask();
913 - ga->bounds[n][1] = HI_COMMPAGE + TARGET_PAGE_SIZE - 1;
912 + ga->bounds[n].lo = HI_COMMPAGE & qemu_real_host_page_mask();
913 + ga->bounds[n].hi = HI_COMMPAGE + TARGET_PAGE_SIZE - 1;
914 n++;
915 }
916
@@ -976,8 +976,8 @@ static uintptr_t pgb_try_itree(const PGBAddrs *ga, uintptr_t base,
976 IntervalTreeRoot *root)
977 {
978 for (int i = ga->nbounds - 1; i >= 0; --i) {
979 - uintptr_t s = base + ga->bounds[i][0];
980 - uintptr_t l = base + ga->bounds[i][1];
979 + uintptr_t s = base + ga->bounds[i].lo;
980 + uintptr_t l = base + ga->bounds[i].hi;
981 IntervalTreeNode *n;
982
983 if (l < s) {
@@ -1076,9 +1076,9 @@ static void pgb_dynamic(const char *image_name, uintptr_t guest_loaddr,
1076 "guest address mapping requirements", image_name);
1077
1078 for (int i = 0; i < ga.nbounds; ++i) {
1079 - error_printf(" %0*" PRIx64 "-%0*" PRIx64 "\n",
1080 - w, (uint64_t)ga.bounds[i][0],
1081 - w, (uint64_t)ga.bounds[i][1]);
1079 + error_printf(" %0*" VADDR_PRIx "-%0*" VADDR_PRIx "\n",
1080 + w, ga.bounds[i].lo,
1081 + w, ga.bounds[i].hi);
1082 }
1083 exit(EXIT_FAILURE);
1084 }
linux-user/user-internals.h
+5
@@ -75,6 +75,11 @@ void clone_fork_end(bool child);
75 void fork_start(void);
76 void fork_end(pid_t pid);
77
78 +typedef struct PGBRange {
79 + vaddr lo;
80 + vaddr hi;
81 +} PGBRange;
82 +
83 /**
84 * probe_guest_base:
85 * @image_name: the executable being loaded