Compare commits
No commits in common. "7a2e313a2070e314b8bfe5e50c138e4c2b142bf0" and "531afc3d6f6a2432bc1b04d281c8aa8186d8c476" have entirely different histories.
7a2e313a20
...
531afc3d6f
@ -1,4 +1,4 @@
|
|||||||
APPS := init sym
|
APPS := init
|
||||||
|
|
||||||
APPS_DIR := $(LUNA_ROOT)/apps
|
APPS_DIR := $(LUNA_ROOT)/apps
|
||||||
APPS_SRC := $(APPS_DIR)/src
|
APPS_SRC := $(APPS_DIR)/src
|
||||||
|
@ -117,17 +117,7 @@ int main()
|
|||||||
|
|
||||||
if (fclose(config) < 0) { perror("fclose"); }
|
if (fclose(config) < 0) { perror("fclose"); }
|
||||||
|
|
||||||
sleep(2);
|
printf("\n\nPress any key to restart.\n");
|
||||||
|
|
||||||
printf("\n\nPress any key to restart.\n\n");
|
|
||||||
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
if (execv("/bin/sym", NULL) < 0)
|
|
||||||
{
|
|
||||||
perror("execv");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
FILE* syms = fopen("/sys/moon.sym", "r");
|
|
||||||
if (!syms)
|
|
||||||
{
|
|
||||||
perror("fopen");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[1025];
|
|
||||||
|
|
||||||
if (fseek(syms, 8000, SEEK_SET) < 0)
|
|
||||||
{
|
|
||||||
perror("fseek");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t nread = fread(buf, 1024, 1, syms);
|
|
||||||
if (ferror(syms))
|
|
||||||
{
|
|
||||||
perror("fread");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf[nread] = 0;
|
|
||||||
|
|
||||||
printf("%s\n", strchr(buf, '\n') + 1);
|
|
||||||
|
|
||||||
fclose(syms);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -17,5 +17,3 @@ void* memcpy(void* dest, const void* src, size_t n);
|
|||||||
void* memset(void* dest, int c, size_t n);
|
void* memset(void* dest, int c, size_t n);
|
||||||
int memcmp(const void* a, const void* b, size_t n);
|
int memcmp(const void* a, const void* b, size_t n);
|
||||||
void* memmove(void* dest, void* src, size_t n);
|
void* memmove(void* dest, void* src, size_t n);
|
||||||
|
|
||||||
char* strdup(const char* src);
|
|
@ -1,5 +1,4 @@
|
|||||||
#include "std/string.h"
|
#include <string.h>
|
||||||
#include "std/stdlib.h"
|
|
||||||
|
|
||||||
size_t strlen(const char* __s)
|
size_t strlen(const char* __s)
|
||||||
{
|
{
|
||||||
@ -123,11 +122,3 @@ void* memmove(void* dest, void* src, size_t n)
|
|||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* strdup(const char* src)
|
|
||||||
{
|
|
||||||
size_t length = strlen(src);
|
|
||||||
char* duplicated = (char*)kmalloc(length + 1);
|
|
||||||
memcpy(duplicated, src, length + 1);
|
|
||||||
return duplicated;
|
|
||||||
}
|
|
@ -4,8 +4,6 @@
|
|||||||
#include "errno.h"
|
#include "errno.h"
|
||||||
#include "interrupts/Interrupts.h"
|
#include "interrupts/Interrupts.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include "std/stdlib.h"
|
|
||||||
#include "std/string.h"
|
|
||||||
#include "sys/elf/ELFLoader.h"
|
#include "sys/elf/ELFLoader.h"
|
||||||
#include "thread/Scheduler.h"
|
#include "thread/Scheduler.h"
|
||||||
|
|
||||||
@ -33,28 +31,22 @@ void sys_exec(Context* context, const char* pathname)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* kpathname = strdup(
|
// FIXME: This should be done later, but since there is a very high chance that loading the executed program's ELF
|
||||||
pathname); // Since we are going to free the original task's memory, we cannot use anything coming from it.
|
// image will overwrite ours, we have to do it here.
|
||||||
|
|
||||||
// FIXME: This should be done later, but since there is a very high chance that loading the executed program's
|
|
||||||
// ELF image will overwrite ours, we have to do it here.
|
|
||||||
ELFLoader::release_elf_image(Scheduler::current_task()->image);
|
ELFLoader::release_elf_image(Scheduler::current_task()->image);
|
||||||
|
|
||||||
// FIXME: Check the ELF image is valid before loading it into memory. This will allow us to first check, then free
|
// FIXME: Check the ELF image is valid before loading it into memory. This will allow us to first check, then free
|
||||||
// the previous image, then load, which should reduce the chances of loading failing to almost zero.
|
// the previous image, then load, which should reduce the chances of loading failing to almost zero.
|
||||||
ELFImage* image = ELFLoader::load_elf_from_filesystem(kpathname);
|
ELFImage* image = ELFLoader::load_elf_from_filesystem(pathname);
|
||||||
if (!image)
|
if (!image)
|
||||||
{
|
{
|
||||||
MemoryManager::release_pages((void*)allocated_stack, TASK_PAGES_IN_STACK);
|
MemoryManager::release_pages((void*)allocated_stack, TASK_PAGES_IN_STACK);
|
||||||
Scheduler::current_task()->image = nullptr;
|
Scheduler::current_task()->image = nullptr;
|
||||||
kfree(kpathname);
|
kwarnln("exec(): ERROR: Failed to load program. Previous program has already been freed, thus cannot "
|
||||||
kerrorln("exec(): ERROR: Failed to load program. Previous program has already been freed, thus cannot "
|
"return to it.");
|
||||||
"return to it.");
|
|
||||||
return Scheduler::task_exit(context, -255);
|
return Scheduler::task_exit(context, -255);
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(kpathname);
|
|
||||||
|
|
||||||
Interrupts::disable();
|
Interrupts::disable();
|
||||||
ASSERT(!Interrupts::are_enabled()); // This part is pretty sensitive.
|
ASSERT(!Interrupts::are_enabled()); // This part is pretty sensitive.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user