KernelNewbies
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Kernel Hacking

  • Frontpage

  • Kernel Hacking

  • Kernel Documentation

  • Kernel Glossary

  • FAQ

  • Found a bug?

  • Kernel Changelog

  • Upstream Merge Guide

Projects

  • KernelJanitors

  • KernelMentors

  • KernelProjects

Community

  • Why a community?

  • Regional Kernelnewbies

  • Personal Pages

  • Upcoming Events

References

  • Mailing Lists

  • Related Sites

  • Programming Links

Wiki

  • Recent Changes

  • Site Editors

  • Side Bar

  • Tips for Editors

  • Hosted by WikiWall

Navigation

  • RecentChanges
  • FindPage
  • HelpContents

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

KernelNewbies:
  • MemModuleSource
/*
 * tyler@agat.net
 *
 * Virtual Memory Module (intended to Linux Kernel 2.6(.12))
 *
 * This module just explains the concept and the mechanism of the Linux
 * virtual memory system
 */
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>

unsigned long new_page ;
unsigned long temp ;

struct page *new_desc_page ;

int init_module()
{
        new_page = __get_free_page(GFP_KERNEL) ;

        new_desc_page = (struct page *)virt_to_page(new_page) ;

        /*
         * That's how the virtual memory system works.
         * To retrieve the virtual adress corresponding to the page,
         * we get the index in the page frame (new_desc_page-mem_map).
         * We then multiply it by the size of the page. We get the physical adress.
         * And in kernel mode, the differences between virtual and physical adresses
         * is just an offset of PAGE_OFFSET. So we add PAGE_OFFSET
         */
        temp = (new_desc_page-mem_map)*PAGE_SIZE+PAGE_OFFSET ;

        printk("0x%x\n",temp) ;
        printk("0x%x\n",new_page) ;

        /* 
         * In kernel mode, the virtual adresses has just an offset of PAGE_OFFSET
         * (the page tables are properly configured to do this)
         * On i386, the PAGE_OFFSET=0xC0000000
         */
        temp = __pa(new_page) ;

        printk("0x%x\n",new_page-PAGE_OFFSET) ;
        printk("0x%x\n",temp) ;

        return 0 ;
}

void cleanup_module()
{
        free_page(new_page) ;
}
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01