mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-24 23:23:58 +00:00
Start fixing things up to build with a proper cross-compiler.
This commit is contained in:
parent
42342d2337
commit
6788dcdb58
Notes:
sideshowbarker
2024-07-19 15:38:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6788dcdb583
4 changed files with 41 additions and 44 deletions
|
@ -8,7 +8,7 @@ namespace AK {
|
|||
inline void StringBuilder::will_append(size_t 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)
|
||||
|
|
|
@ -6,38 +6,41 @@
|
|||
|
||||
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) {
|
||||
mmx_memcpy(dest_ptr, src_ptr, n);
|
||||
return;
|
||||
return mmx_memcpy(dest_ptr, src_ptr, n);
|
||||
}
|
||||
|
||||
dword dest = (dword)dest_ptr;
|
||||
dword src = (dword)src_ptr;
|
||||
size_t dest = (size_t)dest_ptr;
|
||||
size_t src = (size_t)src_ptr;
|
||||
// FIXME: Support starting at an unaligned address.
|
||||
if (!(dest & 0x3) && !(src & 0x3) && n >= 12) {
|
||||
size_t dwords = n / sizeof(dword);
|
||||
size_t size_ts = n / sizeof(size_t);
|
||||
asm volatile(
|
||||
"rep movsl\n"
|
||||
: "=S"(src), "=D"(dest)
|
||||
: "S"(src), "D"(dest), "c"(dwords)
|
||||
: "S"(src), "D"(dest), "c"(size_ts)
|
||||
: "memory"
|
||||
);
|
||||
n -= dwords * sizeof(dword);
|
||||
n -= size_ts * sizeof(size_t);
|
||||
if (n == 0)
|
||||
return;
|
||||
return dest_ptr;
|
||||
}
|
||||
asm volatile(
|
||||
"rep movsb\n"
|
||||
:: "S"(src), "D"(dest), "c"(n)
|
||||
: "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)
|
||||
|
@ -50,22 +53,22 @@ char* strncpy(char* dest, const char* src, size_t n)
|
|||
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.
|
||||
if (!(dest & 0x3) && n >= 12) {
|
||||
size_t dwords = n / sizeof(dword);
|
||||
dword expanded_c = c;
|
||||
size_t size_ts = n / sizeof(size_t);
|
||||
size_t expanded_c = (byte)c;
|
||||
expanded_c |= expanded_c << 8;
|
||||
expanded_c |= expanded_c << 16;
|
||||
asm volatile(
|
||||
"rep stosl\n"
|
||||
: "=D"(dest)
|
||||
: "D"(dest), "c"(dwords), "a"(expanded_c)
|
||||
: "D"(dest), "c"(size_ts), "a"(expanded_c)
|
||||
: "memory"
|
||||
);
|
||||
n -= dwords * sizeof(dword);
|
||||
n -= size_ts * sizeof(size_t);
|
||||
if (n == 0)
|
||||
return dest_ptr;
|
||||
}
|
||||
|
@ -89,9 +92,9 @@ char* strrchr(const char* str, int ch)
|
|||
return last;
|
||||
}
|
||||
|
||||
dword strlen(const char* str)
|
||||
size_t strlen(const char* str)
|
||||
{
|
||||
dword len = 0;
|
||||
size_t len = 0;
|
||||
while (*(str++))
|
||||
++len;
|
||||
return len;
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include <Kernel/types.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
void memcpy(void*, const void*, dword);
|
||||
void strcpy(char*, const char*);
|
||||
static_assert(sizeof(size_t) == 4);
|
||||
|
||||
void* memcpy(void*, const void*, size_t);
|
||||
char* strcpy(char*, const char*);
|
||||
char* strncpy(char*, const char*, size_t);
|
||||
int strcmp(char const*, const char*);
|
||||
size_t strlen(const char*);
|
||||
void *memset(void*, byte, dword);
|
||||
void* memset(void*, int, size_t);
|
||||
char *strdup(const char*);
|
||||
int memcmp(const void*, const void*, size_t);
|
||||
char* strrchr(const char* str, int ch);
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
#define SANITIZE_KMALLOC
|
||||
|
||||
struct [[gnu::packed]] allocation_t {
|
||||
dword start;
|
||||
dword nchunk;
|
||||
size_t start;
|
||||
size_t nchunk;
|
||||
};
|
||||
|
||||
#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)
|
||||
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()
|
||||
|
@ -69,7 +69,7 @@ void* kmalloc_eternal(size_t size)
|
|||
void* kmalloc_aligned(size_t size, size_t alignment)
|
||||
{
|
||||
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)[-1] = ptr;
|
||||
|
@ -84,18 +84,18 @@ void kfree_aligned(void* ptr)
|
|||
void* kmalloc_page_aligned(size_t size)
|
||||
{
|
||||
void* ptr = kmalloc_aligned(size, PAGE_SIZE);
|
||||
dword d = (dword)ptr;
|
||||
size_t d = (size_t)ptr;
|
||||
ASSERT((d & PAGE_MASK) == d);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* kmalloc_impl(dword size)
|
||||
void* kmalloc_impl(size_t size)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
||||
dword chunks_needed, chunks_here, first_chunk;
|
||||
dword real_size;
|
||||
dword i, j, k;
|
||||
size_t chunks_needed, chunks_here, first_chunk;
|
||||
size_t real_size;
|
||||
size_t i, j, k;
|
||||
|
||||
/* We need space for the allocation_t structure at the head of the block. */
|
||||
real_size = size + sizeof(allocation_t);
|
||||
|
@ -174,16 +174,8 @@ void kfree(void *ptr)
|
|||
|
||||
allocation_t *a = (allocation_t *)((((byte *)ptr) - sizeof(allocation_t)));
|
||||
|
||||
#if 0
|
||||
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) {
|
||||
for (size_t k = a->start; k < (a->start + a->nchunk); ++k)
|
||||
alloc_map[k / 8] &= ~(1 << (k % 8));
|
||||
}
|
||||
|
||||
sum_alloc -= a->nchunk * CHUNK_SIZE;
|
||||
sum_free += a->nchunk * CHUNK_SIZE;
|
||||
|
@ -213,12 +205,12 @@ void operator delete[](void* ptr)
|
|||
return kfree(ptr);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr, unsigned int)
|
||||
void operator delete(void* ptr, size_t)
|
||||
{
|
||||
return kfree(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr, unsigned int)
|
||||
void operator delete[](void* ptr, size_t)
|
||||
{
|
||||
return kfree(ptr);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue