mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
Start fixing things up to build with a proper cross-compiler.
This commit is contained in:
parent
42342d2337
commit
6788dcdb58
4 changed files with 41 additions and 44 deletions
|
@ -8,7 +8,7 @@ namespace AK {
|
||||||
inline void StringBuilder::will_append(size_t size)
|
inline void StringBuilder::will_append(size_t size)
|
||||||
{
|
{
|
||||||
if ((m_length + size) > m_buffer.size())
|
if ((m_length + size) > m_buffer.size())
|
||||||
m_buffer.grow(max(16u, m_buffer.size() * 2 + size));
|
m_buffer.grow(max((size_t)16, m_buffer.size() * 2 + size));
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder::StringBuilder(size_t initial_capacity)
|
StringBuilder::StringBuilder(size_t initial_capacity)
|
||||||
|
|
|
@ -6,38 +6,41 @@
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void memcpy(void* dest_ptr, const void* src_ptr, dword n)
|
void* memcpy(void* dest_ptr, const void* src_ptr, size_t n)
|
||||||
{
|
{
|
||||||
if (n >= 1024) {
|
if (n >= 1024) {
|
||||||
mmx_memcpy(dest_ptr, src_ptr, n);
|
return mmx_memcpy(dest_ptr, src_ptr, n);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dword dest = (dword)dest_ptr;
|
size_t dest = (size_t)dest_ptr;
|
||||||
dword src = (dword)src_ptr;
|
size_t src = (size_t)src_ptr;
|
||||||
// FIXME: Support starting at an unaligned address.
|
// FIXME: Support starting at an unaligned address.
|
||||||
if (!(dest & 0x3) && !(src & 0x3) && n >= 12) {
|
if (!(dest & 0x3) && !(src & 0x3) && n >= 12) {
|
||||||
size_t dwords = n / sizeof(dword);
|
size_t size_ts = n / sizeof(size_t);
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"rep movsl\n"
|
"rep movsl\n"
|
||||||
: "=S"(src), "=D"(dest)
|
: "=S"(src), "=D"(dest)
|
||||||
: "S"(src), "D"(dest), "c"(dwords)
|
: "S"(src), "D"(dest), "c"(size_ts)
|
||||||
: "memory"
|
: "memory"
|
||||||
);
|
);
|
||||||
n -= dwords * sizeof(dword);
|
n -= size_ts * sizeof(size_t);
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return;
|
return dest_ptr;
|
||||||
}
|
}
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"rep movsb\n"
|
"rep movsb\n"
|
||||||
:: "S"(src), "D"(dest), "c"(n)
|
:: "S"(src), "D"(dest), "c"(n)
|
||||||
: "memory"
|
: "memory"
|
||||||
);
|
);
|
||||||
|
return dest_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void strcpy(char* dest, const char *src)
|
char* strcpy(char* dest, const char *src)
|
||||||
{
|
{
|
||||||
while ((*dest++ = *src++) != '\0');
|
auto* dest_ptr = dest;
|
||||||
|
auto* src_ptr = src;
|
||||||
|
while ((*dest_ptr++ = *src_ptr++) != '\0');
|
||||||
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* strncpy(char* dest, const char* src, size_t n)
|
char* strncpy(char* dest, const char* src, size_t n)
|
||||||
|
@ -50,22 +53,22 @@ char* strncpy(char* dest, const char* src, size_t n)
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* memset(void* dest_ptr, byte c, dword n)
|
void* memset(void* dest_ptr, int c, size_t n)
|
||||||
{
|
{
|
||||||
dword dest = (dword)dest_ptr;
|
size_t dest = (size_t)dest_ptr;
|
||||||
// FIXME: Support starting at an unaligned address.
|
// FIXME: Support starting at an unaligned address.
|
||||||
if (!(dest & 0x3) && n >= 12) {
|
if (!(dest & 0x3) && n >= 12) {
|
||||||
size_t dwords = n / sizeof(dword);
|
size_t size_ts = n / sizeof(size_t);
|
||||||
dword expanded_c = c;
|
size_t expanded_c = (byte)c;
|
||||||
expanded_c |= expanded_c << 8;
|
expanded_c |= expanded_c << 8;
|
||||||
expanded_c |= expanded_c << 16;
|
expanded_c |= expanded_c << 16;
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"rep stosl\n"
|
"rep stosl\n"
|
||||||
: "=D"(dest)
|
: "=D"(dest)
|
||||||
: "D"(dest), "c"(dwords), "a"(expanded_c)
|
: "D"(dest), "c"(size_ts), "a"(expanded_c)
|
||||||
: "memory"
|
: "memory"
|
||||||
);
|
);
|
||||||
n -= dwords * sizeof(dword);
|
n -= size_ts * sizeof(size_t);
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return dest_ptr;
|
return dest_ptr;
|
||||||
}
|
}
|
||||||
|
@ -89,9 +92,9 @@ char* strrchr(const char* str, int ch)
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
dword strlen(const char* str)
|
size_t strlen(const char* str)
|
||||||
{
|
{
|
||||||
dword len = 0;
|
size_t len = 0;
|
||||||
while (*(str++))
|
while (*(str++))
|
||||||
++len;
|
++len;
|
||||||
return len;
|
return len;
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include <Kernel/types.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void memcpy(void*, const void*, dword);
|
static_assert(sizeof(size_t) == 4);
|
||||||
void strcpy(char*, const char*);
|
|
||||||
|
void* memcpy(void*, const void*, size_t);
|
||||||
|
char* strcpy(char*, const char*);
|
||||||
char* strncpy(char*, const char*, size_t);
|
char* strncpy(char*, const char*, size_t);
|
||||||
int strcmp(char const*, const char*);
|
int strcmp(char const*, const char*);
|
||||||
size_t strlen(const char*);
|
size_t strlen(const char*);
|
||||||
void *memset(void*, byte, dword);
|
void* memset(void*, int, size_t);
|
||||||
char *strdup(const char*);
|
char *strdup(const char*);
|
||||||
int memcmp(const void*, const void*, size_t);
|
int memcmp(const void*, const void*, size_t);
|
||||||
char* strrchr(const char* str, int ch);
|
char* strrchr(const char* str, int ch);
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#define SANITIZE_KMALLOC
|
#define SANITIZE_KMALLOC
|
||||||
|
|
||||||
struct [[gnu::packed]] allocation_t {
|
struct [[gnu::packed]] allocation_t {
|
||||||
dword start;
|
size_t start;
|
||||||
dword nchunk;
|
size_t nchunk;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CHUNK_SIZE 64
|
#define CHUNK_SIZE 64
|
||||||
|
@ -41,7 +41,7 @@ bool is_kmalloc_address(const void* ptr)
|
||||||
{
|
{
|
||||||
if (ptr >= (byte*)ETERNAL_BASE_PHYSICAL && ptr < s_next_eternal_ptr)
|
if (ptr >= (byte*)ETERNAL_BASE_PHYSICAL && ptr < s_next_eternal_ptr)
|
||||||
return true;
|
return true;
|
||||||
return (dword)ptr >= BASE_PHYSICAL && (dword)ptr <= (BASE_PHYSICAL + POOL_SIZE);
|
return (size_t)ptr >= BASE_PHYSICAL && (size_t)ptr <= (BASE_PHYSICAL + POOL_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kmalloc_init()
|
void kmalloc_init()
|
||||||
|
@ -69,7 +69,7 @@ void* kmalloc_eternal(size_t size)
|
||||||
void* kmalloc_aligned(size_t size, size_t alignment)
|
void* kmalloc_aligned(size_t size, size_t alignment)
|
||||||
{
|
{
|
||||||
void* ptr = kmalloc(size + alignment + sizeof(void*));
|
void* ptr = kmalloc(size + alignment + sizeof(void*));
|
||||||
dword max_addr = (dword)ptr + alignment;
|
size_t max_addr = (size_t)ptr + alignment;
|
||||||
void* aligned_ptr = (void*)(max_addr - (max_addr % alignment));
|
void* aligned_ptr = (void*)(max_addr - (max_addr % alignment));
|
||||||
|
|
||||||
((void**)aligned_ptr)[-1] = ptr;
|
((void**)aligned_ptr)[-1] = ptr;
|
||||||
|
@ -84,18 +84,18 @@ void kfree_aligned(void* ptr)
|
||||||
void* kmalloc_page_aligned(size_t size)
|
void* kmalloc_page_aligned(size_t size)
|
||||||
{
|
{
|
||||||
void* ptr = kmalloc_aligned(size, PAGE_SIZE);
|
void* ptr = kmalloc_aligned(size, PAGE_SIZE);
|
||||||
dword d = (dword)ptr;
|
size_t d = (size_t)ptr;
|
||||||
ASSERT((d & PAGE_MASK) == d);
|
ASSERT((d & PAGE_MASK) == d);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* kmalloc_impl(dword size)
|
void* kmalloc_impl(size_t size)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
|
|
||||||
dword chunks_needed, chunks_here, first_chunk;
|
size_t chunks_needed, chunks_here, first_chunk;
|
||||||
dword real_size;
|
size_t real_size;
|
||||||
dword i, j, k;
|
size_t i, j, k;
|
||||||
|
|
||||||
/* We need space for the allocation_t structure at the head of the block. */
|
/* We need space for the allocation_t structure at the head of the block. */
|
||||||
real_size = size + sizeof(allocation_t);
|
real_size = size + sizeof(allocation_t);
|
||||||
|
@ -174,16 +174,8 @@ void kfree(void *ptr)
|
||||||
|
|
||||||
allocation_t *a = (allocation_t *)((((byte *)ptr) - sizeof(allocation_t)));
|
allocation_t *a = (allocation_t *)((((byte *)ptr) - sizeof(allocation_t)));
|
||||||
|
|
||||||
#if 0
|
for (size_t k = a->start; k < (a->start + a->nchunk); ++k)
|
||||||
dword hdr = (dword)a;
|
|
||||||
dword mhdr = hdr & ~0x7;
|
|
||||||
kprintf("hdr / mhdr %p / %p\n", hdr, mhdr);
|
|
||||||
ASSERT(hdr == mhdr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (dword k = a->start; k < (a->start + a->nchunk); ++k) {
|
|
||||||
alloc_map[k / 8] &= ~(1 << (k % 8));
|
alloc_map[k / 8] &= ~(1 << (k % 8));
|
||||||
}
|
|
||||||
|
|
||||||
sum_alloc -= a->nchunk * CHUNK_SIZE;
|
sum_alloc -= a->nchunk * CHUNK_SIZE;
|
||||||
sum_free += a->nchunk * CHUNK_SIZE;
|
sum_free += a->nchunk * CHUNK_SIZE;
|
||||||
|
@ -213,12 +205,12 @@ void operator delete[](void* ptr)
|
||||||
return kfree(ptr);
|
return kfree(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void* ptr, unsigned int)
|
void operator delete(void* ptr, size_t)
|
||||||
{
|
{
|
||||||
return kfree(ptr);
|
return kfree(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete[](void* ptr, unsigned int)
|
void operator delete[](void* ptr, size_t)
|
||||||
{
|
{
|
||||||
return kfree(ptr);
|
return kfree(ptr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue