Package ghidra.pcode.emu.unix
Class AbstractEmuUnixSyscallUseropLibrary<T>
java.lang.Object
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
Modifier and TypeClassDescriptionstatic enum
The errno values as defined by the OS simulatorprotected class
System calls defined using Structured SleighNested classes/interfaces inherited from class ghidra.pcode.emu.sys.AnnotatedEmuSyscallUseropLibrary
AnnotatedEmuSyscallUseropLibrary.EmuSyscall, AnnotatedEmuSyscallUseropLibrary.StructuredPart
Nested classes/interfaces inherited from class ghidra.pcode.exec.AnnotatedPcodeUseropLibrary
AnnotatedPcodeUseropLibrary.AnnotatedPcodeUseropDefinition<T>, AnnotatedPcodeUseropLibrary.FixedArgsAnnotatedPcodeUseropDefinition<T>, AnnotatedPcodeUseropLibrary.OpExecutor, AnnotatedPcodeUseropLibrary.OpLibrary, AnnotatedPcodeUseropLibrary.OpOutput, AnnotatedPcodeUseropLibrary.OpState, AnnotatedPcodeUseropLibrary.PcodeUserop, AnnotatedPcodeUseropLibrary.VariadicAnnotatedPcodeUseropDefinition<T>
Nested classes/interfaces inherited from interface ghidra.pcode.emu.sys.EmuSyscallLibrary
EmuSyscallLibrary.EmuSyscallDefinition<T>, EmuSyscallLibrary.SyscallPcodeUseropDefinition<T>
Nested classes/interfaces inherited from interface ghidra.pcode.exec.PcodeUseropLibrary
PcodeUseropLibrary.EmptyPcodeUseropLibrary, PcodeUseropLibrary.PcodeUseropDefinition<T>
-
Field Summary
Modifier and TypeFieldDescriptionprotected final NavigableSet
<Integer> protected final Map
<Integer, EmuUnixFileDescriptor<T>> protected final EmuUnixFileSystem
<T> protected final int
protected EmuUnixUser
Fields inherited from class ghidra.pcode.emu.sys.AnnotatedEmuSyscallUseropLibrary
additionalArchives, CACHE_BY_CLASS, cSpec, dtMachineWord, machine, program, SYSCALL_SPACE_NAME, syscallMap
Fields inherited from class ghidra.pcode.exec.AnnotatedPcodeUseropLibrary
ops
Fields inherited from interface ghidra.pcode.emu.sys.EmuSyscallLibrary
SYSCALL_CONVENTION_NAME
Fields inherited from interface ghidra.pcode.exec.PcodeUseropLibrary
NIL
-
Constructor Summary
ConstructorDescriptionAbstractEmuUnixSyscallUseropLibrary
(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 int
claimFd
(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 int
Get the platform-specific errno value for the given simulator-defined errnoboolean
handleError
(PcodeExecutor<T> executor, PcodeExecutionException err) Try to handle an error, usually by returning it to the user programprotected int
lowestFd()
Get the first available file descriptorprotected AnnotatedEmuSyscallUseropLibrary<T>.StructuredPart
Plug 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 numberprotected abstract boolean
returnErrno
(PcodeExecutor<T> executor, int errno) Place the errno into the machine as expected by the simulated platform's ABIunix_close
(T fd) The UNIXclose
system callThe UNIXexit
system callvoid
unix_group_exit
(T status) The UNIXgroup_exit
system callThe UNIXopen
system callThe UNIXread
system callunix_write
(PcodeExecutorState<T> state, T fd, T bufPtr, T count) The UNIXwrite
system callMethods inherited from class ghidra.pcode.emu.sys.AnnotatedEmuSyscallUseropLibrary
disposeAdditionalArchives, getAdditionalArchives, getSyscalls, getSyscallUserop, mapAndBindSyscalls, mapAndBindSyscalls, newBoundSyscall
Methods inherited from class ghidra.pcode.exec.AnnotatedPcodeUseropLibrary
getMethodLookup, getOperandType, getUserops
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.pcode.emu.sys.EmuSyscallLibrary
readSyscallNumber, syscall
Methods inherited from interface ghidra.pcode.exec.PcodeUseropLibrary
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.EBADF
if 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.EBADF
if the file descriptor is invalid
-
newStructuredPart
Plug our Sleigh-defined syscalls in- Overrides:
newStructuredPart
in 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
-
returnErrno
Place the errno into the machine as expected by the simulated platform's ABI- Parameters:
executor
- the executor for the thread running this system callerrno
- the error number- Returns:
- true if the errno was successfully placed
-
handleError
Description copied from interface:EmuSyscallLibrary
Try to handle an error, usually by returning it to the user programIf the particular error was not expected, it is best practice to return false, causing the emulator to interrupt. Otherwise, some state is set in the machine that, by convention, communicates the error back to the user program.
- Parameters:
executor
- the executor for the thread that caused the errorerr
- the error- Returns:
- true if execution can continue uninterrupted
-
unix_exit
The UNIXexit
system callThis just throws an exception, which the overall simulator or script should catch.
- Parameters:
status
- the status code- Returns:
- never
- Throws:
EmuProcessExitedException
- always
-
unix_read
The UNIXread
system call- Parameters:
state
- to receive the thread's statefd
- 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
The UNIXwrite
system call- Parameters:
state
- to receive the thread's statefd
- 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
The UNIXopen
system call- Parameters:
state
- to receive the thread's statepathnamePtr
- the file's path (pointer to character string)flags
- the flagsmode
- the mode- Returns:
- the file descriptor
-
unix_close
The UNIXclose
system call- Parameters:
fd
- the file descriptor- Returns:
- 0 for success
-
unix_group_exit
The UNIXgroup_exit
system callThis just throws an exception, which the overall simulator or script should catch.
- Parameters:
status
- the status code- Throws:
EmuProcessExitedException
- always
-