mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 13:11:46 +03:00
Import very modest Userland.
This commit is contained in:
parent
4cbf079a17
commit
63764b3a65
Notes:
sideshowbarker
2024-07-19 18:45:13 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/63764b3a652
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
#include "kassert.h"
|
||||
#else
|
||||
#include <assert.h>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
#include <Kernel/StdLib.h>
|
||||
#else
|
||||
#include <cstring>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(SERENITY_KERNEL) || defined(SERENITY_LIBC)
|
||||
#if defined(SERENITY)
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned short word;
|
||||
typedef unsigned int dword;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
#include <Kernel/kmalloc.h>
|
||||
#else
|
||||
#include <new>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
#include <Kernel/kstdio.h>
|
||||
#else
|
||||
#include <cstdio>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
#include <Kernel/ktime.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "ELFImage.h"
|
||||
#include <AK/kstdio.h>
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
ELFImage::ELFImage(ByteBuffer&& buffer)
|
||||
: m_buffer(buffer)
|
||||
{
|
||||
@ -136,7 +136,7 @@ const char* ELFImage::tableString(unsigned offset) const
|
||||
|
||||
const char* ELFImage::rawData(unsigned offset) const
|
||||
{
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
return reinterpret_cast<const char*>(m_buffer.pointer()) + offset;
|
||||
#else
|
||||
return reinterpret_cast<const char*>(m_file.pointer()) + offset;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SERENITY_KERNEL
|
||||
#ifndef SERENITY
|
||||
#include <AK/MappedFile.h>
|
||||
#endif
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
class ELFImage {
|
||||
public:
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
explicit ELFImage(ByteBuffer&&);
|
||||
#else
|
||||
explicit ELFImage(MappedFile&&);
|
||||
@ -131,7 +131,7 @@ private:
|
||||
const char* sectionHeaderTableString(unsigned offset) const;
|
||||
const char* sectionIndexToString(unsigned index);
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
ByteBuffer m_buffer;
|
||||
#else
|
||||
MappedFile m_file;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "ELFLoader.h"
|
||||
#include <AK/kstdio.h>
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
ELFLoader::ELFLoader(ExecSpace& execSpace, ByteBuffer&& file)
|
||||
#else
|
||||
ELFLoader::ELFLoader(ExecSpace& execSpace, MappedFile&& file)
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
class ELFLoader {
|
||||
public:
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
ELFLoader(ExecSpace&, ByteBuffer&&);
|
||||
#else
|
||||
ELFLoader(ExecSpace&, MappedFile&&);
|
||||
|
@ -12,7 +12,7 @@ ExecSpace::~ExecSpace()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
int puts(const char* str)
|
||||
{
|
||||
kprintf("%s\n", str);
|
||||
@ -25,7 +25,7 @@ void ExecSpace::initializeBuiltins()
|
||||
m_symbols.set("puts", { (char*)puts, 0 });
|
||||
}
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
bool ExecSpace::loadELF(ByteBuffer&& file)
|
||||
#else
|
||||
bool ExecSpace::loadELF(MappedFile&& file)
|
||||
@ -49,7 +49,7 @@ static void disassemble(const char* data, size_t length)
|
||||
if (!length)
|
||||
return;
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
for (unsigned i = 0; i < length; ++i) {
|
||||
kprintf("%b ", (unsigned char)data[i]);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
ExecSpace();
|
||||
~ExecSpace();
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
bool loadELF(ByteBuffer&&);
|
||||
#else
|
||||
bool loadELF(MappedFile&&);
|
||||
|
@ -61,7 +61,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_KERNEL -DSANITIZE_PTRS
|
||||
DEFINES = -DSERENITY -DSANITIZE_PTRS
|
||||
|
||||
CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(KERNEL_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
|
||||
#CXX = /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-g++
|
||||
|
2
LibC/.gitignore
vendored
Normal file
2
LibC/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.o
|
||||
LibC.a
|
@ -1,6 +1,7 @@
|
||||
OBJS = \
|
||||
stdio.o \
|
||||
unistd.o
|
||||
unistd.o \
|
||||
entry.o
|
||||
|
||||
LIBRARY = LibC.a
|
||||
ARCH_FLAGS =
|
||||
@ -11,7 +12,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_LIBC -DSANITIZE_PTRS
|
||||
DEFINES = -DSERENITY -DSANITIZE_PTRS
|
||||
|
||||
CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(LIBC_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
|
||||
CXX = g++
|
||||
|
12
LibC/entry.cpp
Normal file
12
LibC/entry.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" int main(int, char**);
|
||||
|
||||
extern "C" int elf_entry()
|
||||
{
|
||||
// FIXME: Pass appropriate argc/argv.
|
||||
main(0, nullptr);
|
||||
|
||||
// Birger's birthday <3
|
||||
return 20150614;
|
||||
}
|
27
Userland/Makefile
Normal file
27
Userland/Makefile
Normal file
@ -0,0 +1,27 @@
|
||||
OBJS = \
|
||||
id.o
|
||||
|
||||
ARCH_FLAGS =
|
||||
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
|
||||
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
|
||||
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
|
||||
FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -falign-functions=1 -falign-jumps=1 -falign-loops=1 -fno-pie -fno-pic
|
||||
OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables
|
||||
INCLUDE_FLAGS = -I.. -I.
|
||||
|
||||
DEFINES = -DSERENITY -DSANITIZE_PTRS
|
||||
|
||||
CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(USERLAND_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
|
||||
CXX = g++
|
||||
LD = ld
|
||||
AR = ar
|
||||
LDFLAGS = -T linker.ld --strip-debug -melf_i386 --gc-sections --build-id=none -z norelro -z now
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
||||
clean:
|
||||
@echo "CLEAN"; rm -f $(LIBRARY) $(OBJS)
|
||||
|
12
Userland/id.cpp
Normal file
12
Userland/id.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibC/stdio.h>
|
||||
|
||||
int main(int c, char** v)
|
||||
{
|
||||
uid_t uid = getuid();
|
||||
gid_t gid = getgid();
|
||||
pid_t pid = getpid();
|
||||
printf("uid=%u, gid=%u, pid=%u\n", uid, gid, pid);
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <AK/Retainable.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
// FIXME: Support 64-bit DiskOffset
|
||||
typedef dword DiskOffset;
|
||||
#else
|
||||
|
@ -13,7 +13,7 @@ FileHandle::~FileHandle()
|
||||
{
|
||||
}
|
||||
|
||||
#ifndef SERENITY_KERNEL
|
||||
#ifndef SERENITY
|
||||
bool additionWouldOverflow(Unix::off_t a, Unix::off_t b)
|
||||
{
|
||||
ASSERT(a > 0);
|
||||
@ -69,7 +69,7 @@ Unix::off_t FileHandle::seek(Unix::off_t offset, int whence)
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
newOffset = m_currentOffset + offset;
|
||||
#ifndef SERENITY_KERNEL
|
||||
#ifndef SERENITY
|
||||
if (additionWouldOverflow(m_currentOffset, offset))
|
||||
return -EOVERFLOW;
|
||||
#endif
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
|
||||
ByteBuffer readEntireFile();
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
int fd() const { return m_fd; }
|
||||
void setFD(int fd) { m_fd = fd; }
|
||||
#endif
|
||||
@ -26,7 +26,7 @@ private:
|
||||
|
||||
Unix::off_t m_currentOffset { 0 };
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
int m_fd { -1 };
|
||||
#endif
|
||||
};
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "UnixTypes.h"
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
inline static const Unix::off_t maxFileOffset = 2147483647;
|
||||
#else
|
||||
#include <limits>
|
||||
|
@ -15,7 +15,7 @@ typedef dword nlink_t;
|
||||
typedef dword uid_t;
|
||||
typedef dword gid_t;
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
#ifdef SERENITY
|
||||
// FIXME: Support 64-bit offsets!
|
||||
typedef signed_dword off_t;
|
||||
typedef unsigned int time_t;
|
||||
|
Loading…
Reference in New Issue
Block a user