BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
From XS code, I'd like to obtain the address of either the earliest allocated (lowest memory position) SV*, or some other address below which no memory will be dynamically allocated. Any suggestions of a variable accessible from XS code that fits the bill?
The reason is that some coderefs, for example *DynaLoader::, have links in their opcode chains (as traversed by Devel::Size), that are invalid:
C:\Perl\packages\Devel-Size-X>perl -Mblib -MPOSIX -MDevel::Size=total_ +size -wle" print total_size( *DynaLoader:: )" Devel::Size: Calculated sizes for compiled regexes are incompatible, a +nd probably always will be op_last:019D7014 baseop->op_next: 000000D5 ignored! op_last:0189669C baseop->op_next: 000000D3 ignored! op_last:01892C7C baseop->op_next: 00000084 ignored! 69229
In this case I have observed opcode->op_next with values of 0xD5, OxD3, Ox84. Whilst these are obviously erroneous, there are others like 0x00035ffe somewhere in *POSIX:: that look reasonable, but none the less point to pieces of virual memory that do not exist in the process address space, and so attempting to indirect through them is a walk into oblivion.
So my idea is to find some existing XS-accessible variable who's address is a reasonable lower bound below which D::S will not walk. Whilst this will not prevent all traps through uninitialised pointers, from observations, it would catch a large majority of those that I've seen.
Suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [XS]:The address of the first dynamically allocated SV*?
by jettero (Monsignor) on Oct 05, 2008 at 10:23 UTC | |
|
Re: [XS]:The address of the first dynamically allocated SV*?
by Anonymous Monk on Oct 05, 2008 at 12:44 UTC | |
by BrowserUk (Patriarch) on Oct 05, 2008 at 23:41 UTC |