C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-15-2009, 06:44 AM   #1
Registered User
 
Join Date: Sep 2009
Posts: 1
Read data of a page frame (linux) make freeze the system

Hello,

I'm writing a linux driver that reading the data of a page frame of an process. But when I use it, it make immediately freeze the system. Can you help me? Thank for reading my question!

system: Ubuntu 9.04, kernel 2.6.28.15, Intel Duo

Code:
static int read_addr(int pid, unsigned long linear_addr, unsigned int n_bytes, char* buff){
	/* 
	pid: id of process
	linear_addr: linear address of memory region to be read
	n_bytes: nombre bytes to be read
	buff: the buffer containing the result
	*/
	
	struct task_struct *task;
   	struct mm_struct *mm = NULL;

    pgd_t *pgd;
    pmd_t *pmd;

    pte_t *pte;

    unsigned long pteval;

	int ret = 0;    

	for_each_process(task) {
		if ( task->pid == pid) {
		    mm = task->mm;
		}
	}
	if(mm == NULL)
		return 1;


    spin_lock(&mm->page_table_lock);

    
    pgd = pgd_offset(mm, linear_addr);

    if (pgd_none(*pgd)) { ret = 2; goto out; }
    
    pmd = pmd_offset(pgd, linear_addr);

    if (pmd_none(*pmd)) { ret = 3; goto out; }
    
    pte = pte_offset_map(pmd, linear_addr);
	
    if (pte_present(*pte)){
		unsigned long pteid = pte_index(linear_addr);
		pteval = pte_val(*pte);
		memcpy(buff, pteval + pteid, n_bytes);     
    } else {

		ret = 4;
		goto out;
    }

    pte_unmap(pte);
    spin_unlock(&mm->page_table_lock);
    return 0;


 out:
 	printk("error: %d\n", ret);

    spin_unlock(&mm->page_table_lock);
	return ret;		
}
hahai is offline   Reply With Quote
Old 09-16-2009, 09:01 AM   #2
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
Narrow down the snippet of code where it is hanging and go from there.
itCbitC is offline   Reply With Quote
Reply

Tags
linux driver, linux programming, read physical data

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
program terminates abruptly roaan C Programming 3 08-28-2009 03:53 PM
Abnormal Program Termination when executed from C:\Program Files\... m37h0d Windows Programming 48 09-26-2008 03:45 AM
C Programming Question TK A Brief History of Cprogramming.com 13 07-04-2002 07:11 PM
data read problem Supra C Programming 0 02-03-2002 07:02 PM
read data in_need C Programming 2 10-30-2001 08:10 AM


All times are GMT -6. The time now is 03:47 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22