Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SegFault on require for JS module which uses RegEx with iotjs snapshots #1971

Open
tysenmoore-xse opened this issue Mar 11, 2021 · 0 comments

Comments

@tysenmoore-xse
Copy link

tysenmoore-xse commented Mar 11, 2021

I am am trying to migrate a reasonable large webpacked module to iot.js for running on an embedded target. Some of my node dependencies require the url module--I have bo control over this. It seems iot.js does not natively support a polyfil for the url module. I saw PR #1528 which was written to address this limitation but it was moved to iotjs-modules but the submodule link is now broken. However, I took the original developers code and integrated it into iotjs. When using the code as originally written there were two statements that were causing crashes when the url module was required into the test program. The two lines are:

var protocolPattern = /^[a-z0-9.+-]+:/i;
var portPattern = /:[0-9]*$/;

After a bunch of trial and error I determined:

  • The original code would cause a seg fault on the require("url") in snapshot_load_compiled_code() on the line ECMA_SET_INTERNAL_VALUE_POINTER (args_p->realm_value, ecma_builtin_get_global ());.
  • If I commented out the two lines it load fine, no seg faults
  • If I built with --no-snapshot using the original code (unaltered) it worked fine, no seg faults
  • If I instead ran the test but included the code using a relative path it worked fine (e.g. var urlModule = require('./src/js/url.js'); instead of var urlModule = require('url');)
  • If I change the code to not use the two line definitions and change their usage to somthing like var proto = (RegExp('^[a-z0-9.+-]+:', 'i')).exec(rest); the code worked fine, no seg faults

It would seem the code generating the snapshot does not like the regex syntax and causes a seg fault when parsed. The fact that it works when included using a relative path indicates to me that the jerry-script itself does not have a problem with the syntax. I could however be way off here.

I am new to iotjs/jerry-scipt. I am wondering if this a known limitation when creating native JS modules inside iotjs or is it a bug? Is that syntax allowed for normal use but not supported in the JS modules for iotjs? Or am I completely missing something and it is a different problem all together?

Thanks in advance for any info or help.

My initial testing is done using:

  • Ubuntu 18.04
  • iotjs master branch
  • ./tools/build.py --jerry-heaplimit=10240 --jerry-profile=es.next --clean (I have a large application that needs a large heap due to string data. We plan to investigate using snapshots to increase load times)

working.tar.gz -- these are my working files. You can see what I commented out in the url file. Also the test_url.js has the relative path commented out at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant