Methods and apparatuses for automatic type checking via poisoned pointers
AssigneeApple Inc.
InventorFilip J. Pizlo
Life of this patent
Estimating the term…
Abstract
A method and an apparatus that modify pointer values pointing to typed data with type information are described. The type information can be automatically checked against the typed data leveraging hardware based safety check mechanisms when performing memory access operations to the typed data via the modified pointer values. As a result, hardware built in logic can be used for a broad class of programming language safety check when executing software codes using modified pointers that are subject to the safety check without executing compare and branch instructions in the software codes.
Claims20
A machine-readable non-transitory storage medium having instructions therein, which when executed by a machine, cause the machine to perform a method, the method comprising:
- registering a trap handler with a slow path code to access a property of a structured data for an executable code, the slow path code including lookup operations to determine a type of the structured data, wherein the type of the structured data is dynamically created during runtime of the executable code;
- optimizing the executable code, during the runtime of the executable code, with an expected type of the structured data to access the property of the structured data without performing compare and branch operations.
- providing a pointer embedded with the type of the structured data, the pointer to represent the structured data addressable in a memory via an address, the pointer specifying both the address and the type of the structured data;
- updating the pointer with an identifier identifying the expected type without performing operations to determine the type of the structured data;
- loading data addressed by the updated pointer, wherein the property of the structured data is loaded as the data if the type matches the expected type;
- and
- diverting execution of the optimized executable code to the slow path code to access the property via the trap handler activated by a hardware trap issued if the type does not match the expected type.
A machine-readable non-transitory storage medium having instructions therein, which when executed by a machine, cause the machine to perform a method, the method comprising:
- registering a trap handler to access a property of an object data for an executable code, the trap handler including lookup operations to determine a type of the object data, wherein the type is dynamically created during runtime of the executable code;
- storing, during runtime of the executable code, a first type identifier and a memory address to represent a first object data of a first type identified by the first type identifier, the first object data allocated at the memory address in a memory;
- caching an offset and a second type identifier identifying a second type, wherein a second object data of the second type is structured with a data element located with the offset within the second object data;
- providing a pointer embedded with the first type identifier for the first object data, the pointer specifying both the memory address and the first type identifier;
- configuring the pointer to access a particular data element of the first object data of the first type based on the cached offset;
- loading the particular data element of the first object data via the configured pointer without performing compare and branch operations to determine a type of the first object data, wherein the particular data element is loaded if the first type identifier matches the second type identifier;
- and
- diverting execution of the executable code to the trap handler to determine the type of the first object data for loading the particular data element, the trap handler activated by a hardware trap issued if the first type identifier does not match the second type identifier.
A computer implemented method comprising:
- registering a trap handler with a slow path code to access a property of a structured data for an executable code, the slow path code including lookup operations to determine a type of the structured data, wherein the type is dynamically created during runtime of the executable code;
- optimizing the executable code, during the runtime of the executable code, with an expected type of the structured data to access the property of the structured data without performing compare and branch operations;
- providing a pointer embedded with the type of the structured data, the pointer to represent the structured data addressable in a memory via an address, the pointer specifying both the address and the type of the structured data;
- updating the pointer with an identifier identifying the expected type without performing operations to determine the type of the structured data;
- loading data addressed by the updated pointer, wherein the property of the structured data is loaded as the data if the type matches the expected type;
- and
- diverting execution of the optimized executable code to the slow path code to access the property via the trap handler activated by a hardware trap issued if the type does not match the expected type.
A computer system comprising:
- a memory storing executable instructions including executable code, the memory capable of storing data addressable in an address space;
- a detection logic to detect whether a data address is within the address space;
- and
- a processor logic coupled to the memory and the detection logic to execute the executable instructions, the processor logic being configured to:
- register a trap handler with a slow path code to access a property of a structured data for the executable code, the slow path code including lookup operations to determine a type of the structured data, wherein the type is dynamically created during runtime of the executable code,
- optimize the executable code, during the runtime of the executable code, with an expected type of the structured data to access the property of the structured data without performing branch and compare operations,
- provide a pointer embedded with the type of the structured data, the pointer to represent the structured data addressable in a memory via an address, the pointer specifying both the address and the type of the structured data,
- update the pointer with an identifier identifying the expected type without performing operations to determine a type of the structured data,
- load data addressed by the updated pointer, wherein the property of the structured data is loaded as the data if the type matches the known type, and
- divert execution of the optimized executable code to the slow path code to access the property via the trap handler activated by the detection logic if the type does not match the expected type.
Dependencies are inferred from the claim text.