link files in mock to platform/kernel/

This commit is contained in:
Alireza moradi 2026-01-05 00:52:22 +03:30 committed by alish14
parent 1eb72d1621
commit a25f81483c
7 changed files with 1117 additions and 5 deletions

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,49 @@
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "../header/Mem.h"
#ifdef __linux__
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/string.h>
#include "../header/module_info.h"
void* MemAllocKernel(size_t Size)
{
void* ptr = kzalloc(Size, GFP_KERNEL);
if (ptr)
printk(KERN_INFO "MemAllocKernel: Allocated %zu bytes at %px\n", Size, ptr);
else
printk(KERN_ERR "MemAllocKernel: failed to allocate %zu bytes\n", Size);
return ptr;
}
void MemFree(void* Ptr)
{
if (Ptr) {
printk(KERN_INFO "MemFree: Freeing memory at %px\n", Ptr);
kfree(Ptr);
}
}
void MemCopy(void* Destination, const void* Source, size_t Size)
{
memcpy(Destination, Source, Size);
}
void MemSet(void* Destination, int Value, size_t Size)
{
memset(Destination, Value, Size);
}
#elif defined(_WIN32)
#include "pch.h"
/**
@ -87,3 +130,7 @@ PlatformMemFreePool(PVOID BufferAddress)
{
ExFreePoolWithTag(BufferAddress, POOLTAG);
}
#else
#error "Unsupported platform"
#endif

Binary file not shown.

View file

@ -19,6 +19,14 @@
//
// Some functions are globally defined in SDK
//
#ifdef __linux__
#include <linux/types.h>
void* MemAllocKernel(size_t Size);
void MemFree(void* Ptr);
void MemCopy(void* Destination, const void* Source, size_t Size);
void MemSet(void* Destination, int Value, size_t Size);
#elif defined(_WIN32)
PVOID
PlatformMemAllocateContiguousZeroedMemory(SIZE_T NumberOfBytes);
@ -37,3 +45,6 @@ PlatformMemAllocateZeroedNonPagedPool(SIZE_T NumberOfBytes);
VOID
PlatformMemFreePool(PVOID BufferAddress);
#else
#error "Unsupported platform"
#endif

View file

@ -0,0 +1,13 @@
// module_info.h
#ifndef MODULE_INFO_H
#define MODULE_INFO_H
#include <linux/module.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Alish");
MODULE_DESCRIPTION("Linux Kernel module Mock");
MODULE_VERSION("0.1");
#endif // _MODULE_INFO_H_

View file

@ -1,10 +1,13 @@
obj-m += mymodule.o
mymodule-objs := mock.o mem.o
mymodule-objs := mock.o \
../../include/platform/kernel/code/Mem.o
PWD := $(CURDIR)
KDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
EXTRA_CFLAGS += -I$(PWD)/../../include/platform/kernel/header
all:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
$(MAKE) -C $(KDIR) M=$(PWD) clean

View file

@ -3,7 +3,7 @@
#include <linux/slab.h>
#include <linux/string.h>
#include "module_info.h"
#include "mem.h"
#include "../../include/platform/kernel/header/Mem.h"
static void* g_AllocatedBuffer;