From bd8967069edaee903c3e491027546a10793365e1 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 23 Sep 2012 13:55:58 +0200 Subject: [PATCH] Replace libmaxsi headers with libc headers. --- libmaxsi/c++.cpp | 4 +- libmaxsi/format.cpp | 22 +++++----- libmaxsi/heap.cpp | 30 ++++++++------ libmaxsi/include/libmaxsi/platform.h | 58 -------------------------- libmaxsi/include/libmaxsi/types.h | 61 ---------------------------- libmaxsi/init.cpp | 1 - libmaxsi/integer.cpp | 2 +- libmaxsi/memory.cpp | 18 ++++---- libmaxsi/process.cpp | 7 ++-- libmaxsi/random.cpp | 2 - libmaxsi/signal.cpp | 1 - libmaxsi/time.cpp | 3 +- sortix/x64/x64.cpp | 2 +- sortix/x86-family/x86-family.cpp | 2 +- sortix/x86/x86.cpp | 2 +- 15 files changed, 48 insertions(+), 167 deletions(-) delete mode 100644 libmaxsi/include/libmaxsi/platform.h delete mode 100644 libmaxsi/include/libmaxsi/types.h diff --git a/libmaxsi/c++.cpp b/libmaxsi/c++.cpp index 5293e171..c90538e8 100644 --- a/libmaxsi/c++.cpp +++ b/libmaxsi/c++.cpp @@ -22,14 +22,14 @@ ******************************************************************************/ -#include +#include extern "C" void __attribute__ ((weak)) __cxa_pure_virtual() { // This shouldn't happen. TODO: Possibly crash the kernel here. } -#ifdef PLATFORM_X86 +#if defined(__i386__) extern "C" uint64_t __attribute__ ((weak)) __udivdi3(uint64_t a, uint64_t b) { diff --git a/libmaxsi/format.cpp b/libmaxsi/format.cpp index 8b04c6b3..5208eaec 100644 --- a/libmaxsi/format.cpp +++ b/libmaxsi/format.cpp @@ -22,7 +22,7 @@ ******************************************************************************/ -#include +#include #include #include @@ -190,21 +190,21 @@ namespace Maxsi if ( *format == '%' ) { continue; } - const nat UNSIGNED = 0; - const nat INTEGER = (1<<0); - const nat BIT64 = (1<<1); - const nat HEX = (1<<2); - const nat STRING = 8; - const nat CHARACTER = 9; - #ifdef PLATFORM_X64 - const nat WORDWIDTH = BIT64; + const unsigned UNSIGNED = 0; + const unsigned INTEGER = (1<<0); + const unsigned BIT64 = (1<<1); + const unsigned HEX = (1<<2); + const unsigned STRING = 8; + const unsigned CHARACTER = 9; + #if defined(__x86_64__) + const unsigned WORDWIDTH = BIT64; #else - const nat WORDWIDTH = 0; + const unsigned WORDWIDTH = 0; #endif // TODO: Support signed datatypes! - nat type = 0; + unsigned type = 0; bool scanning = true; while ( scanning ) diff --git a/libmaxsi/heap.cpp b/libmaxsi/heap.cpp index 69c75759..1c6cd883 100644 --- a/libmaxsi/heap.cpp +++ b/libmaxsi/heap.cpp @@ -23,7 +23,6 @@ *******************************************************************************/ #include -#include #ifdef SORTIX_KERNEL #define HEAP_GROWS_DOWNWARDS @@ -31,13 +30,13 @@ #ifndef SORTIX_KERNEL #include -#include #include #endif #include #include #include +#include #include #define PARANOIA 1 @@ -50,6 +49,11 @@ #include #endif +#ifndef _ADDR_T_DECLARED +#define _ADDR_T_DECLARED +typedef uintptr_t addr_t; +#endif + namespace Maxsi { namespace Memory @@ -59,7 +63,7 @@ namespace Maxsi // skip ahead to the actual algorithm. // -#ifdef PLATFORM_X64 +#if defined(__x86_64__) const size_t MAGIC = 0xDEADDEADDEADDEADUL; const size_t ALIGNMENT = 16UL; #else @@ -473,7 +477,7 @@ namespace Maxsi return true; } - DUAL_FUNCTION(void*, malloc, Allocate, (size_t size)) + extern "C" void* malloc(size_t size) { #ifdef SORTIX_KERNEL Sortix::ScopedLock scopedlock(&heaplock); @@ -660,7 +664,7 @@ namespace Maxsi } } - DUAL_FUNCTION(void, free, Free, (void* addr)) + extern "C" void free(void* addr) { #ifdef SORTIX_KERNEL Sortix::ScopedLock scopedlock(&heaplock); @@ -701,7 +705,7 @@ namespace Maxsi extern "C" void* calloc(size_t nmemb, size_t size) { size_t total = nmemb * size; - void* result = Allocate(total); + void* result = malloc(total); if ( !result ) { return NULL; } memset(result, 0, total); return result; @@ -710,23 +714,23 @@ namespace Maxsi // TODO: Implement this function properly. extern "C" void* realloc(void* ptr, size_t size) { - if ( !ptr ) { return Allocate(size); } + if ( !ptr ) { return malloc(size); } Chunk* chunk = (Chunk*) ((addr_t) ptr - sizeof(Chunk)); assert(chunk->IsUsed()); assert(chunk->IsSane()); size_t allocsize = chunk->size - OVERHEAD; if ( size < allocsize ) { return ptr; } - void* newptr = Allocate(size); + void* newptr = malloc(size); if ( !newptr ) { return NULL; } memcpy(newptr, ptr, allocsize); - Free(ptr); + free(ptr); return newptr; } } } -void* operator new(size_t Size) { return Maxsi::Memory::Allocate(Size); } -void* operator new[](size_t Size) { return Maxsi::Memory::Allocate(Size); } -void operator delete (void* Addr) { return Maxsi::Memory::Free(Addr); }; -void operator delete[](void* Addr) { return Maxsi::Memory::Free(Addr); }; +void* operator new(size_t Size) { return malloc(Size); } +void* operator new[](size_t Size) { return malloc(Size); } +void operator delete (void* Addr) { return free(Addr); }; +void operator delete[](void* Addr) { return free(Addr); }; diff --git a/libmaxsi/include/libmaxsi/platform.h b/libmaxsi/include/libmaxsi/platform.h deleted file mode 100644 index dc31e852..00000000 --- a/libmaxsi/include/libmaxsi/platform.h +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - - COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012. - - This file is part of LibMaxsi. - - LibMaxsi is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - more details. - - You should have received a copy of the GNU Lesser General Public License - along with LibMaxsi. If not, see . - - platform.h - Defines platform specific stuff. - -*******************************************************************************/ - -#ifndef LIBMAXSI_PLATFORM_H -#define LIBMAXSI_PLATFORM_H - - #if !defined(PLATFORM_X64) && defined(__x86_64__) - #define PLATFORM_X64 - #elif !defined(PLATFORM_X86) && defined(__i386__) - #define PLATFORM_X86 - #endif - - // Detect which platform we are compiling to and declare some useful macros. - #if !defined(CPU) && defined(PLATFORM_X86) - #define CPU X86 - #endif - - #if !defined(CPU) && defined(PLATFORM_X64) - #define CPU X64 - #endif - - #if !defined(CPU_FAMILY) && defined(PLATFORM_X86) || defined(PLATFORM_X64) - #define PLATFORM_X86_FAMILY - #define CPU_FAMILY X86_FAMILY - #endif - - // Libmaxsi is also compatible as a C library, if enabled. - #ifdef LIBMAXSI_LIBRARY - #define DUAL_FUNCTION(Type, CName, LibMaxsiName, Parameters) \ - Type LibMaxsiName Parameters __attribute__ ((weak, alias (#CName))); \ - extern "C" Type CName Parameters - #endif - - // Define common datatypes. - #include "types.h" - -#endif diff --git a/libmaxsi/include/libmaxsi/types.h b/libmaxsi/include/libmaxsi/types.h deleted file mode 100644 index e4234627..00000000 --- a/libmaxsi/include/libmaxsi/types.h +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - - COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. - - This file is part of LibMaxsi. - - LibMaxsi is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - more details. - - You should have received a copy of the GNU Lesser General Public License - along with LibMaxsi. If not, see . - - types.h - Declares the required datatypes based on the kernel's configuration. - -******************************************************************************/ - -#ifndef LIBMAXSI_TYPES_H -#define LIBMAXSI_TYPES_H - -#include - -@include(NULL.h) - -@include(intn_t.h) - -@include(wint_t.h) -@include(id_t.h) -@include(gid_t.h) -@include(pid_t.h) -@include(uid_t.h) -@include(locale_t.h) -@include(mode_t.h) -@include(off_t.h) -@include(gid_t.h) -@include(ino_t.h) -@include(nlink_t.h) -@include(blksize_t.h) -@include(blkcnt_t.h) -@include(dev_t.h) -@include(time_t.h) - -@include(va_list.h) - -// Maxsi datatype extentions. -typedef __nat nat; -typedef uint8_t byte; -#ifndef _ADDR_T_DECLARED -#define _ADDR_T_DECLARED -typedef uintptr_t addr_t; -#endif - -#endif - diff --git a/libmaxsi/init.cpp b/libmaxsi/init.cpp index 4c8e62cb..c1d964d8 100644 --- a/libmaxsi/init.cpp +++ b/libmaxsi/init.cpp @@ -23,7 +23,6 @@ *******************************************************************************/ -#include #include #include diff --git a/libmaxsi/integer.cpp b/libmaxsi/integer.cpp index 68682591..7148c07f 100644 --- a/libmaxsi/integer.cpp +++ b/libmaxsi/integer.cpp @@ -23,7 +23,7 @@ ******************************************************************************/ -#include +#include namespace Maxsi { diff --git a/libmaxsi/memory.cpp b/libmaxsi/memory.cpp index f528beca..be13c75c 100644 --- a/libmaxsi/memory.cpp +++ b/libmaxsi/memory.cpp @@ -22,10 +22,10 @@ ******************************************************************************/ -#include #ifndef SORTIX_KERNEL #include #endif +#include #include namespace Maxsi @@ -83,7 +83,7 @@ namespace Maxsi return (addr / WORDSIZE * WORDSIZE) == addr; } - DUAL_FUNCTION(void*, memcpy, Copy, (void* destptr, const void* srcptr, size_t length)) + extern "C" void* memcpy(void* destptr, const void* srcptr, size_t length) { if ( IsWordAligned((uintptr_t) destptr) && IsWordAligned((uintptr_t) srcptr) && @@ -102,9 +102,9 @@ namespace Maxsi return dest; } - DUAL_FUNCTION(void*, memset, Set, (void* Dest, int Value, size_t Length)) + extern "C" void* memset(void* Dest, int Value, size_t Length) { - byte* D = (byte*) Dest; + uint8_t* D = (uint8_t*) Dest; for ( size_t I = 0; I < Length; I++ ) { @@ -114,10 +114,10 @@ namespace Maxsi return Dest; } - DUAL_FUNCTION(int, memcmp, Compare, (const void* a, const void* b, size_t size)) + extern "C" int memcmp(const void* a, const void* b, size_t size) { - const byte* buf1 = (const byte*) a; - const byte* buf2 = (const byte*) b; + const uint8_t* buf1 = (const uint8_t*) a; + const uint8_t* buf2 = (const uint8_t*) b; for ( size_t i = 0; i < size; i++ ) { if ( buf1[i] != buf2[i] ) { return (int)(buf1[i]) - (int)(buf2[i]); } @@ -125,9 +125,9 @@ namespace Maxsi return 0; } - DUAL_FUNCTION(void*, memchr, Seek, (const void* s, int c, size_t size)) + extern "C" void* memchr(const void* s, int c, size_t size) { - const byte* buf = (const byte*) s; + const uint8_t* buf = (const uint8_t*) s; for ( size_t i = 0; i < size; i++ ) { if ( buf[i] == c ) { return (void*) (buf + i); } diff --git a/libmaxsi/process.cpp b/libmaxsi/process.cpp index 6f580d46..c73517fe 100644 --- a/libmaxsi/process.cpp +++ b/libmaxsi/process.cpp @@ -23,7 +23,6 @@ *******************************************************************************/ #define _WANT_ENVIRON -#include #include #include #include @@ -171,17 +170,17 @@ namespace Maxsi return __call_tfork_with_regs(flags); } - DUAL_FUNCTION(pid_t, fork, Fork, ()) + extern "C" pid_t fork() { return sfork(SFFORK); } - DUAL_FUNCTION(pid_t, getpid, GetPID, ()) + extern "C" pid_t getpid() { return SysGetPID(); } - DUAL_FUNCTION(pid_t, getppid, GetParentPID, ()) + extern "C" pid_t getppid() { return SysGetParentPID(); } diff --git a/libmaxsi/random.cpp b/libmaxsi/random.cpp index 09256583..056ab350 100644 --- a/libmaxsi/random.cpp +++ b/libmaxsi/random.cpp @@ -22,8 +22,6 @@ *******************************************************************************/ -#include - namespace Maxsi { namespace Random diff --git a/libmaxsi/signal.cpp b/libmaxsi/signal.cpp index 7c33abb4..b67d1141 100644 --- a/libmaxsi/signal.cpp +++ b/libmaxsi/signal.cpp @@ -22,7 +22,6 @@ *******************************************************************************/ -#include #include #include #include diff --git a/libmaxsi/time.cpp b/libmaxsi/time.cpp index f65329b6..b253bec9 100644 --- a/libmaxsi/time.cpp +++ b/libmaxsi/time.cpp @@ -22,11 +22,12 @@ *******************************************************************************/ -#include #include #include #include #include +#include +#include namespace Maxsi { diff --git a/sortix/x64/x64.cpp b/sortix/x64/x64.cpp index f82a8fbe..850a1f27 100644 --- a/sortix/x64/x64.cpp +++ b/sortix/x64/x64.cpp @@ -22,7 +22,7 @@ ******************************************************************************/ -#include +#include #include "x64.h" #include diff --git a/sortix/x86-family/x86-family.cpp b/sortix/x86-family/x86-family.cpp index baf9b989..c52d16cf 100644 --- a/sortix/x86-family/x86-family.cpp +++ b/sortix/x86-family/x86-family.cpp @@ -22,7 +22,7 @@ ******************************************************************************/ -#include +#include namespace Sortix { diff --git a/sortix/x86/x86.cpp b/sortix/x86/x86.cpp index 48b85b12..09488824 100644 --- a/sortix/x86/x86.cpp +++ b/sortix/x86/x86.cpp @@ -22,7 +22,7 @@ ******************************************************************************/ -#include +#include #include "x86.h" #include