Dereferencing pointers returned by syscall

T

tad.bochan

Hi,

I'm using 'syscall' in ruby to access the 'mmap' function in Unix (HPUX),
to try to read/write a memory-mapped file.
The 'mmap' function returns a pointer to the mapped file.
I can't figure out how I am supposed to be able to use
this pointer to access the data from ruby.

PROT-NONE = 0
PROT-USER = 0
PROT-READ = 1
PROT-WRITE = 2
MAP-SHARED = 1
prot=PROT_READ | PROT_WRITE
flags=MAP_SHARED
len=1024
ofs=0
mmfptr=syscall(71, 0, prot, flags, filedes, ofs)

mmfptr is now a pointer to a 1024 byte structure.

How can I get ruby to access this structure ?

Regards,

Tad. (ruby,perl,unix newbie)





This message and any attachments (the "message") is
intended solely for the addressees and is confidential.
If you receive this message in error, please delete it and
immediately notify the sender. Any use not in accord with
its purpose, any dissemination or disclosure, either whole
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message.
BNP PARIBAS (and its subsidiaries) shall (will) not
therefore be liable for the message if modified.

---------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le
"message") sont etablis a l'intention exclusive de ses
destinataires et sont confidentiels. Si vous recevez ce
message par erreur, merci de le detruire et d'en avertir
immediatement l'expediteur. Toute utilisation de ce
message non conforme a sa destination, toute diffusion
ou toute publication, totale ou partielle, est interdite, sauf
autorisation expresse. L'internet ne permettant pas
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce
message, dans l'hypothese ou il aurait ete modifie.
 
F

Florian Gross

Hi,
Moin!

I'm using 'syscall' in ruby to access the 'mmap' function in Unix (HPUX),
to try to read/write a memory-mapped file.
The 'mmap' function returns a pointer to the mapped file.
I can't figure out how I am supposed to be able to use
this pointer to access the data from ruby.

Have a look at Ruby/DL which is part of Standard Ruby. With
DL::Importable you can create a struct like this:

Foo = struct [
"long foo",
"int bar",
...
]

And later you can do Foo.new(DL::ptrData.new(ptr)).

Regards,
Florian Gross
 
N

nobu.nokada

Hi,

At Fri, 27 Aug 2004 04:05:35 +0900,
Florian Gross wrote in [ruby-talk:110570]:
And later you can do Foo.new(DL::ptrData.new(ptr)).

munmap(2) takes two arguments, but DL::ptrData passes to its
free functions just one argument.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top