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

Allow C code to call into Rust code #1508

Closed
brson opened this issue Jan 13, 2012 · 2 comments
Closed

Allow C code to call into Rust code #1508

brson opened this issue Jan 13, 2012 · 2 comments
Assignees
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

Comments

@brson
Copy link
Contributor

brson commented Jan 13, 2012

There are probably a number of things needed to make this happen:

Scheduler:

  • Instead of reusing the scheduler's stack to call C code, we'll want each scheduler thread to hold a cache of big stacks, give each task a pointer to a C stack, a stack of C contexts and a stack of Rust contexts.
  • When calling into C code, if the task already has a C stack it reuses it, if not it checks whether the scheduler has any C stacks and pops one, or it allocates a new one, and pushes the Rust context onto the Rust context stack.
  • &c.
  • When it pops the last Rust context it returns the C stack to the scheduler's pool.

Language:

  • Would be really nice to be able to create functions with appropriate native signatures such that they could be called directly

Extensions:

  • Any glue that might be needed could be generated via a syntax extension.
@nikomatsakis
Copy link
Contributor

This is the best solution. However, there is a simpler variant that might be worth doing as a "first try": allow a subset of Rust code that is "non-blocking" and only allow C callbacks into that. This would probably take the form of requiring a "blocking" flag similar to "unsafe"... hmm... this is probably not worth the language complexity price. So, never mind, I think the idea is poor, but I will leave this comment for reference anyhow.

@brson
Copy link
Contributor Author

brson commented Feb 14, 2012

Done.

@brson brson closed this as completed Feb 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
Projects
None yet
Development

No branches or pull requests

3 participants