|
| 1 | +--- a/gdb/nat/linux-btrace.c 2025-04-21 01:22:05.000000000 +0800 |
| 2 | ++++ b/gdb/nat/linux-btrace.c 2025-08-26 10:04:03.839124442 +0800 |
| 3 | +@@ -30,6 +30,7 @@ |
| 4 | + #include <inttypes.h> |
| 5 | + |
| 6 | + #include <sys/syscall.h> |
| 7 | ++#include <unistd.h> |
| 8 | + |
| 9 | + #if HAVE_LINUX_PERF_EVENT_H && defined(SYS_perf_event_open) |
| 10 | + #include <unistd.h> |
| 11 | +@@ -516,6 +517,8 @@ |
| 12 | + __u64 data_offset; |
| 13 | + int pid, pg; |
| 14 | + |
| 15 | ++ long page_size = sysconf(_SC_PAGESIZE); |
| 16 | ++ |
| 17 | + if (!cpu_supports_bts ()) |
| 18 | + error (_("BTS support has been disabled for the target cpu.")); |
| 19 | + |
| 20 | +@@ -546,8 +549,8 @@ |
| 21 | + diagnose_perf_event_open_fail (); |
| 22 | + |
| 23 | + /* Convert the requested size in bytes to pages (rounding up). */ |
| 24 | +- pages = ((size_t) conf->size / PAGE_SIZE |
| 25 | +- + ((conf->size % PAGE_SIZE) == 0 ? 0 : 1)); |
| 26 | ++ pages = ((size_t) conf->size / page_size |
| 27 | ++ + ((conf->size % page_size) == 0 ? 0 : 1)); |
| 28 | + /* We need at least one page. */ |
| 29 | + if (pages == 0) |
| 30 | + pages = 1; |
| 31 | +@@ -566,17 +569,17 @@ |
| 32 | + size_t length; |
| 33 | + __u64 data_size; |
| 34 | + |
| 35 | +- data_size = (__u64) pages * PAGE_SIZE; |
| 36 | ++ data_size = (__u64) pages * page_size; |
| 37 | + |
| 38 | + /* Don't ask for more than we can represent in the configuration. */ |
| 39 | + if ((__u64) UINT_MAX < data_size) |
| 40 | + continue; |
| 41 | + |
| 42 | + size = (size_t) data_size; |
| 43 | +- length = size + PAGE_SIZE; |
| 44 | ++ length = size + page_size; |
| 45 | + |
| 46 | + /* Check for overflows. */ |
| 47 | +- if ((__u64) length != data_size + PAGE_SIZE) |
| 48 | ++ if ((__u64) length != data_size + page_size) |
| 49 | + continue; |
| 50 | + |
| 51 | + errno = 0; |
| 52 | +@@ -591,7 +594,7 @@ |
| 53 | + |
| 54 | + struct perf_event_mmap_page *header = (struct perf_event_mmap_page *) |
| 55 | + data.get (); |
| 56 | +- data_offset = PAGE_SIZE; |
| 57 | ++ data_offset = page_size; |
| 58 | + |
| 59 | + #if defined (PERF_ATTR_SIZE_VER5) |
| 60 | + if (offsetof (struct perf_event_mmap_page, data_size) <= header->size) |
| 61 | +@@ -664,6 +667,8 @@ |
| 62 | + size_t pages; |
| 63 | + int pid, pg; |
| 64 | + |
| 65 | ++ long page_size = sysconf(_SC_PAGESIZE); |
| 66 | ++ |
| 67 | + pid = ptid.lwp (); |
| 68 | + if (pid == 0) |
| 69 | + pid = ptid.pid (); |
| 70 | +@@ -703,7 +708,7 @@ |
| 71 | + diagnose_perf_event_open_fail (); |
| 72 | + |
| 73 | + /* Allocate the configuration page. */ |
| 74 | +- scoped_mmap data (nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, |
| 75 | ++ scoped_mmap data (nullptr, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, |
| 76 | + fd.get (), 0); |
| 77 | + if (data.get () == MAP_FAILED) |
| 78 | + error (_("Failed to map trace user page: %s."), safe_strerror (errno)); |
| 79 | +@@ -714,8 +719,8 @@ |
| 80 | + header->aux_offset = header->data_offset + header->data_size; |
| 81 | + |
| 82 | + /* Convert the requested size in bytes to pages (rounding up). */ |
| 83 | +- pages = ((size_t) conf->size / PAGE_SIZE |
| 84 | +- + ((conf->size % PAGE_SIZE) == 0 ? 0 : 1)); |
| 85 | ++ pages = ((size_t) conf->size / page_size |
| 86 | ++ + ((conf->size % page_size) == 0 ? 0 : 1)); |
| 87 | + /* We need at least one page. */ |
| 88 | + if (pages == 0) |
| 89 | + pages = 1; |
| 90 | +@@ -734,7 +739,7 @@ |
| 91 | + size_t length; |
| 92 | + __u64 data_size; |
| 93 | + |
| 94 | +- data_size = (__u64) pages * PAGE_SIZE; |
| 95 | ++ data_size = (__u64) pages * page_size; |
| 96 | + |
| 97 | + /* Don't ask for more than we can represent in the configuration. */ |
| 98 | + if ((__u64) UINT_MAX < data_size) |
| 99 | +@@ -805,7 +810,8 @@ |
| 100 | + static void |
| 101 | + linux_disable_bts (struct linux_btrace_target_info *tinfo) |
| 102 | + { |
| 103 | +- munmap ((void *) tinfo->header, tinfo->pev.size + PAGE_SIZE); |
| 104 | ++ long page_size = sysconf(_SC_PAGESIZE); |
| 105 | ++ munmap ((void *) tinfo->header, tinfo->pev.size + page_size); |
| 106 | + close (tinfo->file); |
| 107 | + } |
| 108 | + |
| 109 | +@@ -814,8 +820,9 @@ |
| 110 | + static void |
| 111 | + linux_disable_pt (struct linux_btrace_target_info *tinfo) |
| 112 | + { |
| 113 | ++ long page_size = sysconf(_SC_PAGESIZE); |
| 114 | + munmap ((void *) tinfo->pev.mem, tinfo->pev.size); |
| 115 | +- munmap ((void *) tinfo->header, PAGE_SIZE); |
| 116 | ++ munmap ((void *) tinfo->header, page_size); |
| 117 | + close (tinfo->file); |
| 118 | + } |
| 119 | + |
0 commit comments