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

Intercept clone to handle CLONE_CHILD_CLEARTID #154

Closed
davidchisnall opened this issue May 4, 2020 · 2 comments
Closed

Intercept clone to handle CLONE_CHILD_CLEARTID #154

davidchisnall opened this issue May 4, 2020 · 2 comments
Assignees
Labels
area: sgx-lkl Core SGX-LKL functionality enhancement p1 Medium priority
Milestone

Comments

@davidchisnall
Copy link
Contributor

The CLONE_CHILD_CLEARTID flag to clone turns the return value into a futex that is signalled on thread exit. We should intercept this and register the futex location with the lthread library so that it can be zeroed and sent a wakeup when the underlying lthread exits. We need to also intercept set_tid_address in the same way.

@davidchisnall
Copy link
Contributor Author

Once #259 is merged, this should be possible. We need to:

  • Add a field on the lthread structure to store the exit futex location.
  • On thread_destroy_host, check that field and, if it is non-null, zero the value at that address and wake the futex.
  • Add an interceptor for the clone system call that sets this field in the newly created futex.
  • Add an interceptor for set_tid_address, which does the same thing.

Carrying the value between the clone interceptor and thread_create_host is non-trivial. The simplest thing to do is to store the value in the stack. The distance between the sp value and sp-128 is the red zone, but anything after that is fair game according to the ABI. We can store the futex address (or 0) at sp-136 and then check this in thread_create_host.

@davidchisnall
Copy link
Contributor Author

This is no longer required. If we move to using the LKL futex implementation for all of userspace, this works already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: sgx-lkl Core SGX-LKL functionality enhancement p1 Medium priority
Projects
None yet
Development

No branches or pull requests

3 participants