EP-4738762-A2 - SYSTEMS AND METHODS FOR PERFORMING BINARY TRANSLATION
Abstract
Systems and methods for performing binary translation include a system that is capable of translating binaries written for use in a source execution environment to binaries compatible with a target execution environment. Consistent with some embodiments, a binary translation system includes a system service and a runtime code module that exists in an application memory address space. The binary translation system translates object-level binaries corresponding to executables, linkers, libraries, and the like and stores the translation in a translation cache that is cryptographically secured to ensure that only a system having a specific key is able to access the translations. If the application or application binary has been modified since the translation was performed, the system service will ensure that the translation is removed from the cache, a new translation is performed, and all threads accessing that translation are updated to the new translation.
Inventors
- ZWARICH, CAMERON
- PALMANS, Denis
Assignees
- Apple Inc.
Dates
- Publication Date
- 20260506
- Application Date
- 20210610
Claims (15)
- A system, comprising: a memory storing one or more application binaries, the one or more application binaries written for execution in a first execution environment; one or more processors configured to execute application binaries in a second execution environment different than the first execution environment; a binary translator configured to: manage translations of the application binaries; and manage just-in-time, JIT, translations of the application binaries for which the binary translator lacks corresponding translations; and a translation cache stored within the memory and configured to store one or more translations, wherein a given translation of the one or more translations corresponds to at least a portion of the one or more application binaries, and wherein the one or more translations are for execution in the second execution environment; wherein the binary translator is configured to determine if the one or more application binaries corresponding to the given translation has been made writeable, wherein, when the one or more application binaries has been made writeable, the system is further configured to: remove target addresses of translations associated with the one or more application binaries from a global indirect branch table; unlink translations stored in the translation cache that directly jump to the removed target addresses; halt the execution of threads related to the one or more application binaries; force the threads related to the one or more application binaries to JIT translation of the one or more application binaries; and resume the execution of the threads.
- The system of claim 1, wherein, when the one or more application binaries has been made writeable, the system is further configured to advance a global counter used to deallocate shared resources, wherein the global counter is shared by a plurality of threads.
- The system of claim 1, wherein the binary translator is further configured to maintain a mapping of untranslated code addresses that are translation entry points to corresponding translations; and wherein, when the one or more application binaries has been made writeable, the system is further configured to invalidate the mapping of untranslated code addresses associated with the one or more application binaries.
- The system of claim 1, wherein, after resuming the execution of the threads, the JIT translations of the threads are not stored in the translation cache.
- The system of claim 1, wherein the one or more processors are configured to execute a cached translation of the one or more application binaries within a runtime code module of the binary translator that determines if the one or more application binaries corresponding to the executing translation has been made writeable.
- The system of claim 5, wherein an exception handler of the runtime code module removes translations associated with the one or more application binaries from the global indirect branch table.
- The system of claim 1, wherein a system service of the binary translator is configured to: generate a hash value based on information associated with the one or more application binaries; and store the generated hash value in an associative array in the memory, and wherein the generated hash value is used to determine if the one or more application binaries are available in the translation cache and to determine if the one or more application binaries have been modified.
- The system of claim 1, wherein the given translation of the one or more application binaries is signed using a key unique to the system.
- The system of claim 1, wherein the given translation of the one or more application binaries is encrypted with a key unique to the system.
- The system of claim 8 or claim 9, further comprising: a secure enclave processor coupled to the one or more processors and the memory, wherein the secure enclave processor is configured to generate the unique key.
- The system of claim 1, wherein the given translation of the one or more application binaries includes an object-level translation of the one or more application binaries generated prior to the execution of the one or more applications represented by the one or more application binaries.
- The system of claim 11, wherein the object-level translation includes a translation of a library used by the one or more application binaries during execution.
- A method performed by a computer, the method comprising: launching a first application binary for execution in a system, wherein the first application binary is written for a first execution environment and one or more processors in the system are configured to execute application binaries in a second execution environment different from the first execution environment; determining if a translated code sequence generated by a binary translator is stored in a translation cache in the system; executing the cached translated code sequence based on the translated code sequence being cached in the translation cache; in response to the binary translator determining that the first application binary has been made writeable: removing target addresses of translations associated with the first application binary from a global indirect branch table; unlinking translations stored in the translation cache that directly jump to the removed target addresses; halting the execution of threads related to the first application binary; forcing the threads related to the first application binary to just-in-time (JIT) translation of the first application binary; and resuming the execution of the threads.
- The method of claim 13, further comprising: maintaining a mapping of untranslated code addresses that are translation entry points to corresponding translations; and in response to the binary translator determining that the first application binary has been made writeable, invalidating the mapping of untranslated code addresses associated with the first application binary.
- A non-transitory computer readable medium having program instructions stored therein that are executable by a system to perform operations comprising: launching a first application binary for execution in the system, wherein the first application binary is written for a first execution environment and one or more processors in the system are configured to execute application binaries in a second execution environment different from the first execution environment; determining if a translated code sequence generated by a binary translator is stored in a translation cache in the system; executing the cached translated code sequence based on the translated code sequence being cached in the translation cache; in response to the binary translator determining that the first application binary has been made writeable: removing target addresses of translations associated with the first application binary from a global indirect branch table; unlinking translations stored in the translation cache that directly jump to the removed target addresses; halting the execution of threads related to the first application binary; forcing the threads related to the first application binary to just-in-time (JIT) translation of the first application binary; and resuming the execution of the threads.
Description
BACKGROUND Technical Field Embodiments described herein are related to binary translation. In particular, embodiments described herein are related to caching translated binaries in a translation cache for rapid retrieval by a system service that manages the cached translations. Description of the Related Art The standard way that developers enable an application written for a first execution environment to be executed a second execution environment is to port the application over to the second execution environment, which involves rebuilding and recompiling the application for the second execution environment. The port can take extensive time and effort for a large application and may involve good working knowledge of the second execution environment and the correct tools to recompile for that execution environment. To bridge the gap while an application is rebuilt and recompiled, developers have often used emulators (e.g., interpreters and/or translators) to run the code on a different execution environment. Interpreters typically read the application instructions iteratively in the first, or source, execution environment and perform the operations in the source execution environment running in a software environment within the second, or target, execution environment. Other emulators operate in a similar fashion but will utilize portions of the underlying hardware of the second environment to optimize the interpretation. For example, an emulator may use underlying memory and the underlying processor and system such that the application can appear to be running natively in the second environment, where the application is running at a speed that determined by the power of the underlying hardware and the performance of the interpreter. Binary translators translate various instructions and code of the application from the first execution environment to the second execution environment. Binary translators may typically be either static or dynamic. A static binary translator attempts to convert all of the application code from the first execution environment to the second execution environment without actually executing the code beforehand. Dynamic binary translation translates discrete blocks of code during execution and caches the translated block for use during the execution of the application containing that code. The Rosetta dynamic translation layer that was used to translate PowerPC applications to x86 is an example of a dynamic binary translator. While dynamic binary translators may be more accurate in that it can account for all of the code that needs translation, it often results in greater hardware overhead during the execution of the application due to the dynamic translation which can cause the application to execute slowly with lag noticeable to a user. Further, if the application that is being translated includes just-in-time (JIT) compilations that require translation, this will further include user-noticeable delays in the application as it is undergoing dynamic binary translation. SUMMARY In an embodiment, a system may comprise a memory storing an operating system and one or more application binaries. The one or more application binaries may be written for execution in a first execution environment. The system may further comprise one or more processors configured to execute application binaries in a second execution environment different than the first execution environment. The system may also comprise a binary translator that comprises a system service executable in a separate address space from the application binaries, and a runtime code module executable in an address space with the application binaries. The system service may be configured to manage translations of the application binaries, and the runtime code module may be configured to manage just-in-time (JIT) translations of the application binaries for which the system service lacks corresponding translations. In an embodiment, the system service may also manage library binaries (e.g., libraries provided by the operating system and/or user-provided libraries). The system may still further comprise a persistent translation cache stored within the memory. The persistent translation cache may store one or more translations, wherein a given translation corresponds to at least a portion of the one more application binaries. The one or more translations may be for execution in the second execution environment, wherein: the translation of the one or more application binaries may include an object-level translation of the one or more application binaries generated prior to the execution of the one or more applications represented by the one or more application binaries; and the one or more processors may be configured to execute the cached translation of the one or more application binaries within the runtime code module when the operating system calls for the execution of the one or more application binaries. In an embodiment, the first