NunyaOS System Calls

What are these for?

Many operations provided by the operating system are only accessible through what are called system calls. Features such as the clock, window drawing, and process creation are all administered by the kernel on a process' behalf. The system calls in NunyaOS also work to enforce the permissions that are so central to the vision of the project. Use the system calls provided in syscall.h to interact with the kernel when needed. Below are overviews of the modules provided by the system; dive into the header files of each module to see the details of the functions provided.

When writing processes, however, do not just include a single module; rather, include syscall.h to simply include the entire library of system calls. This decision was made to assert the namespace of the system calls and simplify the procedure for writing user processes.

System Call Modules


This module contains functions for the creation, suspension, and termination of processes. Use these functions when you want to create and run a child process.

int32_t run(char *process_path, uint32_t permissions_identifier)

This is how a process creates and runs a child process. Pass in the path of the executable and the identifier of the permissions capability, and the child process will begin execution.

int32_t exit(int32_t status)

Pass in the exit code of the process to end execution of the process and begin process cleanup. Ensure this function is called whenever a process terminates.

int32_t yield()

This function manually pauses execution of the current process and allows another process in the ready queue to execute.


Use these functions to create and delete process capabilities, which are needed in order to declare the permissions of a child process.

int32_t permissions_capability_create()

This function creates a permissions capability and returns its identifier, which you can edit as needed and then pass to run().

void permissions_capability_delete(uint32_t identifier)

Use this to delete any permissions capabilities you create. Capabilities count toward a process' memory allocation, so be sure to delete them to free up memory when no longer needed.


Use this module to query the operating system for the memory usage of the current process. This information is important to know to ensure that the process and any potential children do not exceed the allocation. Additionally, this module enables editing of a process capability to change its maximum memory usage.

int32_t get_current_memory_usage()

Use this to query the system on how much memory the current process is using.

int32_t get_max_memory()

Use this to remind the current process of its maximum memory allocation.

int32_t capability_set_max_memory(uint32_t identifier, uint32_t pages)

This function is used to edit a permissions capability; pass in the capability identifier and the desired maximum number of pages, and processes created with that capability will be held to that maximum. The desired maximum cannot exceed that of the current process.


The functions in this module enable the opening, reading, and writing of files within the operating system, as well as editing the file permissions of a process capability.

int32_t open(const char *path, const char *mode)

Pass in a path and a mode (reading, writing, etc) to open a file. The function returns a descriptor to be used in other file operations.

int32_t close(uint32_t fd)

This function closes an open file descriptor.

int32_t read(char *dest, uint32_t bytes, uint32_t fd)

Use this to read an amount from a file into a destination buffer.

int32_t write(const char *src, uint32_t bytes, uint32_t fd)

Use this to write an amount from a source to a given file.


This module declares the functions related to window creation and drawing, as well as editing the graphics permissions of a process capability.

int32_t create_window(int x, int y, uint32_t width, uint32_t height)

This function creates a window for a process to draw within.

int32_t clear()

This clears the content of the window.

int32_t get_event(struct event *e)

This queries the system for any events waiting in the process' queue, such as mouse clicks and keyboard strokes.

int32_t set_border_color(const struct graphics_color *border_color)

Use this to set the border color of the window.

iint32_t draw_line(int x1, int y1, int x2, int y2, const struct graphics_color *color)

This function draws a line in the desired color from one point to another.

int32_t draw_arc(int x, int y, const struct arc_info *arc, const struct graphics_color *c)

This draws a curved line with the given information and center.

draw_circle(int x, int y, const double *r, const struct graphics_color *c)

Use this to draw a circle with the specified information and center.

draw_char(int x, int y, char c, const struct graphics_color *fgcolor, const struct graphics_color *bgcolor)

This draws a character at the given location.

draw_string(int x, int y, const char *str, const struct graphics_color *fgcolor, const struct graphics_color *bgcolor)

Draw entire strings with this function.


Use the functions within this module to interact with the system's real-time clock (RTC).

int32_t read_rtc(struct rtc_time *t)

Reads from the RTC and stores the information in the given struct.


To access the system's clock, use these functions.

int32_t read_clock(clock_t *clock)

Reads from the system clock and stores the information in the given struct.

int32_t sleep(uint32_t half_millis)

Causes the current process to sleep for the given number of half-milliseconds.