added recent changes
This commit is contained in:
5
KernelModule/Hugepages/Makefile
Normal file
5
KernelModule/Hugepages/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
KMOD= superpage
|
||||
SRCS= superpage.c
|
||||
|
||||
.include <bsd.kmod.mk>
|
||||
|
||||
0
KernelModule/Hugepages/build
Normal file
0
KernelModule/Hugepages/build
Normal file
6
KernelModule/Hugepages/build.sh
Normal file
6
KernelModule/Hugepages/build.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
cc -O2 -pipe -march=morello -Xclang -morello-vararg=new -Xclang -morello-bounded-memargs=caller-only -mabi=purecap-benchmark -D__LP64__=1 -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc -include /usr/home/akilan/Alloc-Test/CHERI-Allocator/KernelModule/Hugepages/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -fdebug-prefix-map=./machine=/usr/src/sys/arm64/include -MD -MF.depend.superpage.o -MTsuperpage.o -mgeneral-regs-only -ffixed-x18 -march=morello -Xclang -morello-vararg=new -Xclang -morello-bounded-memargs=caller-only -mabi=purecap -ffreestanding -fwrapv -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length -Werror=implicit-function-declaration -std=gnu99 -c superpage.c -o superpage.o
|
||||
|
||||
ld -m aarch64elf_cheri -d -warn-common --build-id=sha1 --no-relax --morello-c64-plt -r -o superpage.kld superpage.o
|
||||
:> export_syms
|
||||
|
||||
objcopy --strip-debug superpage.ko
|
||||
4
KernelModule/Hugepages/meson.build
Normal file
4
KernelModule/Hugepages/meson.build
Normal file
@@ -0,0 +1,4 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# Copyright(c) 2017 Intel Corporation
|
||||
|
||||
sources = files('superpage.c')
|
||||
59
KernelModule/Hugepages/superpage.c
Normal file
59
KernelModule/Hugepages/superpage.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/systm.h>
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_extern.h>
|
||||
#include <vm/vm_page.h>
|
||||
#include <vm/vm_kern.h>
|
||||
|
||||
#define HUGE_PAGE_SIZE (2 * 1024 * 1024) // 2MB Huge Page
|
||||
|
||||
static void *hugepage_ptr = NULL;
|
||||
|
||||
// Load function - allocate memory
|
||||
static int load_handler(module_t mod, int event, void *arg) {
|
||||
switch (event) {
|
||||
case MOD_LOAD:
|
||||
printf("Loading Huge Page Kernel Module...\n");
|
||||
|
||||
// Allocate contiguous memory
|
||||
hugepage_ptr = kmem_alloc_contig(HUGE_PAGE_SIZE, M_NOWAIT,
|
||||
VM_MIN_KERNEL_ADDRESS, VM_MAX_KERNEL_ADDRESS,
|
||||
HUGE_PAGE_SIZE, 0,
|
||||
VM_MEMATTR_DEFAULT);
|
||||
|
||||
if (hugepage_ptr == NULL) {
|
||||
printf("Failed to allocate a huge page!\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
printf("Huge page allocated at %p\n", hugepage_ptr);
|
||||
break;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
printf("Unloading Huge Page Kernel Module...\n");
|
||||
|
||||
// Free memory if allocated
|
||||
if (hugepage_ptr) {
|
||||
kmem_free(hugepage_ptr, HUGE_PAGE_SIZE);
|
||||
printf("Huge page freed.\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Register module
|
||||
static moduledata_t superpage_mod = {
|
||||
"superpage", // Module name
|
||||
load_handler,
|
||||
NULL
|
||||
};
|
||||
|
||||
DECLARE_MODULE(superpage, superpage_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
|
||||
|
||||
Reference in New Issue
Block a user