yggdrasil/lib/abi-def/yggdrasil.abi

245 lines
7.6 KiB
Plaintext
Raw Normal View History

2024-03-12 13:37:40 +02:00
// vi:syntax=yggdrasil_abi:
extern {
type Duration = core::time::Duration;
type SocketAddr = core::net::SocketAddr;
type AtomicU32 = core::sync::atomic::AtomicU32;
type MappingSource;
type SystemInfo = yggdrasil_abi::system::SystemInfo;
type SignalEntryData = yggdrasil_abi::process::SignalEntryData;
type SpawnOptions = yggdrasil_abi::process::SpawnOptions;
type MutexOperation = yggdrasil_abi::process::MutexOperation;
type ExecveOptions = yggdrasil_abi::process::ExecveOptions;
#[thin]
type ExitCode = yggdrasil_abi::process::ExitCode;
type SocketOption = yggdrasil_abi::net::SocketOption;
type SentMessage = yggdrasil_abi::io::SentMessage;
type ReceivedMessageMetadata = yggdrasil_abi::io::ReceivedMessageMetadata;
type MountOptions = yggdrasil_abi::io::MountOptions;
type UnmountOptions = yggdrasil_abi::io::UnmountOptions;
type DeviceRequest = yggdrasil_abi::io::DeviceRequest;
type FileMetadataUpdate = yggdrasil_abi::io::FileMetadataUpdate;
type DirectoryEntry = yggdrasil_abi::io::DirectoryEntry;
type FileAttr = yggdrasil_abi::io::FileAttr;
#[thin]
type SeekFrom = yggdrasil_abi::io::SeekFrom;
#[thin]
type MessageDestination = yggdrasil_abi::io::MessageDestination;
type TerminalOptions = yggdrasil_abi::io::TerminalOptions;
type TerminalSize = yggdrasil_abi::io::TerminalSize;
}
// abi::error
enum Error(u32) {
OutOfMemory = 1,
AlreadyExists = 2,
NotImplemented = 3,
DoesNotExist = 4,
InvalidFile = 5,
InvalidArgument = 6,
Interrupted = 7,
WouldBlock = 8,
UnrecognizedExecutable = 9,
InvalidOperation = 10,
InvalidMemoryOperation = 11,
NotADirectory = 12,
IsADirectory = 13,
ReadOnly = 14,
PermissionDenied = 15,
AddrInUse = 16,
QueueFull = 17,
BufferTooSmall = 18,
ConnectionReset = 19,
MissingData = 20,
NetworkUnreachable = 21,
TimedOut = 22,
ConnectionRefused = 23,
HostUnreachable = 24,
UndefinedSyscall = 25,
DirectoryNotEmpty = 26,
}
// abi::process
enum Signal(u32) {
/// Process has tried to perform an illegal memory operation
MemoryAccessViolation = 1,
/// Process has hit a breakpoint or was aborted
Aborted = 2,
/// Process was killed
Killed = 3,
/// Process was interrupted
Interrupted = 4,
}
newtype ProcessId(u32);
newtype ThreadId(u32);
2024-03-12 13:37:40 +02:00
// abi::io
newtype RawFd(u32);
newtype UserId(u32);
newtype GroupId(u32);
newtype ChannelPublisherId(u32);
2024-03-12 13:37:40 +02:00
bitfield FileMode(u32) {
/// Other user execution access
OTHER_EXEC: 0,
/// Other user write access
OTHER_WRITE: 1,
/// Other user read access
OTHER_READ: 2,
/// Group execution access
GROUP_EXEC: 3,
/// Group write access
GROUP_WRITE: 4,
/// Group read access
GROUP_READ: 5,
/// User execution access
USER_EXEC: 6,
/// User write access
USER_WRITE: 7,
/// User read access
USER_READ: 8,
}
bitfield OpenOptions(u32) {
/// The file is to be opened with read capability
READ: 0,
/// The file is to be opened with write capability
WRITE: 1,
/// Open file at the end
APPEND: 2,
/// Truncate the file to zero bytes when opening
TRUNCATE: 3,
/// Create the file if it does not exist
CREATE: 4,
/// When combined with CREATE, will fail if the file already exists
CREATE_EXCL: 5,
}
enum FileType(u32) {
/// Regular file
File = 1,
/// Directory
Directory = 2,
/// Not yet implemented
Symlink = 3,
/// Block device
Block = 4,
/// Character device (e.g. terminal)
Char = 5,
}
enum PollControl(u32) {
AddFd = 1,
}
// abi::net
enum SocketType(u32) {
/// Raw packet socket
RawPacket = 0,
/// TCP stream socket
TcpStream = 1,
/// UDP packet socket
UdpPacket = 2,
}
// TODO allow splitting types into separate modules
syscall debug_trace(message: &str);
syscall get_random(buffer: &mut [u8]);
syscall get_system_info(info: &mut SystemInfo) -> Result<()>;
syscall mount(opts: &MountOptions<'_>) -> Result<()>;
syscall unmount(opts: &UnmountOptions) -> Result<()>;
// Memory management
syscall map_memory(hint: Option<NonZeroUsize>, len: usize, source: &MappingSource) -> Result<usize>;
syscall unmap_memory(address: usize, len: usize) -> Result<()>;
// Process/thread management
syscall exit_process(code: ExitCode) -> !;
syscall spawn_process(options: &SpawnOptions<'_>) -> Result<ProcessId>;
syscall wait_process(pid: ProcessId, status: &mut ExitCode) -> Result<()>;
syscall get_pid() -> ProcessId;
2024-03-12 13:37:40 +02:00
syscall nanosleep(dur: &Duration);
syscall exit_signal(frame: &SignalEntryData) -> !;
syscall set_signal_entry(ip: usize, sp: usize);
syscall send_signal(target: ProcessId, signal: Signal) -> Result<()>;
2024-03-12 13:37:40 +02:00
syscall mutex(mutex: &AtomicU32, op: &MutexOperation) -> Result<()>;
syscall start_session() -> Result<()>;
// I/O
syscall open(at: Option<RawFd>, path: &str, opts: OpenOptions, mode: FileMode) -> Result<RawFd>;
syscall close(fd: RawFd) -> Result<()>;
syscall write(fd: RawFd, data: &[u8]) -> Result<usize>;
syscall read(fd: RawFd, data: &mut [u8]) -> Result<usize>;
syscall seek(fd: RawFd, pos: SeekFrom) -> Result<u64>;
syscall open_directory(at: Option<RawFd>, path: &str) -> Result<RawFd>;
syscall read_directory_entries(fd: RawFd, entries: &mut [MaybeUninit<DirectoryEntry>]) -> Result<usize>;
syscall create_directory(at: Option<RawFd>, path: &str, mode: FileMode) -> Result<()>;
syscall remove_directory(at: Option<RawFd>, path: &str) -> Result<()>;
syscall remove(at: Option<RawFd>, path: &str) -> Result<()>;
syscall clone_fd(source: RawFd, target: Option<RawFd>) -> Result<RawFd>;
syscall update_metadata(at: Option<RawFd>, path: &str, update: &FileMetadataUpdate) -> Result<()>;
syscall get_metadata(at: Option<RawFd>, path: &str, metadata: &mut MaybeUninit<FileAttr>, follow: bool) -> Result<()>;
syscall device_request(fd: RawFd, req: &mut DeviceRequest) -> Result<()>;
// Misc I/O
syscall open_channel(name: &str, subscribe: bool) -> Result<RawFd>;
syscall create_timer(repeat: bool) -> Result<RawFd>;
syscall create_pty(opts: &TerminalOptions, size: &TerminalSize, fds: &mut [MaybeUninit<RawFd>; 2]) -> Result<()>;
syscall create_shared_memory(size: usize) -> Result<RawFd>;
syscall create_poll_channel() -> Result<RawFd>;
syscall create_pipe(fds: &mut [MaybeUninit<RawFd>; 2]) -> Result<()>;
syscall poll_channel_wait(
poll_fd: RawFd,
timeout: &Option<Duration>,
output: &mut Option<(RawFd, Result<()>)>
) -> Result<()>;
syscall poll_channel_control(poll_fd: RawFd, ctl: PollControl, fd: RawFd) -> Result<()>;
syscall send_message(fd: RawFd, msg: &SentMessage<'_>, dst: MessageDestination) -> Result<()>;
syscall receive_message(
fd: RawFd,
meta: &mut MaybeUninit<ReceivedMessageMetadata>,
data: &mut [u8],
from: &mut MaybeUninit<ChannelPublisherId>
2024-03-12 13:37:40 +02:00
) -> Result<()>;
// Network
syscall connect_socket(sock_fd: Option<RawFd>, remote: &SocketAddr, ty: SocketType, local: &mut MaybeUninit<SocketAddr>) -> Result<RawFd>;
syscall bind_socket(address: &SocketAddr, ty: SocketType) -> Result<RawFd>;
syscall accept(sock_fd: RawFd, remote: &mut MaybeUninit<SocketAddr>) -> Result<RawFd>;
syscall send_to(sock_fd: RawFd, data: &[u8], remote: &Option<SocketAddr>) -> Result<usize>;
syscall receive_from(sock_fd: RawFd, data: &mut [u8], remote: &mut MaybeUninit<SocketAddr>) -> Result<usize>;
syscall get_socket_option(sock_fd: RawFd, option: &mut SocketOption<'_>) -> Result<()>;
syscall set_socket_option(sock_fd: RawFd, option: &SocketOption<'_>) -> Result<()>;
// C compat
syscall fork() -> Result<ProcessId>;
2024-03-12 13:37:40 +02:00
syscall execve(options: &ExecveOptions<'_>) -> Result<()>;