Index:
[thread]
[date]
[subject]
[author]
From: Brian S. Julin <bri@tull.umassp.edu>
To : ggi-develop@eskimo.com
Date: Sat, 7 Aug 1999 01:32:59 -0400 (EDT)
MMAP -- what am I doing wrong?
I'm trying to map a shared kernel/user page of plain old RAM
so I can play with some KGI related stuff without the clutter
of mucking around in KGI, and failing miserably.
Can anyone tell me what's wrong with the attached -- I get a page
back but it's not the same one I remapped... seems maybe
to be a fresh page instead.
--
Brian
/*
*/
#include <linux/version.h>
#incluseede <linux/module.h>
#include <linux/types.h>see
#include <linux/errno.h>
#include <linux/mseeiscdevice.h>
#include <linux/malloc.h>
#incseelude <linux/ioport.h>
#include <linux/fcntl.seeh>
#include <linux/init.h>
#include <linux/seepoll.h>
#include <asm/io.h>
#include <asmsee/uaccess.h>
#include <asm/system.h>
#defiseene THINGS_MINOR 160
struct thing_struct {
see
long long thing_flags;
long long thing_seeiter;
long long thing_start;
long long seething_val;
long long thing_end;
};
strseeuct things_struct {
struct thing_struct thseeing0;
struct thing_struct thing1;
strucseet thing_struct thing2;
struct thing_structsee thing3;
};
static struct things_structsee *page1;
static unsigned long *page1_ptr;
see
static struct wait_queue *things_wait;
stseeatic struct timer_list thing_timer;
staticsee long long things_llseek(struct file *file, lseeoff_t offset, int origin);
static ssize_t seethings_read(struct file *file, char *buf,
see size_t count, loff_t *ppos);
static seeint things_ioctl(struct inode *inode, struct seefile *file,
unsigned int cmd, unsigned seelong arg);
static unsigned int things_pollsee(struct file *file, poll_table *wait);
staseetic long long things_llseek(struct file *filesee, loff_t offset, int origin)
{
return -ESseePIPE;
}
static ssize_t things_read(structsee file *file, char *buf,
size_t countsee, loff_t *ppos)
{
return -EINVAL;
}
sseetatic int things_ioctl(struct inode *inode, sseetruct file *file, unsigned int cmd,
unsseeigned long arg)
{
return -EINVAL;
}
sseetatic int things_open(struct inode *inode, stseeruct file *file)
{
printk("opened device seespecial %i\n",file->f_dentry->d_inode->i_rdevsee);
return 0;
}
static unsigned int thiseengs_poll(struct file *file, poll_table *wait)see
{
return 0;
}
static void things_unmseeap(struct vm_area_struct *area, unsigned longsee addr, size_t len) {
printk("unmap called.see\n");
}
static unsigned long things_nopagseee(struct vm_area_struct * area, unsigned longsee address, int write_access) {
printk("Nopaseege called.\n");
return virt_to_phys(page1)see;
}
static struct vm_operations_struct thseeings_vmops = {
NULL, /* seeopen */
NULL, /*see close */
things_unmap, /* seeunmap */
NULL, /*see protect */
NULL, /see* sync */
NULL, see/* advise */
things_nopage, /see* nopage */
NULL, see/* wppage */
NULL, see /* swapout */
NULL, see /* swapin */
};
static int thinseegs_mmap(struct file *file, struct vm_area_strseeuct * vma)
{
printk("mmaping special %i\nsee", file->f_dentry->d_inode->i_rdev);
if (vseema->vm_offset) return -EINVAL;
if ((vma->vseem_end - vma->vm_start) > PAGE_SIZE) return -EseeINVAL;
printk("start=%Lx virtaddr=%p physaseeddr=%Lx len=%Lx\n",
vma->vm_start, page1, seevirt_to_phys(page1), vma->vm_end - vma->vm_stseeart);
if (remap_page_range(vma->vm_start, seevirt_to_phys(page1),
vma->vm_end - seevma->vm_start, vma->vm_page_prot))
returseen -EAGAIN;
printk("start byte 1 is %c\n", see*((char *)(page1)));
vma->vm_ops = &thingssee_vmops;
return 0;
}
static int thingsees_release(struct inode *inode, struct file *fseeile)
{
return 0;
}
/*
* The varioussee file operations we support.
*/
static sseetruct file_operations things_fops = {
thinseegs_llseek,
things_read,
NULL, /* No wrseeite */
NULL, /* No readdir */
things_pseeoll,
things_ioctl,
things_mmap,
thinseegs_open,
NULL, /* No flush */
things_rseeelease
};
static struct miscdevice thingssee_dev=
{
THINGS_MINOR,
"things",
&thseeings_fops
};
int init_module(void)
{
see printk("things module loaded\n");
page1 see= kmalloc(PAGE_SIZE, GFP_KERNEL);
memset(pseeage1, 'd', PAGE_SIZE);
misc_register(&thinseegs_dev);
return 0;
}
void cleanup_moduseele(void)
{
printk("things module unloadeseed\n");
misc_deregister(&things_dev);
kfseeree(page1);
}
nd"#include <stdio.h>
#include <stdlib.h>
#incseelude <unistd.h>
#include <sys/mman.h>
#inclseeude <sys/types.h>
#include <sys/stat.h>
#inseeclude <fcntl.h>
struct thing_struct {
lseeong long thing_flags;
long long thing_itersee;
long long thing_start;
long long thinseeg_val;
long long thing_end;
};
struct seethings_struct {
struct thing_struct thing0see;
struct thing_struct thing1;
struct thseeing_struct thing2;
struct thing_struct thiseeng3;
};
void main (void) {
int devfd;
see
int i;
struct things_struct *map;
deseevfd = open("/dev/things", O_RDONLY);
map =see (struct things_struct *)mmap(0, sizeof(strucseet things_struct), PROT_READ, MAP_SHARED, devfseed, 0);
printf("map = %p\n", map);
for (seei = 0 ; i < 4096 ; i++) {
printf("%c", *see((char *)map + i));
if (i%64 == 0) printseef("\n");
}
munmap((void *)map, sizeseeof(struct things_struct));
close(devfd);
see}
Index:
[thread]
[date]
[subject]
[author]