LibC: add needed stubs to build executables with our compiler

This commit is contained in:
Bananymous 2023-04-12 17:53:02 +03:00
parent 8637959289
commit fe87c08a02
8 changed files with 57 additions and 6 deletions

View File

@ -9,7 +9,7 @@ _start:
movl %esp, %ebp movl %esp, %ebp
# Prepare signals, memory allocation, stdio and such. # Prepare signals, memory allocation, stdio and such.
call initialize_standard_library #call initialize_standard_library
# Run the global constructors. # Run the global constructors.
call _init call _init

View File

@ -13,7 +13,7 @@ _start:
pushq %rdi pushq %rdi
# Prepare signals, memory allocation, stdio and such. # Prepare signals, memory allocation, stdio and such.
call initialize_standard_library #call initialize_standard_library
# Run the global constructors. # Run the global constructors.
call _init call _init

View File

@ -15,6 +15,9 @@
#define SEEK_END 1 #define SEEK_END 1
#define SEEK_SET 2 #define SEEK_SET 2
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
__BEGIN_DECLS __BEGIN_DECLS
struct FILE; struct FILE;

View File

@ -6,6 +6,7 @@
__BEGIN_DECLS __BEGIN_DECLS
[[noreturn]] void abort(void); [[noreturn]] void abort(void);
[[noreturn]] void exit(int);
int abs(int); int abs(int);

View File

@ -0,0 +1,3 @@
#pragma once
#include <kernel/Syscall.h>

View File

@ -6,16 +6,17 @@
#define STDOUT_FILENO 1 #define STDOUT_FILENO 1
#define STDERR_FILENO 2 #define STDERR_FILENO 2
// fork(), execv(), execve(), execvp(), getpid()
__BEGIN_DECLS __BEGIN_DECLS
[[noreturn]] void _exit(int);
pid_t fork(void); pid_t fork(void);
pid_t getpid(void);
int execv(const char*, char* const[]); int execv(const char*, char* const[]);
int execve(const char*, char* const[], char* const[]); int execve(const char*, char* const[], char* const[]);
int execvp(const char*, char* const[]); int execvp(const char*, char* const[]);
pid_t getpid(void); long syscall(long, ...);
__END_DECLS __END_DECLS

View File

@ -1,10 +1,18 @@
#include <BAN/Assert.h>
#include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <unistd.h>
void abort(void) void abort(void)
{ {
ASSERT_NOT_REACHED();
}
void exit(int status)
{
_exit(status);
ASSERT_NOT_REACHED();
} }
int abs(int val) int abs(int val)

View File

@ -1,5 +1,40 @@
#include <BAN/Assert.h>
#include <stdarg.h>
#include <stddef.h>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
void _exit(int status)
{
syscall(SYS_EXIT, status);
ASSERT_NOT_REACHED();
}
long syscall(long syscall, ...)
{
va_list args;
va_start(args, syscall);
long ret = 0;
switch (syscall)
{
case SYS_EXIT:
ret = Kernel::syscall(SYS_EXIT, va_arg(args, int));
break;
case SYS_READ:
ret = Kernel::syscall(SYS_READ, va_arg(args, int), va_arg(args, void*), va_arg(args, size_t));
break;
case SYS_WRITE:
ret = Kernel::syscall(SYS_WRITE, va_arg(args, int), va_arg(args, const void*), va_arg(args, size_t));
break;
}
va_end(args);
return ret;
}
pid_t fork(void) pid_t fork(void)
{ {
return -1; return -1;