Class AbstractEmuUnixSyscallUseropLibrary<T>
java.lang.Object
ghidra.pcode.exec.DefaultPcodeUseropLibrary<T>
ghidra.pcode.exec.AnnotatedPcodeUseropLibrary<T>
ghidra.pcode.emu.sys.AnnotatedEmuSyscallUseropLibrary<T>
ghidra.pcode.emu.unix.AbstractEmuUnixSyscallUseropLibrary<T>
- Type Parameters:
T- the type of values processed by the library
- All Implemented Interfaces:
EmuSyscallLibrary<T>, PcodeUseropLibrary<T>
- Direct Known Subclasses:
AbstractEmuLinuxSyscallUseropLibrary
public abstract class AbstractEmuUnixSyscallUseropLibrary<T>
extends AnnotatedEmuSyscallUseropLibrary<T>
An abstract library of UNIX system calls, suitable for use with any processor
See the UNIX manual pages for more information about each specific system call, error numbers, etc.
TODO: The rest of the system calls common to UNIX.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe errno values as defined by the OS simulatorprotected classSystem calls defined using Structured SleighNested classes/interfaces inherited from class AnnotatedEmuSyscallUseropLibrary
AnnotatedEmuSyscallUseropLibrary.EmuSyscall, AnnotatedEmuSyscallUseropLibrary.StructuredPartNested classes/interfaces inherited from class AnnotatedPcodeUseropLibrary
AnnotatedPcodeUseropLibrary.AnnotatedPcodeUseropDefinition<T>, AnnotatedPcodeUseropLibrary.FixedArgsAnnotatedPcodeUseropDefinition<T>, AnnotatedPcodeUseropLibrary.OpExecutor, AnnotatedPcodeUseropLibrary.OpInput, AnnotatedPcodeUseropLibrary.OpLibrary, AnnotatedPcodeUseropLibrary.OpOp, AnnotatedPcodeUseropLibrary.OpOutput, AnnotatedPcodeUseropLibrary.OpState, AnnotatedPcodeUseropLibrary.PcodeUserop, AnnotatedPcodeUseropLibrary.VariadicAnnotatedPcodeUseropDefinition<T>Nested classes/interfaces inherited from interface EmuSyscallLibrary
EmuSyscallLibrary.EmuSyscallDefinition<T>Nested classes/interfaces inherited from interface PcodeUseropLibrary
PcodeUseropLibrary.EmptyPcodeUseropLibrary, PcodeUseropLibrary.PcodeUseropDefinition<T>, PcodeUseropLibrary.PcodeUseropSymbolMap -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final NavigableSet<Integer> protected final Map<Integer, EmuUnixFileDescriptor<T>> protected final EmuUnixFileSystem<T> protected final intprotected EmuUnixUserFields inherited from class AnnotatedEmuSyscallUseropLibrary
additionalArchives, CACHE_BY_CLASS, cSpec, dtMachineWord, machine, program, SYSCALL_SPACE_NAME, syscallMapFields inherited from class DefaultPcodeUseropLibrary
opsFields inherited from interface EmuSyscallLibrary
FALLBACK_EMU_SYSCALL, SYSCALL_CONVENTION_NAMEFields inherited from interface PcodeUseropLibrary
NIL, SYMBOL_CACHE -
Constructor Summary
ConstructorsConstructorDescriptionAbstractEmuUnixSyscallUseropLibrary(PcodeMachine<T> machine, EmuUnixFileSystem<T> fs, Program program) Construct a new libraryAbstractEmuUnixSyscallUseropLibrary(PcodeMachine<T> machine, EmuUnixFileSystem<T> fs, Program program, EmuUnixUser user) Construct a new library -
Method Summary
Modifier and TypeMethodDescriptionprotected Tabstract_unix_read(PcodeExecutorState<T> state, T fd, T bufPtr, T count) protected intclaimFd(EmuUnixFileDescriptor<T> desc) Claim the lowest available file descriptor number for the given descriptor objectprotected abstract Set<EmuUnixFileSystem.OpenFlag> convertFlags(int flags) Convert the flags as defined for this platform to flags understood by the simulatorprotected EmuUnixFileDescriptor<T> createHandle(EmuUnixFile<T> file, int flags) A factory method for creating an open file handleprotected EmuUnixFileDescriptor<T> findFd(int fd) Get the file descriptor object for the given file descriptor numberprotected abstract intGet the platform-specific errno value for the given simulator-defined errnoprotected intlowestFd()Get the first available file descriptorprotected AnnotatedEmuSyscallUseropLibrary<T>.StructuredPartPlug our Sleigh-defined syscalls inputDescriptor(int fd, EmuUnixFileDescriptor<T> desc) Put a descriptor into the process' open file handlesprotected EmuUnixFileDescriptor<T> releaseFd(int fd) Release/invalidate the given file descriptor numberintunix_close(int fd) The UNIXclosesystem callvoidunix_exit(long status) The UNIXexitsystem callvoidunix_group_exit(long status) The UNIXgroup_exitsystem callintunix_open(long pathnamePtr, int flags, int mode) The UNIXopensystem callintunix_read(int fd, long bufPtr, int count) The UNIXreadsystem callintunix_write(int fd, long bufPtr, int count) The UNIXwritesystem callMethods inherited from class AnnotatedEmuSyscallUseropLibrary
disposeAdditionalArchives, getAdditionalArchives, getSyscalls, mapAndBindSyscalls, mapAndBindSyscalls, newBoundSyscallMethods inherited from class AnnotatedPcodeUseropLibrary
getMethodLookup, getOperandTypeMethods inherited from class DefaultPcodeUseropLibrary
getUserops, putOpMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EmuSyscallLibrary
emu_rt_syscall, emu_syscallMethods inherited from interface PcodeUseropLibrary
compose, compose, getSymbols, getUserops
-
Field Details
-
fs
-
user
-
intSize
protected final int intSize -
closedFds
-
descriptors
-
-
Constructor Details
-
AbstractEmuUnixSyscallUseropLibrary
public AbstractEmuUnixSyscallUseropLibrary(PcodeMachine<T> machine, EmuUnixFileSystem<T> fs, Program program) Construct a new library- Parameters:
machine- the machine emulating the hardwarefs- the file system to export to the user-space programprogram- a program containing the syscall definitions and conventions, likely the target program
-
AbstractEmuUnixSyscallUseropLibrary
public AbstractEmuUnixSyscallUseropLibrary(PcodeMachine<T> machine, EmuUnixFileSystem<T> fs, Program program, EmuUnixUser user) Construct a new library- Parameters:
machine- the machine emulating the hardwarefs- a file system to export to the user-space programprogram- a program containing the syscall definitions and conventions, likely the target programuser- the "current user" to simulate
-
-
Method Details
-
lowestFd
protected int lowestFd()Get the first available file descriptor- Returns:
- the lowest available descriptor
-
claimFd
Claim the lowest available file descriptor number for the given descriptor objectThe descriptor will be added to the descriptor table for the claimed number
- Parameters:
desc- the descriptor object- Returns:
- the descriptor number
-
findFd
Get the file descriptor object for the given file descriptor number- Parameters:
fd- the descriptor number- Returns:
- the descriptor object
- Throws:
EmuUnixException- withAbstractEmuUnixSyscallUseropLibrary.Errno.EBADFif the file descriptor is invalid
-
releaseFd
Release/invalidate the given file descriptor number- Parameters:
fd- the file descriptor number- Returns:
- the removed descriptor object
- Throws:
EmuUnixException- withAbstractEmuUnixSyscallUseropLibrary.Errno.EBADFif the file descriptor is invalid
-
newStructuredPart
Plug our Sleigh-defined syscalls in- Overrides:
newStructuredPartin classAnnotatedEmuSyscallUseropLibrary<T>- Returns:
- the structured part
-
convertFlags
Convert the flags as defined for this platform to flags understood by the simulator- Parameters:
flags- the platform-defined flags- Returns:
- the simulator-defined flags
-
createHandle
A factory method for creating an open file handle- Parameters:
file- the file opened by the handleflags- the open flags, as specified by the user, as defined by the platform- Returns:
- the handle
-
getErrno
Get the platform-specific errno value for the given simulator-defined errno- Parameters:
err- the simulator-defined errno- Returns:
- the platform-defined errno
-
putDescriptor
Put a descriptor into the process' open file handles- Parameters:
fd- the file descriptor valuedesc- the simulated descriptor (handle, console, etc.)- Returns:
- the previous descriptor, which probably ought to be
null
-
unix_exit
public void unix_exit(long status) The UNIXexitsystem callThis just throws an exception, which the overall simulator or script should catch.
- Parameters:
status- the status code- Throws:
EmuProcessExitedException- always
-
abstract_unix_read
-
unix_read
public int unix_read(int fd, long bufPtr, int count) The UNIXreadsystem call- Parameters:
fd- the file descriptorbufPtr- the pointer to the buffer to receive the datacount- the number of bytes to read- Returns:
- the number of bytes successfully read
-
unix_write
public int unix_write(int fd, long bufPtr, int count) The UNIXwritesystem call- Parameters:
fd- the file descriptorbufPtr- the pointer to the buffer of data to writecount- the number of bytes to write- Returns:
- the number of bytes successfully written
-
unix_open
public int unix_open(long pathnamePtr, int flags, int mode) The UNIXopensystem call- Parameters:
pathnamePtr- the file's path (pointer to character string)flags- the flagsmode- the mode- Returns:
- the file descriptor
-
unix_close
public int unix_close(int fd) The UNIXclosesystem call- Parameters:
fd- the file descriptor- Returns:
- 0 for success
-
unix_group_exit
public void unix_group_exit(long status) The UNIXgroup_exitsystem callThis just throws an exception, which the overall simulator or script should catch.
- Parameters:
status- the status code- Throws:
EmuProcessExitedException- always
-