{"id":97,"date":"2010-07-14T18:30:19","date_gmt":"2010-07-14T23:30:19","guid":{"rendered":"http:\/\/fw.hardijzer.nl\/?p=97"},"modified":"2010-07-14T18:30:19","modified_gmt":"2010-07-14T23:30:19","slug":"v8-crashing-with-uncaught-rangeerror-maximum-call-stack-size-exceeded","status":"publish","type":"post","link":"https:\/\/fw.hardijzer.nl\/?p=97","title":{"rendered":"V8 crashing with &#8216;Uncaught RangeError: Maximum call stack size exceeded&#8217;"},"content":{"rendered":"<p>While working with V8 in another process, it kept crashing at initialization with the message &#8216;Uncaught RangeError: Maximum call stack size exceeded&#8217;. I wasn&#8217;t doing anything big, just initialization.<br \/>\nAfter about 3 hour of debugging, I found out what was wrong. Normally, V8 will assume that you have no more than 512KB of stack space. To prevent stack overflows, it will take a stack address, substract 512kb from it, and remember that address. If it ever passes that address, it&#8217;ll throw a RangeError.<\/p>\n<p>The problem lies in the fact that the program I was working with had a stack somewhere around 0x60000 or 384kb. V8 then substracts 512 from that, but instead of getting a nice stack-boundary, it ends up with an incredibly big number due to integer underflow. The next time it checks the stack, it compares the stack address (still somewhere around 0x60000) with it&#8217;s calculated stack limited (which, due to the underflow, is about 0xFFFE0000), and assumes it has a stack overflow.<\/p>\n<p>To fix this, I had to manually set the stack limit. Basically, the following code takes a random stack address, divides it by 2, and uses that as the lower-limit to the stack:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\tv8::ResourceConstraints rc;\r\n\trc.set_stack_limit((uint32_t *)(((uint32_t)&amp;rc)\/2));\r\n\tv8::SetResourceConstraints(&amp;rc);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>While working with V8 in another process, it kept crashing at initialization with the message &#8216;Uncaught RangeError: Maximum call stack size exceeded&#8217;. I wasn&#8217;t doing anything big, just initialization. After about 3 hour of debugging, I found out what was wrong. Normally, V8 will assume that you have no more than 512KB of stack space. &hellip; <a href=\"https:\/\/fw.hardijzer.nl\/?p=97\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">V8 crashing with &#8216;Uncaught RangeError: Maximum call stack size exceeded&#8217;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=97"}],"version-history":[{"count":2,"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fw.hardijzer.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}