51 panic(
"Failed to get TCB");
54 dbg_printf(
"\nTHREAD DESTROYING %p (arg: %p)\n", tcb, arg);
66 static inline void push_user_stackframe(
struct thread *tcb)
82 isr_frame = (
struct pt_regs *)user_frame;
92 isr_frame->
es = isr_frame->
ds;
93 isr_frame->
fs = isr_frame->
ds;
94 isr_frame->
gs = isr_frame->
ds;
97 isr_frame->
eflags = 0x0202;
117 static inline void push_kernel_stackframe(
struct thread *tcb,
118 unsigned long eip,
unsigned long arg)
122 unsigned long *exit_stack;
124 exit_stack = (
unsigned long *)tcb->
esp;
134 *exit_stack = (
unsigned long)tcb;
145 thread_frame->
ret_addr = (
unsigned long)cleanup;
146 thread_frame->
arg = (
unsigned long)arg;
155 isr_frame = (
struct pt_regs *)thread_frame;
165 isr_frame->
es = isr_frame->
ds;
166 isr_frame->
fs = isr_frame->
ds;
167 isr_frame->
gs = isr_frame->
ds;
170 isr_frame->
eflags = 0x0202;
172 isr_frame->
ebp = (
unsigned long)&thread_frame->
arg;
191 arch_data =
malloc(
sizeof(*arch_data));
193 dbg_printf(
"Failed to allocate heap for arch_data\n");
197 arch_data->
pma_pgd = read_cr3();
203 tcb =
malloc(
sizeof(*tcb));
211 dbg_printf(
"Failed to create a new thread\n");
238 static inline int update_thread_user_data(
struct thread *tcb)
242 new_user_data =
calloc(1,
sizeof(*new_user_data));
243 if (!new_user_data) {
251 static inline int update_thread_for_user(
struct thread *tcb)
255 struct pgde *src_pgd;
312 ret = update_thread_user_data(tcb);
321 arch_data->
rpgd = rpgd;
326 int execl(
const char *path,
const char *arg, ...)
336 ret = update_thread_for_user(tcb);
354 int execle(
const char *path,
const char *arg, ...)
364 ret = update_thread_for_user(tcb);
392 ret = update_thread_for_user(tcb);
410 int execv(
const char *path,
char *
const argv[])
421 &&
"Main thread is not able to be a user level thread");
423 ret = update_thread_for_user(tcb);
428 load_elf(tcb, argv[0]);
440 int execvpe(
const char *
file,
const char *
const argv[],
char *
const envp[])
449 ret = update_thread_for_user(tcb);
474 ret = update_thread_for_user(tcb);
490 void *(*func)(
void *),
void *arg)
497 arch_data =
malloc(
sizeof(*arch_data));
504 tcb =
malloc(
sizeof(*tcb));
550 attr =
malloc(
sizeof(*attr));
555 memcpy(attr, &init_attr,
sizeof(init_attr));
585 tcb = (
struct thread *)handle;
587 printf(
"Join: %p\n", tcb);
595 tcb = (
struct thread *)handle;
597 printf(
"Detach: %p\n", tcb);
607 th1 = (
struct thread *)t1;
608 th2 = (
struct thread *)t2;
636 tcb = (
struct thread *)thid;
639 dbg_printf(
"Let's canceling the thread %p (ring: %d)\n", tcb, ring);
721 register unsigned long esp
asm(
"esp");
727 unit =
esp & ~(unit - 1);
734 if ((
unsigned long)local < unit) {