[][src]Struct sunrise_kernel::cpu_locals::CpuLocalRegion

struct CpuLocalRegion {
    ptr: usize,
    layout: Layout,
    tcb_offset: usize,
}

Represents an allocated cpu local region.

Because cpu regions have a really specific layout, we don't use Box and instead interact with the allocator directly. This type is the equivalent of a Box, it stores the pointer to the allocated memory, and deallocates it on Drop.

Fields

ptr: usize

Pointer to the allocated memory

layout: Layout

Layout of the allocated memory. Used when deallocating.

tcb_offset: usize

Offset of the TCB in this allocation.

Implementations

impl CpuLocalRegion[src]

fn tcb(&self) -> &ThreadControlBlock[src]

Returns a pointer to the ThreadControlBlock in the allocated region. All cpu-local arithmetic are done relative to this pointer.

For TLS to work, the value stored at this address should be the address itself, i.e. having a pointer pointing to itself.

fn allocate(block_src: &[u8], block_size: usize, block_align: usize) -> Self[src]

Allocates a CpuLocalRegion.

The region's content is copied from the TLS initialisation image described by block_src, padded with 0s for block_size, to which is appended a ThreadControlBlock.

The CpuLocalRegion uses PT_TLS's p_align field passed in block_align to compute its layout and total size.

Alignment


        V----------------------V  tls_align_up(tls_size_1, align_1)

                               +-- gs:0
                               |
        +----------------------|-- tlsoffset_1 = gs:0 - tls_align_up(tls_size_1, align_1)
        |                      |
        V                      V

        j----------------~-----j---------j
   ...  |    tls_size_1  | pad |   TCB   |
        j----------------~-----j---------j

   ^    ^                      ^
   |    |                      |
   |    |                      +-- TCB_align: Determines alignment of everything.
   |    |                          = max(align_of::<TCB>(), align_1). e.g. : 16.
   |    |
   |    +------------------------- TCB_align - n * align_1
   |                               => still aligned to align_1 because TCB is aligned to align_1.
   |
   +------------------------------ alloc_align == TCB_align
                                   => &TCB = &alloc + tls_align_up(gs:0 - tls_offset_1, TCB_align)

   ^---^                           alloc_pad

Trait Implementations

impl Debug for CpuLocalRegion[src]

impl Drop for CpuLocalRegion[src]

fn drop(&mut self)[src]

Dropping a CpuLocalRegion deallocates it.

Auto Trait Implementations

impl RefUnwindSafe for CpuLocalRegion

impl Send for CpuLocalRegion

impl Sync for CpuLocalRegion

impl Unpin for CpuLocalRegion

impl UnwindSafe for CpuLocalRegion

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.