LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-22-2009, 09:24 PM   #1
raghu2383
LQ Newbie
 
Registered: Jun 2008
Posts: 20

Rep: Reputation: 0
Find Physical address of memory provided by kmalloc


Hi,

I allocated a chunk of memory using kmalloc in a Device Driver. Kmalloc provides a pointer to the allocated memory. This is one of my first few drivers, so please bear with me if my concepts are wrong.

I assume that the address returned is a Virtual address. I need to find the physical address of the memory location. I am working on an Intel 64 bit Fedora machine. I used the virt_to_phys() routine present in <asm/io_64.h>. I found that this routine returns an unsigned long value (32 bit) instead of an unsigned long long value (64 bit). Moreover, it seems that it simply returns the address - OFFSET instead of extracting the value in the page tables.

So is there any function / system call in Linux which will allow me to see the actual physical address on the Intel 64 arch.

Thanks for responding.
 
Old 10-22-2009, 10:28 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by raghu2383 View Post
Hi,

I allocated a chunk of memory using kmalloc in a Device Driver. Kmalloc provides a pointer to the allocated memory. This is one of my first few drivers, so please bear with me if my concepts are wrong.

I assume that the address returned is a Virtual address. I need to find the physical address of the memory location. I am working on an Intel 64 bit Fedora machine. I used the virt_to_phys() routine present in <asm/io_64.h>. I found that this routine returns an unsigned long value (32 bit) instead of an unsigned long long value (64 bit). Moreover, it seems that it simply returns the address - OFFSET instead of extracting the value in the page tables.

So is there any function / system call in Linux which will allow me to see the actual physical address on the Intel 64 arch.

Thanks for responding.
try :
Code:
struct address {
unsigned segment,offset;
};

address get_pointer_address(void *p){
address ret;
int i;
asm {
mov eax,cs
mov i,eax
}
ret.segment = i;
ret.offset = (unsigned)p;
return ret;
}
i am not sure if it will work
 
Old 10-23-2009, 02:07 PM   #3
raghu2383
LQ Newbie
 
Registered: Jun 2008
Posts: 20

Original Poster
Rep: Reputation: 0
CS is the code segment right? If I am right would that give me the location of where the executable code is loaded?
 
Old 10-23-2009, 02:25 PM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by raghu2383 View Post
CS is the code segment right? If I am right would that give me the location of where the executable code is loaded?
yes.
heres an example of how it might work:
Code:
struct address {
unsigned segment,offset;
};

address get_pointer_address(void *p){
address ret;
int i;
asm {
mov eax,cs
mov i,eax
}
ret.segment = i;
ret.offset = (unsigned)p;
return ret;
}
int main(){
void *p=kmalloc(10);
address x;
x = get_pointer_address(p);
printf("the address of the pointer is %u:%u", x.segment, x.offset);
kfree(p);
}
should work.
 
  


Reply

Tags
linux



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
How much physical memory can a 32-bit installation address gschmitt99 Linux - General 1 09-19-2008 01:10 PM
How do I find MAC or physical address jjabflames Linux - Newbie 2 10-04-2007 02:20 AM
Examples about Logical,Linear and Physical address in Linux Memory Addressing muralis Linux - Kernel 5 08-04-2007 08:18 PM
how to find physical address of kernel virtual address kushneeraj Programming 0 10-20-2006 07:29 PM
Memory Mapping (same physical address = virtual address) skd.tech Linux - Kernel 7 07-24-2006 11:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:07 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