TSysCall
#include <lib/debug.h>
#include <lib/pmap.h>
#include <lib/types.h>
#include <lib/x86.h>
#include <lib/trap.h>
#include <lib/syscall.h>
#include "import.h"<lib/debug.h>: Provides debugging macros likeKERN_INFOfor logging kernel information.<lib/pmap.h>: Includes page management and memory mapping utilities.<lib/types.h>: Defines standard types likeuint8_t,unsigned int, etc.<lib/x86.h>: Contains architecture-specific macros and utilities for x86.<lib/trap.h>: Defines structures and utilities for trap handling.<lib/syscall.h>: Declares syscall numbers and related utilities."import.h": Includes project-specific imports like kernel constants and utilities.
sys_puts
sys_putsPurpose
Prints a string from user space to the kernel log. This is invoked by the user-level printf as a system call.
Code Analysis
get_curid(): Fetches the current process ID.syscall_get_arg2()andsyscall_get_arg3(): Retrieve string address and length passed by the user process.
Validates if the string lies within the allowed user virtual address space.
E_INVAL_ADDR: Error code for invalid address.
Purpose: Copies the string from user space in chunks of
PAGESIZEtosys_buf, ensuring safe access.Logging: Uses
KERN_INFOto print the string.Error Handling: Returns
E_MEMif memory copy fails.
sys_spawn
sys_spawnPurpose
Creates a new child process using a predefined ELF binary in memory. Statically loads the binary and allocates resources.
Code Analysis
syscall_get_arg2()andsyscall_get_arg3(): Fetch ELF identifier and quota.
Ensures valid ELF ID (
1-3). ReturnsE_INVAL_PIDfor invalid IDs.
Maps
elf_idto predefined ELF binaries.
proc_create(): Creates a new process with the ELF binary.Error Handling: Returns
E_MEMif process creation fails.Use Case: Spawn predefined processes for specific user-level functionality.
sys_yield
sys_yieldPurpose
Allows a process to voluntarily yield the CPU to another process.
Code Analysis
thread_yield(): Forces the current thread to yield CPU control.Error Handling: Always succeeds (
E_SUCC).
sys_fork
sys_forkPurpose
Creates a new child process by duplicating the address space of the current process. Uses a predefined ELF binary for the test.
Code Analysis
proc_create(): Spawns a new process with the predefined ELF binary forfork_test.
Returns the child process ID on success or
NUM_IDSwith an error code (E_MEM) on failure.
Summary of Use Cases
sys_puts: Enables user processes to log messages.sys_spawn: Creates predefined child processes for applications likeping,pong, ording.sys_yield: Facilitates cooperative multitasking.sys_fork: Implements process duplication for testing and multitasking.
Each function ensures robust error handling and complies with syscall conventions in mCertiKOS. If you need more specific details or formatting, let me know!
Last updated