Interface EmuSyscallLibrary<T>
- Type Parameters:
T- the type of data processed by the system calls, typicallybyte[]
- All Superinterfaces:
PcodeUseropLibrary<T>
- All Known Implementing Classes:
AbstractEmuLinuxSyscallUseropLibrary, AbstractEmuUnixSyscallUseropLibrary, AnnotatedEmuSyscallUseropLibrary, EmuLinuxAmd64SyscallUseropLibrary, EmuLinuxX86SyscallUseropLibrary, TaintFileReadsLinuxAmd64SyscallLibrary
A system call library is a collection of p-code executable routines, invoked by a system call
dispatcher. That dispatcher is represented by
emu_syscall(PcodeExecutor, PcodeUseropLibrary, PcodeOp, Varnode), and is exported as a
Sleigh userop. If this interface is "mixed in" with AnnotatedPcodeUseropLibrary, that
userop is automatically included in the userop library. The simplest means of implementing a
syscall library is probably via AnnotatedEmuSyscallUseropLibrary. It implements this
interface and extends AnnotatedPcodeUseropLibrary. In addition, it provides its own
annotation system for exporting userops as system calls.
-
Nested Class Summary
Nested ClassesChangeModifier and TypeInterfaceDescriptionstatic interfaceThe definition of a system callNested classes/interfaces inherited from interface PcodeUseropLibrary
PcodeUseropLibrary.EmptyPcodeUseropLibrary, PcodeUseropLibrary.PcodeUseropDefinition<T>, PcodeUseropLibrary.PcodeUseropSymbolMap -
Field Summary
FieldsChangeModifier and TypeFieldDescriptionstatic final SleighPcodeUseropDefinitionThe Sleigh code to defer to run-time system call resolutionstatic final Stringstatic final StringFields inherited from interface PcodeUseropLibrary
NIL, SYMBOL_CACHE -
Method Summary
ChangeModifier and TypeMethodDescriptiondefault voidemu_rt_syscall(PcodeExecutor<T> executor, PcodeUseropLibrary<T> library, long syscallNumber) A Java-callback implementation of "emu_syscall" that reads the syscall number and dispatches to the appropriate system call implementation at run time.default voidemu_syscall(PcodeExecutor<T> executor, PcodeUseropLibrary<T> library, PcodeOp op, Varnode syscallNumber) The entry point for executing a system call on the given executorGet the map of syscalls by numberstatic Map<Long, PrototypeModel> loadSyscallConventionMap(Program program) Derive a syscall number to calling convention map by scraping functions in the program's "syscall" space.loadSyscallFunctionMap(Program program) Scrape functions from the given program's "syscall" space.loadSyscallNumberMap(Program program) Derive a syscall number to name map by scraping functions in the program's "syscall" space.loadSyscallNumberMap(String dataFileName) Derive a syscall number to name map from the specification in a given file.REMOVEDPcodeUseropDefinition<T>RemovedMethods inherited from interface PcodeUseropLibrary
compose, compose, getSymbols, getUserops
-
Field Details
-
SYSCALL_SPACE_NAME
- See Also:
-
SYSCALL_CONVENTION_NAME
- See Also:
-
FALLBACK_EMU_SYSCALL NEW
The Sleigh code to defer to run-time system call resolution
-
-
Method Details
-
loadSyscallNumberMap
Derive a syscall number to name map from the specification in a given file.- Parameters:
dataFileName- the file name to be found in a modules data directory- Returns:
- the map
- Throws:
IOException- if the file could not be read
-
loadSyscallFunctionMap
-
loadSyscallNumberMap
-
loadSyscallConventionMap
Derive a syscall number to calling convention map by scraping functions in the program's "syscall" space.- Parameters:
program- the program whose "syscall" space to scrape- Returns:
- the map of syscall number to calling convention
-
emu_rt_syscall
default void emu_rt_syscall(PcodeExecutor<T> executor, PcodeUseropLibrary<T> library, long syscallNumber) A Java-callback implementation of "emu_syscall" that reads the syscall number and dispatches to the appropriate system call implementation at run time.This is the normal behavior for the interpretation-based p-code emulator anyway. However, for an execution engine that attempts to resolve system calls "just in time," it may be necessary to explicitly defer to this implementation to prevent any further attempt to resolve the system call, when it becomes impossible to do so.
- Parameters:
executor- the executorlibrary- the p-code userop library (often including exported system calls)syscallNumber- the system call number
-
emu_syscall
default void emu_syscall(PcodeExecutor<T> executor, PcodeUseropLibrary<T> library, PcodeOp op, Varnode syscallNumber) The entry point for executing a system call on the given executorThe executor's state must already be prepared according to the relevant system calling conventions. The extended or composed library must provide the "syscall" and/or other relevant userops defined in the Sleigh. That "syscall" userop should invoke this userop, passing the system call number then place the result where it belongs according to the target ABI.
- Parameters:
executor- the executorlibrary- the libraryop- the callother useropsyscallNumber- the varnode containing the syscall number- Implementation Notes:
- At run time, the logic here will do exactly as it says. For the
interpretation-based emulator, nothing special happens. We read the system call
number and defer to
emu_rt_syscall(PcodeExecutor, PcodeUseropLibrary, long), which looks it up and executes it. The try-catch forConcretionErrorappears totally useless.For the JIT-accelerated emulator, things are more interesting. Because
AnnotatedPcodeUseropLibrary.PcodeUserop.canInline()is set here, we receive this callback during the decode phase of the translation. We read the system call number and defer toemu_rt_syscall(PcodeExecutor, PcodeUseropLibrary, long)as before. (Note thatAnnotatedPcodeUseropLibrary.PcodeUserop.canInline()being false does not prevent us from invoking it from Java, even though the engine is currently trying to inline us.) The try-catch thus protects the attempt to concretize the syscall number. During decode,T :=MaskedBytes, so if the syscall turns out to be a constant (which it often does), then we can dispatch it at decode time. That syscall (or at least the logic that reads arguments and stores the result) can thus be inlined. If concretization fails, then we fall back to invoking {#emu_rt_syscall} at run time.
-
getSyscalls
Map<Long, EmuSyscallLibrary.EmuSyscallDefinition<T>> getSyscalls()Get the map of syscalls by numberNote this method will be invoked for every interpreted syscall, so it should be a simple accessor. Any computations needed to create the map should be done ahead of time.
- Returns:
- the system call map
-