+ uint32_t *esp;
+ struct thread *t;
+
+ /* Copy the CPU's stack pointer into `esp', and then round that
+ down to the start of a page. Because `struct thread' is
+ always at the beginning of a page and the stack pointer is
+ somewhere in the middle, this locates the curent thread. */
+ asm ("movl %%esp, %0\n" : "=g" (esp));
+ t = pg_round_down (esp);
+
+ /* Make sure T is really a thread.
+ If this assertion fires, then your thread may have
+ overflowed its stack. Each thread has less than 4 kB of
+ stack, so a few big automatic arrays or moderate recursion
+ can cause stack overflow. */
+ ASSERT (is_thread (t));
+
+ return t;