Module rsyscall.memory.allocation_interface

Defines AllocationInterface.

Expand source code Browse git
"Defines AllocationInterface."
from __future__ import annotations
import abc
import typing as t

class UseAfterFreeError(Exception):
    pass

class AllocationInterface:
    """Represents an allocation of a range of bytes in some file

    The file is typically mapped into memory. Essentially, this is a single allocation
    returned by malloc; but it's not necessarily tied to memory.

    """
    @abc.abstractmethod
    def offset(self) -> int:
        """Get the offset of this allocation in its memory mapping; throws if this allocation has been invalidated.

        TODO this should return the offset of the allocation

        """
        pass
    @abc.abstractmethod
    def size(self) -> int:
        "Get the size of this allocation."
        pass
    @abc.abstractmethod
    def split(self, size: int) -> t.Tuple[AllocationInterface, AllocationInterface]:
        """Invalidate this allocation and split it into two adjacent allocations.

        These two allocations can be independently freed, or split again, ad infinitum;
        they can also be merged back together with merge.

        """
        pass
    @abc.abstractmethod
    def merge(self, other: AllocationInterface) -> AllocationInterface:
        """Invalidate these two adjacent allocations and merge them into one; only works if they came from split.

        Call this on the left allocation returned from split, and pass the right allocation.

        Depending on the characteristics of the underlying allocator, this may also work
        for two unrelated allocations rather than just ones that came from split, but you
        certainly shouldn't try.

        """
        pass
    @abc.abstractmethod
    def free(self) -> None:
        "Invalidate this allocation and return its range for re-allocation; also called automatically on __del__."
        pass

Classes

class UseAfterFreeError (*args, **kwargs)

Common base class for all non-exit exceptions.

Expand source code Browse git
class UseAfterFreeError(Exception):
    pass

Ancestors

  • builtins.Exception
  • builtins.BaseException
class AllocationInterface

Represents an allocation of a range of bytes in some file

The file is typically mapped into memory. Essentially, this is a single allocation returned by malloc; but it's not necessarily tied to memory.

Expand source code Browse git
class AllocationInterface:
    """Represents an allocation of a range of bytes in some file

    The file is typically mapped into memory. Essentially, this is a single allocation
    returned by malloc; but it's not necessarily tied to memory.

    """
    @abc.abstractmethod
    def offset(self) -> int:
        """Get the offset of this allocation in its memory mapping; throws if this allocation has been invalidated.

        TODO this should return the offset of the allocation

        """
        pass
    @abc.abstractmethod
    def size(self) -> int:
        "Get the size of this allocation."
        pass
    @abc.abstractmethod
    def split(self, size: int) -> t.Tuple[AllocationInterface, AllocationInterface]:
        """Invalidate this allocation and split it into two adjacent allocations.

        These two allocations can be independently freed, or split again, ad infinitum;
        they can also be merged back together with merge.

        """
        pass
    @abc.abstractmethod
    def merge(self, other: AllocationInterface) -> AllocationInterface:
        """Invalidate these two adjacent allocations and merge them into one; only works if they came from split.

        Call this on the left allocation returned from split, and pass the right allocation.

        Depending on the characteristics of the underlying allocator, this may also work
        for two unrelated allocations rather than just ones that came from split, but you
        certainly shouldn't try.

        """
        pass
    @abc.abstractmethod
    def free(self) -> None:
        "Invalidate this allocation and return its range for re-allocation; also called automatically on __del__."
        pass

Subclasses

  • rsyscall.loader.StaticAllocation
  • Allocation
  • rsyscall.memory.ram.NullAllocation
  • rsyscall.memory.socket_transport.SpanAllocation

Methods

def offset(self) ‑> int

Get the offset of this allocation in its memory mapping; throws if this allocation has been invalidated.

TODO this should return the offset of the allocation

Expand source code Browse git
@abc.abstractmethod
def offset(self) -> int:
    """Get the offset of this allocation in its memory mapping; throws if this allocation has been invalidated.

    TODO this should return the offset of the allocation

    """
    pass
def size(self) ‑> int

Get the size of this allocation.

Expand source code Browse git
@abc.abstractmethod
def size(self) -> int:
    "Get the size of this allocation."
    pass
def split(self, size: int) ‑> Tuple[AllocationInterfaceAllocationInterface]

Invalidate this allocation and split it into two adjacent allocations.

These two allocations can be independently freed, or split again, ad infinitum; they can also be merged back together with merge.

Expand source code Browse git
@abc.abstractmethod
def split(self, size: int) -> t.Tuple[AllocationInterface, AllocationInterface]:
    """Invalidate this allocation and split it into two adjacent allocations.

    These two allocations can be independently freed, or split again, ad infinitum;
    they can also be merged back together with merge.

    """
    pass
def merge(self, other: AllocationInterface) ‑> AllocationInterface

Invalidate these two adjacent allocations and merge them into one; only works if they came from split.

Call this on the left allocation returned from split, and pass the right allocation.

Depending on the characteristics of the underlying allocator, this may also work for two unrelated allocations rather than just ones that came from split, but you certainly shouldn't try.

Expand source code Browse git
@abc.abstractmethod
def merge(self, other: AllocationInterface) -> AllocationInterface:
    """Invalidate these two adjacent allocations and merge them into one; only works if they came from split.

    Call this on the left allocation returned from split, and pass the right allocation.

    Depending on the characteristics of the underlying allocator, this may also work
    for two unrelated allocations rather than just ones that came from split, but you
    certainly shouldn't try.

    """
    pass
def free(self) ‑> NoneType

Invalidate this allocation and return its range for re-allocation; also called automatically on del.

Expand source code Browse git
@abc.abstractmethod
def free(self) -> None:
    "Invalidate this allocation and return its range for re-allocation; also called automatically on __del__."
    pass