Annotation of XNU/osfmk/kern/xpr.c, revision 1.1

1.1     ! root        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:  * HISTORY
        !            27:  * 
        !            28:  * Revision 1.1.1.1  1998/09/22 21:05:32  wsanchez
        !            29:  * Import of Mac OS X kernel (~semeria)
        !            30:  *
        !            31:  * Revision 1.1.1.1  1998/03/07 02:25:57  wsanchez
        !            32:  * Import of OSF Mach kernel (~mburg)
        !            33:  *
        !            34:  * Revision 1.2.46.1  1997/09/22  17:41:21  barbou
        !            35:  *     MP+RT: protect cpu_number() usage against preemption.
        !            36:  *     [97/09/16            barbou]
        !            37:  *
        !            38:  * Revision 1.2.25.5  1996/07/31  09:56:06  paire
        !            39:  *     Merged with nmk20b7_shared (1.2.41.1)
        !            40:  *     [96/06/10            paire]
        !            41:  * 
        !            42:  * Revision 1.2.41.1  1996/04/15  14:35:12  bernadat
        !            43:  *     Keep interrupts disabled while accessing XPR_TIMESTAMP.
        !            44:  *     [96/04/12            bernadat]
        !            45:  * 
        !            46:  * Revision 1.2.25.4  1995/02/24  15:22:42  alanl
        !            47:  *     DIPC:  Merge from nmk17b2 to nmk18b8.
        !            48:  *     Notes:  Restore portable locks package, derived from nmk17b2.
        !            49:  *     [95/02/07            alanl]
        !            50:  * 
        !            51:  * Revision 1.2.28.3  1994/12/09  22:25:16  dwm
        !            52:  *     mk6 CR801 - merge up from nmk18b4 to nmk18b7
        !            53:  *     * Rev 1.2.25.2  1994/10/21  18:30:41  joe
        !            54:  *       Added ETAP support
        !            55:  *     [1994/12/09  21:10:59  dwm]
        !            56:  * 
        !            57:  * Revision 1.2.28.2  1994/11/10  06:15:29  dwm
        !            58:  *     mk6 CR764 - s/spinlock/simple_lock/ (name change only)
        !            59:  *     [1994/11/10  05:58:48  dwm]
        !            60:  * 
        !            61:  * Revision 1.2.28.1  1994/11/04  10:10:56  dwm
        !            62:  *     mk6 CR668 - 1.3b26 merge
        !            63:  *     * Revision 1.2.5.7  1994/05/06  18:54:13  tmt
        !            64:  *     Merge in DEC Alpha changes to osc1.3b19.
        !            65:  *     include <mach/machine/vm_types.h>
        !            66:  *     64 bit cleanup.
        !            67:  *     * End1.3merge
        !            68:  *     [1994/11/04  09:39:17  dwm]
        !            69:  * 
        !            70:  * Revision 1.2.25.1  1994/09/23  02:32:39  ezf
        !            71:  *     change marker to not FREE
        !            72:  *     [1994/09/22  21:38:29  ezf]
        !            73:  * 
        !            74:  * Revision 1.2.22.1  1994/06/09  14:14:11  dswartz
        !            75:  *     Preemption merge.
        !            76:  *     [1994/06/09  14:08:38  dswartz]
        !            77:  * 
        !            78:  * Revision 1.2.5.5  1993/08/12  20:16:51  bernard
        !            79:  *     Last pass for ANSI prototypes - CR#9523
        !            80:  *     [1993/08/12  15:43:24  bernard]
        !            81:  * 
        !            82:  * Revision 1.2.5.4  1993/08/02  17:26:05  rod
        !            83:  *     ANSI prototypes:  zap explicit include of machine/setjmp.h.  CR #9523.
        !            84:  *     [1993/08/01  13:36:31  rod]
        !            85:  * 
        !            86:  * Revision 1.2.5.3  1993/07/27  18:09:05  rod
        !            87:  *     Add ANSI prototypes.  CR #9523.
        !            88:  *     [1993/07/27  14:33:23  rod]
        !            89:  * 
        !            90:  * Revision 1.2.5.2  1993/06/09  02:39:13  gm
        !            91:  *     CR9176 - ANSI C violations: trailing tokens on CPP
        !            92:  *     directives, extra semicolons after decl_ ..., asm keywords
        !            93:  *     [1993/06/07  19:07:51  jeffc]
        !            94:  * 
        !            95:  *     Added to OSF/1 R1.3 from NMK15.0.
        !            96:  *     [1993/06/02  21:15:13  jeffc]
        !            97:  * 
        !            98:  * Revision 1.2  1993/04/19  16:31:21  devrcs
        !            99:  *     Added void to fcns that still needed it.
        !           100:  *     [93/02/05            bruel]
        !           101:  * 
        !           102:  * Revision 1.1  1992/09/30  02:10:39  robert
        !           103:  *     Initial revision
        !           104:  * 
        !           105:  * $EndLog$
        !           106:  */
        !           107: /* CMU_HIST */
        !           108: /*
        !           109:  * Revision 2.9.5.2  92/03/03  16:20:57  jeffreyh
        !           110:  *     Fix Log.
        !           111:  *     [92/02/24  13:24:44  jeffreyh]
        !           112:  * 
        !           113:  * Revision 2.9.5.1  92/02/18  19:13:03  jeffreyh
        !           114:  *     Added an xpr_search function to which you can give
        !           115:  *     a selection function.
        !           116:  *     [92/02/11  08:13:23  bernadat]
        !           117:  * 
        !           118:  * Revision 2.9.4.1  92/02/13  18:53:47  jeffreyh
        !           119:  *     Added an xpr_search function to which you can give
        !           120:  *     a selection function.
        !           121:  *     [92/02/11  08:13:23  bernadat]
        !           122:  * 
        !           123:  * Revision 2.9.3.1  92/02/11  17:19:59  jeffreyh
        !           124:  *     Added an xpr_search function to which you can give
        !           125:  *     a selection function.
        !           126:  *     [92/02/11  08:13:23  bernadat]
        !           127:  * 
        !           128:  * Revision 2.9.2.1  92/02/11  08:13:23  bernadat
        !           129:  *     Added an xpr_search function to which you can give
        !           130:  *     a selection function.
        !           131:  * 
        !           132:  * 
        !           133:  * Revision 2.9  91/10/09  16:11:50  af
        !           134:  *     Removed xpr_save.  Modified xpr_dump to make it useful
        !           135:  *     for dumping xpr buffers in user space tasks.
        !           136:  *     [91/09/20            rpd]
        !           137:  * 
        !           138:  *     Turned on xprenable by default.  xprbootstrap now preserves
        !           139:  *     the original contents of the buffer if xprenable is off.
        !           140:  *     [91/09/18            rpd]
        !           141:  * 
        !           142:  * Revision 2.8  91/08/28  11:14:56  jsb
        !           143:  *     Fixed xprbootstrap to zero the allocate memory.
        !           144:  *     [91/08/18            rpd]
        !           145:  * 
        !           146:  * Revision 2.7  91/05/18  14:34:37  rpd
        !           147:  *     Added xprenable and other minor changes so that the xpr buffer
        !           148:  *     may be examined after a spontaneous reboot.
        !           149:  *     [91/05/03            rpd]
        !           150:  *     Fixed the initialization check in xpr.
        !           151:  *     Fixed xpr_dump.
        !           152:  *     [91/04/02            rpd]
        !           153:  * 
        !           154:  * Revision 2.6  91/05/14  16:50:09  mrt
        !           155:  *     Correcting copyright
        !           156:  * 
        !           157:  * Revision 2.5  91/03/16  14:53:24  rpd
        !           158:  *     Updated for new kmem_alloc interface.
        !           159:  *     [91/03/03            rpd]
        !           160:  * 
        !           161:  * Revision 2.4  91/02/05  17:31:13  mrt
        !           162:  *     Changed to new Mach copyright
        !           163:  *     [91/02/01  16:21:17  mrt]
        !           164:  * 
        !           165:  * Revision 2.3  90/09/09  14:33:04  rpd
        !           166:  *     Use decl_simple_lock_data.
        !           167:  *     [90/08/30            rpd]
        !           168:  * 
        !           169:  * Revision 2.2  89/11/29  14:09:21  af
        !           170:  *     Added xpr_dump() to print on console the content of the buffer,
        !           171:  *     only valid for KDB usage.
        !           172:  *     [89/11/12            af]
        !           173:  * 
        !           174:  *     MACH_KERNEL: include sys/cpu_number.h instead of machine/cpu.h.
        !           175:  *     Clean up comments.
        !           176:  *     [88/12/19            dbg]
        !           177:  * 
        !           178:  * Revision 2.1  89/08/03  15:49:11  rwd
        !           179:  * Created.
        !           180:  * 
        !           181:  * Revision 2.2  88/12/19  02:48:30  mwyoung
        !           182:  *     Fix include file references.
        !           183:  *     [88/11/22  02:17:01  mwyoung]
        !           184:  *     
        !           185:  *     Separate initialization into two phases.
        !           186:  *     [88/11/22  01:13:11  mwyoung]
        !           187:  * 
        !           188:  *  6-Jan-88  Michael Young (mwyoung) at Carnegie-Mellon University
        !           189:  *     Eliminate use of arg6 in order to allow a more shapely event structure.
        !           190:  *
        !           191:  * 30-Dec-87  David Golub (dbg) at Carnegie-Mellon University
        !           192:  *     Delinted.
        !           193:  *
        !           194:  *  7-Dec-87  Richard Sanzi (sanzi) at Carnegie-Mellon University
        !           195:  *     Added xpr_save() routine.
        !           196:  *
        !           197:  */ 
        !           198: /* CMU_ENDHIST */
        !           199: /* 
        !           200:  * Mach Operating System
        !           201:  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
        !           202:  * All Rights Reserved.
        !           203:  * 
        !           204:  * Permission to use, copy, modify and distribute this software and its
        !           205:  * documentation is hereby granted, provided that both the copyright
        !           206:  * notice and this permission notice appear in all copies of the
        !           207:  * software, derivative works or modified versions, and any portions
        !           208:  * thereof, and that both notices appear in supporting documentation.
        !           209:  * 
        !           210:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
        !           211:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
        !           212:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
        !           213:  * 
        !           214:  * Carnegie Mellon requests users of this software to return to
        !           215:  * 
        !           216:  *  Software Distribution Coordinator  or  [email protected]
        !           217:  *  School of Computer Science
        !           218:  *  Carnegie Mellon University
        !           219:  *  Pittsburgh PA 15213-3890
        !           220:  * 
        !           221:  * any improvements or extensions that they make and grant Carnegie Mellon
        !           222:  * the rights to redistribute these changes.
        !           223:  */
        !           224: #include <mach_kdb.h>
        !           225: /*
        !           226:  * xpr silent tracing circular buffer.
        !           227:  */
        !           228: 
        !           229: #include <cpus.h>
        !           230: 
        !           231: #include <mach/machine/vm_types.h>
        !           232: #include <kern/xpr.h>
        !           233: #include <kern/lock.h>
        !           234: #include <kern/spl.h>
        !           235: #include <kern/cpu_number.h>
        !           236: #include <kern/misc_protos.h>
        !           237: #include <kern/thread.h>
        !           238: #include <vm/vm_kern.h>
        !           239: #include <string.h>
        !           240: 
        !           241: /*
        !           242:  *     After a spontaneous reboot, it is desirable to look
        !           243:  *     at the old xpr buffer.  Assuming xprbootstrap allocates
        !           244:  *     the buffer in the same place in physical memory and
        !           245:  *     the reboot doesn't clear memory, this should work.
        !           246:  *     xprptr will be reset, but the saved value should be OK.
        !           247:  *     Just set xprenable false so the buffer isn't overwritten.
        !           248:  */
        !           249: 
        !           250: decl_simple_lock_data(,xprlock)
        !           251: boolean_t xprenable = TRUE;    /* Enable xpr tracing */
        !           252: int nxprbufs = 0;      /* Number of contiguous xprbufs allocated */
        !           253: int xprflags = 0;      /* Bit mask of xpr flags enabled */
        !           254: struct xprbuf *xprbase;        /* Pointer to circular buffer nxprbufs*sizeof(xprbuf)*/
        !           255: struct xprbuf *xprptr; /* Currently allocated xprbuf */
        !           256: struct xprbuf *xprlast;        /* Pointer to end of circular buffer */
        !           257: 
        !           258: void
        !           259: xpr(
        !           260:        char    *msg,
        !           261:        long    arg1,
        !           262:        long    arg2,
        !           263:        long    arg3,
        !           264:        long    arg4,
        !           265:        long    arg5)
        !           266: {
        !           267:        spl_t s;
        !           268:        register struct xprbuf *x;
        !           269: 
        !           270:        /* If we aren't initialized, ignore trace request */
        !           271:        if (!xprenable || (xprptr == 0))
        !           272:                return;
        !           273:        /* Guard against all interrupts and allocate next buffer. */
        !           274: 
        !           275:        s = splhigh();
        !           276:        simple_lock(&xprlock);
        !           277:        x = xprptr++;
        !           278:        if (xprptr >= xprlast) {
        !           279:                /* wrap around */
        !           280:                xprptr = xprbase;
        !           281:        }
        !           282:        /* Save xprptr in allocated memory. */
        !           283:        *(struct xprbuf **)xprlast = xprptr;
        !           284:        simple_unlock(&xprlock);
        !           285:        x->timestamp = XPR_TIMESTAMP;
        !           286:        splx(s);
        !           287:        x->msg = msg;
        !           288:        x->arg1 = arg1;
        !           289:        x->arg2 = arg2;
        !           290:        x->arg3 = arg3;
        !           291:        x->arg4 = arg4;
        !           292:        x->arg5 = arg5;
        !           293:        mp_disable_preemption();
        !           294:        x->cpuinfo = cpu_number();
        !           295:        mp_enable_preemption();
        !           296: }
        !           297: 
        !           298: void 
        !           299: xprbootstrap(void)
        !           300: {
        !           301:        vm_offset_t     addr;
        !           302:        vm_size_t       size;
        !           303:        kern_return_t   kr;
        !           304: 
        !           305:        simple_lock_init(&xprlock, ETAP_MISC_XPR);
        !           306:        if (nxprbufs == 0)
        !           307:                return; /* assume XPR support not desired */
        !           308: 
        !           309:        /* leave room at the end for a saved copy of xprptr */
        !           310:        size = nxprbufs * sizeof(struct xprbuf) + sizeof xprptr;
        !           311: 
        !           312:        kr = kmem_alloc_wired(kernel_map, &addr, size);
        !           313:        if (kr != KERN_SUCCESS)
        !           314:                panic("xprbootstrap");
        !           315: 
        !           316:        if (xprenable) {
        !           317:                /*
        !           318:                 *      If xprenable is set (the default) then we zero
        !           319:                 *      the buffer so xpr_dump doesn't encounter bad pointers.
        !           320:                 *      If xprenable isn't set, then we preserve
        !           321:                 *      the original contents of the buffer.  This is useful
        !           322:                 *      if memory survives reboots, so xpr_dump can show
        !           323:                 *      the previous buffer contents.
        !           324:                 */
        !           325: 
        !           326:                (void) memset((void *) addr, 0, size);
        !           327:        }
        !           328: 
        !           329:        xprbase = (struct xprbuf *) addr;
        !           330:        xprlast = &xprbase[nxprbufs];
        !           331:        xprptr = xprbase;       /* setting xprptr enables tracing */
        !           332: }
        !           333: 
        !           334: int            xprinitial = 0;
        !           335: 
        !           336: void
        !           337: xprinit(void)
        !           338: {
        !           339:        xprflags |= xprinitial;
        !           340: }
        !           341: 
        !           342: #if    MACH_KDB
        !           343: #include <ddb/db_output.h>
        !           344: 
        !           345: /*
        !           346:  * Prototypes for functions called from the debugger
        !           347:  */
        !           348: void
        !           349: xpr_dump(
        !           350:        struct xprbuf   *base,
        !           351:        int             nbufs);
        !           352: 
        !           353: void
        !           354: xpr_search(
        !           355:        int     arg_index,
        !           356:        int     value);
        !           357: 
        !           358: extern jmp_buf_t *db_recover;
        !           359: 
        !           360: /*
        !           361:  *     Print current content of xpr buffers (KDB's sake)
        !           362:  *     Use stack order to make it understandable.
        !           363:  *
        !           364:  *     Called as "!xpr_dump" this dumps the kernel's xpr buffer.
        !           365:  *     Called with arguments, it can dump xpr buffers in user tasks,
        !           366:  *     assuming they use the same format as the kernel.
        !           367:  */
        !           368: void
        !           369: xpr_dump(
        !           370:        struct xprbuf   *base,
        !           371:        int             nbufs)
        !           372: {
        !           373:        jmp_buf_t db_jmpbuf;
        !           374:        jmp_buf_t *prev;
        !           375:        struct xprbuf *last, *ptr;
        !           376:        register struct xprbuf *x;
        !           377:        int i;
        !           378:        spl_t s;
        !           379: 
        !           380:        if (base == 0) {
        !           381:                base = xprbase;
        !           382:                nbufs = nxprbufs;
        !           383:        }
        !           384: 
        !           385:        if (nbufs == 0)
        !           386:                return;
        !           387: 
        !           388:        if (base == xprbase) {
        !           389:                s = splhigh();
        !           390:                simple_lock(&xprlock);
        !           391:        }
        !           392: 
        !           393:        last = base + nbufs;
        !           394:        ptr = * (struct xprbuf **) last;
        !           395: 
        !           396:        prev = db_recover;
        !           397:        if (_setjmp(db_recover = &db_jmpbuf) == 0)
        !           398:            for (x = ptr, i = 0; i < nbufs; i++) {
        !           399:                if (--x < base)
        !           400:                        x = last - 1;
        !           401: 
        !           402:                if (x->msg == 0)
        !           403:                        break;
        !           404: 
        !           405:                db_printf("<%d:%x:%x> ", x - base, x->cpuinfo, x->timestamp);
        !           406:                db_printf(x->msg, x->arg1,x->arg2,x->arg3,x->arg4,x->arg5);
        !           407:            }
        !           408:        db_recover = prev;
        !           409: 
        !           410:        if (base == xprbase) {
        !           411:                simple_unlock(&xprlock);
        !           412:                splx(s);
        !           413:        }
        !           414: }
        !           415: 
        !           416: /*
        !           417:  * dump xpr table with a selection criteria.
        !           418:  * argument number "arg_index" must equal "value"
        !           419:  */
        !           420: 
        !           421: void
        !           422: xpr_search(
        !           423:        int     arg_index,
        !           424:        int     value)
        !           425: {
        !           426:        jmp_buf_t db_jmpbuf;
        !           427:        jmp_buf_t *prev;
        !           428:        register struct xprbuf *x;
        !           429:        spl_t s;
        !           430:        int n;
        !           431: 
        !           432:        if (!nxprbufs)
        !           433:                return;
        !           434: 
        !           435:        n = nxprbufs;
        !           436: 
        !           437:        s = splhigh();
        !           438:        simple_lock(&xprlock);
        !           439: 
        !           440:        prev = db_recover;
        !           441:        if (_setjmp(db_recover = &db_jmpbuf) == 0)
        !           442:            for (x = *(struct xprbuf **)xprlast ; n--; ) {
        !           443:                if (--x < xprbase)
        !           444:                        x = xprlast - 1;
        !           445: 
        !           446:                if (x->msg == 0) {
        !           447:                        break;
        !           448:                }
        !           449: 
        !           450:                if (*((&x->arg1)+arg_index) != value)
        !           451:                        continue;
        !           452: 
        !           453:                db_printf("<%d:%d:%x> ", x - xprbase,
        !           454:                          x->cpuinfo, x->timestamp);
        !           455:                db_printf(x->msg, x->arg1,x->arg2,x->arg3,x->arg4,x->arg5);
        !           456:            }
        !           457:        db_recover = prev;
        !           458: 
        !           459:        simple_unlock(&xprlock);
        !           460:        splx(s);
        !           461: }
        !           462: #endif /* MACH_KDB */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.