Valid 3 code version
This commit is contained in:
@@ -34,7 +34,7 @@ Modification:
|
||||
|
||||
struct MemUsage {
|
||||
TraceTag tag;
|
||||
RbtNode* mem_block_root;
|
||||
RbtTree mem_block_map;
|
||||
};
|
||||
|
||||
bool module_phymem_init();
|
||||
@@ -47,6 +47,8 @@ bool kfree_by_ownership(TraceTag owner, void* vaddr);
|
||||
|
||||
char* raw_alloc(size_t size);
|
||||
bool raw_free(char* paddr);
|
||||
void* raw_alloc_by_ownership(TraceTag owner, uintptr_t size);
|
||||
bool raw_free_by_ownership(TraceTag owner, void* vaddr);
|
||||
|
||||
void show_phymem_info();
|
||||
|
||||
|
||||
@@ -23,6 +23,14 @@
|
||||
|
||||
#include "list.h"
|
||||
#include "object_allocator.h"
|
||||
#include "rbtree.h"
|
||||
|
||||
typedef uintptr_t sem_id_t;
|
||||
typedef int32_t sem_val_t;
|
||||
|
||||
enum {
|
||||
INVALID_SEM_ID = 0,
|
||||
};
|
||||
|
||||
/// @warning this is no in use
|
||||
enum {
|
||||
@@ -30,8 +38,8 @@ enum {
|
||||
};
|
||||
|
||||
struct ksemaphore {
|
||||
uint32_t id;
|
||||
int val;
|
||||
sem_id_t id;
|
||||
sem_val_t val;
|
||||
/* list of waiting threads */
|
||||
struct double_list_node wait_list_guard;
|
||||
/* list to manage semaphores */
|
||||
@@ -40,12 +48,17 @@ struct ksemaphore {
|
||||
};
|
||||
|
||||
struct XiziSemaphorePool {
|
||||
uint32_t next_sem_id;
|
||||
sem_id_t next_sem_id;
|
||||
struct slab_allocator allocator;
|
||||
struct double_list_node sem_list_guard;
|
||||
RbtTree sem_pool_map;
|
||||
sem_val_t nr_sem;
|
||||
};
|
||||
|
||||
void semaphore_pool_init(struct XiziSemaphorePool* sem_pool);
|
||||
int ksemaphore_alloc(struct XiziSemaphorePool* sem_pool, int val);
|
||||
bool ksemaphore_free(struct XiziSemaphorePool* sem_pool, uint32_t sem_id);
|
||||
bool ksemaphore_signal(struct XiziSemaphorePool* sem_pool, uint32_t sem_id);
|
||||
sem_id_t ksemaphore_alloc(struct XiziSemaphorePool* sem_pool, sem_val_t val);
|
||||
bool ksemaphore_free(struct XiziSemaphorePool* sem_pool, sem_id_t sem_id);
|
||||
bool ksemaphore_signal(struct XiziSemaphorePool* sem_pool, sem_id_t sem_id);
|
||||
bool ksemaphore_signal_no_wake(struct XiziSemaphorePool* sem_pool, sem_id_t sem_id);
|
||||
|
||||
bool ksemaphore_consume(struct XiziSemaphorePool* sem_pool, sem_id_t sem_id, sem_val_t decre);
|
||||
|
||||
@@ -50,7 +50,8 @@ struct MemSpace {
|
||||
/* trace node */
|
||||
TraceTag tag;
|
||||
/* mem usage info */
|
||||
struct MemUsage mem_usage;
|
||||
struct MemUsage kernspace_mem_usage;
|
||||
struct MemUsage userspace_mem_usage;
|
||||
|
||||
/* task memory resources */
|
||||
struct TopLevelPageDirectory pgdir; // [phy] vm pgtbl base address
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct QueueNode {
|
||||
uintptr_t key;
|
||||
void* data;
|
||||
struct QueueNode* next;
|
||||
} QueueNode;
|
||||
|
||||
typedef struct Queue {
|
||||
QueueNode* front;
|
||||
QueueNode* rear;
|
||||
int nr_ele;
|
||||
} Queue;
|
||||
|
||||
void queue_init(Queue* queue);
|
||||
QueueNode* queue_front(Queue* queue);
|
||||
bool queue_is_empty(Queue* queue);
|
||||
void dequeue(Queue* queue);
|
||||
void enqueue(Queue* queue, uintptr_t key, void* data);
|
||||
|
||||
void module_queue_factory_init(TraceTag* _softkernel_tag);
|
||||
@@ -21,11 +21,13 @@ typedef struct RbtNode {
|
||||
enum rbt_type color;
|
||||
} RbtNode;
|
||||
|
||||
struct RbtNode* rbt_insert(struct RbtNode* T, uintptr_t key, void* data);
|
||||
struct RbtNode* rbt_delete(struct RbtNode* T, struct RbtNode* z);
|
||||
struct RbtNode* rbt_search(struct RbtNode* root, int x);
|
||||
typedef struct RbtTree {
|
||||
RbtNode* root;
|
||||
} RbtTree;
|
||||
|
||||
void preorder(struct RbtNode* root);
|
||||
void levelorder(struct RbtNode* root);
|
||||
void rbtree_init(RbtTree* tree);
|
||||
int rbt_insert(RbtTree* tree, uintptr_t key, void* data);
|
||||
RbtNode* rbt_search(RbtTree* tree, uintptr_t key);
|
||||
int rbt_delete(RbtTree* tree, uintptr_t key);
|
||||
|
||||
void module_rbt_factory_init(TraceTag* _softkernel_tag);
|
||||
@@ -32,12 +32,13 @@ Modification:
|
||||
#include <stdint.h>
|
||||
|
||||
#include "actracer.h"
|
||||
#include "ksemaphore.h"
|
||||
#include "list.h"
|
||||
#include "task.h"
|
||||
|
||||
/// @brief userland session info copy
|
||||
struct Session {
|
||||
int id;
|
||||
uintptr_t id;
|
||||
int capacity;
|
||||
int head;
|
||||
int tail;
|
||||
@@ -48,7 +49,7 @@ struct Session {
|
||||
#define CLIENT_SESSION_BACKEND(session) CONTAINER_OF(session, struct session_backend, client_side)
|
||||
|
||||
struct server_session {
|
||||
struct double_list_node node; // list_head of server task's ipc pipes
|
||||
struct double_list_node node; // list node of server task's ipc pipes
|
||||
uintptr_t buf_addr;
|
||||
int capacity;
|
||||
int head;
|
||||
@@ -57,7 +58,7 @@ struct server_session {
|
||||
};
|
||||
|
||||
struct client_session {
|
||||
struct double_list_node node; // list_head of client task's ipc pipes
|
||||
struct double_list_node node; // list node of client task's ipc pipes
|
||||
uintptr_t buf_addr;
|
||||
int capacity;
|
||||
bool closed;
|
||||
@@ -72,6 +73,7 @@ struct session_backend {
|
||||
struct Thread* client; // client of this pipe
|
||||
struct Thread* server; // server of this pipe
|
||||
|
||||
sem_id_t client_sem_to_wait;
|
||||
uintptr_t buf_kernel_addr;
|
||||
};
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ Modification:
|
||||
|
||||
#define SYSCALL_SEMAPHORE 13 // semaphore related operations
|
||||
#define SYSCALL_SLEEP 14 // sleep
|
||||
|
||||
#define SYSCALL_WAIT_SESSION 15
|
||||
// clang-format on
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
@@ -105,6 +107,7 @@ int sys_register_as_server(char* name);
|
||||
int sys_connect_session(char* path, int capacity, struct Session* user_session);
|
||||
int sys_poll_session(struct Session* userland_session_arr, int arr_capacity);
|
||||
int sys_close_session(struct Thread* task, struct Session* session);
|
||||
int sys_wait_session(struct Session* userland_session);
|
||||
|
||||
int sys_exec(char* img_start, char* name, char** argv);
|
||||
int sys_state(sys_state_option option, sys_state_info* info);
|
||||
|
||||
@@ -37,6 +37,7 @@ Modification:
|
||||
#include "memspace.h"
|
||||
#include "object_allocator.h"
|
||||
#include "pagetable.h"
|
||||
#include "queue.h"
|
||||
#include "share_page.h"
|
||||
#include "spinlock.h"
|
||||
|
||||
@@ -98,6 +99,10 @@ struct Thread {
|
||||
/* task communication resources */
|
||||
struct double_list_node cli_sess_listhead;
|
||||
struct double_list_node svr_sess_listhead;
|
||||
RbtTree cli_sess_map;
|
||||
RbtTree svr_sess_map;
|
||||
Queue sessions_to_be_handle;
|
||||
Queue sessions_in_handle;
|
||||
struct TraceTag server_identifier;
|
||||
bool advance_unblock;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user