]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/pcb.c
5f1e65e5594a1a9f8709b981edcec475dd73d8ab
[apple/xnu.git] / osfmk / i386 / pcb.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50
51 #include <cpus.h>
52 #include <mach_rt.h>
53 #include <mach_debug.h>
54 #include <mach_ldebug.h>
55
56 #include <sys/kdebug.h>
57
58 #include <mach/kern_return.h>
59 #include <mach/thread_status.h>
60 #include <mach/vm_param.h>
61 #include <mach/rpc.h>
62
63 #include <kern/counters.h>
64 #include <kern/mach_param.h>
65 #include <kern/task.h>
66 #include <kern/thread.h>
67 #include <kern/thread_act.h>
68 #include <kern/thread_swap.h>
69 #include <kern/sched_prim.h>
70 #include <kern/misc_protos.h>
71 #include <kern/assert.h>
72 #include <kern/spl.h>
73 #include <ipc/ipc_port.h>
74 #include <vm/vm_kern.h>
75 #include <vm/pmap.h>
76
77 #include <i386/thread.h>
78 #include <i386/eflags.h>
79 #include <i386/proc_reg.h>
80 #include <i386/seg.h>
81 #include <i386/tss.h>
82 #include <i386/user_ldt.h>
83 #include <i386/fpu.h>
84 #include <i386/iopb_entries.h>
85
86 /*
87 * Maps state flavor to number of words in the state:
88 */
89 unsigned int state_count[] = {
90 /* FLAVOR_LIST */ 0,
91 i386_NEW_THREAD_STATE_COUNT,
92 i386_FLOAT_STATE_COUNT,
93 i386_ISA_PORT_MAP_STATE_COUNT,
94 i386_V86_ASSIST_STATE_COUNT,
95 i386_REGS_SEGS_STATE_COUNT,
96 i386_THREAD_SYSCALL_STATE_COUNT,
97 /* THREAD_STATE_NONE */ 0,
98 i386_SAVED_STATE_COUNT,
99 };
100
101 /* Forward */
102
103 void act_machine_throughcall(thread_act_t thr_act);
104 extern thread_t Switch_context(
105 thread_t old,
106 void (*cont)(void),
107 thread_t new);
108 extern void Thread_continue(void);
109 extern void Load_context(
110 thread_t thread);
111
112 /*
113 * consider_machine_collect:
114 *
115 * Try to collect machine-dependent pages
116 */
117 void
118 consider_machine_collect()
119 {
120 }
121
122 void
123 consider_machine_adjust()
124 {
125 }
126
127
128 /*
129 * machine_kernel_stack_init:
130 *
131 * Initialize a kernel stack which has already been
132 * attached to its thread_activation.
133 */
134
135 void
136 machine_kernel_stack_init(
137 thread_t thread,
138 void (*start_pos)(thread_t))
139 {
140 thread_act_t thr_act = thread->top_act;
141 vm_offset_t stack;
142
143 assert(thr_act);
144 stack = thread->kernel_stack;
145 assert(stack);
146
147 #if MACH_ASSERT
148 if (watchacts & WA_PCB) {
149 printf("machine_kernel_stack_init(thr=%x,stk=%x,start_pos=%x)\n",
150 thread,stack,start_pos);
151 printf("\tstack_iks=%x, stack_iel=%x\n",
152 STACK_IKS(stack), STACK_IEL(stack));
153 }
154 #endif /* MACH_ASSERT */
155
156 /*
157 * We want to run at start_pos, giving it as an argument
158 * the return value from Load_context/Switch_context.
159 * Thread_continue takes care of the mismatch between
160 * the argument-passing/return-value conventions.
161 * This function will not return normally,
162 * so we don`t have to worry about a return address.
163 */
164 STACK_IKS(stack)->k_eip = (int) Thread_continue;
165 STACK_IKS(stack)->k_ebx = (int) start_pos;
166 STACK_IKS(stack)->k_esp = (int) STACK_IEL(stack);
167
168 /*
169 * Point top of kernel stack to user`s registers.
170 */
171 STACK_IEL(stack)->saved_state = &thr_act->mact.pcb->iss;
172 }
173
174
175 #if NCPUS > 1
176 #define curr_gdt(mycpu) (mp_gdt[mycpu])
177 #define curr_ktss(mycpu) (mp_ktss[mycpu])
178 #else
179 #define curr_gdt(mycpu) (gdt)
180 #define curr_ktss(mycpu) (&ktss)
181 #endif
182
183 #define gdt_desc_p(mycpu,sel) \
184 ((struct real_descriptor *)&curr_gdt(mycpu)[sel_idx(sel)])
185
186 void
187 act_machine_switch_pcb( thread_act_t new_act )
188 {
189 pcb_t pcb = new_act->mact.pcb;
190 int mycpu;
191 {
192 register iopb_tss_t tss = pcb->ims.io_tss;
193 vm_offset_t pcb_stack_top;
194
195 assert(new_act->thread != NULL);
196 assert(new_act->thread->kernel_stack != 0);
197 STACK_IEL(new_act->thread->kernel_stack)->saved_state =
198 &new_act->mact.pcb->iss;
199
200 /*
201 * Save a pointer to the top of the "kernel" stack -
202 * actually the place in the PCB where a trap into
203 * kernel mode will push the registers.
204 * The location depends on V8086 mode. If we are
205 * not in V8086 mode, then a trap into the kernel
206 * won`t save the v86 segments, so we leave room.
207 */
208
209 pcb_stack_top = (pcb->iss.efl & EFL_VM)
210 ? (int) (&pcb->iss + 1)
211 : (int) (&pcb->iss.v86_segs);
212
213 mp_disable_preemption();
214 mycpu = cpu_number();
215
216 if (tss == 0) {
217 /*
218 * No per-thread IO permissions.
219 * Use standard kernel TSS.
220 */
221 if (!(gdt_desc_p(mycpu,KERNEL_TSS)->access & ACC_TSS_BUSY))
222 set_tr(KERNEL_TSS);
223 curr_ktss(mycpu)->esp0 = pcb_stack_top;
224 }
225 else {
226 /*
227 * Set the IO permissions. Use this thread`s TSS.
228 */
229 *gdt_desc_p(mycpu,USER_TSS)
230 = *(struct real_descriptor *)tss->iopb_desc;
231 tss->tss.esp0 = pcb_stack_top;
232 set_tr(USER_TSS);
233 gdt_desc_p(mycpu,KERNEL_TSS)->access &= ~ ACC_TSS_BUSY;
234 }
235 }
236
237 {
238 register user_ldt_t ldt = pcb->ims.ldt;
239 /*
240 * Set the thread`s LDT.
241 */
242 if (ldt == 0) {
243 /*
244 * Use system LDT.
245 */
246 set_ldt(KERNEL_LDT);
247 }
248 else {
249 /*
250 * Thread has its own LDT.
251 */
252 *gdt_desc_p(mycpu,USER_LDT) = ldt->desc;
253 set_ldt(USER_LDT);
254 }
255 }
256 mp_enable_preemption();
257 /*
258 * Load the floating-point context, if necessary.
259 */
260 fpu_load_context(pcb);
261
262 }
263
264 /*
265 * flush out any lazily evaluated HW state in the
266 * owning thread's context, before termination.
267 */
268 void
269 thread_machine_flush( thread_act_t cur_act )
270 {
271 fpflush(cur_act);
272 }
273
274 /*
275 * Switch to the first thread on a CPU.
276 */
277 void
278 load_context(
279 thread_t new)
280 {
281 act_machine_switch_pcb(new->top_act);
282 Load_context(new);
283 }
284
285 /*
286 * Number of times we needed to swap an activation back in before
287 * switching to it.
288 */
289 int switch_act_swapins = 0;
290
291 /*
292 * machine_switch_act
293 *
294 * Machine-dependent details of activation switching. Called with
295 * RPC locks held and preemption disabled.
296 */
297 void
298 machine_switch_act(
299 thread_t thread,
300 thread_act_t old,
301 thread_act_t new,
302 int cpu)
303 {
304 /*
305 * Switch the vm, ast and pcb context.
306 * Save FP registers if in use and set TS (task switch) bit.
307 */
308 fpu_save_context(thread);
309
310 active_stacks[cpu] = thread->kernel_stack;
311 ast_context(new, cpu);
312
313 PMAP_SWITCH_CONTEXT(old, new, cpu);
314 act_machine_switch_pcb(new);
315 }
316
317 /*
318 * Switch to a new thread.
319 * Save the old thread`s kernel state or continuation,
320 * and return it.
321 */
322 thread_t
323 switch_context(
324 thread_t old,
325 void (*continuation)(void),
326 thread_t new)
327 {
328 register thread_act_t old_act = old->top_act,
329 new_act = new->top_act;
330
331 #if MACH_RT
332 assert(old_act->kernel_loaded ||
333 active_stacks[cpu_number()] == old_act->thread->kernel_stack);
334 assert (get_preemption_level() == 1);
335 #endif
336 check_simple_locks();
337
338 /*
339 * Save FP registers if in use.
340 */
341 fpu_save_context(old);
342
343 #if MACH_ASSERT
344 if (watchacts & WA_SWITCH)
345 printf("\tswitch_context(old=%x con=%x new=%x)\n",
346 old, continuation, new);
347 #endif /* MACH_ASSERT */
348
349 /*
350 * Switch address maps if need be, even if not switching tasks.
351 * (A server activation may be "borrowing" a client map.)
352 */
353 {
354 int mycpu = cpu_number();
355
356 PMAP_SWITCH_CONTEXT(old_act, new_act, mycpu)
357 }
358
359 /*
360 * Load the rest of the user state for the new thread
361 */
362 act_machine_switch_pcb(new_act);
363 return(Switch_context(old, continuation, new));
364 }
365
366 void
367 pcb_module_init(void)
368 {
369 fpu_module_init();
370 iopb_init();
371 }
372
373 void
374 pcb_init( register thread_act_t thr_act )
375 {
376 register pcb_t pcb;
377
378 assert(thr_act->mact.pcb == (pcb_t)0);
379 pcb = thr_act->mact.pcb = &thr_act->mact.xxx_pcb;
380
381 #if MACH_ASSERT
382 if (watchacts & WA_PCB)
383 printf("pcb_init(%x) pcb=%x\n", thr_act, pcb);
384 #endif /* MACH_ASSERT */
385
386 /*
387 * We can't let random values leak out to the user.
388 * (however, act_create() zeroed the entire thr_act, mact, pcb)
389 * bzero((char *) pcb, sizeof *pcb);
390 */
391 simple_lock_init(&pcb->lock, ETAP_MISC_PCB);
392
393 /*
394 * Guarantee that the bootstrapped thread will be in user
395 * mode.
396 */
397 pcb->iss.cs = USER_CS;
398 pcb->iss.ss = USER_DS;
399 pcb->iss.ds = USER_DS;
400 pcb->iss.es = USER_DS;
401 pcb->iss.fs = USER_DS;
402 pcb->iss.gs = USER_DS;
403 pcb->iss.efl = EFL_USER_SET;
404 }
405
406 /*
407 * Adjust saved register state for thread belonging to task
408 * created with kernel_task_create().
409 */
410 void
411 pcb_user_to_kernel(
412 thread_act_t thr_act)
413 {
414 register pcb_t pcb = thr_act->mact.pcb;
415
416 pcb->iss.cs = KERNEL_CS;
417 pcb->iss.ss = KERNEL_DS;
418 pcb->iss.ds = KERNEL_DS;
419 pcb->iss.es = KERNEL_DS;
420 pcb->iss.fs = KERNEL_DS;
421 pcb->iss.gs = CPU_DATA;
422 }
423
424 void
425 pcb_terminate(
426 register thread_act_t thr_act)
427 {
428 register pcb_t pcb = thr_act->mact.pcb;
429
430 assert(pcb);
431
432 if (pcb->ims.io_tss != 0)
433 iopb_destroy(pcb->ims.io_tss);
434 if (pcb->ims.ifps != 0)
435 fp_free(pcb->ims.ifps);
436 if (pcb->ims.ldt != 0)
437 user_ldt_free(pcb->ims.ldt);
438 thr_act->mact.pcb = (pcb_t)0;
439 }
440
441 /*
442 * pcb_collect:
443 *
444 * Attempt to free excess pcb memory.
445 */
446
447 void
448 pcb_collect(
449 register thread_act_t thr_act)
450 {
451 /* accomplishes very little */
452 }
453
454 /*
455 * act_machine_sv_free
456 * release saveareas associated with an act. if flag is true, release
457 * user level savearea(s) too, else don't
458 */
459 void
460 act_machine_sv_free(thread_act_t act, int flag)
461 {
462
463 }
464
465 /*
466 * act_machine_set_state:
467 *
468 * Set the status of the specified thread. Called with "appropriate"
469 * thread-related locks held (see act_lock_thread()), so
470 * thr_act->thread is guaranteed not to change.
471 */
472
473 kern_return_t
474 act_machine_set_state(
475 thread_act_t thr_act,
476 thread_flavor_t flavor,
477 thread_state_t tstate,
478 mach_msg_type_number_t count)
479 {
480 int kernel_act = thr_act->kernel_loading ||
481 thr_act->kernel_loaded;
482
483 #if MACH_ASSERT
484 if (watchacts & WA_STATE)
485 printf("act_%x act_m_set_state(thr_act=%x,flav=%x,st=%x,cnt=%x)\n",
486 current_act(), thr_act, flavor, tstate, count);
487 #endif /* MACH_ASSERT */
488
489 switch (flavor) {
490 case THREAD_SYSCALL_STATE:
491 {
492 register struct thread_syscall_state *state;
493 register struct i386_saved_state *saved_state = USER_REGS(thr_act);
494
495 state = (struct thread_syscall_state *) tstate;
496 saved_state->eax = state->eax;
497 saved_state->edx = state->edx;
498 if (kernel_act)
499 saved_state->efl = state->efl;
500 else
501 saved_state->efl = (state->efl & ~EFL_USER_CLEAR) | EFL_USER_SET;
502 saved_state->eip = state->eip;
503 saved_state->uesp = state->esp;
504 break;
505 }
506
507 case i386_SAVED_STATE:
508 {
509 register struct i386_saved_state *state;
510 register struct i386_saved_state *saved_state;
511
512 if (count < i386_SAVED_STATE_COUNT) {
513 return(KERN_INVALID_ARGUMENT);
514 }
515
516 state = (struct i386_saved_state *) tstate;
517
518 saved_state = USER_REGS(thr_act);
519
520 /*
521 * General registers
522 */
523 saved_state->edi = state->edi;
524 saved_state->esi = state->esi;
525 saved_state->ebp = state->ebp;
526 saved_state->uesp = state->uesp;
527 saved_state->ebx = state->ebx;
528 saved_state->edx = state->edx;
529 saved_state->ecx = state->ecx;
530 saved_state->eax = state->eax;
531 saved_state->eip = state->eip;
532 if (kernel_act)
533 saved_state->efl = state->efl;
534 else
535 saved_state->efl = (state->efl & ~EFL_USER_CLEAR)
536 | EFL_USER_SET;
537
538 /*
539 * Segment registers. Set differently in V8086 mode.
540 */
541 if (state->efl & EFL_VM) {
542 /*
543 * Set V8086 mode segment registers.
544 */
545 saved_state->cs = state->cs & 0xffff;
546 saved_state->ss = state->ss & 0xffff;
547 saved_state->v86_segs.v86_ds = state->ds & 0xffff;
548 saved_state->v86_segs.v86_es = state->es & 0xffff;
549 saved_state->v86_segs.v86_fs = state->fs & 0xffff;
550 saved_state->v86_segs.v86_gs = state->gs & 0xffff;
551
552 /*
553 * Zero protected mode segment registers.
554 */
555 saved_state->ds = 0;
556 saved_state->es = 0;
557 saved_state->fs = 0;
558 saved_state->gs = 0;
559
560 if (thr_act->mact.pcb->ims.v86s.int_table) {
561 /*
562 * Hardware assist on.
563 */
564 thr_act->mact.pcb->ims.v86s.flags =
565 state->efl & (EFL_TF | EFL_IF);
566 }
567 }
568 else if (!kernel_act) {
569 /*
570 * 386 mode. Set segment registers for flat
571 * 32-bit address space.
572 */
573 saved_state->cs = USER_CS;
574 saved_state->ss = USER_DS;
575 saved_state->ds = USER_DS;
576 saved_state->es = USER_DS;
577 saved_state->fs = USER_DS;
578 saved_state->gs = USER_DS;
579 }
580 else {
581 /*
582 * User setting segment registers.
583 * Code and stack selectors have already been
584 * checked. Others will be reset by 'iret'
585 * if they are not valid.
586 */
587 saved_state->cs = state->cs;
588 saved_state->ss = state->ss;
589 saved_state->ds = state->ds;
590 saved_state->es = state->es;
591 saved_state->fs = state->fs;
592 saved_state->gs = state->gs;
593 }
594 break;
595 }
596
597 case i386_NEW_THREAD_STATE:
598 case i386_REGS_SEGS_STATE:
599 {
600 register struct i386_new_thread_state *state;
601 register struct i386_saved_state *saved_state;
602
603 if (count < i386_NEW_THREAD_STATE_COUNT) {
604 return(KERN_INVALID_ARGUMENT);
605 }
606
607 if (flavor == i386_REGS_SEGS_STATE) {
608 /*
609 * Code and stack selectors must not be null,
610 * and must have user protection levels.
611 * Only the low 16 bits are valid.
612 */
613 state->cs &= 0xffff;
614 state->ss &= 0xffff;
615 state->ds &= 0xffff;
616 state->es &= 0xffff;
617 state->fs &= 0xffff;
618 state->gs &= 0xffff;
619
620 if (!kernel_act &&
621 (state->cs == 0 || (state->cs & SEL_PL) != SEL_PL_U
622 || state->ss == 0 || (state->ss & SEL_PL) != SEL_PL_U))
623 return KERN_INVALID_ARGUMENT;
624 }
625
626 state = (struct i386_new_thread_state *) tstate;
627
628 saved_state = USER_REGS(thr_act);
629
630 /*
631 * General registers
632 */
633 saved_state->edi = state->edi;
634 saved_state->esi = state->esi;
635 saved_state->ebp = state->ebp;
636 saved_state->uesp = state->uesp;
637 saved_state->ebx = state->ebx;
638 saved_state->edx = state->edx;
639 saved_state->ecx = state->ecx;
640 saved_state->eax = state->eax;
641 saved_state->eip = state->eip;
642 if (kernel_act)
643 saved_state->efl = state->efl;
644 else
645 saved_state->efl = (state->efl & ~EFL_USER_CLEAR)
646 | EFL_USER_SET;
647
648 /*
649 * Segment registers. Set differently in V8086 mode.
650 */
651 if (state->efl & EFL_VM) {
652 /*
653 * Set V8086 mode segment registers.
654 */
655 saved_state->cs = state->cs & 0xffff;
656 saved_state->ss = state->ss & 0xffff;
657 saved_state->v86_segs.v86_ds = state->ds & 0xffff;
658 saved_state->v86_segs.v86_es = state->es & 0xffff;
659 saved_state->v86_segs.v86_fs = state->fs & 0xffff;
660 saved_state->v86_segs.v86_gs = state->gs & 0xffff;
661
662 /*
663 * Zero protected mode segment registers.
664 */
665 saved_state->ds = 0;
666 saved_state->es = 0;
667 saved_state->fs = 0;
668 saved_state->gs = 0;
669
670 if (thr_act->mact.pcb->ims.v86s.int_table) {
671 /*
672 * Hardware assist on.
673 */
674 thr_act->mact.pcb->ims.v86s.flags =
675 state->efl & (EFL_TF | EFL_IF);
676 }
677 }
678 else if (flavor == i386_NEW_THREAD_STATE && !kernel_act) {
679 /*
680 * 386 mode. Set segment registers for flat
681 * 32-bit address space.
682 */
683 saved_state->cs = USER_CS;
684 saved_state->ss = USER_DS;
685 saved_state->ds = USER_DS;
686 saved_state->es = USER_DS;
687 saved_state->fs = USER_DS;
688 saved_state->gs = USER_DS;
689 }
690 else {
691 /*
692 * User setting segment registers.
693 * Code and stack selectors have already been
694 * checked. Others will be reset by 'iret'
695 * if they are not valid.
696 */
697 saved_state->cs = state->cs;
698 saved_state->ss = state->ss;
699 saved_state->ds = state->ds;
700 saved_state->es = state->es;
701 saved_state->fs = state->fs;
702 saved_state->gs = state->gs;
703 }
704 break;
705 }
706
707 case i386_FLOAT_STATE: {
708
709 if (count < i386_FLOAT_STATE_COUNT)
710 return(KERN_INVALID_ARGUMENT);
711
712 return fpu_set_state(thr_act,(struct i386_float_state*)tstate);
713 }
714
715 /*
716 * Temporary - replace by i386_io_map
717 */
718 case i386_ISA_PORT_MAP_STATE: {
719 register struct i386_isa_port_map_state *state;
720 register iopb_tss_t tss;
721
722 if (count < i386_ISA_PORT_MAP_STATE_COUNT)
723 return(KERN_INVALID_ARGUMENT);
724
725 break;
726 }
727
728 case i386_V86_ASSIST_STATE:
729 {
730 register struct i386_v86_assist_state *state;
731 vm_offset_t int_table;
732 int int_count;
733
734 if (count < i386_V86_ASSIST_STATE_COUNT)
735 return KERN_INVALID_ARGUMENT;
736
737 state = (struct i386_v86_assist_state *) tstate;
738 int_table = state->int_table;
739 int_count = state->int_count;
740
741 if (int_table >= VM_MAX_ADDRESS ||
742 int_table +
743 int_count * sizeof(struct v86_interrupt_table)
744 > VM_MAX_ADDRESS)
745 return KERN_INVALID_ARGUMENT;
746
747 thr_act->mact.pcb->ims.v86s.int_table = int_table;
748 thr_act->mact.pcb->ims.v86s.int_count = int_count;
749
750 thr_act->mact.pcb->ims.v86s.flags =
751 USER_REGS(thr_act)->efl & (EFL_TF | EFL_IF);
752 break;
753 }
754
755 case i386_THREAD_STATE: {
756 struct i386_saved_state *saved_state;
757 i386_thread_state_t *state25;
758
759 saved_state = USER_REGS(thr_act);
760 state25 = (i386_thread_state_t *)tstate;
761
762 saved_state->eax = state25->eax;
763 saved_state->ebx = state25->ebx;
764 saved_state->ecx = state25->ecx;
765 saved_state->edx = state25->edx;
766 saved_state->edi = state25->edi;
767 saved_state->esi = state25->esi;
768 saved_state->ebp = state25->ebp;
769 saved_state->uesp = state25->esp;
770 saved_state->efl = (state25->eflags & ~EFL_USER_CLEAR)
771 | EFL_USER_SET;
772 saved_state->eip = state25->eip;
773 saved_state->cs = USER_CS; /* FIXME? */
774 saved_state->ss = USER_DS;
775 saved_state->ds = USER_DS;
776 saved_state->es = USER_DS;
777 saved_state->fs = USER_DS;
778 saved_state->gs = USER_DS;
779 }
780 break;
781
782 default:
783 return(KERN_INVALID_ARGUMENT);
784 }
785
786 return(KERN_SUCCESS);
787 }
788
789 /*
790 * thread_getstatus:
791 *
792 * Get the status of the specified thread.
793 */
794
795
796 kern_return_t
797 act_machine_get_state(
798 thread_act_t thr_act,
799 thread_flavor_t flavor,
800 thread_state_t tstate,
801 mach_msg_type_number_t *count)
802 {
803 #if MACH_ASSERT
804 if (watchacts & WA_STATE)
805 printf("act_%x act_m_get_state(thr_act=%x,flav=%x,st=%x,cnt@%x=%x)\n",
806 current_act(), thr_act, flavor, tstate,
807 count, (count ? *count : 0));
808 #endif /* MACH_ASSERT */
809
810 switch (flavor) {
811
812 case i386_SAVED_STATE:
813 {
814 register struct i386_saved_state *state;
815 register struct i386_saved_state *saved_state;
816
817 if (*count < i386_SAVED_STATE_COUNT)
818 return(KERN_INVALID_ARGUMENT);
819
820 state = (struct i386_saved_state *) tstate;
821 saved_state = USER_REGS(thr_act);
822
823 /*
824 * First, copy everything:
825 */
826 *state = *saved_state;
827
828 if (saved_state->efl & EFL_VM) {
829 /*
830 * V8086 mode.
831 */
832 state->ds = saved_state->v86_segs.v86_ds & 0xffff;
833 state->es = saved_state->v86_segs.v86_es & 0xffff;
834 state->fs = saved_state->v86_segs.v86_fs & 0xffff;
835 state->gs = saved_state->v86_segs.v86_gs & 0xffff;
836
837 if (thr_act->mact.pcb->ims.v86s.int_table) {
838 /*
839 * Hardware assist on
840 */
841 if ((thr_act->mact.pcb->ims.v86s.flags &
842 (EFL_IF|V86_IF_PENDING)) == 0)
843 state->efl &= ~EFL_IF;
844 }
845 }
846 else {
847 /*
848 * 386 mode.
849 */
850 state->ds = saved_state->ds & 0xffff;
851 state->es = saved_state->es & 0xffff;
852 state->fs = saved_state->fs & 0xffff;
853 state->gs = saved_state->gs & 0xffff;
854 }
855 *count = i386_SAVED_STATE_COUNT;
856 break;
857 }
858
859 case i386_NEW_THREAD_STATE:
860 case i386_REGS_SEGS_STATE:
861 {
862 register struct i386_new_thread_state *state;
863 register struct i386_saved_state *saved_state;
864
865 if (*count < i386_NEW_THREAD_STATE_COUNT)
866 return(KERN_INVALID_ARGUMENT);
867
868 state = (struct i386_new_thread_state *) tstate;
869 saved_state = USER_REGS(thr_act);
870
871 /*
872 * General registers.
873 */
874 state->edi = saved_state->edi;
875 state->esi = saved_state->esi;
876 state->ebp = saved_state->ebp;
877 state->ebx = saved_state->ebx;
878 state->edx = saved_state->edx;
879 state->ecx = saved_state->ecx;
880 state->eax = saved_state->eax;
881 state->eip = saved_state->eip;
882 state->efl = saved_state->efl;
883 state->uesp = saved_state->uesp;
884
885 state->cs = saved_state->cs;
886 state->ss = saved_state->ss;
887 if (saved_state->efl & EFL_VM) {
888 /*
889 * V8086 mode.
890 */
891 state->ds = saved_state->v86_segs.v86_ds & 0xffff;
892 state->es = saved_state->v86_segs.v86_es & 0xffff;
893 state->fs = saved_state->v86_segs.v86_fs & 0xffff;
894 state->gs = saved_state->v86_segs.v86_gs & 0xffff;
895
896 if (thr_act->mact.pcb->ims.v86s.int_table) {
897 /*
898 * Hardware assist on
899 */
900 if ((thr_act->mact.pcb->ims.v86s.flags &
901 (EFL_IF|V86_IF_PENDING)) == 0)
902 state->efl &= ~EFL_IF;
903 }
904 }
905 else {
906 /*
907 * 386 mode.
908 */
909 state->ds = saved_state->ds & 0xffff;
910 state->es = saved_state->es & 0xffff;
911 state->fs = saved_state->fs & 0xffff;
912 state->gs = saved_state->gs & 0xffff;
913 }
914 *count = i386_NEW_THREAD_STATE_COUNT;
915 break;
916 }
917
918 case THREAD_SYSCALL_STATE:
919 {
920 register struct thread_syscall_state *state;
921 register struct i386_saved_state *saved_state = USER_REGS(thr_act);
922
923 state = (struct thread_syscall_state *) tstate;
924 state->eax = saved_state->eax;
925 state->edx = saved_state->edx;
926 state->efl = saved_state->efl;
927 state->eip = saved_state->eip;
928 state->esp = saved_state->uesp;
929 *count = i386_THREAD_SYSCALL_STATE_COUNT;
930 break;
931 }
932
933 case THREAD_STATE_FLAVOR_LIST:
934 if (*count < 5)
935 return (KERN_INVALID_ARGUMENT);
936 tstate[0] = i386_NEW_THREAD_STATE;
937 tstate[1] = i386_FLOAT_STATE;
938 tstate[2] = i386_ISA_PORT_MAP_STATE;
939 tstate[3] = i386_V86_ASSIST_STATE;
940 tstate[4] = THREAD_SYSCALL_STATE;
941 *count = 5;
942 break;
943
944 case i386_FLOAT_STATE: {
945
946 if (*count < i386_FLOAT_STATE_COUNT)
947 return(KERN_INVALID_ARGUMENT);
948
949 *count = i386_FLOAT_STATE_COUNT;
950 return fpu_get_state(thr_act,(struct i386_float_state *)tstate);
951 }
952
953 /*
954 * Temporary - replace by i386_io_map
955 */
956 case i386_ISA_PORT_MAP_STATE: {
957 register struct i386_isa_port_map_state *state;
958 register iopb_tss_t tss;
959
960 if (*count < i386_ISA_PORT_MAP_STATE_COUNT)
961 return(KERN_INVALID_ARGUMENT);
962
963 state = (struct i386_isa_port_map_state *) tstate;
964 tss = thr_act->mact.pcb->ims.io_tss;
965
966 if (tss == 0) {
967 int i;
968
969 /*
970 * The thread has no ktss, so no IO permissions.
971 */
972
973 for (i = 0; i < sizeof state->pm; i++)
974 state->pm[i] = 0xff;
975 } else {
976 /*
977 * The thread has its own ktss.
978 */
979
980 bcopy((char *) tss->bitmap,
981 (char *) state->pm,
982 sizeof state->pm);
983 }
984
985 *count = i386_ISA_PORT_MAP_STATE_COUNT;
986 break;
987 }
988
989 case i386_V86_ASSIST_STATE:
990 {
991 register struct i386_v86_assist_state *state;
992
993 if (*count < i386_V86_ASSIST_STATE_COUNT)
994 return KERN_INVALID_ARGUMENT;
995
996 state = (struct i386_v86_assist_state *) tstate;
997 state->int_table = thr_act->mact.pcb->ims.v86s.int_table;
998 state->int_count = thr_act->mact.pcb->ims.v86s.int_count;
999
1000 *count = i386_V86_ASSIST_STATE_COUNT;
1001 break;
1002 }
1003
1004 case i386_THREAD_STATE: {
1005 struct i386_saved_state *saved_state;
1006 i386_thread_state_t *state;
1007
1008 saved_state = USER_REGS(thr_act);
1009 state = (i386_thread_state_t *)tstate;
1010
1011 state->eax = saved_state->eax;
1012 state->ebx = saved_state->ebx;
1013 state->ecx = saved_state->ecx;
1014 state->edx = saved_state->edx;
1015 state->edi = saved_state->edi;
1016 state->esi = saved_state->esi;
1017 state->ebp = saved_state->ebp;
1018 state->esp = saved_state->uesp;
1019 state->eflags = saved_state->efl;
1020 state->eip = saved_state->eip;
1021 state->cs = saved_state->cs;
1022 state->ss = saved_state->ss;
1023 state->ds = saved_state->ds;
1024 state->es = saved_state->es;
1025 state->fs = saved_state->fs;
1026 state->gs = saved_state->gs;
1027 break;
1028 }
1029
1030 default:
1031 return(KERN_INVALID_ARGUMENT);
1032 }
1033
1034 return(KERN_SUCCESS);
1035 }
1036
1037 /*
1038 * Alter the thread`s state so that a following thread_exception_return
1039 * will make the thread return 'retval' from a syscall.
1040 */
1041 void
1042 thread_set_syscall_return(
1043 thread_t thread,
1044 kern_return_t retval)
1045 {
1046 thread->top_act->mact.pcb->iss.eax = retval;
1047 }
1048
1049 /*
1050 * Initialize the machine-dependent state for a new thread.
1051 */
1052 kern_return_t
1053 thread_machine_create(thread_t thread, thread_act_t thr_act, void (*start_pos)(thread_t))
1054 {
1055 MachineThrAct_t mact = &thr_act->mact;
1056
1057 #if MACH_ASSERT
1058 if (watchacts & WA_PCB)
1059 printf("thread_machine_create(thr=%x,thr_act=%x,st=%x)\n",
1060 thread, thr_act, start_pos);
1061 #endif /* MACH_ASSERT */
1062
1063 assert(thread != NULL);
1064 assert(thr_act != NULL);
1065
1066 /*
1067 * Allocate a kernel stack per shuttle
1068 */
1069 thread->kernel_stack = (int)stack_alloc(thread,start_pos);
1070 thread->stack_privilege = thread->kernel_stack;
1071 assert(thread->kernel_stack != 0);
1072
1073 /*
1074 * Point top of kernel stack to user`s registers.
1075 */
1076 STACK_IEL(thread->kernel_stack)->saved_state = &mact->pcb->iss;
1077
1078 return(KERN_SUCCESS);
1079 }
1080
1081 /*
1082 * Machine-dependent cleanup prior to destroying a thread
1083 */
1084 void
1085 thread_machine_destroy( thread_t thread )
1086 {
1087 spl_t s;
1088
1089 if (thread->kernel_stack != 0) {
1090 s = splsched();
1091 stack_free(thread);
1092 splx(s);
1093 }
1094 }
1095
1096 /*
1097 * This is used to set the current thr_act/thread
1098 * when starting up a new processor
1099 */
1100 void
1101 thread_machine_set_current( thread_t thread )
1102 {
1103 register int my_cpu;
1104
1105 mp_disable_preemption();
1106 my_cpu = cpu_number();
1107
1108 cpu_data[my_cpu].active_thread = thread;
1109 active_kloaded[my_cpu] =
1110 thread->top_act->kernel_loaded ? thread->top_act : THR_ACT_NULL;
1111
1112 mp_enable_preemption();
1113 }
1114
1115
1116 /*
1117 * Pool of kernel activations.
1118 */
1119
1120 void act_machine_init()
1121 {
1122 int i;
1123 thread_act_t thr_act;
1124
1125 #if MACH_ASSERT
1126 if (watchacts & WA_PCB)
1127 printf("act_machine_init()\n");
1128 #endif /* MACH_ASSERT */
1129
1130 /* Good to verify this once */
1131 assert( THREAD_MACHINE_STATE_MAX <= THREAD_STATE_MAX );
1132
1133 /*
1134 * If we start using kernel activations,
1135 * would normally create kernel_thread_pool here,
1136 * populating it from the act_zone
1137 */
1138 }
1139
1140 kern_return_t
1141 act_machine_create(task_t task, thread_act_t thr_act)
1142 {
1143 MachineThrAct_t mact = &thr_act->mact;
1144 pcb_t pcb;
1145
1146 #if MACH_ASSERT
1147 if (watchacts & WA_PCB)
1148 printf("act_machine_create(task=%x,thr_act=%x) pcb=%x\n",
1149 task,thr_act, &mact->xxx_pcb);
1150 #endif /* MACH_ASSERT */
1151
1152 /*
1153 * Clear & Init the pcb (sets up user-mode s regs)
1154 */
1155 pcb_init(thr_act);
1156
1157 return KERN_SUCCESS;
1158 }
1159
1160 void
1161 act_virtual_machine_destroy(thread_act_t thr_act)
1162 {
1163 return;
1164 }
1165
1166 void
1167 act_machine_destroy(thread_act_t thr_act)
1168 {
1169
1170 #if MACH_ASSERT
1171 if (watchacts & WA_PCB)
1172 printf("act_machine_destroy(0x%x)\n", thr_act);
1173 #endif /* MACH_ASSERT */
1174
1175 pcb_terminate(thr_act);
1176 }
1177
1178 void
1179 act_machine_return(int code)
1180 {
1181 thread_act_t thr_act = current_act();
1182
1183 #if MACH_ASSERT
1184 /*
1185 * We don't go through the locking dance here needed to
1186 * acquire thr_act->thread safely.
1187 */
1188
1189 if (watchacts & WA_EXIT)
1190 printf("act_machine_return(0x%x) cur_act=%x(%d) thr=%x(%d)\n",
1191 code, thr_act, thr_act->ref_count,
1192 thr_act->thread, thr_act->thread->ref_count);
1193 #endif /* MACH_ASSERT */
1194
1195 /*
1196 * This code is called with nothing locked.
1197 * It also returns with nothing locked, if it returns.
1198 *
1199 * This routine terminates the current thread activation.
1200 * If this is the only activation associated with its
1201 * thread shuttle, then the entire thread (shuttle plus
1202 * activation) is terminated.
1203 */
1204 assert( code == KERN_TERMINATED );
1205 assert( thr_act );
1206
1207 #ifdef CALLOUT_RPC_MODEL
1208 /*
1209 * JMM - RPC is not going to be done with a callout/direct-
1210 * stack manipulation mechanism. Instead we will return/
1211 * unwind normally as if from a continuation.
1212 */
1213 act_lock_thread(thr_act);
1214
1215 if (thr_act->thread->top_act != thr_act) {
1216 /*
1217 * this is not the top activation;
1218 * if possible, we should clone the shuttle so that
1219 * both the root RPC-chain and the soon-to-be-orphaned
1220 * RPC-chain have shuttles
1221 *
1222 * JMM - Cloning shuttles isn't the right approach. We
1223 * need to alert the higher up activations to return our
1224 * shuttle (because scheduling attributes may TRUELY be
1225 * unique and not cloneable.
1226 */
1227 act_unlock_thread(thr_act);
1228 panic("act_machine_return: ORPHAN CASE NOT YET IMPLEMENTED");
1229 }
1230
1231 if (thr_act->lower != THR_ACT_NULL) {
1232 thread_t cur_thread = current_thread();
1233 thread_act_t cur_act;
1234 struct ipc_port *iplock;
1235
1236 /* send it an appropriate return code */
1237 thr_act->lower->alerts |= SERVER_TERMINATED;
1238 install_special_handler(thr_act->lower);
1239
1240 /* Return to previous act with error code */
1241 act_locked_act_reference(thr_act); /* keep it around */
1242 act_switch_swapcheck(cur_thread, (ipc_port_t)0);
1243 (void) switch_act(THR_ACT_NULL);
1244 /* assert(thr_act->ref_count == 0); */ /* XXX */
1245 cur_act = cur_thread->top_act;
1246 MACH_RPC_RET(cur_act) = KERN_RPC_SERVER_TERMINATED;
1247
1248 machine_kernel_stack_init(cur_thread, mach_rpc_return_error);
1249 /*
1250 * The following unlocks must be done separately since fields
1251 * used by `act_unlock_thread()' have been cleared, meaning
1252 * that it would not release all of the appropriate locks.
1253 */
1254 iplock = thr_act->pool_port; /* remember for unlock call */
1255 rpc_unlock(cur_thread);
1256 if (iplock) ip_unlock(iplock); /* must be done separately */
1257 act_unlock(thr_act);
1258 act_deallocate(thr_act); /* free it */
1259 Load_context(cur_thread);
1260 /*NOTREACHED*/
1261
1262 panic("act_machine_return: TALKING ZOMBIE! (2)");
1263 }
1264 act_unlock_thread(thr_act);
1265
1266 #endif /* CALLOUT_RPC_MODEL */
1267
1268 /* This is the only activation attached to the shuttle... */
1269 /* terminate the entire thread (shuttle plus activation) */
1270
1271 assert(thr_act->thread->top_act == thr_act);
1272 thread_terminate_self();
1273
1274 /*NOTREACHED*/
1275
1276 panic("act_machine_return: TALKING ZOMBIE! (1)");
1277 }
1278
1279
1280 /*
1281 * Perform machine-dependent per-thread initializations
1282 */
1283 void
1284 thread_machine_init(void)
1285 {
1286 pcb_module_init();
1287 }
1288
1289 /*
1290 * Some routines for debugging activation code
1291 */
1292 static void dump_handlers(thread_act_t);
1293 void dump_regs(thread_act_t);
1294
1295 static void
1296 dump_handlers(thread_act_t thr_act)
1297 {
1298 ReturnHandler *rhp = thr_act->handlers;
1299 int counter = 0;
1300
1301 printf("\t");
1302 while (rhp) {
1303 if (rhp == &thr_act->special_handler){
1304 if (rhp->next)
1305 printf("[NON-Zero next ptr(%x)]", rhp->next);
1306 printf("special_handler()->");
1307 break;
1308 }
1309 printf("hdlr_%d(%x)->",counter,rhp->handler);
1310 rhp = rhp->next;
1311 if (++counter > 32) {
1312 printf("Aborting: HUGE handler chain\n");
1313 break;
1314 }
1315 }
1316 printf("HLDR_NULL\n");
1317 }
1318
1319 void
1320 dump_regs(thread_act_t thr_act)
1321 {
1322 if (thr_act->mact.pcb) {
1323 register struct i386_saved_state *ssp = USER_REGS(thr_act);
1324 /* Print out user register state */
1325 printf("\tRegs:\tedi=%x esi=%x ebp=%x ebx=%x edx=%x\n",
1326 ssp->edi, ssp->esi, ssp->ebp, ssp->ebx, ssp->edx);
1327 printf("\t\tecx=%x eax=%x eip=%x efl=%x uesp=%x\n",
1328 ssp->ecx, ssp->eax, ssp->eip, ssp->efl, ssp->uesp);
1329 printf("\t\tcs=%x ss=%x\n", ssp->cs, ssp->ss);
1330 }
1331 }
1332
1333 int
1334 dump_act(thread_act_t thr_act)
1335 {
1336 if (!thr_act)
1337 return(0);
1338
1339 printf("thr_act(0x%x)(%d): thread=%x(%d) task=%x(%d)\n",
1340 thr_act, thr_act->ref_count,
1341 thr_act->thread, thr_act->thread ? thr_act->thread->ref_count:0,
1342 thr_act->task, thr_act->task ? thr_act->task->ref_count : 0);
1343
1344 if (thr_act->pool_port) {
1345 thread_pool_t actpp = &thr_act->pool_port->ip_thread_pool;
1346 printf("\tpool(acts_p=%x, waiting=%d) pool_next %x\n",
1347 actpp->thr_acts, actpp->waiting, thr_act->thread_pool_next);
1348 }else
1349 printf("\tno thread_pool\n");
1350
1351 printf("\talerts=%x mask=%x susp=%d user_stop=%d active=%x ast=%x\n",
1352 thr_act->alerts, thr_act->alert_mask,
1353 thr_act->suspend_count, thr_act->user_stop_count,
1354 thr_act->active, thr_act->ast);
1355 printf("\thi=%x lo=%x\n", thr_act->higher, thr_act->lower);
1356 printf("\tpcb=%x\n", thr_act->mact.pcb);
1357
1358 if (thr_act->thread && thr_act->thread->kernel_stack) {
1359 vm_offset_t stack = thr_act->thread->kernel_stack;
1360
1361 printf("\tk_stk %x eip %x ebx %x esp %x iss %x\n",
1362 stack, STACK_IKS(stack)->k_eip, STACK_IKS(stack)->k_ebx,
1363 STACK_IKS(stack)->k_esp, STACK_IEL(stack)->saved_state);
1364 }
1365
1366 dump_handlers(thr_act);
1367 dump_regs(thr_act);
1368 return((int)thr_act);
1369 }
1370 unsigned int
1371 get_useraddr()
1372 {
1373
1374 thread_act_t thr_act = current_act();
1375
1376 if (thr_act->mact.pcb)
1377 return(thr_act->mact.pcb->iss.eip);
1378 else
1379 return(0);
1380
1381 }
1382
1383 void
1384 thread_swapin_mach_alloc(thread_t thread)
1385 {
1386
1387 /* 386 does not have saveareas */
1388
1389 }
1390 /*
1391 * detach and return a kernel stack from a thread
1392 */
1393
1394 vm_offset_t
1395 stack_detach(thread_t thread)
1396 {
1397 vm_offset_t stack;
1398
1399 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_SCHED,MACH_STACK_DETACH),
1400 thread, thread->priority,
1401 thread->sched_pri, 0,
1402 0);
1403
1404 stack = thread->kernel_stack;
1405 thread->kernel_stack = 0;
1406 return(stack);
1407 }
1408
1409 /*
1410 * attach a kernel stack to a thread and initialize it
1411 */
1412
1413 void
1414 stack_attach(struct thread_shuttle *thread,
1415 vm_offset_t stack,
1416 void (*start_pos)(thread_t))
1417 {
1418 struct i386_kernel_state *statep;
1419
1420 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_SCHED,MACH_STACK_ATTACH),
1421 thread, thread->priority,
1422 thread->sched_pri, continuation,
1423 0);
1424
1425 assert(stack);
1426 statep = STACK_IKS(stack);
1427 thread->kernel_stack = stack;
1428
1429 statep->k_eip = (unsigned long) Thread_continue;
1430 statep->k_ebx = (unsigned long) start_pos;
1431 statep->k_esp = (unsigned long) STACK_IEL(stack);
1432 assert(thread->top_act);
1433 STACK_IEL(stack)->saved_state = &thread->top_act->mact.pcb->iss;
1434
1435 return;
1436 }
1437
1438 /*
1439 * move a stack from old to new thread
1440 */
1441
1442 void
1443 stack_handoff(thread_t old,
1444 thread_t new)
1445 {
1446
1447 vm_offset_t stack;
1448 pmap_t new_pmap;
1449
1450 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_SCHED,MACH_STACK_HANDOFF),
1451 thread, thread->priority,
1452 thread->sched_pri, continuation,
1453 0);
1454
1455 assert(new->top_act);
1456 assert(old->top_act);
1457
1458 stack = stack_detach(old);
1459 stack_attach(new, stack, 0);
1460
1461 new_pmap = new->top_act->task->map->pmap;
1462 if (old->top_act->task->map->pmap != new_pmap)
1463 PMAP_ACTIVATE_MAP(new->top_act->task->map, cpu_number());
1464
1465 thread_machine_set_current(new);
1466
1467 active_stacks[cpu_number()] = new->kernel_stack;
1468
1469 return;
1470 }
1471
1472 struct i386_act_context {
1473 struct i386_saved_state ss;
1474 struct i386_float_state fs;
1475 };
1476
1477 void *
1478 act_thread_csave(void)
1479 {
1480 struct i386_act_context *ic;
1481 kern_return_t kret;
1482 int val;
1483
1484 ic = (struct i386_act_context *)kalloc(sizeof(struct i386_act_context));
1485
1486 if (ic == (struct i386_act_context *)NULL)
1487 return((void *)0);
1488
1489 val = i386_SAVED_STATE_COUNT;
1490 kret = act_machine_get_state(current_act(), i386_SAVED_STATE, &ic->ss, &val);
1491 if (kret != KERN_SUCCESS) {
1492 kfree((vm_offset_t)ic,sizeof(struct i386_act_context));
1493 return((void *)0);
1494 }
1495 val = i386_FLOAT_STATE_COUNT;
1496 kret = act_machine_get_state(current_act(), i386_FLOAT_STATE, &ic->fs, &val);
1497 if (kret != KERN_SUCCESS) {
1498 kfree((vm_offset_t)ic,sizeof(struct i386_act_context));
1499 return((void *)0);
1500 }
1501 return(ic);
1502 }
1503 void
1504 act_thread_catt(void *ctx)
1505 {
1506 struct i386_act_context *ic;
1507 kern_return_t kret;
1508 int val;
1509
1510 ic = (struct i386_act_context *)ctx;
1511
1512 if (ic == (struct i386_act_context *)NULL)
1513 return;
1514
1515 kret = act_machine_set_state(current_act(), i386_SAVED_STATE, &ic->ss, i386_SAVED_STATE_COUNT);
1516 if (kret != KERN_SUCCESS)
1517 goto out;
1518
1519 kret = act_machine_set_state(current_act(), i386_FLOAT_STATE, &ic->fs, i386_FLOAT_STATE_COUNT);
1520 if (kret != KERN_SUCCESS)
1521 goto out;
1522 out:
1523 kfree((vm_offset_t)ic,sizeof(struct i386_act_context));
1524 }
1525
1526 void act_thread_cfree(void *ctx)
1527 {
1528 kfree((vm_offset_t)ctx,sizeof(struct i386_act_context));
1529 }
1530