Re: 64 bit pointer to string
by BrowserUk (Patriarch) on Sep 05, 2003 at 19:25 UTC
|
Instinct suggests that if you use the 'p' or 'P' pack format specifiers on a 64-bit system, the you will get a 64-bit pointer to the target string packed into the output. Whether this actually occurs I have no way of checking, but if it doesn't, it wouldn't be a valid pointer would it?
I do seem to recall that some 64-bit processors can utilise 32-bit "pointers" which are simply offsets relative to some base-register, much in the fashion of the segmented stuff from early intel 32-bit systems, but it is doubtful that perl would have anything to do with these.
Have you actually tried this on a 64-bit system and had it fail?
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
| [reply] |
|
|
sure it fails with openbsd/sparc64:
fatal error: Bad address
so when the ioctl system call wants to write to that area i get the above error.
i tried P with g instead if l, even l! for native length longs... (also p with a \0 terminated string)
i don't really know what pointer types are common on 64 bit and how to adress them from perl... | [reply] [d/l] |
|
|
I really don't know anything about perl on 64-bit systems, but in the absence of any other responses...
What do you get if you do
my $x = 'hello world!';
my $px = pack 'P', $x;
print length $px; # Ought to print '8' on a 64-bit system
print unpack 'p', $px; # Should print 'Hello world!'
If that works, then Perl is packing the pointers correctly and you are 'using them wrong'. Sorry for such a vague diagnosis:)
If that doesn't work, then you maybe have discovered a bug in 64-bit perl and should raise it to p5p.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
| [reply] [d/l] |
|
|
|
|
|
|
|
|
|
The 'hello world' example works as expected on both openbsd/sparc64 and openbsd/alpha (64-bit systems) where the original example fails.
| [reply] |
|
|
Okay. If the hello world test works then you know that the pointer perl is producing is correct. If the ioctl call is rejecting the pointer, then one possibility is that the alignment is wrong.
Sometimes processors are fussy about the alignment of pointers. Some 32-bit processors require pointers to located on 2 or 4 byte boundaries. Maybe your 64-bit processor requires them to be aligned on a 4 or 8 byte boundary. I think I would try using perls 'N' (or 'V') and 'Q' format specifier to pack the integer that you are currently packing as a 16-bit value and see what if any difference that makes.
In truth, I think that I've gone about as far as I can go with educated guesswork and your probably going to have to either find some documentation specific to your hardware or ask your question in a forum where you will encounter those familar with it.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
| [reply] |
Re: 64 bit pointer to string
by Anonymous Monk on Sep 07, 2003 at 18:54 UTC
|
Just to wrap it up: The pointer needs to be 64bit aligned.
$tocentry=pack "CCCCxxxxP", $CDROM_MSF,0,$size_hi,$size_lo,$toc;
This works. This one is cooler:
$tocentry=pack "CCCCx![P]P", $CDROM_MSF,0,$size_hi,$size_lo,$toc;
but just works with perl >=5.8.0. | [reply] [d/l] [select] |
|
|
| [reply] |