How to access kernel memory in user mode

I allocated DMA memory in driver.
I tried to read DMA memory from application by getting the VirtAddress of DMA memory into user area (application) using ioctl but it failed.
(Segmentation fault (core dumped) error)

For windows, the memory allocated in the kernel area can be used in the user area using the MmMapLockedPagesSpecifyCache function.

Is there a function like MmMapLockedPagesSpecifyCache in linux as well?
How can I check the DMA memory allocated by the driver in the application program in the user area?

For the linux kernel you can use mmap()

https://man7.org/linux/man-pages/man2/mmap.2.html

Thank you for answering ShaneCCC.

I tried to read kernel memory from user area using mmap but it failed.

I allocated DMA memory using dma_alloc_coherent in driver code.
I want to read this memory in application.

My code is as below and when I check pUserAddr in application, it doesn’t contain any data. (all 0 or ff)
(dma is usually assigned to 0xff000000)

What am i doing wrong?
How can I check the DMA allocated from the kernel (driver) in the application (user area)?


driver


dma_addr_t* pdmaAddr;
void* pVirtAddr = dma_alloc_coherent(dev, Memsize, pdmaAddr, GFP_KERNEL);

unsigned char* pTmp = (unsigned char*) pVirtAddr ;
for(int i = 0; i < 10; i++)
{
*pTemp = i;
pTmep++;
}

long ioctl(strct file* filePtr, unsigned int cmd, unsigned long arg)
{
switch(cmd)
case IOCTL_GET_DMA_ADDR:
{
unsigned long DMAAddr;
DMAAddr = pdmaAddr;
if(copy_to_user((void __user*)arg, (void *)&DMAAddr, sizeof(unsigned long))
{
printk(KERN_INFO “copy_to_user error”);
}
}
}


user application


int devOpen = open("/dev/mydev", O_RDWR);
unsigned long DMAAddr;
ioctl(devOpen , IOCTL_GET_DMA_ADDR, &DMAAddr);

int fd = open("/dev/mem", O_RDWR);
void* pUserAddr = mmap( 0, Memsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, dmaAddr);

Your driver need to implement the .mmap like below reference.