-
Notifications
You must be signed in to change notification settings - Fork 0
Syscall Reference
Complete reference for ModuOS system calls.
Registers:
RAX: Syscall number
RDI: Argument 1
RSI: Argument 2
RDX: Argument 3
RCX: Argument 4
R8: Argument 5
R9: Argument 6
Return: RAX (0 or positive on success, negative on error)
Trigger: int 0x80
void exit(int status);Terminate current process with exit code.
int getpid(void);Get current process ID.
Returns: Process ID
int fork(void);Create child process (not fully implemented).
Returns: 0 in child, child PID in parent, negative on error
int exec(const char *path, char **argv);Execute program from file.
Returns: Negative on error (doesn't return on success)
void yield(void);Yield CPU to other processes.
int sleep(uint64_t milliseconds);Sleep for specified time.
Returns: 0 on success
int open(const char *path, int flags);Open file.
Flags:
-
O_RDONLY(0): Read only -
O_WRONLY(1): Write only -
O_RDWR(2): Read/Write
Returns: File descriptor, or negative on error
int close(int fd);Close file descriptor.
Returns: 0 on success, negative on error
int read(int fd, void *buffer, size_t count);Read from file.
Returns: Bytes read, or negative on error
int write(int fd, const void *buffer, size_t count);Write to file.
Returns: Bytes written, or negative on error
void* brk(void *addr);Change data segment size.
Returns: New break address, or NULL on error
void* mmap(void *addr, size_t length, int prot, int flags);Map memory region.
Returns: Mapped address, or NULL on error
int munmap(void *addr, size_t length);Unmap memory region.
Returns: 0 on success, negative on error
#define ESUCCESS 0 // Success
#define EPERM -1 // Operation not permitted
#define ENOENT -2 // No such file or directory
#define EBADF -3 // Bad file descriptor
#define ENOMEM -4 // Out of memory
#define EINVAL -5 // Invalid argument
#define ENOSYS -6 // Function not implemented// Open and read file
int fd = open("/file.txt", O_RDONLY);
if (fd < 0) {
// Error handling
return;
}
char buffer[1024];
int bytes = read(fd, buffer, sizeof(buffer));
close(fd);
// Exit program
exit(0);- System Calls - Implementation details
- Kernel API - Kernel functions