Skip to content

Commit

Permalink
x86/copy: Add memset symbol size
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
  • Loading branch information
heatd committed Apr 9, 2023
1 parent 98f58a4 commit f684524
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion kernel/arch/arm64/make.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ KERNEL_ARCH_LDFLAGS:=-z max-page-size=0x1000
# ARM64 has no crti.o nor crtn.o
ARCH_NO_CRTI_N:=1

LIBK_ARCH_OBJS:= string/memcpy.o
LIBK_ARCH_OBJS:= string/memcpy.o string/memset.o
2 changes: 1 addition & 1 deletion kernel/arch/riscv64/make.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ KERNEL_ARCH_LDFLAGS:=-z max-page-size=0x1000
# RISCV has no crti.o nor crtn.o
ARCH_NO_CRTI_N:=1

LIBK_ARCH_OBJS:= string/memcpy.o
LIBK_ARCH_OBJS:= string/memcpy.o string/memset.o
2 changes: 1 addition & 1 deletion kernel/arch/riscv64/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extern "C" void thread_finish_destruction(void *___thread)

thread_remove_from_list(thread);

memset_s(&thread->lock, 0x80, sizeof(struct spinlock));
memset_explicit(&thread->lock, 0x80, sizeof(struct spinlock));
((volatile struct thread *) thread)->canary = THREAD_DEAD_CANARY;
/* Free the thread */
delete thread;
Expand Down
11 changes: 8 additions & 3 deletions kernel/arch/x86_64/copy.S
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ __set_non_temporal:

RET

.global memset
.type memset, @function
memset:
.global __memset
.type __memset, @function
__memset:
push %rbp
mov %rsp, %rbp

Expand All @@ -104,3 +104,8 @@ memset:

pop %rbp
RET

.size __memset, . - __memset

.weak memset
.set memset, __memset
2 changes: 1 addition & 1 deletion kernel/arch/x86_64/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ extern "C" void thread_finish_destruction(void *___thread)

thread_remove_from_list(thread);

memset_s(&thread->lock, 0x80, sizeof(struct spinlock));
memset_explicit(&thread->lock, 0x80, sizeof(struct spinlock));
((volatile struct thread *) thread)->canary = THREAD_DEAD_CANARY;
/* Free the thread */
delete thread;
Expand Down
2 changes: 1 addition & 1 deletion kernel/kernel/mm/pagealloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void page_node::add_region(uintptr_t base, size_t size)
size_t area_size = min(size, arena_default_size);
struct page_arena *arena = (struct page_arena *) __ksbrk(sizeof(struct page_arena));
assert(arena != NULL);
memset_s(arena, 0, sizeof(struct page_arena));
memset_explicit(arena, 0, sizeof(struct page_arena));

arena->start_arena = (void *) base;
arena->end_arena = (void *) (base + area_size);
Expand Down
2 changes: 1 addition & 1 deletion kernel/kernel/mm/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void vm_region_destroy(struct vm_region *region)
vmo_unref(region->vmo);
}

memset_s(region, 0xfd, sizeof(struct vm_region));
memset_explicit(region, 0xfd, sizeof(struct vm_region));

vm_free_vmregion(region);
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/lib/libk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ LIBK_OBJS:=\
stdio/printf.o \
stdio/puts.o \
string/memcmp.o \
string/memset.o \
string/memset_explicit.o \
string/strlen.o \
string/strcpy.o \
string/strcmp.o \
Expand Down
1 change: 1 addition & 0 deletions kernel/lib/libk/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void *__memcpy(void *__restrict dest, const void *__restrict src, size_t len);
void *__memmove(void *dest, const void *src, size_t len);

void *memset (void *, int, size_t);
void *memset_explicit(void *s, int c, size_t n);
void explicit_bzero(void *ptr, size_t size);
int memcmp (const void *, const void *, size_t);
void *memchr (const void *, int, size_t);
Expand Down
3 changes: 0 additions & 3 deletions kernel/lib/libk/include/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ char *index (const char *, int);
char *rindex (const char *, int);
#endif

/* Non standard memset_s */
void *memset_s(void *s, int c, size_t n);

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
int ffs (int);
int ffsl (long);
Expand Down
5 changes: 0 additions & 5 deletions kernel/lib/libk/string/memset.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,3 @@ void *__memset(void *bufptr, int value, size_t size)
}

weak_alias(__memset, memset);

void *memset_s(void *s, int c, size_t n)
{
return memset(s, c, n);
}
16 changes: 16 additions & 0 deletions kernel/lib/libk/string/memset_explicit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2016 - 2023 Pedro Falcato
* This file is part of Onyx, and is released under the terms of the MIT License
* check LICENSE at the root directory for more information
*
* SPDX-License-Identifier: MIT
*/

#include <string.h>

void *memset_explicit(void *s, int c, size_t n)
{
void *dest = memset(s, c, n);
__asm__ __volatile__("" ::"r"(dest) : "memory");
return dest;
}

0 comments on commit f684524

Please sign in to comment.