+zk_thread_current(void)
+{
+ kthread_t *kt = pthread_getspecific(kthread_key);
+
+ ASSERT3P(kt, !=, NULL);
+
+ return kt;
+}
+
+void *
+zk_thread_helper(void *arg)
+{
+ kthread_t *kt = (kthread_t *) arg;
+
+ VERIFY3S(pthread_setspecific(kthread_key, kt), ==, 0);
+
+ VERIFY3S(pthread_mutex_lock(&kthread_lock), ==, 0);
+ kthread_nr++;
+ VERIFY3S(pthread_mutex_unlock(&kthread_lock), ==, 0);
+
+ kt->t_tid = pthread_self();
+ ((thread_func_arg_t) kt->t_func)(kt->t_arg);
+
+ /* Unreachable, thread must exit with thread_exit() */
+ abort();
+
+ return NULL;
+}
+
+kthread_t *
+zk_thread_create(caddr_t stk, size_t stksize, thread_func_t func, void *arg,
+ size_t len, proc_t *pp, int state, pri_t pri)
+{
+ kthread_t *kt;
+ pthread_attr_t attr;
+ size_t stack;
+
+ ASSERT3S(state & ~TS_RUN, ==, 0);
+
+ kt = umem_zalloc(sizeof(kthread_t), UMEM_NOFAIL);
+ kt->t_func = func;
+ kt->t_arg = arg;
+
+ /*
+ * The Solaris kernel stack size is 24k for x86/x86_64.
+ * The Linux kernel stack size is 8k for x86/x86_64.
+ *
+ * We reduce the default stack size in userspace, to ensure
+ * we observe stack overruns in user space as well as in
+ * kernel space. PTHREAD_STACK_MIN is the minimum stack
+ * required for a NULL procedure in user space and is added
+ * in to the stack requirements.
+ *
+ * Some buggy NPTL threading implementations include the
+ * guard area within the stack size allocations. In
+ * this case we allocate an extra page to account for the
+ * guard area since we only have two pages of usable stack
+ * on Linux.
+ */
+
+ stack = PTHREAD_STACK_MIN + MAX(stksize, STACK_SIZE) +
+ EXTRA_GUARD_BYTES;
+
+ VERIFY3S(pthread_attr_init(&attr), ==, 0);
+ VERIFY3S(pthread_attr_setstacksize(&attr, stack), ==, 0);
+ VERIFY3S(pthread_attr_setguardsize(&attr, PAGESIZE), ==, 0);
+
+ VERIFY3S(pthread_create(&kt->t_tid, &attr, &zk_thread_helper, kt),
+ ==, 0);
+
+ VERIFY3S(pthread_attr_destroy(&attr), ==, 0);
+
+ return kt;
+}
+
+void
+zk_thread_exit(void)