Pointer to the stack limit

2018-12-19 Thread Henri Sivonen
Is it possible to dynamically at run-time obtain a pointer to call
stack limit? I mean the address that is the lowest address that the
run-time stack can grow into without the process getting terminated
with a stack overflow.

I'm particularly interested in a solution that'd work on 32-bit
Windows and on Dalvik. (On ART, desktop Linux, and 64-bit platforms we
can make the stack "large enough" anyway.)

Use case: Implementing a dynamic recursion limit.

-- 
Henri Sivonen
hsivo...@mozilla.com
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Pointer to the stack limit

2018-12-19 Thread David Major
You'll need platform-specific code, but on Windows there's 
https://searchfox.org/mozilla-central/rev/13788edbabb04d004e4a1ceff41d4de68a8320a2/js/xpconnect/src/XPCJSContext.cpp#986.

And, to get a sense of caution, have a look at the ifdef madness surrounding 
the caller -- 
https://searchfox.org/mozilla-central/rev/13788edbabb04d004e4a1ceff41d4de68a8320a2/js/xpconnect/src/XPCJSContext.cpp#1125
 -- to see the number of hoops we have to jump through to accommodate various 
build configs.

On Wed, Dec 19, 2018, at 7:12 AM, Henri Sivonen wrote:
> Is it possible to dynamically at run-time obtain a pointer to call
> stack limit? I mean the address that is the lowest address that the
> run-time stack can grow into without the process getting terminated
> with a stack overflow.
> 
> I'm particularly interested in a solution that'd work on 32-bit
> Windows and on Dalvik. (On ART, desktop Linux, and 64-bit platforms we
> can make the stack "large enough" anyway.)
> 
> Use case: Implementing a dynamic recursion limit.
> 
> -- 
> Henri Sivonen
> hsivo...@mozilla.com
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Pointer to the stack limit

2018-12-19 Thread Henri Sivonen
On Wed, Dec 19, 2018 at 2:37 PM David Major  wrote:
> You'll need platform-specific code, but on Windows there's 
> https://searchfox.org/mozilla-central/rev/13788edbabb04d004e4a1ceff41d4de68a8320a2/js/xpconnect/src/XPCJSContext.cpp#986.
>
> And, to get a sense of caution, have a look at the ifdef madness surrounding 
> the caller -- 
> https://searchfox.org/mozilla-central/rev/13788edbabb04d004e4a1ceff41d4de68a8320a2/js/xpconnect/src/XPCJSContext.cpp#1125
>  -- to see the number of hoops we have to jump through to accommodate various 
> build configs.

Thanks. It looks like the Android case just hard-codes a limit that
works for Dalvik instead of querying from the OS or ever querying for
the API level to decide between a limit that works for Dalvik and a
limit that works for ART.

(On IRC, I was pointed to the code that uses the limit:
https://searchfox.org/mozilla-central/search?q=symbol:_ZN2js19CheckRecursionLimitEP9JSContext&redirect=false
)

-- 
Henri Sivonen
hsivo...@mozilla.com
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Pointer to the stack limit

2018-12-19 Thread Kris Maglione

On Wed, Dec 19, 2018 at 07:36:52AM -0500, David Major wrote:

You'll need platform-specific code, but on Windows there's 
https://searchfox.org/mozilla-central/rev/13788edbabb04d004e4a1ceff41d4de68a8320a2/js/xpconnect/src/XPCJSContext.cpp#986.

And, to get a sense of caution, have a look at the ifdef madness surrounding 
the caller -- 
https://searchfox.org/mozilla-central/rev/13788edbabb04d004e4a1ceff41d4de68a8320a2/js/xpconnect/src/XPCJSContext.cpp#1125
 -- to see the number of hoops we have to jump through to accommodate various 
build configs.


For glibc Linux, there's also:

https://searchfox.org/mozilla-central/rev/2e5e28f518524f8af5b158ddb605022b6a2d68cf/xpcom/threads/nsThread.cpp#506-557

Other Unix platforms require similarly super-specific code.


On Wed, Dec 19, 2018, at 7:12 AM, Henri Sivonen wrote:

Is it possible to dynamically at run-time obtain a pointer to call
stack limit? I mean the address that is the lowest address that the
run-time stack can grow into without the process getting terminated
with a stack overflow.

I'm particularly interested in a solution that'd work on 32-bit
Windows and on Dalvik. (On ART, desktop Linux, and 64-bit platforms we
can make the stack "large enough" anyway.)

Use case: Implementing a dynamic recursion limit.

___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform