Skip to content

Commit

Permalink
klibc: Use builtins for memcpy and similar
Browse files Browse the repository at this point in the history
  • Loading branch information
marv7000 committed Nov 24, 2024
1 parent 3810c3e commit 24fb1d0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 20 deletions.
7 changes: 1 addition & 6 deletions include/klibc/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@
#include <menix/common.h>

// Copies a string to a buffer. Both sizes must be known at compile time.
#define fixed_strncpy(dst, src) memcpy(dst, src, MIN(sizeof(dst), sizeof(src)));
#define fixed_strncpy(dst, src) memcpy(dst, src, MIN(sizeof(dst), sizeof(src)))

i32 memcmp(const void* s1, const void* s2, usize len);

// Copies `len` bytes from `src` to `dst`. Pointers may not overlap.
void* memcpy(void* restrict dst, const void* restrict src, usize len);

// Copies `len` 32-bit integers from `src` to `dst`. Pointers may not overlap.
void* memcpy32(void* restrict dst, const void* restrict src, usize len);

// Copies `len` bytes from `src` to `dst`.
void* memmove(void* dst, const void* src, usize len);

// Sets `len` bytes to `val`, starting at dst.
void* memset(void* dst, u8 val, usize len);

// Sets `len` 32-bit integers to `value`, starting at `dst`.
void* memset32(void* dst, u32 value, usize size);
usize strlen(const char* src);
usize strnlen(const char* src, usize len);
char* strdup(const char* src);
Expand Down
10 changes: 2 additions & 8 deletions kernel/system/video/fb_defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ void fb_default_draw_region(FrameBuffer* fb, FbDrawRegion* args)
void* addr_dst = (void*)fb->info.mmio_base + (mode->pitch * (args->y_src + y)) + (args->x_src * mode->cpp);

// Copy a single line.
if (mode->cpp == sizeof(u32))
memcpy32(addr_dst, addr_src, args->width);
else
memcpy(addr_dst, addr_src, args->width * mode->cpp);
memcpy(addr_dst, addr_src, args->width * mode->cpp);
}
}

Expand All @@ -82,9 +79,6 @@ void fb_default_update_region(FrameBuffer* fb, FbUpdateRegion* args)
const usize offset = ((mode->pitch * (args->y_src + y)) + (mode->cpp * (args->x_src)));

// Copy a single line.
if (mode->cpp == sizeof(u32))
memcpy32((void*)fb->info.mmio_base + offset, (void*)args->back_buffer + offset, args->width);
else
memcpy((void*)fb->info.mmio_base + offset, (void*)args->back_buffer + offset, args->width * mode->cpp);
memcpy((void*)fb->info.mmio_base + offset, (void*)args->back_buffer + offset, args->width * mode->cpp);
}
}
1 change: 0 additions & 1 deletion modules/drv/video/fbcon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ MODULE_FN void fbcon_putchar(u32 ch)

// Mark this region as modified. If we've exceeded the limit, force a redraw.
if (update_count >= UPDATE_QUEUE_MAX)

fbcon_copy_screen();
else
{
Expand Down
5 changes: 0 additions & 5 deletions toolchain/compiler/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
# Common options
target_compile_options(common INTERFACE
-ffreestanding
-nostdlib
-fno-omit-frame-pointer
-fno-builtin
-fno-stack-protector
-fno-stack-check
-Wall
-Werror
)
target_link_options(common INTERFACE
-nostdlib
"SHELL:-z max-page-size=${max_page_size}"
"SHELL:-z noexecstack"
-Wl,--build-id=none
)
Expand Down

0 comments on commit 24fb1d0

Please sign in to comment.