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

Passing a callable to a foreign function #128

Closed
mdorier opened this issue Jun 15, 2021 · 5 comments
Closed

Passing a callable to a foreign function #128

mdorier opened this issue Jun 15, 2021 · 5 comments

Comments

@mdorier
Copy link
Contributor

mdorier commented Jun 15, 2021

I could not find any documentation on this: how can I pass a callable from jx9 to a foreign function written in C, and call this callable on some data?
I tried looking at how db_fetch_all is implemented, but it seems to be using a function that is not in the API (here).

@symisc
Copy link
Owner

symisc commented Jun 17, 2021

Passing a callable to a foreign function is done via an internal Jx9 API hence jx9VmCallUserFunction() which is not publicly exported for obvious security reasons.

@symisc symisc closed this as completed Jun 17, 2021
@mdorier
Copy link
Contributor Author

mdorier commented Jun 17, 2021

I'm not sure I understand the security reasons, could you give me an example of a situation where such a functionality would be unsafe?

@symisc
Copy link
Owner

symisc commented Jun 17, 2021

Well, Jx9 was designed to run on restricted embedded devices such as your home router or set top box where memory and stack is limited. Suppose if a broken callable enter in an endless recursive calls/loop on your router...

@mdorier
Copy link
Contributor Author

mdorier commented Jun 17, 2021

How would that be different from executing the same callable from the jx9 script itself?

@symisc
Copy link
Owner

symisc commented Jun 17, 2021

Jx9 internal callable are certified not to broke such as calling a recursive function or entering an infinite loop unlike passing a user defined callable to the VM which cannot be controlled. Nevertheless, making callable public shoud be straightforward by simply writing a wrapper around jx9VmCallUserFunction().

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

2 participants