# US 2022/0066780 A1 · Dual architecture function pointers having consistent reference addresses

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2022/0066780 A1
- Document ID: US20220066780A1
- Status: Published application
- Kind: A1
- Application number: 17/008,163
- Filed: 2020-08-31
- Published: 2022-03-03
- Earliest claimed: 2020-08-31
- Assignees: Microsoft Technology Licensing, LLC
- Applicants: Microsoft Technology Licensing, LLC
- Inventors: Darek Josip MIHOCKA; Clarence Siu Yeen DANG; Pedro Miguel SEQUEIRA DE JUSTO TEIXEIRA; Pavlo LEBEDYNSKIY; James David CLEARY; Jon Robert BERRY; YongKang ZHU; Tiansheng TAN
- Web page: https://patentgrep.com/patent/US20220066780A1

## CPC

- G06F 9/30174: {for non-native instruction set, e.g. Javabyte, legacy code}
- G06F 9/44542: {Retargetable}
- G06F 9/445: Program loading or initiating (bootstrapping G06F9/4401; security arrangements for program loading or initiating G06F21/57)
- G06F 9/4484: {Executing subprograms}
- G06F 9/455: Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F 9/45504: {Abstract machines for program code execution, e.g. Java virtual machine [JVM], interpreters or emulators}
- G06F 9/45516: {Runtime code conversion or optimisation}
- G06F 9/4552: {Involving translation to a different instruction set architecture, e.g. just-in-time translation in a JVM}
- G06F 9/541: {via adapters, e.g. between incompatible applications}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Using a common reference address when processing calls among a native ABI and a foreign ABI. Based on caller calling using a reference address, a lookup structure is used to determine whether the reference address is within a memory range storing native code (and that the callee is native) or a memory range not storing native code (and that the callee is foreign). Execution of the callee is initiated based on one of (i) when the caller is native and when the callee is foreign, calling the callee using the reference address within an emulator; (ii) when the caller is foreign and the callee is native, calling an entry thunk; (iii) when the caller is native and the callee is foreign, calling an exit thunk; or (iv) when the caller is native and the callee is native, directly calling the callee using the reference address.

## Claims

### Claim 1

A method, implemented at a computer system that includes a processor implementing a native instruction set architecture (ISA), for using a common reference memory address when processing calls within a process that supports execution of both (i) native code targeting a native application binary interface (ABI) that corresponds to the native ISA and that has a first calling convention, and (ii) foreign code targeting a foreign ABI that corresponds to a foreign ISA and that has a second calling convention, the method comprising:
based at least on identifying a call that targets a reference memory address for a callee function, determining whether the callee function corresponds to the native ABI or to the foreign ABI, wherein:
the callee function is determined to correspond to the native ABI based on one of (i) a lookup structure indicating that the reference memory address is contained within a first memory range storing native code, or (ii) a fast-forward sequence being identified at the reference memory address, and
the callee function is determined to correspond to the foreign ABI based at least on the lookup structure indicating that the reference memory address is contained within a second memory range not storing native code; and
based at least on the determining, initiating execution of the callee function based on performing one of:
when a caller function corresponds to the foreign ABI, and when the callee function is determined to correspond to the foreign ABI, directly calling the callee function using the reference memory address within an emulator;
when the caller function corresponds to the foreign ABI, and when the callee function is determined to correspond to the native ABI, calling an entry thunk that (i) adapts a second calling convention to the first calling convention and then (ii) directly calls the callee function using the reference memory address;
when the caller function corresponds to the native ABI, and when the callee function is determined to correspond to the foreign ABI, calling an exit thunk that (i) adapts a first calling convention of the native ABI to a second calling convention of the foreign ABI and then (ii) invokes the emulator to directly call the callee function using the reference memory address; or
when the caller function corresponds to the native ABI, and when the callee function is determined to correspond to the native ABI, directly calling the callee function using the reference memory address.

### Claim 2 (depends on 1)

The method of claim 1, wherein the caller function corresponds to the foreign ABI and the callee function is determined to correspond to the foreign ABI, and wherein initiating execution of the callee function comprises directly calling the callee function using the reference memory address within the emulator.

### Claim 3 (depends on 1)

The method of claim 1, wherein the caller function corresponds to the foreign ABI and the callee function is determined to correspond to the native ABI, and wherein initiating execution of the callee function comprises calling the entry thunk.

### Claim 4 (depends on 3)

The method of claim 3, further comprising identifying a location of the entry thunk based at least on (i) reading a block of memory immediately preceding the reference memory address, and (ii) determining from the block of memory an offset or a pointer to the location of entry thunk.

### Claim 5 (depends on 1)

The method of claim 1, wherein the caller function corresponds to the native ABI and the callee function is determined to correspond to the foreign ABI, and wherein initiating execution of the callee function comprises calling the exit thunk.

### Claim 6 (depends on 5)

The method of claim 5, wherein a location of the exit thunk is contained within the caller function.

### Claim 7 (depends on 1)

The method of claim 1, wherein the caller function corresponds to the native ABI and the callee function is determined to correspond to the native ABI, and wherein initiating execution of the callee function comprises directly calling the callee function using the reference memory address.

### Claim 8 (depends on 1)

The method of claim 1, further comprising, when the fast-forward sequence is identified at the reference memory address, updating the reference memory address with a new reference memory address obtained from the fast-forward sequence.

### Claim 9 (depends on 1)

The method of claim 1, further comprising, when the lookup structure indicates that the reference memory address is contained within the second memory range not storing native code, determining whether the fast-forward sequence is identifiable at the reference memory address.

### Claim 10 (depends on 1)

The method of claim 1, wherein the lookup structure comprises at least one of a bitmap, a hash table, or a binary tree.

### Claim 11

A computer system for using a common reference memory address when processing calls within a process that supports execution of both (i) native code targeting a native application binary interface (ABI) that corresponds to a native instruction set architecture (ISA) and that has a first calling convention, and (ii) foreign code targeting a foreign ABI that corresponds to a foreign ISA and that has a second calling convention, comprising:
a processor implementing the native ISA; and
a hardware storage device that stores computer-executable instructions that are executable by the processor to cause the computer system to perform at least the following:
based at least on identifying a call that targets a reference memory address for a callee function, determine whether the callee function corresponds to the native ABI or to the foreign ABI, wherein:
the callee function is determined to correspond to the native ABI based on one of (i) a lookup structure indicating that the reference memory address is contained within a first memory range storing native code, or (ii) a fast-forward sequence being identified at the reference memory address, and
the callee function is determined to correspond to the foreign ABI based at least on the lookup structure indicating that the reference memory address is contained within a second memory range not storing native code; and
based at least on the determining, initiate execution of the callee function based on performing one of:
when a caller function corresponds to the foreign ABI, and when the callee function is determined to correspond to the foreign ABI, directly calling the callee function using the reference memory address within an emulator;
when the caller function corresponds to the foreign ABI, and when the callee function is determined to correspond to the native ABI, calling an entry thunk that (i) adapts a second calling convention to the first calling convention and then (ii) directly calls the callee function using the reference memory address;
when the caller function corresponds to the native ABI, and when the callee function is determined to correspond to the foreign ABI, calling an exit thunk that (i) adapts a first calling convention of the native ABI to a second calling convention of the foreign ABI and then (ii) invokes the emulator to directly call the callee function using the reference memory address; or
when the caller function corresponds to the native ABI, and when the callee function is determined to correspond to the native ABI, directly calling the callee function using the reference memory address.

### Claim 12 (depends on 11)

The computer system of claim 11, wherein the caller function corresponds to the foreign ABI and the callee function is determined to correspond to the foreign ABI, and wherein initiating execution of the callee function comprises directly calling the callee function using the reference memory address within the emulator.

### Claim 13 (depends on 11)

The computer system of claim 11, wherein the caller function corresponds to the foreign ABI and the callee function is determined to correspond to the native ABI, and wherein initiating execution of the callee function comprises calling the entry thunk.

### Claim 14 (depends on 13)

The computer system of claim 13, the computer-executable instructions also executable by the processor to cause the computer system to identify a location of the entry thunk based at least on (i) reading a block of memory immediately preceding the reference memory address, and (ii) determining from the block of memory an offset or a pointer to the location of entry thunk.

### Claim 15 (depends on 11)

The computer system of claim 11, wherein the caller function corresponds to the native ABI and the callee function is determined to correspond to the foreign ABI, and wherein initiating execution of the callee function comprises calling the exit thunk.

### Claim 16 (depends on 15)

The computer system of claim 15, wherein a location of the exit thunk is contained within the caller function.

### Claim 17 (depends on 11)

The computer system of claim 11, wherein the caller function corresponds to the native ABI and the callee function is determined to correspond to the native ABI, and wherein initiating execution of the callee function comprises directly calling the callee function using the reference memory address.

### Claim 18 (depends on 11)

The computer system of claim 11, the computer-executable instructions also executable by the processor to cause the computer system to update the reference memory address with a new reference memory address obtained from the fast-forward sequence when the fast-forward sequence is identified at the reference memory address.

### Claim 19 (depends on 11)

The computer system of claim 11, the computer-executable instructions also executable by the processor to cause the computer system to determine whether the fast-forward sequence is identifiable at the reference memory address when the lookup structure indicates that the reference memory address is contained within the second memory range not storing native code.

### Claim 20

A computer program product for using a common reference memory address when processing calls within a process that supports execution of both (i) native code targeting a native application binary interface (ABI) that corresponds to a native instruction set architecture (ISA) and that has a first calling convention, and (ii) foreign code targeting a foreign ABI that corresponds to a foreign ISA and that has a second calling convention, the computer program product comprising a hardware storage device that stores computer-executable instructions that are executable by a processor implementing the native ISA to cause a computer system to perform at least the following:
based at least on identifying a call that targets a reference memory address for a callee function, determine whether the callee function corresponds to the native ABI or to the foreign ABI, wherein:
the callee function is determined to correspond to the native ABI based on one of (i) a lookup structure indicating that the reference memory address is contained within a first memory range storing native code, or (ii) a fast-forward sequence being identified at the reference memory address, and
the callee function is determined to correspond to the foreign ABI based at least on the lookup structure indicating that the reference memory address is contained within a second memory range not storing native code; and
based at least on the determining, initiate execution of the callee function based on performing one of:
when a caller function corresponds to the foreign ABI, and when the callee function is determined to correspond to the foreign ABI, directly calling the callee function using the reference memory address within an emulator;
when the caller function corresponds to the foreign ABI, and when the callee function is determined to correspond to the native ABI, calling an entry thunk that (i) adapts a second calling convention to the first calling convention and then (ii) directly calls the callee function using the reference memory address;
when the caller function corresponds to the native ABI, and when the callee function is determined to correspond to the foreign ABI, calling an exit thunk that (i) adapts a first calling convention of the native ABI to a second calling convention of the foreign ABI and then (ii) invokes the emulator to directly call the callee function using the reference memory address; or
when the caller function corresponds to the native ABI, and when the callee function is determined to correspond to the native ABI, directly calling the callee function using the reference memory address.
