22 /* FIXME: Dynamic allocation. */
23 static struct range ranges[PAGE_SIZE * 8 / sizeof (struct range)];
24 static struct range *ranges_static_end = ranges;
25 static struct range *ranges_end = ranges; /* = ranges_static_end */
28 /* Returns 0 on readable start..end-1. */
29 /* TODO: Sort + binary search. */
30 INTERNAL int maps_verify (void *start, void *end)
39 for (range = ranges; start < end && range < ranges_end; range++)
40 if (start >= range->start && start < range->end)
46 while (start < end && changed);
54 INTERNAL void maps_static_setup (void *start, void *end)
56 if (ranges_static_end >= ranges + N_ELEMENTS (ranges))
59 ranges_static_end->start = start;
60 ranges_static_end->end = end;
64 fprintf (stderr,"static: %p - %p\n", start, end);
67 INTERNAL void maps_read (void)
74 ranges_end = ranges_static_end;
76 /* Do not use level 3 I/O as it may be too SIGSEGV intrusive. */
77 fd = open (MAPS_FILENAME, O_RDONLY);
80 bytes_read = read (fd, ranges_end, (char *) ranges + sizeof (ranges)
81 - (char *) ranges_end - 1);
86 s = (char *) ranges_end;
91 unsigned long start, end;
92 char prot_read, prot_write, prot_exec, prot_mayshare;
94 const char *vdso_name = " [vdso]";
95 const size_t vdso_len = strlen (vdso_name);
97 i = sscanf (s, "%lx-%lx %c%c%c%c %n", &start, &end, &prot_read,
98 &prot_write, &prot_exec, &prot_mayshare, &offset);
102 /* Reuse the trailing absolute pathname?
103 Currently we use the relative one from dl_iterate_phdr(3). */
104 while (*s && *s != '\n')
106 /* Skip [vdso] entry to discard its dl_iterate_phdr(3) which has the
107 same name as the main executable - "". */
108 if (s >= (char *) ranges + vdso_len
109 && memcmp (s - vdso_len, vdso_name, vdso_len) == 0)
111 if (prot_read != 'r')
113 if (prot_write != '-')
115 if (prot_exec != 'x')
117 if (prot_mayshare != 'p')
119 ranges_end->start = (void *) start;
120 ranges_end->end = (void *) end;
124 fprintf (stderr,"range: %p - %p\n", (void *) start, (void *) end);
126 if (ranges_end >= ranges + N_ELEMENTS (ranges))