The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/modules/panic/panic.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: panic.c,v 1.2 2021/06/21 03:08:07 christos Exp $ */
    2 
    3 /*
    4  * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. The name of the author may not be used to endorse or promote products
   13  *    derived from this software without specific prior written permission.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
   22  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 
   28 #include <sys/cdefs.h>
   29 __KERNEL_RCSID(0, "$NetBSD: panic.c,v 1.2 2021/06/21 03:08:07 christos Exp $");
   30 
   31 #include <sys/module.h>
   32 
   33 MODULE(MODULE_CLASS_MISC, panic, NULL);
   34 
   35 static void
   36 panic_dopanic(void)
   37 {
   38         /* just call panic */
   39         panic("oops");
   40 }
   41 
   42 static void
   43 panic_donullptr(void)
   44 {
   45         /* null ptr dereference */
   46         *(int *)NULL = 1;
   47 }
   48 
   49 static const struct {
   50         const char *name;
   51         void (*func)(void);
   52 } panic_howto[] = {
   53         { "panic",      panic_dopanic },
   54         { "nullptr",    panic_donullptr },
   55 };
   56 
   57 static int
   58 panic_modcmd(modcmd_t cmd, void *opaque)
   59 {
   60         if (cmd == MODULE_CMD_INIT) {
   61                 prop_dictionary_t props = opaque;
   62                 const char *how = NULL;
   63                 unsigned int i;
   64 
   65                 if (props)
   66                         prop_dictionary_get_string(props, "how", &how);
   67                 if (how == NULL)
   68                         how = "panic";
   69 
   70                 for (i = 0; i < __arraycount(panic_howto); i++) {
   71                         if (strcmp(how, panic_howto[i].name) == 0) {
   72                                 panic_howto[i].func();
   73                                 break;
   74                         }
   75                 }
   76                 if (i == __arraycount(panic_howto))
   77                         printf("%s: no how '%s'\n", __func__, how);
   78                 else
   79                         printf("%s: how '%s' didn't panic?\n", __func__, how);
   80 
   81                 return EINVAL;
   82         }
   83 
   84         return ENOTTY;
   85 }

Cache object: feae0cb3a24f797efeb9cc4e4d047c06


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.