matos/userspace/main_user.c
2022-09-03 22:43:41 +02:00

78 lines
1.9 KiB
C

#include "libc.h"
int func_yolo()
{
yolo();
return 0;
}
int func_help()
{
printf("\nAvailable Commands:\n");
printf(" yolo\n");
printf(" suicide\n");
printf(" help\n");
printf(" syscall5\n");
printf(" alloc\n");
return 0;
}
int func_suicide()
{
printf("User is about to suicide\n");
int *yolo = 0;
*yolo = 1;
return 0;
}
void * initialHeap = 0;
int func_alloc(){
if(initialHeap == 0){
initialHeap = brk(0);
}
void * currentHeap = brk(0);
if (currentHeap - initialHeap < 4096){
brk(initialHeap + 4096);
}
int * allocatedData = (int *)initialHeap;
for(unsigned int i = 0 ; i < 4096/sizeof(int); i++){
allocatedData[i] =i;
}
return 0;
}
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
char buf[64];
printf("Shell starting... type \"help\" for help\n");
while (1) {
printf(">");
if (readline(buf, sizeof(buf)))
continue;
if (strcmp(buf, "yolo") == 0) {
func_yolo();
continue;
}
if (strcmp(buf, "help") == 0) {
func_help();
continue;
}
if (strcmp(buf, "suicide") == 0) {
func_suicide();
continue;
}
if (strcmp(buf, "syscall5") == 0) {
testSycall5(1, 2, 3, 4, 5);
continue;
}
if (strcmp(buf, "alloc") == 0) {
func_alloc();
continue;
}
}
return 0;
}