Skip to content

Commit

Permalink
slab: Convert to C
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Falcato <[email protected]>
  • Loading branch information
heatd committed Aug 19, 2024
1 parent 9eadf43 commit 56025df
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 125 deletions.
4 changes: 4 additions & 0 deletions kernel/include/onyx/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ struct cpu_message
struct list_head node;
};

__BEGIN_CDECLS

void cpu_identify();
void cpu_init_late();
unsigned int get_nr_cpus();
Expand All @@ -347,6 +349,8 @@ void cpu_messages_init(unsigned int cpu);
void *cpu_handle_messages(void *stack);
void *cpu_resched(void *stack);

__END_CDECLS

/* CPU messages */
#define CPU_KILL (unsigned long) -1
#define CPU_TRY_RESCHED (unsigned long) 0
Expand Down
14 changes: 10 additions & 4 deletions kernel/include/onyx/cpumask.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#ifndef _ONYX_CPUMASK_H
#define _ONYX_CPUMASK_H

#ifndef CONFIG_SMP_NR_CPUS
#define CONFIG_SMP_NR_CPUS 64
#endif
#include <string.h>

struct cpumask
{
Expand All @@ -17,7 +15,7 @@ struct cpumask
unsigned long mask[CPUMASK_SIZE];

#ifdef __cplusplus
explicit constexpr cpumask() : mask{}
constexpr cpumask() : mask{}
{
}

Expand Down Expand Up @@ -200,4 +198,12 @@ struct cpumask
#endif
};

static inline struct cpumask cpumask_all_but_one(unsigned long cpu)
{
struct cpumask c;
memset(&c, 0xff, sizeof(c));
c.mask[cpu / LONG_SIZE_BITS] &= ~(1UL << (cpu % LONG_SIZE_BITS));
return c;
}

#endif
18 changes: 8 additions & 10 deletions kernel/include/onyx/mm/kasan.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,23 @@
#include <stddef.h>
#include <stdint.h>

#include <onyx/compiler.h>

__BEGIN_CDECLS

void kasan_init();
int kasan_alloc_shadow(unsigned long addr, size_t size, bool accessible);

#ifdef __cplusplus
extern "C"
#endif
void
kasan_set_state(unsigned long *ptr, size_t size, int state);
void kasan_set_state(unsigned long *ptr, size_t size, int state);
void asan_unpoison_shadow(unsigned long addr, size_t size);
void asan_poison_shadow(unsigned long addr, size_t size, uint8_t value);

/**
* @brief Flush the KASAN memory quarantine
*
*/
#ifdef __cplusplus
extern "C"
#endif
void
kasan_flush_quarantine();

void kasan_flush_quarantine();

/**
* @brief Add a chunk to the KASAN quarantine
Expand All @@ -58,4 +55,5 @@ size_t kasan_get_redzone_size(size_t objsize);
#define KASAN_QUARANTINED 0x9e
#define KASAN_LEFT_REDZONE 0xfa

__END_CDECLS
#endif
21 changes: 15 additions & 6 deletions kernel/include/onyx/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

#include <stddef.h>

#include <onyx/cpumask.h>
#include <onyx/limits.h>
#include <onyx/percpu.h>

#ifdef __cplusplus
#define SYNC_CALL_NOWAIT (1 << 0)

#include <onyx/cpumask.h>
typedef void (*sync_call_func)(void *context);

#ifdef __cplusplus

namespace smp
{
Expand All @@ -27,10 +30,6 @@ unsigned int get_online_cpus();

void boot_cpus();

using sync_call_func = void (*)(void *context);

#define SYNC_CALL_NOWAIT (1 << 0)

/**
* @brief Calls f on every CPU
*
Expand Down Expand Up @@ -89,6 +88,16 @@ __attribute__((always_inline)) static inline unsigned int get_cpu_nr()
void smp_parse_cpus(void *madt);
void smp_boot_cpus();

/**
* @brief Calls f on every CPU
*
* @param f The function to call on every cpu
* @param context Context to get passed to f
* @param mask Mask of cpus that will execute this
* @param flags Flags for the sync call
*/
void smp_sync_call(sync_call_func f, void *context, const struct cpumask *mask, unsigned int flags);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions kernel/include/onyx/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ __END_CDECLS
__auto_type __y = y; \
__x > __y ? __x : __y; \
})

#define align_up2(number, alignment) (((number) + ((alignment) -1)) & -(alignment))
#else

template <typename Type>
Expand Down
2 changes: 1 addition & 1 deletion kernel/kernel/mm/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mm-y:= bootmem.o page.o pagealloc.o vm_object.o vm.o vmalloc.o reclaim.o anon.o mincore.o page_lru.o swap.o rmap.o
mm-y:= bootmem.o page.o pagealloc.o vm_object.o vm.o vmalloc.o reclaim.o anon.o mincore.o page_lru.o swap.o rmap.o slab_cache_pool.o
mm-$(CONFIG_KUNIT)+= vm_tests.o
mm-$(CONFIG_X86)+= memory.o
mm-$(CONFIG_RISCV)+= memory.o
Expand Down
Loading

0 comments on commit 56025df

Please sign in to comment.