LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-09-2017, 01:10 AM   #1
control3@medhaindia.com
LQ Newbie
 
Registered: Dec 2017
Posts: 2

Rep: Reputation: Disabled
problem in mmap b/w user and kernel space


am trying to mmap some memory b/w user space and kernel space so that I can use it as a shared memory area.

I tried a sample code from internet in which the following functions were used.

1. mem_map_reserve(page);

2. remap_page_range(start, page, PAGE_SIZE, PAGE_SHARED))


and an include file #include <linux/wrapper.h> was used.


If I compile the same code for imx6 i am getting <linux/wrapper.h> - no such file error , if I am not including the file - i am getting an error - implicit declaration of remap_page_range()


Please let me know which include i have to use to eliminate the error or is there any better way to mmap some memory between user and kernel space.

Thanks in advance.

Vijesh.
 
Old 12-12-2017, 08:51 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,599
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
I don't think that you can do what you have in mind. You can only communicate with a user process in user space. Kernel space is accessible only to the kernel. User space is accessible to user processes and is referenced through the virtual-memory hardware since all addresses there are virtual.

Even if the kernel reserves a buffer in kernel-space, e.g. as a ring-buffer or for DMA purposes, it must move data to-and-from the user-space of a specified process. It cannot give that process direct access to the buffer in kernel space, AFAIK.

Last edited by sundialsvcs; 12-12-2017 at 08:53 AM.
 
Old 12-13-2017, 03:46 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Do you want to share the memory between multiple processes and the kernel or is it only one process and the kernel? If that's the second case, you can allocate the memory in the user space, pass it to kernel and then use get_user_pages()
 
Old 12-15-2017, 01:33 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,599
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
Quote:
Originally Posted by Mara View Post
Do you want to share the memory between multiple processes and the kernel or is it only one process and the kernel? If that's the second case, you can allocate the memory in the user space, pass it to kernel and then use get_user_pages()
And this is ordinarily what is done: the application program allocates some buffer, either with malloc() or maybe some form of shmget(), then provides that to the kernel. The kernel, always suspiciously verifying that the specified area is legitimate, retrieves the data from this area. (It is important to remember that this can involve virtual-memory paging.)
 
Old 01-01-2018, 12:56 PM   #5
cirosantilli
LQ Newbie
 
Registered: Nov 2012
Posts: 4

Rep: Reputation: Disabled
Have a look at: https://stackoverflow.com/questions/...-to-user-space

I have provided a minimal runnable example at: https://github.com/cirosantilli/linu..._module/mmap.c
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to correctly mmap DMA buffer in user space. dkwan Linux - Kernel 10 07-11-2011 02:17 PM
mmap to overlay VME bus into kernel space memory over a PCI? IanVaughan Programming 0 07-31-2009 09:17 AM
linux driver how to mmap many kernel address to user space soararing Programming 1 05-22-2008 05:32 AM
How do you MMAP PCI Configurations Space to User Space jbreaka4lyfe Linux - Kernel 0 03-03-2008 01:15 PM
Mmap and munmap physical address to user space karttik Linux - Software 0 10-28-2007 02:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 10:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration