Port attach_current_thread(), detach_current_thread() to Rust.