From: tad.bochan@... Date: 2004-08-31T19:22:30+09:00 Subject: Réf. : Dereferencing pointers returned by syscall Hi Florian, Thanks very much for your tip. It does intrigue me how you came to know about this one (ruby/DL). Unfortunately, I haven't been able to verify that it works yet because of an apparent bug in ruby when I try the syscall to mmap. I running 1.8.0 on HPUX, and I can't upgrade to a later version just yet. (don't have an ansi C compiler!) """" > cat pntrs.rb #require "dl" #Foo=Struct.new("Foo",:astrg) SYS_mmap = 71 PROT_NONE = 0 PROT_USER = 0 PROT_READ = 1 PROT_WRITE = 2 MAP_SHARED = 1 addr,len,prot,flags,ofs=0,80,PROT_READ, MAP_SHARED,0 filedes=open("shmfile","r+") mmfptr=syscall(SYS_mmap, addr, len, prot, flags, filedes.fileno, ofs) Gives ........................... > ruby pntrs.rb pntrs.rb:11: [BUG] rb_sys_fail() - errno == 0 ruby 1.8.0 (2003-08-04) [hppa2.0w-hpux11.11] Abort(coredump) > """" But a rather odd problem occurs when I run the above with the 'require' line uncommented, > cat pntrs.rb require "dl" #Foo=Struct.new("Foo",:astrg) SYS_mmap = 71 PROT_NONE = 0 PROT_USER = 0 PROT_READ = 1 PROT_WRITE = 2 MAP_SHARED = 1 addr,len,prot,flags,ofs=0,80,PROT_READ, MAP_SHARED,0 filedes=open("shmfile","r+") mmfptr=syscall(SYS_mmap, addr, len, prot, flags, filedes.fileno, ofs) Gives ........................... > ruby pntrs.rb pntrs.rb:11:in `syscall': No such file or directory (Errno::ENOENT) from pntrs.rb:11 > Internet flgr@ccan.de - 26/08/2004 21:05 Veuillez r�pondre � ruby-talk@ruby-lang.org Pour : ruby-talk cc : Objet : Re: Dereferencing pointers returned by syscall tad.bochan@bnpparibas.com wrote: > 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 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.