cd7fbbc456dbbf9b1952471a3e060b2672122139
[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 int app_profile; /* on/off switch for pre-heat cache */
124
125 char copyright[] =
126 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California. All rights reserved.\n\n";
127
128 extern void ux_handler();
129
130 /* Components of the first process -- never freed. */
131 struct proc proc0;
132 struct session session0;
133 struct pgrp pgrp0;
134 struct pcred cred0;
135 struct filedesc filedesc0;
136 struct plimit limit0;
137 struct pstats pstats0;
138 struct sigacts sigacts0;
139 struct proc *kernproc, *initproc;
140
141 long tk_cancc;
142 long tk_nin;
143 long tk_nout;
144 long tk_rawcc;
145
146 /* Global variables to make pstat happy. We do swapping differently */
147 int nswdev, nswap;
148 int nswapmap;
149 void *swapmap;
150 struct swdevt swdevt[1];
151
152 dev_t rootdev; /* device of the root */
153 dev_t dumpdev; /* device to take dumps on */
154 long dumplo; /* offset into dumpdev */
155 long hostid;
156 char hostname[MAXHOSTNAMELEN];
157 int hostnamelen;
158 char domainname[MAXDOMNAMELEN];
159 int domainnamelen;
160
161 char rootdevice[16]; /* hfs device names have at least 9 chars */
162 struct timeval boottime; /* GRODY! This has to go... */
163
164 #ifdef KMEMSTATS
165 struct kmemstats kmemstats[M_LAST];
166 #endif
167
168 int lbolt; /* awoken once a second */
169 struct vnode *rootvp;
170 int boothowto = RB_DEBUG;
171
172 #define BSD_PAGABLE_MAP_SIZE (4 * 512 * 1024)
173 vm_map_t bsd_pageable_map;
174 vm_map_t mb_map;
175 semaphore_t execve_semaphore;
176
177 int cmask = CMASK;
178
179 int parse_bsd_args(void);
180 extern int bsd_hardclockinit;
181 extern task_t bsd_init_task;
182 extern char init_task_failure_data[];
183 extern void time_zone_slock_init(void);
184
185 funnel_t * kernel_flock;
186 funnel_t * network_flock;
187 int disable_funnel = 0; /* disables split funnel */
188 int enable_funnel = 0; /* disables split funnel */
189
190 /*
191 * Initialization code.
192 * Called from cold start routine as
193 * soon as a stack and segmentation
194 * have been established.
195 * Functions:
196 * clear and free user core
197 * turn on clock
198 * hand craft 0th process
199 * call all initialization routines
200 * fork - process 0 to schedule
201 * - process 1 execute bootstrap
202 * - process 2 to page out
203 */
204
205 /*
206 * Sets the name for the given task.
207 */
208 void
209 proc_name(s, p)
210 char *s;
211 struct proc *p;
212 {
213 int length = strlen(s);
214
215 bcopy(s, p->p_comm,
216 length >= sizeof(p->p_comm) ? sizeof(p->p_comm) :
217 length + 1);
218 }
219
220 /* To allow these values to be patched, they're globals here */
221 #include <machine/vmparam.h>
222 struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ };
223 struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ };
224 struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ };
225
226 extern thread_t first_thread;
227 extern thread_act_t cloneproc(struct proc *, int);
228 extern int (*mountroot) __P((void));
229 extern int netboot_mountroot(); /* netboot.c */
230 extern int netboot_setup(struct proc * p);
231
232 /* hook called after root is mounted XXX temporary hack */
233 void (*mountroot_post_hook)(void);
234
235 void
236 bsd_init()
237 {
238 register struct proc *p;
239 extern struct ucred *rootcred;
240 register int i;
241 int s;
242 thread_t th;
243 void lightning_bolt(void );
244 kern_return_t ret;
245 boolean_t funnel_state;
246 extern void uthread_zone_init();
247
248
249
250 #if 1
251 /* split funnel is enabled by default */
252 PE_parse_boot_arg("dfnl", &disable_funnel);
253 #else
254 /* split funnel is disabled befault */
255 disable_funnel = 1;
256 PE_parse_boot_arg("efnl", &enable_funnel);
257 if (enable_funnel) {
258 /* enable only if efnl is set in bootarg */
259 disable_funnel = 0;
260 }
261 #endif
262
263 kernel_flock = funnel_alloc(KERNEL_FUNNEL);
264 if (kernel_flock == (funnel_t *)0 ) {
265 panic("bsd_init: Failed to allocate kernel funnel");
266 }
267
268 funnel_state = thread_funnel_set(kernel_flock, TRUE);
269
270 if (!disable_funnel) {
271 network_flock = funnel_alloc(NETWORK_FUNNEL);
272 if (network_flock == (funnel_t *)0 ) {
273 panic("bsd_init: Failed to allocate network funnel");
274 }
275 } else {
276 network_flock = kernel_flock;
277 }
278
279 printf(copyright);
280
281 kmeminit();
282
283 parse_bsd_args();
284
285 bsd_bufferinit();
286
287 /* Initialize the uthread zone */
288 uthread_zone_init();
289
290 /*
291 * Initialize process and pgrp structures.
292 */
293 procinit();
294
295 kernproc = &proc0;
296
297 p = kernproc;
298
299 /* kernel_task->proc = kernproc; */
300 set_bsdtask_info(kernel_task,(void *)p);
301 p->p_pid = 0;
302
303 /* give kernproc a name */
304 proc_name("kernel_task", p);
305
306 if (current_task() != kernel_task)
307 printf("bsd_init: We have a problem, "
308 "current task is not kernel task\n");
309
310 /*
311 * Create process 0.
312 */
313 LIST_INSERT_HEAD(&allproc, p, p_list);
314 p->p_pgrp = &pgrp0;
315 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
316 LIST_INIT(&pgrp0.pg_members);
317 LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
318
319 pgrp0.pg_session = &session0;
320 session0.s_count = 1;
321 session0.s_leader = p;
322
323 p->task = kernel_task;
324
325 p->p_stat = SRUN;
326 p->p_flag = P_INMEM|P_SYSTEM;
327 p->p_nice = NZERO;
328 p->p_pptr = p;
329 lockinit(&p->signal_lock, PVM, "signal", 0, 0);
330 TAILQ_INIT(&p->p_uthlist);
331 p->sigwait = FALSE;
332 p->sigwait_thread = THREAD_NULL;
333 p->exit_thread = THREAD_NULL;
334
335 /* Create credentials. */
336 lockinit(&cred0.pc_lock, PLOCK, "proc0 cred", 0, 0);
337 cred0.p_refcnt = 1;
338 p->p_cred = &cred0;
339 p->p_ucred = crget();
340 p->p_ucred->cr_ngroups = 1; /* group 0 */
341
342 /* Create the file descriptor table. */
343 filedesc0.fd_refcnt = 1+1; /* +1 so shutdown will not _FREE_ZONE */
344 p->p_fd = &filedesc0;
345 filedesc0.fd_cmask = cmask;
346
347 /* Create the limits structures. */
348 p->p_limit = &limit0;
349 for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
350 limit0.pl_rlimit[i].rlim_cur =
351 limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
352 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
353 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
354 limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack;
355 limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data;
356 limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core;
357 limit0.p_refcnt = 1;
358
359 p->p_stats = &pstats0;
360 p->p_sigacts = &sigacts0;
361
362 /*
363 * Charge root for one process.
364 */
365 (void)chgproccnt(0, 1);
366
367 /*
368 * Allocate a kernel submap for pageable memory
369 * for temporary copying (execve()).
370 */
371 {
372 vm_offset_t min;
373
374 ret = kmem_suballoc(kernel_map,
375 &min,
376 (vm_size_t)BSD_PAGABLE_MAP_SIZE,
377 TRUE,
378 TRUE,
379 &bsd_pageable_map);
380 if (ret != KERN_SUCCESS)
381 panic("bsd_init: Failed to allocate bsd pageable map");
382 }
383
384 /* Initialize the execve() semaphore */
385 ret = semaphore_create(kernel_task, &execve_semaphore,
386 SYNC_POLICY_FIFO, (BSD_PAGABLE_MAP_SIZE / NCARGS));
387 if (ret != KERN_SUCCESS)
388 panic("bsd_init: Failed to create execve semaphore");
389
390 /*
391 * Initialize the calendar.
392 */
393 IOKitResetTime();
394
395 ubc_init();
396
397 /* Initialize the file systems. */
398 vfsinit();
399
400 /* Initialize mbuf's. */
401 mbinit();
402
403 /* Initialize syslog */
404 log_init();
405
406 /* POSIX Shm and Sem */
407 pshm_cache_init();
408 psem_cache_init();
409 time_zone_slock_init();
410
411 /*
412 * Initialize protocols. Block reception of incoming packets
413 * until everything is ready.
414 */
415 s = splimp();
416 sysctl_register_fixed();
417 sysctl_mib_init();
418 dlil_init();
419 socketinit();
420 domaininit();
421 splx(s);
422
423 p->p_fd->fd_cdir = NULL;
424 p->p_fd->fd_rdir = NULL;
425
426 #ifdef GPROF
427 /* Initialize kernel profiling. */
428 kmstartup();
429 #endif
430
431 /* kick off timeout driven events by calling first time */
432 thread_wakeup(&lbolt);
433 timeout(lightning_bolt,0,hz);
434
435 bsd_autoconf();
436
437 /*
438 * We attach the loopback interface *way* down here to ensure
439 * it happens after autoconf(), otherwise it becomes the
440 * "primary" interface.
441 */
442 #include <loop.h>
443 #if NLOOP > 0
444 loopattach(); /* XXX */
445 #endif
446
447 /* Register the built-in dlil ethernet interface family */
448 ether_family_init();
449
450 vnode_pager_bootstrap();
451
452 /* Mount the root file system. */
453 while( TRUE) {
454 int err;
455
456 setconf();
457 /*
458 * read the time after clock_initialize_calendar()
459 * and before nfs mount
460 */
461 microtime(&time);
462
463 bsd_hardclockinit = -1; /* start ticking */
464
465 if (0 == (err = vfs_mountroot()))
466 break;
467 if (mountroot == netboot_mountroot) {
468 printf("cannot mount network root, errno = %d\n", err);
469 mountroot = NULL;
470 if (0 == (err = vfs_mountroot()))
471 break;
472 }
473 printf("cannot mount root, errno = %d\n", err);
474 boothowto |= RB_ASKNAME;
475 }
476
477 mountlist.cqh_first->mnt_flag |= MNT_ROOTFS;
478
479 /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */
480 if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
481 panic("bsd_init: cannot find root vnode");
482 VREF(rootvnode);
483 filedesc0.fd_cdir = rootvnode;
484 VOP_UNLOCK(rootvnode, 0, p);
485
486 if (mountroot == netboot_mountroot) {
487 int err;
488 /* post mount setup */
489 if (err = netboot_setup(p)) {
490 panic("bsd_init: NetBoot could not find root, %d", err);
491 }
492 }
493
494
495 /*
496 * Now can look at time, having had a chance to verify the time
497 * from the file system. Reset p->p_rtime as it may have been
498 * munched in mi_switch() after the time got set.
499 */
500 p->p_stats->p_start = boottime = time;
501 p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
502
503 #if DEVFS
504 {
505 extern void devfs_kernel_mount(char * str);
506
507 devfs_kernel_mount("/dev");
508 }
509 #endif DEVFS
510
511 /* Initialize signal state for process 0. */
512 siginit(p);
513
514 /* printf("Launching user process\n"); */
515
516 bsd_utaskbootstrap();
517
518 /* invoke post-root-mount hook */
519 if (mountroot_post_hook != NULL)
520 mountroot_post_hook();
521
522 (void) thread_funnel_set(kernel_flock, funnel_state);
523 }
524
525 /* Called with kernel funnel held */
526 void
527 bsdinit_task(void)
528 {
529 struct proc *p = current_proc();
530 struct uthread *ut;
531 kern_return_t kr;
532 thread_act_t th_act;
533 shared_region_mapping_t system_region;
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 system_region = lookup_default_shared_region(
564 ENV_DEFAULT_ROOT, ENV_DEFAULT_SYSTEM);
565 if (system_region == NULL) {
566 shared_file_boot_time_init(
567 ENV_DEFAULT_ROOT, ENV_DEFAULT_SYSTEM);
568 } else {
569 vm_set_shared_region(get_threadtask(th_act), system_region);
570 }
571 load_init_program(p);
572 /* turn on app-profiling i.e. pre-heating */
573 app_profile = 1;
574 }
575
576 void
577 lightning_bolt()
578 {
579 boolean_t funnel_state;
580 extern void klogwakeup(void);
581
582 funnel_state = thread_funnel_set(kernel_flock, TRUE);
583
584 thread_wakeup(&lbolt);
585 timeout(lightning_bolt,0,hz);
586 klogwakeup();
587
588 (void) thread_funnel_set(kernel_flock, FALSE);
589 }
590
591 bsd_autoconf()
592 {
593 extern kern_return_t IOKitBSDInit( void );
594
595 kminit();
596
597 /*
598 * Early startup for bsd pseudodevices.
599 */
600 {
601 struct pseudo_init *pi;
602
603 for (pi = pseudo_inits; pi->ps_func; pi++)
604 (*pi->ps_func) (pi->ps_count);
605 }
606
607 return( IOKitBSDInit());
608 }
609
610
611 #include <sys/disklabel.h> // for MAXPARTITIONS
612
613 setconf()
614 {
615 extern kern_return_t IOFindBSDRoot( char * rootName,
616 dev_t * root, u_int32_t * flags );
617 u_int32_t flags;
618 kern_return_t err;
619
620 /*
621 * calls into IOKit can generate networking registrations
622 * which needs to be under network funnel. Right thing to do
623 * here is to drop the funnel alltogether and regrab it afterwards
624 */
625 thread_funnel_set(kernel_flock, FALSE);
626 err = IOFindBSDRoot( rootdevice, &rootdev, &flags );
627 thread_funnel_set(kernel_flock, TRUE);
628 if( err) {
629 printf("setconf: IOFindBSDRoot returned an error (%d);"
630 "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */
631 rootdev = makedev( 6, 0 );
632 strcpy( rootdevice, "sd0a" );
633 flags = 0;
634 }
635
636 if( flags & 1 ) {
637 /* network device */
638 mountroot = netboot_mountroot;
639 } else {
640 /* otherwise have vfs determine root filesystem */
641 mountroot = NULL;
642 }
643
644 }
645
646 bsd_utaskbootstrap()
647 {
648 thread_act_t th_act;
649 struct uthread *ut;
650
651 th_act = cloneproc(kernproc, 0);
652 initproc = pfind(1);
653 /* Set the launch time for init */
654 initproc->p_stats->p_start = time;
655
656 ut = (struct uthread *)get_bsdthread_info(th_act);
657 ut->uu_sigmask = 0;
658 thread_hold(th_act);
659 (void)thread_stop(getshuttle_thread(th_act));
660 act_set_astbsd(th_act);
661 thread_release(th_act);
662 thread_unstop(getshuttle_thread(th_act));
663 (void) thread_resume(th_act);
664 }
665
666 parse_bsd_args()
667 {
668 extern char init_args[];
669 char namep[16];
670 extern int boothowto;
671 extern int srv;
672 extern int ncl;
673
674 int len;
675
676 if (PE_parse_boot_arg("-s", namep)) {
677 boothowto |= RB_SINGLE;
678 len = strlen(init_args);
679 if(len != 0)
680 strcat(init_args," -s");
681 else
682 strcat(init_args,"-s");
683 }
684 if (PE_parse_boot_arg("-b", namep)) {
685 boothowto |= RB_NOBOOTRC;
686 len = strlen(init_args);
687 if(len != 0)
688 strcat(init_args," -b");
689 else
690 strcat(init_args,"-b");
691 }
692
693 if (PE_parse_boot_arg("-F", namep)) {
694 len = strlen(init_args);
695 if(len != 0)
696 strcat(init_args," -F");
697 else
698 strcat(init_args,"-F");
699 }
700
701 if (PE_parse_boot_arg("-v", namep)) {
702 len = strlen(init_args);
703 if(len != 0)
704 strcat(init_args," -v");
705 else
706 strcat(init_args,"-v");
707 }
708
709 if (PE_parse_boot_arg("-x", namep)) { /* safe boot */
710 len = strlen(init_args);
711 if(len != 0)
712 strcat(init_args," -x");
713 else
714 strcat(init_args,"-x");
715 }
716
717 PE_parse_boot_arg("srv", &srv);
718 PE_parse_boot_arg("ncl", &ncl);
719 PE_parse_boot_arg("nbuf", &nbuf);
720
721 return 0;
722 }
723
724 boolean_t
725 thread_funnel_switch(
726 int oldfnl,
727 int newfnl)
728 {
729 thread_t cur_thread;
730 boolean_t funnel_state_prev;
731 int curfnl;
732 funnel_t * curflock;
733 funnel_t * oldflock;
734 funnel_t * newflock;
735 funnel_t * exist_funnel;
736 extern int disable_funnel;
737
738
739 if (disable_funnel)
740 return(TRUE);
741
742 if(oldfnl == newfnl) {
743 panic("thread_funnel_switch: can't switch to same funnel");
744 }
745
746 if ((oldfnl != NETWORK_FUNNEL) && (oldfnl != KERNEL_FUNNEL)) {
747 panic("thread_funnel_switch: invalid oldfunnel");
748 }
749 if ((newfnl != NETWORK_FUNNEL) && (newfnl != KERNEL_FUNNEL)) {
750 panic("thread_funnel_switch: invalid newfunnel");
751 }
752
753 if((curflock = thread_funnel_get()) == THR_FUNNEL_NULL) {
754 panic("thread_funnel_switch: no funnel held");
755 }
756
757 cur_thread = current_thread();
758
759 if ((oldfnl == NETWORK_FUNNEL) && (curflock != network_flock))
760 panic("thread_funnel_switch: network funnel not held");
761
762 if ((oldfnl == KERNEL_FUNNEL) && (curflock != kernel_flock))
763 panic("thread_funnel_switch: kernel funnel not held");
764
765 if(oldfnl == NETWORK_FUNNEL) {
766 oldflock = network_flock;
767 newflock = kernel_flock;
768 } else {
769 oldflock = kernel_flock;
770 newflock = network_flock;
771 }
772 KERNEL_DEBUG(0x603242c | DBG_FUNC_NONE, oldflock, 1, 0, 0, 0);
773 thread_funnel_set(oldflock, FALSE);
774 KERNEL_DEBUG(0x6032428 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0);
775 thread_funnel_set(newflock, TRUE);
776 KERNEL_DEBUG(0x6032434 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0);
777
778 return(TRUE);
779 }