Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#ifndef ZINNIA_ARCHCTL_H
|
||||
#define ZINNIA_ARCHCTL_H
|
||||
|
||||
#include <zinnia/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum {
|
||||
// Does nothing.
|
||||
ZN_ARCHCTL_NONE = 0,
|
||||
#ifdef __x86_64__
|
||||
// On x86_64, sets the FSBASE register to the value.
|
||||
ZN_ARCHCTL_SET_FSBASE = 1,
|
||||
#endif
|
||||
} zn_archctl_t;
|
||||
|
||||
// Performs an architecture-dependent operation identified by `op`.
|
||||
zn_status_t zn_archctl(zn_archctl_t op, size_t value);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef ZINNIA_CHANNEL_H
|
||||
#define ZINNIA_CHANNEL_H
|
||||
|
||||
#include <zinnia/handle.h>
|
||||
#include <zinnia/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Handle which always points to a channel connected to the init server.
|
||||
#define ZN_INIT_CHANNEL ((zn_handle_t)(-1))
|
||||
|
||||
enum zn_channel_flags {
|
||||
// Allow sending messages even if one endpoint is not connected.
|
||||
ZN_CHANNEL_NONBLOCK = 1 << 0,
|
||||
};
|
||||
|
||||
// Creates a new channel.
|
||||
zn_status_t zn_channel_create(enum zn_channel_flags flags, zn_handle_t* endpoint0, zn_handle_t* endpoint1);
|
||||
|
||||
// Maps the message buffer in the address space and returns its base address.
|
||||
// There may only be one message buffer per channel and process.
|
||||
zn_status_t zn_channel_open(
|
||||
zn_handle_t channel,
|
||||
size_t num_handles,
|
||||
size_t num_bytes,
|
||||
zn_handle_t** out_handle_buf,
|
||||
void** out_data_buf
|
||||
);
|
||||
|
||||
// Waits for a new message to appear in the channel buffer.
|
||||
zn_status_t zn_channel_read(zn_handle_t channel);
|
||||
|
||||
// Writes a message to the
|
||||
zn_status_t zn_channel_write(zn_handle_t channel);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef ZINNIA_HANDLE_H
|
||||
#define ZINNIA_HANDLE_H
|
||||
|
||||
#include <zinnia/rights.h>
|
||||
#include <zinnia/status.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// A generic object handle.
|
||||
typedef uint32_t zn_handle_t;
|
||||
|
||||
#define ZN_HANDLE_INVALID ((zn_handle_t)(0))
|
||||
|
||||
// Checks an object handle for validity.
|
||||
zn_status_t zn_handle_validate(zn_handle_t handle);
|
||||
|
||||
// Drops a an object handle.
|
||||
// All further references using this handle are invalid. The numerical value
|
||||
// may become valid again, but it is an error to keep using it.
|
||||
// The underlying object gets freed only once no other handle references it.
|
||||
zn_status_t zn_handle_drop(zn_handle_t handle);
|
||||
|
||||
// Creates a new handle pointing to the same object as pointed to
|
||||
// by the original handle. The new handle may obtain new rights.
|
||||
zn_status_t zn_handle_clone(zn_handle_t handle, zn_rights_t cloned_rights, zn_handle_t* cloned);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef ZINNIA_IPC_POSIX_H
|
||||
#define ZINNIA_IPC_POSIX_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
ZNI_POSIX_OPEN_REQ,
|
||||
ZNI_POSIX_OPEN_RES,
|
||||
};
|
||||
|
||||
struct zni_posix_open {
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef ZINNIA_LOG_H
|
||||
#define ZINNIA_LOG_H
|
||||
|
||||
#include <zinnia/status.h>
|
||||
|
||||
// Panics and returns an error status to the parent process.
|
||||
void zn_panic(zn_status_t status);
|
||||
|
||||
void zn_log(const char* message);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef ZINNIA_MEM_H
|
||||
#define ZINNIA_MEM_H
|
||||
|
||||
#include <zinnia/handle.h>
|
||||
#include <zinnia/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Virtual memory flags.
|
||||
enum zn_vm_flags {
|
||||
ZN_VM_READ = 1 << 0,
|
||||
ZN_VM_WRITE = 1 << 1,
|
||||
ZN_VM_EXEC = 1 << 2,
|
||||
ZN_VM_SHARED = 1 << 3,
|
||||
};
|
||||
|
||||
enum zn_cache_type {
|
||||
// Generic memory
|
||||
ZN_CACHE_NORMAL,
|
||||
// Write combining
|
||||
ZN_CACHE_WC,
|
||||
// Memory-mapped IO
|
||||
ZN_CACHE_MMIO,
|
||||
};
|
||||
|
||||
// Allocates memory
|
||||
zn_status_t zn_mem_alloc(size_t length, zn_handle_t* out);
|
||||
|
||||
zn_status_t zn_mem_map(zn_handle_t mem, void* addr, size_t len, enum zn_vm_flags flags);
|
||||
|
||||
zn_status_t zn_mem_unmap(zn_handle_t mem, void* addr, size_t len, enum zn_vm_flags flags);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef ZINNIA_RIGHTS_H
|
||||
#define ZINNIA_RIGHTS_H
|
||||
|
||||
typedef enum {
|
||||
// Can be read from.
|
||||
ZN_RIGHT_READ = 1u << 0,
|
||||
// Can be written to.
|
||||
ZN_RIGHT_WRITE = 1u << 1,
|
||||
// Can be executed.
|
||||
ZN_RIGHT_EXECUTE = 1u << 2,
|
||||
// Can be mapped in an address space.
|
||||
ZN_RIGHT_MAP = 1u << 3,
|
||||
// Can be moved to another process.
|
||||
ZN_RIGHT_MOVE = 1u << 4,
|
||||
// Can be cloned.
|
||||
ZN_RIGHT_CLONE = 1u << 5,
|
||||
// Can be deleted.
|
||||
ZN_RIGHT_DELETE = 1u << 6,
|
||||
|
||||
// When cloning, use the same rights as the original.
|
||||
ZN_RIGHTS_IDENTICAL = 1u << 31,
|
||||
ZN_RIGHTS_COMMON = (ZN_RIGHT_MOVE | ZN_RIGHT_CLONE),
|
||||
ZN_RIGHTS_RW = (ZN_RIGHT_READ | ZN_RIGHT_WRITE),
|
||||
} zn_rights_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef ZINNIA_STATUS_H
|
||||
#define ZINNIA_STATUS_H
|
||||
|
||||
// Status values that may be returned by the kernel.
|
||||
// A status value of 0 means everything is okay.
|
||||
// A negative value indicates an error from the kernel.
|
||||
// Positive values are available to user processes.
|
||||
typedef enum {
|
||||
ZN_OK = 0,
|
||||
// An internal error occured.
|
||||
ZN_ERR_INTERNAL = -1,
|
||||
// Syscall number is not a recognized syscall.
|
||||
ZN_ERR_BAD_SYSCALL = -2,
|
||||
// This operation is not supported.
|
||||
ZN_ERR_UNSUPPORTED = -3,
|
||||
// System does not have enough free memory for this operation.
|
||||
ZN_ERR_NO_MEMORY = -4,
|
||||
// Process can not own any more handles.
|
||||
ZN_ERR_NO_HANDLES = -5,
|
||||
// One or more of the provided arguments is not valid.
|
||||
ZN_ERR_BAD_ARG = -6,
|
||||
// Argument is outside of the range for valid values.
|
||||
ZN_ERR_BAD_RANGE = -7,
|
||||
// Object handle does not name a valid object or correct type.
|
||||
ZN_ERR_BAD_OBJECT = -8,
|
||||
// Object has insufficient permissions for this operation.
|
||||
ZN_ERR_BAD_PERMS = -9,
|
||||
// Buffer is not large enough or doesn't point to a valid memory region.
|
||||
ZN_ERR_BAD_BUFFER = -10,
|
||||
} zn_status_t;
|
||||
|
||||
// Returns a string describing the error code.
|
||||
const char* zn_status_to_string(zn_status_t status);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef ZINNIA_SYSCALL_NUMBERS_H
|
||||
#define ZINNIA_SYSCALL_NUMBERS_H
|
||||
|
||||
enum {
|
||||
ZN_SYSCALL_PANIC,
|
||||
|
||||
ZN_SYSCALL_LOG,
|
||||
|
||||
ZN_SYSCALL_ARCHCTL,
|
||||
|
||||
ZN_SYSCALL_HANDLE_VALIDATE,
|
||||
ZN_SYSCALL_HANDLE_DROP,
|
||||
ZN_SYSCALL_HANDLE_CLONE,
|
||||
|
||||
ZN_SYSCALL_MEM_ALLOC,
|
||||
ZN_SYSCALL_MEM_FREE,
|
||||
|
||||
ZN_SYSCALL_CHANNEL_CREATE,
|
||||
ZN_SYSCALL_CHANNEL_OPEN,
|
||||
ZN_SYSCALL_CHANNEL_READ,
|
||||
ZN_SYSCALL_CHANNEL_WRITE,
|
||||
|
||||
ZN_SYSCALL_THREAD_CREATE,
|
||||
ZN_SYSCALL_THREAD_DESTROY,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef ZINNIA_THREAD_H
|
||||
#define ZINNIA_THREAD_H
|
||||
|
||||
#include <zinnia/handle.h>
|
||||
#include <zinnia/status.h>
|
||||
|
||||
enum zn_thread_flags {
|
||||
ZN_THREAD_NONE,
|
||||
};
|
||||
|
||||
// Creates a new thread.
|
||||
zn_status_t zn_thread_create(const char* name, zn_handle_t address_space, enum zn_thread_flags flags);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user