mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00:00
Canonicalize the path used by sh.
With a bunch of LibC work to support the feature. LibC now initializes AK::StringImpl by default. It's now fine to use AK in LibC/Userland! :^)
This commit is contained in:
parent
88ad59bfb1
commit
e904f193c1
15 changed files with 170 additions and 24 deletions
|
@ -1,4 +1,11 @@
|
|||
OBJS = \
|
||||
AK_OBJS = \
|
||||
../AK/StringImpl.o \
|
||||
../AK/String.o \
|
||||
../AK/StringBuilder.o \
|
||||
../AK/FileSystemPath.o \
|
||||
../AK/kmalloc.o
|
||||
|
||||
LIBC_OBJS = \
|
||||
stdio.o \
|
||||
unistd.o \
|
||||
string.o \
|
||||
|
@ -8,8 +15,11 @@ OBJS = \
|
|||
stdlib.o \
|
||||
time.o \
|
||||
utsname.o \
|
||||
assert.o \
|
||||
entry.o
|
||||
|
||||
OBJS = $(AK_OBJS) $(LIBC_OBJS)
|
||||
|
||||
LIBRARY = LibC.a
|
||||
ARCH_FLAGS =
|
||||
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
|
||||
|
@ -19,7 +29,7 @@ FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions
|
|||
OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables
|
||||
INCLUDE_FLAGS = -I.. -I.
|
||||
|
||||
DEFINES = -DSERENITY -DSANITIZE_PTRS
|
||||
DEFINES = -DSERENITY -DUSERLAND -DSANITIZE_PTRS
|
||||
|
||||
CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(LIBC_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
|
||||
CXX = g++-8
|
||||
|
|
14
LibC/assert.cpp
Normal file
14
LibC/assert.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func)
|
||||
{
|
||||
printf("ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func);
|
||||
abort();
|
||||
}
|
||||
|
||||
}
|
||||
|
14
LibC/assert.h
Normal file
14
LibC/assert.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
|
||||
void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);
|
||||
|
||||
#define assert(expr) (static_cast<bool>(expr) ? (void)0 : __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
|
||||
#define CRASH() do { asm volatile("ud2"); } while(0)
|
||||
#define ASSERT assert
|
||||
#define RELEASE_ASSERT assert
|
||||
#define ASSERT_NOT_REACHED() assert(false)
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#include <Kernel/Syscall.h>
|
||||
#include <AK/StringImpl.h>
|
||||
|
||||
extern "C" int main(int, char**);
|
||||
|
||||
|
@ -8,6 +9,8 @@ extern "C" int _start()
|
|||
{
|
||||
errno = 0;
|
||||
|
||||
StringImpl::initializeGlobals();
|
||||
|
||||
int argc;
|
||||
char** argv;
|
||||
int rc = Syscall::invoke(Syscall::GetArguments, (dword)&argc, (dword)&argv);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "stdlib.h"
|
||||
#include "mman.h"
|
||||
#include <Kernel/Syscall.h>
|
||||
#include <AK/Assertions.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -20,5 +22,28 @@ void free(void* ptr)
|
|||
munmap(ptr, 4096);
|
||||
}
|
||||
|
||||
void* calloc(size_t nmemb, size_t)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* realloc(void *ptr, size_t)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void exit(int status)
|
||||
{
|
||||
Syscall::invoke(Syscall::PosixExit, (dword)status);
|
||||
}
|
||||
|
||||
void abort()
|
||||
{
|
||||
// FIXME: Implement proper abort().
|
||||
exit(253);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@ extern "C" {
|
|||
|
||||
void* malloc(size_t);
|
||||
void free(void*);
|
||||
void* calloc(size_t nmemb, size_t);
|
||||
void* realloc(void *ptr, size_t);
|
||||
|
||||
void exit(int status);
|
||||
void abort();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,17 @@ int strcmp(const char* s1, const char* s2)
|
|||
return *(const unsigned char*)s1 < *(const unsigned char*)s2 ? -1 : 1;
|
||||
}
|
||||
|
||||
int memcmp(const void* v1, const void* v2, size_t n)
|
||||
{
|
||||
auto* s1 = (const byte*)v1;
|
||||
auto* s2 = (const byte*)v2;
|
||||
while (n-- > 0) {
|
||||
if (*s1++ != *s2++)
|
||||
return s1[-1] < s2[-1] ? -1 : 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void memcpy(void* dest, const void* src, size_t n)
|
||||
{
|
||||
auto* bdest = (unsigned char*)dest;
|
||||
|
|
|
@ -6,6 +6,7 @@ extern "C" {
|
|||
|
||||
size_t strlen(const char*);
|
||||
int strcmp(const char*, const char*);
|
||||
int memcmp(const void*, const void*, size_t);
|
||||
void memcpy(void*, const void*, size_t);
|
||||
const char* strerror(int errnum);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue