-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CM: Pre-checks added before process syscalls
Library functions must validate user input before making a system call. Kernel functions assumes valid input from user. Also includes: * New system call to get OS errors * Process functions moved to cm/process.c & cm.h * New functions to set library mode errors.
- Loading branch information
1 parent
4fad7ae
commit 7c7c01c
Showing
9 changed files
with
144 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* --------------------------------------------------------------------------- | ||
* Megha Operating System V2 - C MOS App library - Library errors | ||
* --------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include <stdint.h> | ||
#ifdef KERNEL | ||
#include <cm/debug.h> | ||
#include <cm/syscall.h> | ||
#include <cm/osif.h> | ||
#else | ||
#include <debug.h> | ||
#include <syscall.h> | ||
#include <osif.h> | ||
#endif | ||
|
||
#define CM_FAILURE (-1) | ||
|
||
typedef enum CMErrors { | ||
// OS Errors start from 0 and must end before the start of library errors | ||
LIBRARY_ERRORS_START = 100, | ||
CM_ERR_INVALID_INPUT = 100, | ||
} CMErrors; | ||
|
||
extern uint32_t cm_error_num__; | ||
|
||
static inline uint32_t cm_get_lib_error() | ||
{ | ||
return cm_error_num__; | ||
} | ||
|
||
static inline uint32_t cm_get_os_error() | ||
{ | ||
return (uint32_t)syscall (OSIF_SYSCALL_GET_OS_ERROR, 0, 0, 0, 0, 0); | ||
} | ||
|
||
/* Can be used to store an error code and return from a function */ | ||
#define CM_RETURN_ERROR__(errno, rval) \ | ||
do { \ | ||
ERROR ("Error %x.", errno); \ | ||
cm_error_num__ = errno; \ | ||
return rval; \ | ||
} while (0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------- | ||
* Megha Operating System V2 - C MOS App Library - Process management | ||
* ------------------------------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include <process.h> | ||
#include <cm/syscall.h> | ||
#include <cm/err.h> | ||
|
||
INT cm_process_create (void* startLocation, SIZE binaryLengthBytes, bool isKernelMode) | ||
{ | ||
if (!startLocation || binaryLengthBytes == 0) { | ||
CM_RETURN_ERROR__ (CM_ERR_INVALID_INPUT, CM_FAILURE); | ||
} | ||
|
||
KProcessFlags flags = PROCESS_FLAGS_NONE; | ||
if (isKernelMode) { | ||
flags |= PROCESS_FLAGS_KERNEL_PROCESS; | ||
} | ||
|
||
INT pid = syscall (OSIF_SYSCALL_CREATE_PROCESS, (U32)startLocation, binaryLengthBytes, | ||
(U32)flags, 0, 0); | ||
if (pid < 0) { | ||
CM_RETURN_ERROR__ (cm_get_os_error(), CM_FAILURE); | ||
} | ||
return pid; | ||
} | ||
|
||
INT cm_thread_create (void (*startLocation)(), bool isKernelMode) | ||
{ | ||
if (!startLocation) { | ||
CM_RETURN_ERROR__ (CM_ERR_INVALID_INPUT, CM_FAILURE); | ||
} | ||
|
||
KProcessFlags flags = PROCESS_FLAGS_THREAD; | ||
if (isKernelMode) { | ||
flags |= PROCESS_FLAGS_KERNEL_PROCESS; | ||
} | ||
|
||
INT pid = syscall (OSIF_SYSCALL_CREATE_PROCESS, (U32)startLocation, 0, (U32)flags, 0, 0); | ||
if (pid < 0) { | ||
CM_RETURN_ERROR__ (cm_get_os_error(), CM_FAILURE); | ||
} | ||
return pid; | ||
} | ||
|
||
bool cm_process_is_yield_requested() | ||
{ | ||
volatile OSIF_ProcessEvent e = { 0 }; | ||
cm_process_pop_event ((OSIF_ProcessEvent*)&e); | ||
return (e.event == OSIF_PROCESS_EVENT_PROCCESS_YIELD_REQ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters