Class 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.

  • Field Details

  • Constructor Details

    • AbstractEmuUnixSyscallUseropLibrary

      public AbstractEmuUnixSyscallUseropLibrary(PcodeMachine<T> machine, EmuUnixFileSystem<T> fs, Program program)
      Construct a new library
      Parameters:
      machine - the machine emulating the hardware
      fs - the file system to export to the user-space program
      program - 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 hardware
      fs - a file system to export to the user-space program
      program - a program containing the syscall definitions and conventions, likely the target program
      user - the "current user" to simulate
  • Method Details

    • lowestFd

      protected int lowestFd()
      Get the first available file descriptor
      Returns:
      the lowest available descriptor
    • claimFd

      protected int claimFd(EmuUnixFileDescriptor<T> desc)
      Claim the lowest available file descriptor number for the given descriptor object

      The descriptor will be added to the descriptor table for the claimed number

      Parameters:
      desc - the descriptor object
      Returns:
      the descriptor number
    • findFd

      protected EmuUnixFileDescriptor<T> findFd(int fd)
      Get the file descriptor object for the given file descriptor number
      Parameters:
      fd - the descriptor number
      Returns:
      the descriptor object
      Throws:
      EmuUnixException - with AbstractEmuUnixSyscallUseropLibrary.Errno.EBADF if the file descriptor is invalid
    • releaseFd

      protected EmuUnixFileDescriptor<T> releaseFd(int fd)
      Release/invalidate the given file descriptor number
      Parameters:
      fd - the file descriptor number
      Returns:
      the removed descriptor object
      Throws:
      EmuUnixException - with AbstractEmuUnixSyscallUseropLibrary.Errno.EBADF if the file descriptor is invalid
    • newStructuredPart

      protected AnnotatedEmuSyscallUseropLibrary<T>.StructuredPart newStructuredPart()
      Plug our Sleigh-defined syscalls in
      Overrides:
      newStructuredPart in class AnnotatedEmuSyscallUseropLibrary<T>
      Returns:
      the structured part
    • convertFlags

      protected abstract Set<EmuUnixFileSystem.OpenFlag> convertFlags(int flags)
      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

      protected EmuUnixFileDescriptor<T> createHandle(EmuUnixFile<T> file, int flags)
      A factory method for creating an open file handle
      Parameters:
      file - the file opened by the handle
      flags - the open flags, as specified by the user, as defined by the platform
      Returns:
      the handle
    • getErrno

      protected abstract int getErrno(AbstractEmuUnixSyscallUseropLibrary.Errno err)
      Get the platform-specific errno value for the given simulator-defined errno
      Parameters:
      err - the simulator-defined errno
      Returns:
      the platform-defined errno
    • putDescriptor

      public EmuUnixFileDescriptor<T> putDescriptor(int fd, EmuUnixFileDescriptor<T> desc)
      Put a descriptor into the process' open file handles
      Parameters:
      fd - the file descriptor value
      desc - 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 UNIX exit system call

      This just throws an exception, which the overall simulator or script should catch.

      Parameters:
      status - the status code
      Throws:
      EmuProcessExitedException - always
    • abstract_unix_read

      protected T abstract_unix_read(PcodeExecutorState<T> state, T fd, T bufPtr, T count)
    • unix_read

      public int unix_read(int fd, long bufPtr, int count)
      The UNIX read system call
      Parameters:
      fd - the file descriptor
      bufPtr - the pointer to the buffer to receive the data
      count - 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 UNIX write system call
      Parameters:
      fd - the file descriptor
      bufPtr - the pointer to the buffer of data to write
      count - 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 UNIX open system call
      Parameters:
      pathnamePtr - the file's path (pointer to character string)
      flags - the flags
      mode - the mode
      Returns:
      the file descriptor
    • unix_close

      public int unix_close(int fd)
      The UNIX close system call
      Parameters:
      fd - the file descriptor
      Returns:
      0 for success
    • unix_group_exit

      public void unix_group_exit(long status)
      The UNIX group_exit system call

      This just throws an exception, which the overall simulator or script should catch.

      Parameters:
      status - the status code
      Throws:
      EmuProcessExitedException - always