mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
add a platform independent function to manage the TLS
This commit is contained in:
parent
e666d91a5b
commit
a8661c1fb8
3 changed files with 28 additions and 2 deletions
|
@ -477,6 +477,24 @@ extern func_read_fsgs readgs;
|
|||
extern func_write_fsgs writefs;
|
||||
extern func_write_fsgs writegs;
|
||||
|
||||
/** @brife Get thread local storage
|
||||
*
|
||||
* Helper function to get the TLS of the current task
|
||||
*/
|
||||
static inline size_t get_tls(void)
|
||||
{
|
||||
return readfs();
|
||||
}
|
||||
|
||||
/** @brief Set thread local storage
|
||||
*
|
||||
* Helper function to set the TLS of the current task
|
||||
*/
|
||||
static inline void set_tls(size_t addr)
|
||||
{
|
||||
writefs(addr);
|
||||
}
|
||||
|
||||
/** @brief Flush cache
|
||||
*
|
||||
* The wbinvd asm instruction which stands for "Write back and invalidate"
|
||||
|
|
|
@ -290,9 +290,9 @@ static int initd(void* arg)
|
|||
memcpy((void*) tls_addr, (void*) curr_task->tls_addr, curr_task->tls_size);
|
||||
|
||||
// set fs register to the TLS segment
|
||||
writefs((size_t) tls_addr);
|
||||
set_tls((size_t) tls_addr);
|
||||
kprintf("Task %d set fs to 0x%zx\n", curr_task->id, tls_addr);
|
||||
} else writefs(0); // no TLS => clear fs register
|
||||
} else set_tls(0); // no TLS => clear fs register
|
||||
|
||||
//init_rcce();
|
||||
|
||||
|
|
|
@ -222,6 +222,7 @@ void finish_task_switch(void)
|
|||
void NORETURN do_exit(int arg)
|
||||
{
|
||||
task_t* curr_task = per_core(current_task);
|
||||
void* tls_addr = NULL;
|
||||
const uint32_t core_id = CORE_ID;
|
||||
|
||||
kprintf("Terminate task: %u, return value %d\n", curr_task->id, arg);
|
||||
|
@ -237,6 +238,13 @@ void NORETURN do_exit(int arg)
|
|||
readyqueues[core_id].nr_tasks--;
|
||||
spinlock_irqsave_unlock(&readyqueues[core_id].lock);
|
||||
|
||||
// do we need to release the TLS?
|
||||
tls_addr = (void*)get_tls();
|
||||
if (tls_addr) {
|
||||
kprintf("Release TLS %p\n", tls_addr);
|
||||
kfree(tls_addr);
|
||||
}
|
||||
|
||||
curr_task->status = TASK_FINISHED;
|
||||
reschedule();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue