How to get stack bounds of current process?

Kostik Belousov kostikbel at gmail.com
Mon May 10 14:58:22 UTC 2010


On Mon, May 10, 2010 at 11:57:08AM +0400, Lev Serebryakov wrote:
> Hello, Freebsd-hackers.
> 
>   I'm  proting  some  application from Linux, which discover its stack
>  bounds   by   reading  and  pasing  "/proc/self/maps".  FreeBSD  have
>  "/prov/curproc/map", but I can not find how to determine which record
>  is  for  stack  (I've  looked  into implementation of proc_fs, but it
>  doesn't contain any specail processing for process stack).
> 
>   How could I determine stack bounds of current process on FreeBSD
> 7/8/9?

I think the right question is why the program needs the information at all.

Really, the system has no data to answer your question. Which stack are
you asking for ? The stack of main thread, set up by kernel, is very
different from the stack established by the threading library for
newly created thread. What should happen for signal altstacks ?
Also, the threading library clips the main thread stack to match its
size with default stack size (I do think this is unsafe and wrong).

Also, the application can legitimately allocate arbitrary memory region
and use it as the stack (this is essentially what threading library does).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20100510/84e2e9a7/attachment.pgp


More information about the freebsd-hackers mailing list