libc: Add support for fork()
That doesn't mean it works. Why doesn't it work?? Oh well...
This commit is contained in:
parent
20cffdb66c
commit
e672f3994b
@ -141,9 +141,13 @@ int main()
|
|||||||
|
|
||||||
fclose(new_stderr);
|
fclose(new_stderr);
|
||||||
|
|
||||||
execv("/bin/sym", NULL);
|
pid_t child = fork();
|
||||||
|
if (child == 0)
|
||||||
|
{
|
||||||
|
msleep(500);
|
||||||
|
printf("I am the child, who is my parent?\n");
|
||||||
|
}
|
||||||
|
else { printf("My child is %ld!", child); }
|
||||||
|
|
||||||
perror("execv"); // If we're here, execv failed
|
return 0;
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "trace/StackTracer.h"
|
#include "trace/StackTracer.h"
|
||||||
#include "memory/Memory.h"
|
#include "memory/Memory.h"
|
||||||
|
#include "memory/VMM.h"
|
||||||
#include "std/stdio.h"
|
#include "std/stdio.h"
|
||||||
#include "trace/Resolve.h"
|
#include "trace/Resolve.h"
|
||||||
|
|
||||||
@ -20,6 +21,11 @@ typedef struct stackframe
|
|||||||
|
|
||||||
void StackTracer::trace()
|
void StackTracer::trace()
|
||||||
{
|
{
|
||||||
|
if (!VMM::is_using_kernel_address_space())
|
||||||
|
{
|
||||||
|
VMM::switch_back_to_kernel_address_space();
|
||||||
|
VMM::apply_address_space();
|
||||||
|
}
|
||||||
stackframe* frame = (stackframe*)m_base_pointer;
|
stackframe* frame = (stackframe*)m_base_pointer;
|
||||||
while (frame && frame->instruction)
|
while (frame && frame->instruction)
|
||||||
{
|
{
|
||||||
@ -27,6 +33,7 @@ void StackTracer::trace()
|
|||||||
get_symbol_name(frame->instruction, symbol_name, sizeof(symbol_name));
|
get_symbol_name(frame->instruction, symbol_name, sizeof(symbol_name));
|
||||||
printf("%lx: %s\n", frame->instruction, symbol_name);
|
printf("%lx: %s\n", frame->instruction, symbol_name);
|
||||||
frame = frame->next;
|
frame = frame->next;
|
||||||
|
if (VMM::get_physical((uint64_t)frame) == (uint64_t)-1) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define SYS_fcntl 13
|
#define SYS_fcntl 13
|
||||||
#define SYS_mprotect 14
|
#define SYS_mprotect 14
|
||||||
#define SYS_clock 15
|
#define SYS_clock 15
|
||||||
|
#define SYS_fork 16
|
||||||
|
|
||||||
#ifndef __want_syscalls
|
#ifndef __want_syscalls
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -22,7 +22,8 @@ extern "C"
|
|||||||
int execve(const char*, char* const[], char* const[]);
|
int execve(const char*, char* const[], char* const[]);
|
||||||
/* Not implemented. */
|
/* Not implemented. */
|
||||||
int execvp(const char*, char* const[]);
|
int execvp(const char*, char* const[]);
|
||||||
/* Not implemented. */
|
|
||||||
|
/* Creates an identical copy of the current process and returns its process ID. */
|
||||||
pid_t fork(void);
|
pid_t fork(void);
|
||||||
|
|
||||||
/* Terminates the program with the status code status. */
|
/* Terminates the program with the status code status. */
|
||||||
|
@ -19,9 +19,10 @@ extern "C"
|
|||||||
{
|
{
|
||||||
NOT_IMPLEMENTED("execvp");
|
NOT_IMPLEMENTED("execvp");
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t fork(void)
|
pid_t fork(void)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED("fork");
|
return syscall(SYS_fork);
|
||||||
}
|
}
|
||||||
|
|
||||||
long syscall(long number, ...)
|
long syscall(long number, ...)
|
||||||
@ -34,6 +35,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
case SYS_clock:
|
case SYS_clock:
|
||||||
case SYS_yield:
|
case SYS_yield:
|
||||||
|
case SYS_fork:
|
||||||
case SYS_gettid: result = __luna_syscall0(number); break;
|
case SYS_gettid: result = __luna_syscall0(number); break;
|
||||||
case SYS_exit:
|
case SYS_exit:
|
||||||
case SYS_close:
|
case SYS_close:
|
||||||
|
Loading…
Reference in New Issue
Block a user