stuff
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <zinnia/handle.h>
|
||||
#include <zinnia/status.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct file;
|
||||
struct inode;
|
||||
struct path;
|
||||
|
||||
// struct file_ops {
|
||||
// zn_status_t (*open)(struct file* self, uint32_t flags);
|
||||
// zn_status_t (*close)(struct file* self);
|
||||
// zn_status_t (*read)(struct file* self, struct iovec_iter* iter, ssize_t* out_read);
|
||||
// zn_status_t (*write)(struct file* self, struct iovec_iter* iter, ssize_t* out_written);
|
||||
// zn_status_t (*devctl)(struct file* self, uint32_t dcmd, void* data, size_t num, int* out_info);
|
||||
// zn_status_t (*poll)(struct file* self, int16_t mask, int16_t* out_mask); // TODO: This is not correct.
|
||||
// zn_status_t (*mmap)(
|
||||
// struct file* self,
|
||||
// zn_handle_t* space,
|
||||
// void* addr,
|
||||
// size_t len,
|
||||
// int prot,
|
||||
// int flags,
|
||||
// off_t offset
|
||||
// );
|
||||
// };
|
||||
|
||||
struct file {
|
||||
const struct file_ops* ops;
|
||||
struct inode* inode;
|
||||
uint32_t mode;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
struct file* file_alloc();
|
||||
struct file* file_from_fd(int fd);
|
||||
|
||||
struct inode_ops {
|
||||
union {
|
||||
struct {
|
||||
zn_status_t (*lookup)(struct inode* inode, struct path* path);
|
||||
} dir;
|
||||
struct {
|
||||
zn_status_t (*truncate)(struct inode* inode);
|
||||
} reg;
|
||||
};
|
||||
};
|
||||
|
||||
struct inode_attr {
|
||||
struct timespec atime, mtime, ctime;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
struct inode {
|
||||
const struct inode_ops* ops;
|
||||
struct inode_attr attr;
|
||||
};
|
||||
|
||||
struct entry {
|
||||
const char* name;
|
||||
struct inode* inode;
|
||||
uint8_t state;
|
||||
};
|
||||
|
||||
struct path {
|
||||
struct entry* entry;
|
||||
struct mount* mount;
|
||||
};
|
||||
|
||||
struct mount {
|
||||
uint32_t flags;
|
||||
struct entry root;
|
||||
struct path mount_point;
|
||||
};
|
||||
|
||||
struct file_system_ops {};
|
||||
|
||||
struct file_system {
|
||||
const char* name;
|
||||
struct file_system_ops ops;
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <zinnia/channel.h>
|
||||
#include <zinnia/handle.h>
|
||||
#include <zinnia/ipc/init.h>
|
||||
#include <zinnia/mem.h>
|
||||
#include <zinnia/status.h>
|
||||
#include <zinnia/system.h>
|
||||
#include <zinnia/thread.h>
|
||||
#include <common/compiler.h>
|
||||
#include <common/utils.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/auxv.h>
|
||||
#include <threads.h>
|
||||
|
||||
thread_local char buf[1024];
|
||||
|
||||
[[__format(printf, 1, 2)]]
|
||||
static void zn_printf(const char* msg, ...) {
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
int32_t len = vsnprintf(buf, sizeof(buf), msg, args);
|
||||
va_end(args);
|
||||
|
||||
zn_log(buf, len);
|
||||
}
|
||||
|
||||
zn_handle_t channel;
|
||||
|
||||
int other_fn(void* arg) {
|
||||
zn_printf("posixd: Hello from the other thread named \"%s\"!\n", (const char*)arg);
|
||||
channel = getauxval(AT_INIT_HANDLE);
|
||||
|
||||
struct ipc_init_register_rq msg = {
|
||||
.id = IPC_MSG_FOO,
|
||||
};
|
||||
char name[] = "posixd";
|
||||
|
||||
zn_status_t status = zn_channel_write(channel, nullptr, &msg, 0, sizeof(msg) + sizeof(name));
|
||||
|
||||
if (status != ZN_OK) {
|
||||
zn_printf("posixd: %s\n", zn_status_to_string(status));
|
||||
}
|
||||
|
||||
return 69;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[], char* envp[]) {
|
||||
zn_printf("posixd: starting...\n");
|
||||
const char* thread_name = "posix_second_thread";
|
||||
|
||||
thrd_t thread;
|
||||
int res = thrd_create(&thread, other_fn, (void*)thread_name);
|
||||
if (res != thrd_success)
|
||||
zn_printf("posixd: errno: %s\n", strerror(errno));
|
||||
zn_printf("posixd: second thread created\n");
|
||||
|
||||
int res2;
|
||||
zn_printf("posixd: waiting on second thread...\n");
|
||||
thrd_join(thread, &res2);
|
||||
zn_printf("posixd: second thread exited with: %i\n", res2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
configure_file(configuration: cfg, output: 'config.h')
|
||||
|
||||
executable(
|
||||
'posixd',
|
||||
'main.c',
|
||||
'uname.c',
|
||||
link_args: '-static',
|
||||
include_directories: [common_includes, 'include'],
|
||||
install: true,
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <config.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
static struct utsname uname_buf = {
|
||||
.sysname = "Zinnia",
|
||||
.release = ZINNIA_VERSION,
|
||||
.version = ZINNIA_COMPILER_ID " " ZINNIA_LINKER_ID,
|
||||
.nodename = "localhost",
|
||||
.machine = ZINNIA_ARCH,
|
||||
};
|
||||
Reference in New Issue
Block a user