- return(KERN_SUCCESS);
-}
-
-kern_return_t
-thread_set_cthread_self(uint32_t self)
-{
- current_thread()->machine.pcb->cthread_self = (uint64_t) self;
-
- return (KERN_SUCCESS);
-}
-
-kern_return_t
-thread_get_cthread_self(void)
-{
- return ((kern_return_t)current_thread()->machine.pcb->cthread_self);
-}
-
-kern_return_t
-thread_fast_set_cthread_self(uint32_t self)
-{
- pcb_t pcb;
- x86_saved_state32_t *iss;
-
- pcb = (pcb_t)current_thread()->machine.pcb;
- thread_compose_cthread_desc(self, pcb);
- pcb->cthread_self = (uint64_t) self; /* preserve old func too */
- iss = saved_state32(pcb->iss);
- iss->gs = USER_CTHREAD;
-
- return (USER_CTHREAD);
-}
-
-kern_return_t
-thread_fast_set_cthread_self64(uint64_t self)
-{
- pcb_t pcb;
- x86_saved_state64_t *iss;
-
- pcb = current_thread()->machine.pcb;
-
- /* check for canonical address, set 0 otherwise */
- if (!IS_USERADDR64_CANONICAL(self))
- self = 0ULL;
- pcb->cthread_self = self;
- current_cpu_datap()->cpu_uber.cu_user_gs_base = self;
-
- /* XXX for 64-in-32 */
- iss = saved_state64(pcb->iss);
- iss->gs = USER_CTHREAD;
- thread_compose_cthread_desc((uint32_t) self, pcb);
-
- return (USER_CTHREAD);
-}
-
-/*
- * thread_set_user_ldt routine is the interface for the user level
- * settable ldt entry feature. allowing a user to create arbitrary
- * ldt entries seems to be too large of a security hole, so instead
- * this mechanism is in place to allow user level processes to have
- * an ldt entry that can be used in conjunction with the FS register.
- *
- * Swapping occurs inside the pcb.c file along with initialization
- * when a thread is created. The basic functioning theory is that the
- * pcb->uldt_selector variable will contain either 0 meaning the
- * process has not set up any entry, or the selector to be used in
- * the FS register. pcb->uldt_desc contains the actual descriptor the
- * user has set up stored in machine usable ldt format.
- *
- * Currently one entry is shared by all threads (USER_SETTABLE), but
- * this could be changed in the future by changing how this routine
- * allocates the selector. There seems to be no real reason at this
- * time to have this added feature, but in the future it might be
- * needed.
- *
- * address is the linear address of the start of the data area size
- * is the size in bytes of the area flags should always be set to 0
- * for now. in the future it could be used to set R/W permisions or
- * other functions. Currently the segment is created as a data segment
- * up to 1 megabyte in size with full read/write permisions only.
- *
- * this call returns the segment selector or -1 if any error occurs
- */
-kern_return_t
-thread_set_user_ldt(uint32_t address, uint32_t size, uint32_t flags)
-{
- pcb_t pcb;
- struct fake_descriptor temp;
- int mycpu;
-
- if (flags != 0)
- return -1; // flags not supported
- if (size > 0xFFFFF)
- return -1; // size too big, 1 meg is the limit
-
- mp_disable_preemption();
- mycpu = cpu_number();
-
- // create a "fake" descriptor so we can use fix_desc()
- // to build a real one...
- // 32 bit default operation size
- // standard read/write perms for a data segment
- pcb = (pcb_t)current_thread()->machine.pcb;
- temp.offset = address;
- temp.lim_or_seg = size;
- temp.size_or_wdct = SZ_32;
- temp.access = ACC_P|ACC_PL_U|ACC_DATA_W;
-
- // turn this into a real descriptor
- fix_desc(&temp,1);
-
- // set up our data in the pcb
- pcb->uldt_desc = *(struct real_descriptor*)&temp;
- pcb->uldt_selector = USER_SETTABLE; // set the selector value
-
- // now set it up in the current table...
- *ldt_desc_p(USER_SETTABLE) = *(struct real_descriptor*)&temp;
-
- mp_enable_preemption();
-
- return USER_SETTABLE;