Replace libmaxsi headers with libc headers.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-23 13:55:58 +02:00
parent c0fabc2e8d
commit bd8967069e
15 changed files with 48 additions and 167 deletions

View File

@ -22,14 +22,14 @@
******************************************************************************/ ******************************************************************************/
#include <libmaxsi/platform.h> #include <stdint.h>
extern "C" void __attribute__ ((weak)) __cxa_pure_virtual() extern "C" void __attribute__ ((weak)) __cxa_pure_virtual()
{ {
// This shouldn't happen. TODO: Possibly crash the kernel here. // 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) extern "C" uint64_t __attribute__ ((weak)) __udivdi3(uint64_t a, uint64_t b)
{ {

View File

@ -22,7 +22,7 @@
******************************************************************************/ ******************************************************************************/
#include <libmaxsi/platform.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -190,21 +190,21 @@ namespace Maxsi
if ( *format == '%' ) { continue; } if ( *format == '%' ) { continue; }
const nat UNSIGNED = 0; const unsigned UNSIGNED = 0;
const nat INTEGER = (1<<0); const unsigned INTEGER = (1<<0);
const nat BIT64 = (1<<1); const unsigned BIT64 = (1<<1);
const nat HEX = (1<<2); const unsigned HEX = (1<<2);
const nat STRING = 8; const unsigned STRING = 8;
const nat CHARACTER = 9; const unsigned CHARACTER = 9;
#ifdef PLATFORM_X64 #if defined(__x86_64__)
const nat WORDWIDTH = BIT64; const unsigned WORDWIDTH = BIT64;
#else #else
const nat WORDWIDTH = 0; const unsigned WORDWIDTH = 0;
#endif #endif
// TODO: Support signed datatypes! // TODO: Support signed datatypes!
nat type = 0; unsigned type = 0;
bool scanning = true; bool scanning = true;
while ( scanning ) while ( scanning )

View File

@ -23,7 +23,6 @@
*******************************************************************************/ *******************************************************************************/
#include <sys/mman.h> #include <sys/mman.h>
#include <libmaxsi/platform.h>
#ifdef SORTIX_KERNEL #ifdef SORTIX_KERNEL
#define HEAP_GROWS_DOWNWARDS #define HEAP_GROWS_DOWNWARDS
@ -31,13 +30,13 @@
#ifndef SORTIX_KERNEL #ifndef SORTIX_KERNEL
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <malloc.h> #include <malloc.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#define PARANOIA 1 #define PARANOIA 1
@ -50,6 +49,11 @@
#include <sortix/kernel/panic.h> #include <sortix/kernel/panic.h>
#endif #endif
#ifndef _ADDR_T_DECLARED
#define _ADDR_T_DECLARED
typedef uintptr_t addr_t;
#endif
namespace Maxsi namespace Maxsi
{ {
namespace Memory namespace Memory
@ -59,7 +63,7 @@ namespace Maxsi
// skip ahead to the actual algorithm. // skip ahead to the actual algorithm.
// //
#ifdef PLATFORM_X64 #if defined(__x86_64__)
const size_t MAGIC = 0xDEADDEADDEADDEADUL; const size_t MAGIC = 0xDEADDEADDEADDEADUL;
const size_t ALIGNMENT = 16UL; const size_t ALIGNMENT = 16UL;
#else #else
@ -473,7 +477,7 @@ namespace Maxsi
return true; return true;
} }
DUAL_FUNCTION(void*, malloc, Allocate, (size_t size)) extern "C" void* malloc(size_t size)
{ {
#ifdef SORTIX_KERNEL #ifdef SORTIX_KERNEL
Sortix::ScopedLock scopedlock(&heaplock); 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 #ifdef SORTIX_KERNEL
Sortix::ScopedLock scopedlock(&heaplock); Sortix::ScopedLock scopedlock(&heaplock);
@ -701,7 +705,7 @@ namespace Maxsi
extern "C" void* calloc(size_t nmemb, size_t size) extern "C" void* calloc(size_t nmemb, size_t size)
{ {
size_t total = nmemb * size; size_t total = nmemb * size;
void* result = Allocate(total); void* result = malloc(total);
if ( !result ) { return NULL; } if ( !result ) { return NULL; }
memset(result, 0, total); memset(result, 0, total);
return result; return result;
@ -710,23 +714,23 @@ namespace Maxsi
// TODO: Implement this function properly. // TODO: Implement this function properly.
extern "C" void* realloc(void* ptr, size_t size) 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)); Chunk* chunk = (Chunk*) ((addr_t) ptr - sizeof(Chunk));
assert(chunk->IsUsed()); assert(chunk->IsUsed());
assert(chunk->IsSane()); assert(chunk->IsSane());
size_t allocsize = chunk->size - OVERHEAD; size_t allocsize = chunk->size - OVERHEAD;
if ( size < allocsize ) { return ptr; } if ( size < allocsize ) { return ptr; }
void* newptr = Allocate(size); void* newptr = malloc(size);
if ( !newptr ) { return NULL; } if ( !newptr ) { return NULL; }
memcpy(newptr, ptr, allocsize); memcpy(newptr, ptr, allocsize);
Free(ptr); free(ptr);
return newptr; return newptr;
} }
} }
} }
void* operator new(size_t Size) { return Maxsi::Memory::Allocate(Size); } void* operator new(size_t Size) { return malloc(Size); }
void* operator new[](size_t Size) { return Maxsi::Memory::Allocate(Size); } void* operator new[](size_t Size) { return malloc(Size); }
void operator delete (void* Addr) { return Maxsi::Memory::Free(Addr); }; void operator delete (void* Addr) { return free(Addr); };
void operator delete[](void* Addr) { return Maxsi::Memory::Free(Addr); }; void operator delete[](void* Addr) { return free(Addr); };

View File

@ -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 <http://www.gnu.org/licenses/>.
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

View File

@ -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 <http://www.gnu.org/licenses/>.
types.h
Declares the required datatypes based on the kernel's configuration.
******************************************************************************/
#ifndef LIBMAXSI_TYPES_H
#define LIBMAXSI_TYPES_H
#include <sortix/bits.h>
@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

View File

@ -23,7 +23,6 @@
*******************************************************************************/ *******************************************************************************/
#include <libmaxsi/platform.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>

View File

@ -23,7 +23,7 @@
******************************************************************************/ ******************************************************************************/
#include <libmaxsi/platform.h> #include <stddef.h>
namespace Maxsi namespace Maxsi
{ {

View File

@ -22,10 +22,10 @@
******************************************************************************/ ******************************************************************************/
#include <libmaxsi/platform.h>
#ifndef SORTIX_KERNEL #ifndef SORTIX_KERNEL
#include <sys/syscall.h> #include <sys/syscall.h>
#endif #endif
#include <stdint.h>
#include <string.h> #include <string.h>
namespace Maxsi namespace Maxsi
@ -83,7 +83,7 @@ namespace Maxsi
return (addr / WORDSIZE * WORDSIZE) == addr; 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) && if ( IsWordAligned((uintptr_t) destptr) &&
IsWordAligned((uintptr_t) srcptr) && IsWordAligned((uintptr_t) srcptr) &&
@ -102,9 +102,9 @@ namespace Maxsi
return dest; 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++ ) for ( size_t I = 0; I < Length; I++ )
{ {
@ -114,10 +114,10 @@ namespace Maxsi
return Dest; 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 uint8_t* buf1 = (const uint8_t*) a;
const byte* buf2 = (const byte*) b; const uint8_t* buf2 = (const uint8_t*) b;
for ( size_t i = 0; i < size; i++ ) for ( size_t i = 0; i < size; i++ )
{ {
if ( buf1[i] != buf2[i] ) { return (int)(buf1[i]) - (int)(buf2[i]); } if ( buf1[i] != buf2[i] ) { return (int)(buf1[i]) - (int)(buf2[i]); }
@ -125,9 +125,9 @@ namespace Maxsi
return 0; 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++ ) for ( size_t i = 0; i < size; i++ )
{ {
if ( buf[i] == c ) { return (void*) (buf + i); } if ( buf[i] == c ) { return (void*) (buf + i); }

View File

@ -23,7 +23,6 @@
*******************************************************************************/ *******************************************************************************/
#define _WANT_ENVIRON #define _WANT_ENVIRON
#include <libmaxsi/platform.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
@ -171,17 +170,17 @@ namespace Maxsi
return __call_tfork_with_regs(flags); return __call_tfork_with_regs(flags);
} }
DUAL_FUNCTION(pid_t, fork, Fork, ()) extern "C" pid_t fork()
{ {
return sfork(SFFORK); return sfork(SFFORK);
} }
DUAL_FUNCTION(pid_t, getpid, GetPID, ()) extern "C" pid_t getpid()
{ {
return SysGetPID(); return SysGetPID();
} }
DUAL_FUNCTION(pid_t, getppid, GetParentPID, ()) extern "C" pid_t getppid()
{ {
return SysGetParentPID(); return SysGetParentPID();
} }

View File

@ -22,8 +22,6 @@
*******************************************************************************/ *******************************************************************************/
#include <libmaxsi/platform.h>
namespace Maxsi namespace Maxsi
{ {
namespace Random namespace Random

View File

@ -22,7 +22,6 @@
*******************************************************************************/ *******************************************************************************/
#include <libmaxsi/platform.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>

View File

@ -22,11 +22,12 @@
*******************************************************************************/ *******************************************************************************/
#include <libmaxsi/platform.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <errno.h> #include <errno.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <stddef.h>
#include <stdint.h>
namespace Maxsi namespace Maxsi
{ {

View File

@ -22,7 +22,7 @@
******************************************************************************/ ******************************************************************************/
#include <libmaxsi/platform.h> #include <sortix/kernel/platform.h>
#include "x64.h" #include "x64.h"
#include <sortix/kernel/log.h> #include <sortix/kernel/log.h>

View File

@ -22,7 +22,7 @@
******************************************************************************/ ******************************************************************************/
#include <libmaxsi/platform.h> #include <sortix/kernel/platform.h>
namespace Sortix namespace Sortix
{ {

View File

@ -22,7 +22,7 @@
******************************************************************************/ ******************************************************************************/
#include <libmaxsi/platform.h> #include <sortix/kernel/platform.h>
#include "x86.h" #include "x86.h"
#include <sortix/kernel/log.h> #include <sortix/kernel/log.h>