----- Original Message ----- From: "Tim Peters" <tim.one@comcast.net> > After digesting some ideas from David Abrahams offlist, I believe I may have > a much simpler way to make a bulletproof "is or isn't this address from a > pymalloc pool?" test. Described as a diff from current pymalloc: > > 1. Keep a contiguous vector of arena base addresses. This is not > sorted. When a new arena is allocated, its base address is simply > appended. Space required is proportional to the # of arenas in > use (4 bytes/arena on a 32-bit box; 8 bytes/arena on a 64-bit box). > > 2. Remove the "magic number" gimmick from pool headers. > > 3. In place of the pooladr member of a pool header, add an arenaindex > member. Every pool in an arena sets this to the index of its arena's > base address, wrt the vector in #2. > > 4. To check an address p, find its pool header address just as now. > Then read up arenaindex. If that's out of bounds for the #2 vector, > it's not a pymalloc address. If it is in bounds, read the arena > base address B out of the #2 vector Fine so far... > , and see whether B <= p < B + 256KB > (which can again be collapsed into a tricksy one-compare test via > exploiting unsigned arithmetic). ...isn't this part just a little too complicated? If I understand correctly, arenas are 4K aligned pages. Given an address, when you find its pool header, you either find a valid arena header that covers all 4K subsequent addresses, or some alien memory. I think you just have to look for the address of the pool header at the appropriate index in the vector. IOW, there should be no need to look at the address you're deallocating after finding its putative arena. -Dave
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4