Is it possible to detect if a variable is in stack or heap based on its address?

Bruno Jesus 00cpxxx at gmail.com
Fri Feb 20 04:48:50 CST 2015


On Fri, Feb 20, 2015 at 1:04 AM, Ken Thomases <ken at codeweavers.com> wrote:
> On Feb 19, 2015, at 7:53 PM, Bruno Jesus <00cpxxx at gmail.com> wrote:
>> Can I be sure the first printed value is from stack and the second from heap?
>
> Are you asking whether that function will print an address on the stack and an address from the heap?  Yes, it will.  Or are you asking if you can determine the difference between the two types of pointers just by inspection?  I don't think there are hard-and-fast rules, but with experience you can make a pretty good guess.  For example, at least on OS X (32-bit), addresses around 0x0033nnnn are typical of the first thread's stack.  You'll see a lot of those as arguments in a relay log because it's common to pass the address of a local in function calls.

Thank you very much, all information was useful.

>
>> A plus question would be: Is it possible to know if an address is a
>> const string?
>
> Do you mean a *static* const string?  If it is, it will be from a mapped executable image.  A +virtual log will show the address ranges to which images are loaded.

I mean:

void test(char *p)
{
    if(magic_test_ptr(p))
       //this is a string declared with ""
    else
       //this is not a string declared with ""
}

void test2()
{
    char p[10];
    test("1234");
    test(p);
}

Best wishes,
Bruno



More information about the wine-devel mailing list