Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: C-like Pointers

by DerHartmut (Novice)
on Nov 16, 2009 at 03:34 UTC ( #807363=note: print w/replies, xml ) Need Help??


in reply to Re: C-like Pointers
in thread C-like Pointers

Thank you for your answer (and either thank to the others) :D

I know the fact, that C can only access virtual memory, I choosed the easier term "RAM" for people which don't know about Paging and stuff.

My real problem is to solve the following problem:

A buddy wrote a program in C which loads a ELF-kernel and execute it. I (I'm either a C progammer and OS-developer) wanted to write the same program in Perl, just for fun. The biggest problem is to access a virtual address within the process' memoryspace and using pointers to these addresses. I have to write this line:

krnl = mmap((void *)0x78000000, lof, PROT_READ, MAP_PRIVATE | MAP_FIXE +D, fileno(kernel), 0);

In Perl. My (not working) solution is:

$mapped_kernel = syscall(\&SYS_mmap, $address, $kernel_size, $page_rea +d, $map_private | $map_fixed, fileno(KERNEL), 0);

where syscall() and \&SYS_mmap are functions/references to functions from syscall.h (converted to .ph via h2ph), $kernel_size, $page_read, $map_private and $map_fixed simple integer-values, KERNEL the filehandle to the loaded kernel and $address the pointer to the address.

In short words, I want to do (void*)0x78000000 in Perl, a pointer to a address defiend by myself (without the help of C :-P). I've searched CPAN for XS and pointers but did not found anything related to my problem (or I was too stupid to find it ^^).

Replies are listed 'Best First'.
Re^3: C-like Pointers
by snoopy (Deacon) on Nov 16, 2009 at 05:11 UTC
    In short words, I want to do (void*)0x78000000 in Perl, a pointer to a address defiend by myself (without the help of C :-P). I've searched CPAN for XS and pointers but did not found anything related to my problem

    Did you come across Sys::Mmap's hardwire() method in your travels?

    Just reading the synopsis for this function:

           hardwire(VARIABLE, ADDRESS, LENGTH)
               Specifies the address in memory of a variable, possibly within a
               region you've "mmap()"ed another variable to. You must use the same
               precautions to keep the variable from being reallocated, and use
               "substr()" with an exact length. If you "munmap()" a region that a
               "hardwire()"ed variable lives in, the "hardwire()"ed variable will
               not automatically be "undef"ed. You must do this manually.
    
    ..and thought it just might be of use. Maybe try:
    use Sys::Mmap; # ... Sys::Mmap::hardwire($address, 0x78000000, $kernel_size);
      Great!

      That's extactly that I searched for. Thank very very very much! It does work now :D

      And many thanks to the others for their answers!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://807363]
help
Chatterbox?
[Corion]: Maybe doing a double-fork (daemonizing) can make go that information away, but maybe not
[Corion]: But I think my knowledge of unix/Linux datastructures is several decades out of date, so I don't really know what information it keeps on processes
[oiskuu]: The useful bits that relate to your process can be found under /proc/self. What information are you thinking of? Tty name?
[tye]: I just daemonized and getlogin() still knew who I had been.
[tye]: perhaps loginuid ? Not that I concede that something not being in /proc means it is not useful.
[Corion]: tye: That's really interesting, but maybe it is because getlogin() returns the name, or the uid, so if that user has been replaced by another user with the same uid in the meantime, that's no problem to the system...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2017-06-23 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (554 votes). Check out past polls.