+ 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)
+{
+ kthread_t *kt = curthread;
+
+ ASSERT(pthread_equal(kt->t_tid, pthread_self()));
+
+ umem_free(kt, sizeof(kthread_t));
+
+ pthread_mutex_lock(&kthread_lock);
+ kthread_nr--;
+ pthread_mutex_unlock(&kthread_lock);
+
+ pthread_cond_broadcast(&kthread_cond);
+ pthread_exit((void *)TS_MAGIC);
+}
+
+void
+zk_thread_join(kt_did_t tid)
+{
+ void *ret;
+
+ pthread_join((pthread_t)tid, &ret);
+ VERIFY3P(ret, ==, (void *)TS_MAGIC);