Operating System - HP-UX
1752590 Members
3001 Online
108788 Solutions
New Discussion

What are valid heap addresses for 64 bit application on HP-UX 11.31?

 
SOLVED
Go to solution
blackwater
Regular Advisor

What are valid heap addresses for 64 bit application on HP-UX 11.31?

If I do this C++ code in a 64-bit program on HP-UX 11.31 and new is successful:

 

  char *p = new char;

 

p points to somewhere in the heap. But what is possible min and max values for p?

I understand  that p is always bigger than 0x6000000000000000. But what are actual min and max values on HP-UX 11.31 for a valid pointer?

 

 

 

 

P.S. This thread has been moved from HP-UX >General > to HP-UX > languages.-Hp forum moderator

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: What are valid heap addresses for 64 bit application on HP-UX 11.31?

Take a look at end(3C).

The heap range is from _end to the current brk value.

 

(gdb) p /x &_end
$8 = 0x6000000000000038
(gdb) p /x sbrk(0)
$9 = 0x38

Unfortunately since there is no debug info for sbrk, it only prints at the low order 32 bits.  :-(

blackwater
Regular Advisor

Re: What are valid heap addresses for 64 bit application on HP-UX 11.31?

Dennis, thank for a reply.

 

Unfortunatelly I still don't quite understand how to get min and max values.

Take this program as an example (I build it: aCC +DD64 -g main2.cpp -o main2)

 

#include <stdio.h>
int main()
{
  char *p = new char;
  printf("%p\n", p);
  delete p;
  return 0;
}

So my question in what range can be p after "new char"?  MIN_VALUE < p < MAX_VALUE ?

I run gdb and did what you suggested:

 

(gdb) r
Starting program: /import/home/sergey.kurenkov/src/ia64.11-31/tests/test.analyze_core/./main2

Breakpoint 1, main () at main2.cpp:4
4         char *p = new char;
(gdb) n
5         printf("%p\n", p);
(gdb) p/x p
$1 = 0x6000000000004790
(gdb) p/x &_end
$2 = 0x6000000000000070
(gdb) p/x &_edata
$3 = 0x6000000000000050
(gdb)

 

Looking at this I can guess that I can use &_end as MIN_VALUE, but how to get MAX_VALUE?

Is it p/x &_end + sbrk(0)? If it is so it is useless in case one analyzes a core file. I mean one can't execute p/x sbrk(0) while analyzing a core file:

(gdb) p/x sbrk(0)
You can't do that without a process to debug.

 

 

Dennis Handly
Acclaimed Contributor
Solution

Re: What are valid heap addresses for 64 bit application on HP-UX 11.31?

>how to get MAX_VALUE?
>Is it p/x &_end + sbrk(0)?

 

No, it's at least: p /x ((long long)&_end >> 32 << 32) + sbrk(0)

 

>If it is so it is useless in case one analyzes a core file.

 

You'll need to compute this outside of gdb:

$ elfdump -o -S core.10472
core.10472:
                *** Program Header ***
Type     Offset           Vaddr            FSize            Memsz
CoreVer  00000000000004d8 0000000000000000 0000000000000004 0000000000000004
...
CoreLoad 000000000000caf8 6000000000000000 0000000000001000 0000000000001000

It's CoreLoad.Vaddr + CoreLoad.Memsz:  0x6000000000000000 + 0x0000000000001000

Or use gdb's "info file":

(gdb) info file
Operating System Information:
  sysname  : B.11.31
...
Symbols from "./a.out".
Local core dump file:
        `./core.10472', file type elf64-big.
        0x6000000000000000 - 0x6000000000001000 is segment5 (PT_HP_CORE_LOADABLE)