1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

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()
{
// 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)
{

View file

@ -22,7 +22,7 @@
******************************************************************************/
#include <libmaxsi/platform.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@ -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 )

View file

@ -23,7 +23,6 @@
*******************************************************************************/
#include <sys/mman.h>
#include <libmaxsi/platform.h>
#ifdef SORTIX_KERNEL
#define HEAP_GROWS_DOWNWARDS
@ -31,13 +30,13 @@
#ifndef SORTIX_KERNEL
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif
#include <assert.h>
#include <errno.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#define PARANOIA 1
@ -50,6 +49,11 @@
#include <sortix/kernel/panic.h>
#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); };

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 <string.h>

View file

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

View file

@ -22,10 +22,10 @@
******************************************************************************/
#include <libmaxsi/platform.h>
#ifndef SORTIX_KERNEL
#include <sys/syscall.h>
#endif
#include <stdint.h>
#include <string.h>
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); }

View file

@ -23,7 +23,6 @@
*******************************************************************************/
#define _WANT_ENVIRON
#include <libmaxsi/platform.h>
#include <sys/syscall.h>
#include <stdio.h>
#include <stdarg.h>
@ -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();
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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