]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_init.c
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / kern / bsd_init.c
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
27 * The Regents of the University of California. All rights reserved.
28 * (c) UNIX System Laboratories, Inc.
29 * All or some portions of this file are derived from material licensed
30 * to the University of California by American Telephone and Telegraph
31 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
32 * the permission of UNIX System Laboratories, Inc.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
63 */
64
65 /*
66 *
67 * Mach Operating System
68 * Copyright (c) 1987 Carnegie-Mellon University
69 * All rights reserved. The CMU software License Agreement specifies
70 * the terms and conditions for use and redistribution.
71 */
72 /*
73 * HISTORY
74 * 16-Apr-98 A. Ramesh at Apple
75 * Created for Apple Core from DR2 init_main.c.
76 */
77
78 #include <quota.h>
79
80 #include <sys/param.h>
81 #include <sys/filedesc.h>
82 #include <sys/kernel.h>
83 #include <sys/mount.h>
84 #include <sys/proc.h>
85 #include <sys/systm.h>
86 #include <sys/vnode.h>
87 #include <sys/conf.h>
88 #include <sys/buf.h>
89 #include <sys/clist.h>
90 #include <sys/user.h>
91 #include <ufs/ufs/quota.h>
92
93 #include <sys/malloc.h>
94 #include <sys/dkstat.h>
95
96 #include <machine/spl.h>
97 #include <kern/thread.h>
98 #include <kern/task.h>
99 #include <kern/ast.h>
100
101 #include <mach/vm_param.h>
102
103 #include <vm/vm_map.h>
104 #include <vm/vm_kern.h>
105
106 #include <sys/ux_exception.h>
107
108 #include <sys/reboot.h>
109 #include <mach/exception_types.h>
110 #include <dev/busvar.h>
111 #include <sys/kdebug.h>
112
113 #include <mach/mach_types.h>
114 #include <mach/vm_prot.h>
115 #include <mach/semaphore.h>
116 #include <mach/sync_policy.h>
117 #include <kern/clock.h>
118 #include <mach/kern_return.h>
119
120 #include <mach/shared_memory_server.h>
121 #include <vm/vm_shared_memory_server.h>
122
123 extern shared_region_mapping_t system_shared_region;
124 extern int app_profile; /* on/off switch for pre-heat cache */
125
126 char copyright[] =
127 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California. All rights reserved.\n\n";
128
129 extern void ux_handler();
130
131 /* Components of the first process -- never freed. */
132 struct proc proc0;
133 struct session session0;
134 struct pgrp pgrp0;
135 struct pcred cred0;
136 struct filedesc filedesc0;
137 struct plimit limit0;
138 struct pstats pstats0;
139 struct sigacts sigacts0;
140 struct proc *kernproc, *initproc;
141
142 long tk_cancc;
143 long tk_nin;
144 long tk_nout;
145 long tk_rawcc;
146
147 /* Global variables to make pstat happy. We do swapping differently */
148 int nswdev, nswap;
149 int nswapmap;
150 void *swapmap;
151 struct swdevt swdevt[1];
152
153 dev_t rootdev; /* device of the root */
154 dev_t dumpdev; /* device to take dumps on */
155 long dumplo; /* offset into dumpdev */
156 long hostid;
157 char hostname[MAXHOSTNAMELEN];
158 int hostnamelen;
159 char domainname[MAXDOMNAMELEN];
160 int domainnamelen;
161
162 char rootdevice[16]; /* hfs device names have at least 9 chars */
163 struct timeval boottime; /* GRODY! This has to go... */
164
165 #ifdef KMEMSTATS
166 struct kmemstats kmemstats[M_LAST];
167 #endif
168
169 int lbolt; /* awoken once a second */
170 struct vnode *rootvp;
171 int boothowto = RB_DEBUG;
172
173 #define BSD_PAGABLE_MAP_SIZE (4 * 512 * 1024)
174 vm_map_t bsd_pageable_map;
175 vm_map_t mb_map;
176 semaphore_t execve_semaphore;
177
178 int cmask = CMASK;
179
180 int parse_bsd_args(void);
181 extern int bsd_hardclockinit;
182 extern task_t bsd_init_task;
183 extern char init_task_failure_data[];
184 extern void time_zone_slock_init(void);
185
186 funnel_t * kernel_flock;
187 funnel_t * network_flock;
188 int disable_funnel = 0; /* disables split funnel */
189 int enable_funnel = 0; /* disables split funnel */
190
191 /*
192 * Initialization code.
193 * Called from cold start routine as
194 * soon as a stack and segmentation
195 * have been established.
196 * Functions:
197 * clear and free user core
198 * turn on clock
199 * hand craft 0th process
200 * call all initialization routines
201 * fork - process 0 to schedule
202 * - process 1 execute bootstrap
203 * - process 2 to page out
204 */
205
206 /*
207 * Sets the name for the given task.
208 */
209 void
210 proc_name(s, p)
211 char *s;
212 struct proc *p;
213 {
214 int length = strlen(s);
215
216 bcopy(s, p->p_comm,
217 length >= sizeof(p->p_comm) ? sizeof(p->p_comm) :
218 length + 1);
219 }
220
221 /* To allow these values to be patched, they're globals here */
222 #include <machine/vmparam.h>
223 struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ };
224 struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ };
225 struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ };
226
227 extern thread_t first_thread;
228 extern thread_act_t cloneproc(struct proc *, int);
229 extern int (*mountroot) __P((void));
230 extern int netboot_mountroot(); /* netboot.c */
231 extern int netboot_setup(struct proc * p);
232
233 /* hook called after root is mounted XXX temporary hack */
234 void (*mountroot_post_hook)(void);
235
236 void
237 bsd_init()
238 {
239 register struct proc *p;
240 extern struct ucred *rootcred;
241 register int i;
242 int s;
243 thread_t th;
244 void lightning_bolt(void );
245 kern_return_t ret;
246 boolean_t funnel_state;
247 extern void uthread_zone_init();
248
249
250
251 #if 1
252 /* split funnel is enabled by default */
253 PE_parse_boot_arg("dfnl", &disable_funnel);
254 #else
255 /* split funnel is disabled befault */
256 disable_funnel = 1;
257 PE_parse_boot_arg("efnl", &enable_funnel);
258 if (enable_funnel) {
259 /* enable only if efnl is set in bootarg */
260 disable_funnel = 0;
261 }
262 #endif
263
264 kernel_flock = funnel_alloc(KERNEL_FUNNEL);
265 if (kernel_flock == (funnel_t *)0 ) {
266 panic("bsd_init: Failed to allocate kernel funnel");
267 }
268
269 funnel_state = thread_funnel_set(kernel_flock, TRUE);
270
271 if (!disable_funnel) {
272 network_flock = funnel_alloc(NETWORK_FUNNEL);
273 if (network_flock == (funnel_t *)0 ) {
274 panic("bsd_init: Failed to allocate network funnel");
275 }
276 } else {
277 network_flock = kernel_flock;
278 }
279
280 printf(copyright);
281
282 kmeminit();
283
284 parse_bsd_args();
285
286 bsd_bufferinit();
287
288 /* Initialize the uthread zone */
289 uthread_zone_init();
290
291 /*
292 * Initialize process and pgrp structures.
293 */
294 procinit();
295
296 kernproc = &proc0;
297
298 p = kernproc;
299
300 /* kernel_task->proc = kernproc; */
301 set_bsdtask_info(kernel_task,(void *)p);
302 p->p_pid = 0;
303
304 /* give kernproc a name */
305 proc_name("kernel_task", p);
306
307 if (current_task() != kernel_task)
308 printf("bsd_init: We have a problem, "
309 "current task is not kernel task\n");
310
311 /*
312 * Create process 0.
313 */
314 LIST_INSERT_HEAD(&allproc, p, p_list);
315 p->p_pgrp = &pgrp0;
316 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
317 LIST_INIT(&pgrp0.pg_members);
318 LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
319
320 pgrp0.pg_session = &session0;
321 session0.s_count = 1;
322 session0.s_leader = p;
323
324 p->task = kernel_task;
325
326 p->p_stat = SRUN;
327 p->p_flag = P_INMEM|P_SYSTEM;
328 p->p_nice = NZERO;
329 p->p_pptr = p;
330 lockinit(&p->signal_lock, PVM, "signal", 0, 0);
331 TAILQ_INIT(&p->p_uthlist);
332 p->sigwait = FALSE;
333 p->sigwait_thread = THREAD_NULL;
334 p->exit_thread = THREAD_NULL;
335
336 /* Create credentials. */
337 lockinit(&cred0.pc_lock, PLOCK, "proc0 cred", 0, 0);
338 cred0.p_refcnt = 1;
339 p->p_cred = &cred0;
340 p->p_ucred = crget();
341 p->p_ucred->cr_ngroups = 1; /* group 0 */
342
343 /* Create the file descriptor table. */
344 filedesc0.fd_refcnt = 1+1; /* +1 so shutdown will not _FREE_ZONE */
345 p->p_fd = &filedesc0;
346 filedesc0.fd_cmask = cmask;
347
348 /* Create the limits structures. */
349 p->p_limit = &limit0;
350 for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
351 limit0.pl_rlimit[i].rlim_cur =
352 limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
353 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
354 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
355 limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack;
356 limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data;
357 limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core;
358 limit0.p_refcnt = 1;
359
360 p->p_stats = &pstats0;
361 p->p_sigacts = &sigacts0;
362
363 /*
364 * Charge root for one process.
365 */
366 (void)chgproccnt(0, 1);
367
368 /*
369 * Allocate a kernel submap for pageable memory
370 * for temporary copying (execve()).
371 */
372 {
373 vm_offset_t min;
374
375 ret = kmem_suballoc(kernel_map,
376 &min,
377 (vm_size_t)BSD_PAGABLE_MAP_SIZE,
378 TRUE,
379 TRUE,
380 &bsd_pageable_map);
381 if (ret != KERN_SUCCESS)
382 panic("bsd_init: Failed to allocate bsd pageable map");
383 }
384
385 /* Initialize the execve() semaphore */
386 ret = semaphore_create(kernel_task, &execve_semaphore,
387 SYNC_POLICY_FIFO, (BSD_PAGABLE_MAP_SIZE / NCARGS));
388 if (ret != KERN_SUCCESS)
389 panic("bsd_init: Failed to create execve semaphore");
390
391 /*
392 * Initialize the calendar.
393 */
394 IOKitResetTime();
395
396 ubc_init();
397
398 /* Initialize the file systems. */
399 vfsinit();
400
401 /* Initialize mbuf's. */
402 mbinit();
403
404 /* Initialize syslog */
405 log_init();
406
407 /* POSIX Shm and Sem */
408 pshm_cache_init();
409 psem_cache_init();
410 time_zone_slock_init();
411
412 /*
413 * Initialize protocols. Block reception of incoming packets
414 * until everything is ready.
415 */
416 s = splimp();
417 sysctl_register_fixed();
418 sysctl_mib_init();
419 dlil_init();
420 socketinit();
421 domaininit();
422 splx(s);
423
424 p->p_fd->fd_cdir = NULL;
425 p->p_fd->fd_rdir = NULL;
426
427 #ifdef GPROF
428 /* Initialize kernel profiling. */
429 kmstartup();
430 #endif
431
432 /* kick off timeout driven events by calling first time */
433 thread_wakeup(&lbolt);
434 timeout(lightning_bolt,0,hz);
435
436 bsd_autoconf();
437
438 /*
439 * We attach the loopback interface *way* down here to ensure
440 * it happens after autoconf(), otherwise it becomes the
441 * "primary" interface.
442 */
443 #include <loop.h>
444 #if NLOOP > 0
445 loopattach(); /* XXX */
446 #endif
447
448 /* Register the built-in dlil ethernet interface family */
449 ether_family_init();
450
451 vnode_pager_bootstrap();
452
453 /* Mount the root file system. */
454 while( TRUE) {
455 int err;
456
457 setconf();
458 /*
459 * read the time after clock_initialize_calendar()
460 * and before nfs mount
461 */
462 microtime(&time);
463
464 bsd_hardclockinit = -1; /* start ticking */
465
466 if (0 == (err = vfs_mountroot()))
467 break;
468 if (mountroot == netboot_mountroot) {
469 printf("cannot mount network root, errno = %d\n", err);
470 mountroot = NULL;
471 if (0 == (err = vfs_mountroot()))
472 break;
473 }
474 printf("cannot mount root, errno = %d\n", err);
475 boothowto |= RB_ASKNAME;
476 }
477
478 mountlist.cqh_first->mnt_flag |= MNT_ROOTFS;
479
480 /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */
481 if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
482 panic("bsd_init: cannot find root vnode");
483 VREF(rootvnode);
484 filedesc0.fd_cdir = rootvnode;
485 VOP_UNLOCK(rootvnode, 0, p);
486
487 if (mountroot == netboot_mountroot) {
488 int err;
489 /* post mount setup */
490 if (err = netboot_setup(p)) {
491 panic("bsd_init: NetBoot could not find root, %d", err);
492 }
493 }
494
495
496 /*
497 * Now can look at time, having had a chance to verify the time
498 * from the file system. Reset p->p_rtime as it may have been
499 * munched in mi_switch() after the time got set.
500 */
501 p->p_stats->p_start = boottime = time;
502 p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
503
504 #if DEVFS
505 {
506 extern void devfs_kernel_mount(char * str);
507
508 devfs_kernel_mount("/dev");
509 }
510 #endif DEVFS
511
512 /* Initialize signal state for process 0. */
513 siginit(p);
514
515 /* printf("Launching user process\n"); */
516
517 bsd_utaskbootstrap();
518
519 /* invoke post-root-mount hook */
520 if (mountroot_post_hook != NULL)
521 mountroot_post_hook();
522
523 (void) thread_funnel_set(kernel_flock, funnel_state);
524 }
525
526 /* Called with kernel funnel held */
527 void
528 bsdinit_task(void)
529 {
530 struct proc *p = current_proc();
531 struct uthread *ut;
532 kern_return_t kr;
533 thread_act_t th_act;
534
535 proc_name("init", p);
536
537 ux_handler_init();
538
539 th_act = current_act();
540 (void) host_set_exception_ports(host_priv_self(),
541 EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
542 EXC_MASK_MACH_SYSCALL |
543 EXC_MASK_RPC_ALERT),
544 ux_exception_port,
545 EXCEPTION_DEFAULT, 0);
546
547 (void) task_set_exception_ports(get_threadtask(th_act),
548 EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
549 EXC_MASK_MACH_SYSCALL |
550 EXC_MASK_RPC_ALERT),
551 ux_exception_port,
552 EXCEPTION_DEFAULT, 0);
553
554
555
556
557 ut = (uthread_t)get_bsdthread_info(th_act);
558 ut->uu_ar0 = (void *)get_user_regs(th_act);
559
560 bsd_hardclockinit = 1; /* Start bsd hardclock */
561 bsd_init_task = get_threadtask(th_act);
562 init_task_failure_data[0] = 0;
563 shared_region_mapping_ref(system_shared_region);
564 vm_set_shared_region(get_threadtask(th_act), system_shared_region);
565 load_init_program(p);
566 /* turn on app-profiling i.e. pre-heating */
567 app_profile = 1;
568 }
569
570 void
571 lightning_bolt()
572 {
573 boolean_t funnel_state;
574 extern void klogwakeup(void);
575
576 funnel_state = thread_funnel_set(kernel_flock, TRUE);
577
578 thread_wakeup(&lbolt);
579 timeout(lightning_bolt,0,hz);
580 klogwakeup();
581
582 (void) thread_funnel_set(kernel_flock, FALSE);
583 }
584
585 bsd_autoconf()
586 {
587 extern kern_return_t IOKitBSDInit( void );
588
589 kminit();
590
591 /*
592 * Early startup for bsd pseudodevices.
593 */
594 {
595 struct pseudo_init *pi;
596
597 for (pi = pseudo_inits; pi->ps_func; pi++)
598 (*pi->ps_func) (pi->ps_count);
599 }
600
601 return( IOKitBSDInit());
602 }
603
604
605 #include <sys/disklabel.h> // for MAXPARTITIONS
606
607 setconf()
608 {
609 extern kern_return_t IOFindBSDRoot( char * rootName,
610 dev_t * root, u_int32_t * flags );
611 u_int32_t flags;
612 kern_return_t err;
613
614 /*
615 * calls into IOKit can generate networking registrations
616 * which needs to be under network funnel. Right thing to do
617 * here is to drop the funnel alltogether and regrab it afterwards
618 */
619 thread_funnel_set(kernel_flock, FALSE);
620 err = IOFindBSDRoot( rootdevice, &rootdev, &flags );
621 thread_funnel_set(kernel_flock, TRUE);
622 if( err) {
623 printf("setconf: IOFindBSDRoot returned an error (%d);"
624 "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */
625 rootdev = makedev( 6, 0 );
626 strcpy( rootdevice, "sd0a" );
627 flags = 0;
628 }
629
630 if( flags & 1 ) {
631 /* network device */
632 mountroot = netboot_mountroot;
633 } else {
634 /* otherwise have vfs determine root filesystem */
635 mountroot = NULL;
636 }
637
638 }
639
640 bsd_utaskbootstrap()
641 {
642 thread_act_t th_act;
643 struct uthread *ut;
644
645 th_act = cloneproc(kernproc, 0);
646 initproc = pfind(1);
647 /* Set the launch time for init */
648 initproc->p_stats->p_start = time;
649
650 ut = (struct uthread *)get_bsdthread_info(th_act);
651 ut->uu_sigmask = 0;
652 thread_hold(th_act);
653 (void)thread_stop(getshuttle_thread(th_act));
654 act_set_astbsd(th_act);
655 thread_release(th_act);
656 thread_unstop(getshuttle_thread(th_act));
657 (void) thread_resume(th_act);
658 }
659
660 parse_bsd_args()
661 {
662 extern char init_args[];
663 char namep[16];
664 extern int boothowto;
665 extern int srv;
666 extern int ncl;
667
668 int len;
669
670 if (PE_parse_boot_arg("-s", namep)) {
671 boothowto |= RB_SINGLE;
672 len = strlen(init_args);
673 if(len != 0)
674 strcat(init_args," -s");
675 else
676 strcat(init_args,"-s");
677 }
678 if (PE_parse_boot_arg("-b", namep)) {
679 boothowto |= RB_NOBOOTRC;
680 len = strlen(init_args);
681 if(len != 0)
682 strcat(init_args," -b");
683 else
684 strcat(init_args,"-b");
685 }
686
687 if (PE_parse_boot_arg("-F", namep)) {
688 len = strlen(init_args);
689 if(len != 0)
690 strcat(init_args," -F");
691 else
692 strcat(init_args,"-F");
693 }
694
695 if (PE_parse_boot_arg("-v", namep)) {
696 len = strlen(init_args);
697 if(len != 0)
698 strcat(init_args," -v");
699 else
700 strcat(init_args,"-v");
701 }
702
703 if (PE_parse_boot_arg("-x", namep)) { /* safe boot */
704 len = strlen(init_args);
705 if(len != 0)
706 strcat(init_args," -x");
707 else
708 strcat(init_args,"-x");
709 }
710
711 PE_parse_boot_arg("srv", &srv);
712 PE_parse_boot_arg("ncl", &ncl);
713 PE_parse_boot_arg("nbuf", &nbuf);
714
715 return 0;
716 }
717
718 boolean_t
719 thread_funnel_switch(
720 int oldfnl,
721 int newfnl)
722 {
723 thread_t cur_thread;
724 boolean_t funnel_state_prev;
725 int curfnl;
726 funnel_t * curflock;
727 funnel_t * oldflock;
728 funnel_t * newflock;
729 funnel_t * exist_funnel;
730 extern int disable_funnel;
731
732
733 if (disable_funnel)
734 return(TRUE);
735
736 if(oldfnl == newfnl) {
737 panic("thread_funnel_switch: can't switch to same funnel");
738 }
739
740 if ((oldfnl != NETWORK_FUNNEL) && (oldfnl != KERNEL_FUNNEL)) {
741 panic("thread_funnel_switch: invalid oldfunnel");
742 }
743 if ((newfnl != NETWORK_FUNNEL) && (newfnl != KERNEL_FUNNEL)) {
744 panic("thread_funnel_switch: invalid newfunnel");
745 }
746
747 if((curflock = thread_funnel_get()) == THR_FUNNEL_NULL) {
748 panic("thread_funnel_switch: no funnel held");
749 }
750
751 cur_thread = current_thread();
752
753 if ((oldfnl == NETWORK_FUNNEL) && (curflock != network_flock))
754 panic("thread_funnel_switch: network funnel not held");
755
756 if ((oldfnl == KERNEL_FUNNEL) && (curflock != kernel_flock))
757 panic("thread_funnel_switch: kernel funnel not held");
758
759 if(oldfnl == NETWORK_FUNNEL) {
760 oldflock = network_flock;
761 newflock = kernel_flock;
762 } else {
763 oldflock = kernel_flock;
764 newflock = network_flock;
765 }
766 KERNEL_DEBUG(0x603242c | DBG_FUNC_NONE, oldflock, 1, 0, 0, 0);
767 thread_funnel_set(oldflock, FALSE);
768 KERNEL_DEBUG(0x6032428 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0);
769 thread_funnel_set(newflock, TRUE);
770 KERNEL_DEBUG(0x6032434 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0);
771
772 return(TRUE);
773 }