I'm writting a task control block(tcb_t). I have use Arc<RwLock<>> to lock the struct to allow different task(or thread) to use the task control block, writing some new values and reading new values. But now, I want to use *mut tcb_t. I'm sure it's unsafe but I still want to use the pointer value to get other locations' address. what can I do?
Get a &mut reference and convert it to a pointer. You should keep the Arc and the RwLockWriteGuard alive while performing the actions with the pointer, however (the Arc so the object won't be freed in the middle and the RwLockWriteGuard guard so that RwLock will know the mutable borrow is still in use and will block usages from another threads:
let task_handle = ...;
let guard = task_handler.0.write().unwrap();
let p: *mut tcb_t = &mut *guard;
unsafe {
// Use `p`...
}
Do you mean you get a NULL from FFI? Then just declare the type as wanted. Or do you want to create NULL from Rust? Then use std::ptr::null() (or std::ptr::null_mut()).