示例#1
0
 def offset(self) -> int:
     if not self.valid:
         raise UseAfterFreeError(
             "This allocation has already been freed; refusing to return its offset for use in pointers",
             self,
         )
     return self.start
示例#2
0
 def offset(self) -> int:
     if not self.valid:
         try:
             idx = self.arena.allocations.index(self)
         except ValueError:
             idx = -1
         raise UseAfterFreeError(
             "This allocation has already been freed; refusing to return its offset for use in pointers",
             self,
             "idx", idx,
             "self.arena.allocations", self.arena.allocations,
         )
     return self.start
示例#3
0
    def near(self) -> rsyscall.near.Address:
        """Return the raw memory address referred to by this Pointer

        This is mostly used by syscalls and passed to the kernel, so that the kernel knows the start
        of the buffer to read to or write from.

        """
        # TODO hmm should maybe validate that this fits in the bounds of the mapping I guess
        self._validate()
        try:
            return self.mapping.near.as_address() + self.allocation.offset()
        except UseAfterFreeError as e:
            raise UseAfterFreeError(
                "Allocation inside this Pointer", self,
                "is freed, but the pointer is still valid; someone violated some invariants",
            ) from e
示例#4
0
 def _validate(self) -> None:
     if not self.valid:
         raise UseAfterFreeError("handle is no longer valid")