Browse Source

Import very modest Userland.

Andreas Kling 6 years ago
parent
commit
63764b3a65

+ 1 - 1
AK/Assertions.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#ifdef SERENITY_KERNEL
+#ifdef SERENITY
 #include "kassert.h"
 #else
 #include <assert.h>

+ 1 - 1
AK/StdLib.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#ifdef SERENITY_KERNEL
+#ifdef SERENITY
 #include <Kernel/StdLib.h>
 #else
 #include <cstring>

+ 1 - 1
AK/Types.h

@@ -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 - 1
AK/kmalloc.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#ifdef SERENITY_KERNEL
+#ifdef SERENITY
 #include <Kernel/kmalloc.h>
 #else
 #include <new>

+ 1 - 1
AK/kstdio.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#ifdef SERENITY_KERNEL
+#ifdef SERENITY
 #include <Kernel/kstdio.h>
 #else
 #include <cstdio>

+ 1 - 1
AK/ktime.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#ifdef SERENITY_KERNEL
+#ifdef SERENITY
 #include <Kernel/ktime.h>
 #else
 #include <time.h>

+ 2 - 2
ELFLoader/ELFImage.cpp

@@ -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;

+ 3 - 3
ELFLoader/ELFImage.h

@@ -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 - 1
ELFLoader/ELFLoader.cpp

@@ -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)

+ 1 - 1
ELFLoader/ELFLoader.h

@@ -9,7 +9,7 @@
 
 class ELFLoader {
 public:
-#ifdef SERENITY_KERNEL
+#ifdef SERENITY
     ELFLoader(ExecSpace&, ByteBuffer&&);
 #else
     ELFLoader(ExecSpace&, MappedFile&&);

+ 3 - 3
ELFLoader/ExecSpace.cpp

@@ -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]);
     }

+ 1 - 1
ELFLoader/ExecSpace.h

@@ -37,7 +37,7 @@ public:
     ExecSpace();
     ~ExecSpace();
 
-#ifdef SERENITY_KERNEL
+#ifdef SERENITY
     bool loadELF(ByteBuffer&&);
 #else
     bool loadELF(MappedFile&&);

+ 1 - 1
Kernel/Makefile

@@ -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 - 0
LibC/.gitignore

@@ -0,0 +1,2 @@
+*.o
+LibC.a

+ 3 - 2
LibC/Makefile

@@ -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 - 0
LibC/entry.cpp

@@ -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 - 0
Userland/Makefile

@@ -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 - 0
Userland/id.cpp

@@ -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;
+}
+

+ 1 - 1
VirtualFileSystem/DiskDevice.h

@@ -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

+ 2 - 2
VirtualFileSystem/FileHandle.cpp

@@ -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

+ 2 - 2
VirtualFileSystem/FileHandle.h

@@ -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
 };

+ 1 - 1
VirtualFileSystem/Limits.h

@@ -2,7 +2,7 @@
 
 #include "UnixTypes.h"
 
-#ifdef SERENITY_KERNEL
+#ifdef SERENITY
 inline static const Unix::off_t maxFileOffset = 2147483647;
 #else
 #include <limits>

+ 1 - 1
VirtualFileSystem/UnixTypes.h

@@ -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;