Fix semop return type. Do some minor style-based fixes.

This commit is contained in:
Enrico Fraccaroli (Galfurian)
2023-06-02 13:49:10 -04:00
parent 116f4a50f7
commit 8891ed7d7a
14 changed files with 73 additions and 69 deletions
+1
View File
@@ -148,6 +148,7 @@ set(KERNEL_SOURCES
${PROJECT_SOURCE_DIR}/src/klib/math.c
${PROJECT_SOURCE_DIR}/src/klib/fcvt.c
${PROJECT_SOURCE_DIR}/src/klib/spinlock.c
${PROJECT_SOURCE_DIR}/src/klib/stdlib.c
${PROJECT_SOURCE_DIR}/src/klib/rbtree.c
${PROJECT_SOURCE_DIR}/src/klib/ndtree.c
${PROJECT_SOURCE_DIR}/src/klib/hashmap.c
+1 -1
View File
@@ -74,4 +74,4 @@ struct ipc_perm register_ipc(key_t key, mode_t mode)
ip.mode = mode;
ip.__seq = 0;
return ip;
}
}
+3 -21
View File
@@ -67,25 +67,6 @@ typedef struct {
/// @brief List of all current active semaphores.
list_head semaphores_list;
// ============================================================================
// KEY GENERATION (Private)
// ============================================================================
/// Seed used to generate random numbers.
static int ipc_sem_rseed = 0;
/// The maximum value returned by the rand function.
#define IPC_SEM_RAND_MAX ((1U << 31U) - 1U)
static inline void ipc_sem_srand(int x)
{
ipc_sem_rseed = x;
}
static inline int ipc_sem_rand()
{
return ipc_sem_rseed = (ipc_sem_rseed * 1103515245U + 12345U) & IPC_SEM_RAND_MAX;
}
// ============================================================================
// MEMORY MANAGEMENT (Private)
// ============================================================================
@@ -213,7 +194,7 @@ long sys_semget(key_t key, int nsems, int semflg)
if (key == IPC_PRIVATE) {
// Exit when i find a unique key.
do {
key = -ipc_sem_rand();
key = -rand();
} while (__list_find_sem_info_by_key(key));
// We have a unique key, create the semaphore set.
sem_info = __sem_info_alloc(key, nsems, semflg);
@@ -516,7 +497,8 @@ ssize_t procipc_sem_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyte
pr_err("Received a NULL file.\n");
return -ENOENT;
}
size_t buffer_len = 0, read_pos = 0, write_count = 0, ret = 0;
size_t buffer_len = 0, read_pos = 0, ret = 0;
ssize_t write_count = 0;
sem_info_t *sem_info = NULL;
char buffer[BUFSIZ];
+19
View File
@@ -0,0 +1,19 @@
/// @file stdlib.c
/// @brief
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "stdlib.h"
/// Seed used to generate random numbers.
static int rseed = 0;
void srand(int x)
{
rseed = x;
}
int rand()
{
return rseed = (rseed * 1103515245U + 12345U) & RAND_MAX;
}
+12 -11
View File
@@ -95,6 +95,7 @@ task_struct *scheduler_get_running_process(pid_t pid)
void scheduler_enqueue_task(task_struct *process)
{
assert(process && "Received a NULL process.");
// If current_process is NULL, then process is the current process.
if (runqueue.curr == NULL) {
runqueue.curr = process;
@@ -109,6 +110,7 @@ void scheduler_enqueue_task(task_struct *process)
void scheduler_dequeue_task(task_struct *process)
{
assert(process && "Received a NULL process.");
scheduler_feedback_task_remove(process->pid);
// Delete the process from the list of running processes.
list_head_remove(&process->run_list);
@@ -208,7 +210,7 @@ void scheduler_enter_user_jmp(uintptr_t location, uintptr_t stack)
/// @param mode The type of wait (TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE).
/// @param sync Specifies if the wakeup should be synchronous.
/// @return 1 on success, 0 on failure.
static inline int try_to_wake_up(task_struct *process, int mode, int sync)
static inline int try_to_wake_up(task_struct *process, unsigned mode, int sync)
{
// Only tasks in the state TASK_UNINTERRUPTIBLE can be woke up
if (process->state == TASK_UNINTERRUPTIBLE || process->state == TASK_STOPPED) {
@@ -229,27 +231,26 @@ wait_queue_entry_t *sleep_on(wait_queue_head_t *wq)
{
// Save the sleeping process registers state
task_struct *sleeping_task = scheduler_get_current_process();
// Stops task from runqueue making it unrunnable.
sleeping_task->state = TASK_UNINTERRUPTIBLE;
#if 0
pt_regs* f = get_current_interrupt_stack_frame();
// Get the interrupt registers.
pt_regs *f = get_current_interrupt_stack_frame();
// Store its context.
scheduler_store_context(f, sleeping_task);
// Select next process in the runqueue as the current, restore it's context,
// we assume that the first process is init wich does not sleep (I hope).
// This is necessary to make the scheduler_run() in syscall_handler work.
task_struct *next = list_entry(runqueue.queue.next, task_struct, run_list);
task_struct *next = scheduler_pick_next_task(&runqueue);
assert((next != sleeping_task) && "The next selected process in the runqueue is the sleeping process");
scheduler_restore_context(next, f);
#endif
// Stops task from runqueue making it unrunnable
sleeping_task->state = TASK_UNINTERRUPTIBLE;
// Add sleeping process to sleep wait queue
// Allocate the wait_queue entry.
wait_queue_entry_t *wait_entry = kmalloc(sizeof(struct wait_queue_entry_t));
// Initialize the entry.
init_waitqueue_entry(wait_entry, sleeping_task);
// Add sleeping process to sleep wait queue.
add_wait_queue(wq, wait_entry);
return wait_entry;
}