#![allow(missing_docs)]

use abi::{error::Error, process::thread};

pub fn get_thread_pointer() -> usize {
    let tp: usize;
    unsafe {
        core::arch::asm!("mov %fs:0, {0}", out(reg) tp, options(att_syntax));
    }
    tp
}

/// Sets the %fs register base to `value` for this thread.
///
/// # Safety
///
/// `value` must hold an address to a structure, first element of which is a pointer to itself.
/// Usual pointer safety requirements apply.
pub unsafe fn set_thread_pointer(value: usize) -> Result<(), Error> {
    crate::process::set_thread_option::<thread::ThreadPointer>(&value)
}
