私はこれをカーネルモジュールに持っています:
/*global scope declared*/
static int array[10]={1,2,3,4,5,6,7,8,9,10};
そして、open close read と write の関数が完全に機能するのでarray[8]
、このページの下部にあるユーザー空間アプリケーションと共有したいと思います。
カーネルモジュールで:
static int *my_mmap (struct file *filep, struct vm_area_struct *vma ) {
if (remap_pfn_range(vma,
vma->vm_start,
virt_to_phys(array)>> PAGE_SHIFT,
10,
vma->vm_page_prot) < 0) {
printk("remap_pfn_range failed\n");
return -EIO;
}
return 0;
ユーザー空間のソース コード内のアプリケーション:
#define LEN (64*1024)
/* prototype for thread routine */
#define FILE_PATH "/dev/my_module"
int main()
{
int i=0;
int fd = open(FILE_PATH,O_RDWR);
int* vadr = mmap(0, LEN, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
for (i=0;i<10;++i){
printf("%d",*(vadr+i));
}
return 0;
}