/* Initialize a dde26 thread. * * - Allocate thread data, as well as a Linux task struct, * - Fill in default values for thread_info, and task, * - Adapt task struct's thread_info backreference * - Initialize the DDE sleep lock */ static dde26_thread_data *init_dde26_thread(void) { /* * Virtual PID counter */ static atomic_t pid_counter = ATOMIC_INIT(0); dde26_thread_data *t = vmalloc(sizeof(dde26_thread_data)); Assert(t); memcpy(&t->_vpid, &init_struct_pid, sizeof(struct pid)); t->_vpid.numbers[0].nr = atomic_inc_return(&pid_counter); memcpy(&LX_THREAD(t), &init_thread, sizeof(struct thread_info)); LX_TASK(t) = vmalloc(sizeof(struct task_struct)); Assert(LX_TASK(t)); memcpy(LX_TASK(t), &init_task, sizeof(struct task_struct)); /* nice: Linux backreferences a task`s thread_info from the * task struct (which in turn can be found using the * thread_info...) */ LX_TASK(t)->stack = &LX_THREAD(t); /* initialize this thread's sleep lock */ SLEEP_LOCK(t) = ddekit_sem_init(0); return t; }
/* Process setup for worker threads */ void dde_linux26_process_add_worker(const char *name) { dde_linux26_thread_data *cur = init_dde_linux26_thread(); /* * If this function is called for a kernel_thread, the thread already has * been set up and we just need to store the DDE kit thread handle. * However, this function may also be called directly to turn other threads * into a DDE thread. Then, we need to initialize here. */ cur->_dde_kit_thread = dde_kit_thread_myself(); if (cur->_dde_kit_thread == NULL) { /* external threads can be adopted */ cur->_dde_kit_thread = dde_kit_thread_adopt_myself(name); if (cur->_dde_kit_thread == NULL) dde_kit_panic("Panic: thread was not adopted by DDE kit"); } dde_kit_thread_set_my_data(cur); attach_pid(LX_TASK(cur), 0, dde_kit_thread_get_id(cur->_dde_kit_thread)); /* * Linux' default is to have this set to 1 initially and let the * scheduler set this to 0 later on. */ current_thread_info()->preempt_count = 0; }
int dde_linux26_process_from_dde_kit(struct dde_kit_thread *t) { dde_linux26_thread_data *cur = init_dde_linux26_thread(); cur->_dde_kit_thread = t; dde_kit_thread_set_data(t, cur); attach_pid(LX_TASK(cur), 0, dde_kit_thread_get_id(t)); return 0; }
/** * Add an already existing DDEKit thread to the set of threads known to the * Linux environment. This is used for the timer thread, which is actually a * DDEKit thread, but Linux code shall see it as a Linux thread as well. */ int l4dde26_process_from_ddekit(ddekit_thread_t *t) { Assert(t); dde26_thread_data *cur = init_dde26_thread(); cur->_ddekit_thread = t; ddekit_thread_set_data(t, cur); attach_pid(LX_TASK(cur), 0, &cur->_vpid); return 0; }
/** * Initialize a DDE Linux 2.6 thread * * - Allocate thread data, as well as a Linux task struct, * - Fill in default values for thread_info, and task, * - Adapt task struct's thread_info backreference * - Initialize the DDE sleep lock */ static inline dde_linux26_thread_data *init_dde_linux26_thread(void) { dde_linux26_thread_data *t = vmalloc(sizeof(dde_linux26_thread_data)); dde_kit_assert(t); memcpy(&LX_THREAD(t), &init_thread, sizeof(struct thread_info)); LX_TASK(t) = vmalloc(sizeof(struct task_struct)); dde_kit_assert(LX_TASK(t)); memcpy(LX_TASK(t), &init_task, sizeof(struct task_struct)); /* nice: Linux backreferences a task`s thread_info from the * task struct (which in turn can be found using the * thread_info...) */ LX_TASK(t)->thread_info = &LX_THREAD(t); /* initialize this thread's sleep lock */ SLEEP_LOCK(t) = dde_kit_sem_init(0); return t; }
/* Process setup for worker threads */ int l4dde26_process_add_worker(void) { dde26_thread_data *cur = init_dde26_thread(); /* If this function is called for a kernel_thread, the thread already has * been set up and we just need to store a reference to the ddekit struct. * However, this function may also be called directly to turn an L4 thread * into a DDE thread. Then, we need to initialize here. */ cur->_ddekit_thread = ddekit_thread_myself(); if (cur->_ddekit_thread == NULL) cur->_ddekit_thread = ddekit_thread_setup_myself(".dde26_thread"); Assert(cur->_ddekit_thread); ddekit_thread_set_my_data(cur); attach_pid(LX_TASK(cur), 0, &cur->_vpid); /* Linux' default is to have this set to 1 initially and let the * scheduler set this to 0 later on. */ current_thread_info()->preempt_count = 0; return 0; }