mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:42:45 +00:00 
			
		
		
		
	Import very modest Userland.
This commit is contained in:
		
							parent
							
								
									4cbf079a17
								
							
						
					
					
						commit
						63764b3a65
					
				
					 23 changed files with 81 additions and 27 deletions
				
			
		|  | @ -1,6 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| #include "kassert.h" | #include "kassert.h" | ||||||
| #else | #else | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| #include <Kernel/StdLib.h> | #include <Kernel/StdLib.h> | ||||||
| #else | #else | ||||||
| #include <cstring> | #include <cstring> | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #if defined(SERENITY_KERNEL) || defined(SERENITY_LIBC) | #if defined(SERENITY) | ||||||
| typedef unsigned char byte; | typedef unsigned char byte; | ||||||
| typedef unsigned short word; | typedef unsigned short word; | ||||||
| typedef unsigned int dword; | typedef unsigned int dword; | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| #include <Kernel/kmalloc.h> | #include <Kernel/kmalloc.h> | ||||||
| #else | #else | ||||||
| #include <new> | #include <new> | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| #include <Kernel/kstdio.h> | #include <Kernel/kstdio.h> | ||||||
| #else | #else | ||||||
| #include <cstdio> | #include <cstdio> | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| #include <Kernel/ktime.h> | #include <Kernel/ktime.h> | ||||||
| #else | #else | ||||||
| #include <time.h> | #include <time.h> | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| #include "ELFImage.h" | #include "ELFImage.h" | ||||||
| #include <AK/kstdio.h> | #include <AK/kstdio.h> | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| ELFImage::ELFImage(ByteBuffer&& buffer) | ELFImage::ELFImage(ByteBuffer&& buffer) | ||||||
|     : m_buffer(buffer) |     : m_buffer(buffer) | ||||||
| { | { | ||||||
|  | @ -136,7 +136,7 @@ const char* ELFImage::tableString(unsigned offset) const | ||||||
| 
 | 
 | ||||||
| const char* ELFImage::rawData(unsigned offset) const | const char* ELFImage::rawData(unsigned offset) const | ||||||
| { | { | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
|     return reinterpret_cast<const char*>(m_buffer.pointer()) + offset; |     return reinterpret_cast<const char*>(m_buffer.pointer()) + offset; | ||||||
| #else | #else | ||||||
|     return reinterpret_cast<const char*>(m_file.pointer()) + offset; |     return reinterpret_cast<const char*>(m_file.pointer()) + offset; | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #ifndef SERENITY_KERNEL | #ifndef SERENITY | ||||||
| #include <AK/MappedFile.h> | #include <AK/MappedFile.h> | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | @ -11,7 +11,7 @@ | ||||||
| 
 | 
 | ||||||
| class ELFImage { | class ELFImage { | ||||||
| public: | public: | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
|     explicit ELFImage(ByteBuffer&&); |     explicit ELFImage(ByteBuffer&&); | ||||||
| #else | #else | ||||||
|     explicit ELFImage(MappedFile&&); |     explicit ELFImage(MappedFile&&); | ||||||
|  | @ -131,7 +131,7 @@ private: | ||||||
|     const char* sectionHeaderTableString(unsigned offset) const; |     const char* sectionHeaderTableString(unsigned offset) const; | ||||||
|     const char* sectionIndexToString(unsigned index); |     const char* sectionIndexToString(unsigned index); | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
|     ByteBuffer m_buffer; |     ByteBuffer m_buffer; | ||||||
| #else | #else | ||||||
|     MappedFile m_file; |     MappedFile m_file; | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| #include "ELFLoader.h" | #include "ELFLoader.h" | ||||||
| #include <AK/kstdio.h> | #include <AK/kstdio.h> | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| ELFLoader::ELFLoader(ExecSpace& execSpace, ByteBuffer&& file) | ELFLoader::ELFLoader(ExecSpace& execSpace, ByteBuffer&& file) | ||||||
| #else | #else | ||||||
| ELFLoader::ELFLoader(ExecSpace& execSpace, MappedFile&& file) | ELFLoader::ELFLoader(ExecSpace& execSpace, MappedFile&& file) | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ | ||||||
| 
 | 
 | ||||||
| class ELFLoader { | class ELFLoader { | ||||||
| public: | public: | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
|     ELFLoader(ExecSpace&, ByteBuffer&&); |     ELFLoader(ExecSpace&, ByteBuffer&&); | ||||||
| #else | #else | ||||||
|     ELFLoader(ExecSpace&, MappedFile&&); |     ELFLoader(ExecSpace&, MappedFile&&); | ||||||
|  |  | ||||||
|  | @ -12,7 +12,7 @@ ExecSpace::~ExecSpace() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| int puts(const char* str) | int puts(const char* str) | ||||||
| { | { | ||||||
|     kprintf("%s\n", str); |     kprintf("%s\n", str); | ||||||
|  | @ -25,7 +25,7 @@ void ExecSpace::initializeBuiltins() | ||||||
|     m_symbols.set("puts", { (char*)puts, 0 }); |     m_symbols.set("puts", { (char*)puts, 0 }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| bool ExecSpace::loadELF(ByteBuffer&& file) | bool ExecSpace::loadELF(ByteBuffer&& file) | ||||||
| #else | #else | ||||||
| bool ExecSpace::loadELF(MappedFile&& file) | bool ExecSpace::loadELF(MappedFile&& file) | ||||||
|  | @ -49,7 +49,7 @@ static void disassemble(const char* data, size_t length) | ||||||
|     if (!length) |     if (!length) | ||||||
|         return; |         return; | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
|     for (unsigned i = 0; i < length; ++i) { |     for (unsigned i = 0; i < length; ++i) { | ||||||
|         kprintf("%b ", (unsigned char)data[i]); |         kprintf("%b ", (unsigned char)data[i]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ public: | ||||||
|     ExecSpace(); |     ExecSpace(); | ||||||
|     ~ExecSpace(); |     ~ExecSpace(); | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
|     bool loadELF(ByteBuffer&&); |     bool loadELF(ByteBuffer&&); | ||||||
| #else | #else | ||||||
|     bool loadELF(MappedFile&&); |     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 | OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables | ||||||
| INCLUDE_FLAGS = -I.. -I. | 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) | 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++
 | #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 = \
 | OBJS = \
 | ||||||
|        stdio.o \
 |        stdio.o \
 | ||||||
|        unistd.o |        unistd.o \
 | ||||||
|  |        entry.o | ||||||
| 
 | 
 | ||||||
| LIBRARY = LibC.a | LIBRARY = LibC.a | ||||||
| ARCH_FLAGS = | 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 | OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables | ||||||
| INCLUDE_FLAGS = -I.. -I. | 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) | CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(LIBC_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) | ||||||
| CXX = g++ | 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/Retainable.h> | ||||||
| #include <AK/Types.h> | #include <AK/Types.h> | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| // FIXME: Support 64-bit DiskOffset
 | // FIXME: Support 64-bit DiskOffset
 | ||||||
| typedef dword DiskOffset; | typedef dword DiskOffset; | ||||||
| #else | #else | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ FileHandle::~FileHandle() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifndef SERENITY_KERNEL | #ifndef SERENITY | ||||||
| bool additionWouldOverflow(Unix::off_t a, Unix::off_t b) | bool additionWouldOverflow(Unix::off_t a, Unix::off_t b) | ||||||
| { | { | ||||||
|     ASSERT(a > 0); |     ASSERT(a > 0); | ||||||
|  | @ -69,7 +69,7 @@ Unix::off_t FileHandle::seek(Unix::off_t offset, int whence) | ||||||
|         break; |         break; | ||||||
|     case SEEK_CUR: |     case SEEK_CUR: | ||||||
|         newOffset = m_currentOffset + offset; |         newOffset = m_currentOffset + offset; | ||||||
| #ifndef SERENITY_KERNEL | #ifndef SERENITY | ||||||
|         if (additionWouldOverflow(m_currentOffset, offset)) |         if (additionWouldOverflow(m_currentOffset, offset)) | ||||||
|             return -EOVERFLOW; |             return -EOVERFLOW; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     ByteBuffer readEntireFile(); |     ByteBuffer readEntireFile(); | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
|     int fd() const { return m_fd; } |     int fd() const { return m_fd; } | ||||||
|     void setFD(int fd) { m_fd = fd; } |     void setFD(int fd) { m_fd = fd; } | ||||||
| #endif | #endif | ||||||
|  | @ -26,7 +26,7 @@ private: | ||||||
| 
 | 
 | ||||||
|     Unix::off_t m_currentOffset { 0 }; |     Unix::off_t m_currentOffset { 0 }; | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
|     int m_fd { -1 }; |     int m_fd { -1 }; | ||||||
| #endif | #endif | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| #include "UnixTypes.h" | #include "UnixTypes.h" | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| inline static const Unix::off_t maxFileOffset = 2147483647; | inline static const Unix::off_t maxFileOffset = 2147483647; | ||||||
| #else | #else | ||||||
| #include <limits> | #include <limits> | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ typedef dword nlink_t; | ||||||
| typedef dword uid_t; | typedef dword uid_t; | ||||||
| typedef dword gid_t; | typedef dword gid_t; | ||||||
| 
 | 
 | ||||||
| #ifdef SERENITY_KERNEL | #ifdef SERENITY | ||||||
| // FIXME: Support 64-bit offsets!
 | // FIXME: Support 64-bit offsets!
 | ||||||
| typedef signed_dword off_t; | typedef signed_dword off_t; | ||||||
| typedef unsigned int time_t; | typedef unsigned int time_t; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling