+void
+thread_set_cthreadself(thread_t thread, uint64_t pself, int isLP64)
+{
+ if (isLP64 == 0) {
+ pcb_t pcb;
+ x86_saved_state32_t *iss;
+
+ pcb = (pcb_t)thread->machine.pcb;
+ thread_compose_cthread_desc(pself, pcb);
+ pcb->cthread_self = (uint64_t) pself; /* preserve old func too */
+ iss = saved_state32(pcb->iss);
+ iss->gs = USER_CTHREAD;
+ } else {
+ pcb_t pcb;
+ x86_saved_state64_t *iss;
+
+ pcb = thread->machine.pcb;
+
+ /* check for canonical address, set 0 otherwise */
+ if (!IS_USERADDR64_CANONICAL(pself))
+ pself = 0ULL;
+ pcb->cthread_self = pself;
+
+ /* XXX for 64-in-32 */
+ iss = saved_state64(pcb->iss);
+ iss->gs = USER_CTHREAD;
+ thread_compose_cthread_desc((uint32_t) pself, pcb);
+ }
+}
+
+