Annotation of objc/objc-moninit-m68k.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * "Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.0 (the 'License').  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License."
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: #ifdef SHLIB
                     25: #import "shlib.h"
                     26: #undef moninitobjc
                     27: #endif
                     28: 
                     29: #ifndef __m68k__
                     30: #error "this is m68k machine dependent"
                     31: #endif
                     32: 
                     33: #include <mach/mach.h>
                     34: 
                     35: /*
                     36:  * objc_exitPoints is a private_extern defined in the objective-C messager
                     37:  * which is a zero terminated table of a list of text lables to write
                     38:  * instructions which will cause the objective-C messager to then call
                     39:  * moncount for each message it dispatches.  The instruction at each of these
                     40:  * text lables is a "jmp a0@" instruction.  The objective-C messager has
                     41:  * allocated space after each of these instructions for moninitobjc to write
                     42:  * the instructions to call moncount for each message it dispatches.
                     43:  * 
                     44:  * The instructions written over the "jmp a0@" and the allocated space after
                     45:  * it are:
                     46:  * exitPoint1: jmp     a0@
                     47:  *             | replace with the following instructions
                     48:  *             movel   a0,sp@-
                     49:  *             movel   a1,sp@-
                     50:  *             movel   a0,sp@-
                     51:  *             movel   sp@(12),sp@-
                     52:  *             jsr     moncount
                     53:  *             addl    #8,sp
                     54:  *             movel   sp@+,a1
                     55:  *             movel   sp@+,a0
                     56:  *             jmp     a0@
                     57:  */
                     58: extern unsigned long objc_exitPoints[];
                     59: 
                     60: /*
                     61:  * objc_entryPoints is a private_extern defined in the objective-C messager
                     62:  * which is a zero terminated table of a list of text lables that should not
                     63:  * have a call inserted to moncount in their shared library branch table slot.
                     64:  */
                     65: extern unsigned long objc_entryPoints[];
                     66: 
                     67: /*
                     68:  * moninitobjc() is a machine dependent routine that causes objective-C
                     69:  * messager to call moncount() for each message it sends.
                     70:  */
                     71: unsigned long *
                     72: moninitobjc(
                     73: unsigned long moncount_addr)
                     74: {
                     75:     unsigned long i, min, max;
                     76:     char *p;
                     77:     kern_return_t r;
                     78: 
                     79:        if(objc_exitPoints[0] == 0)
                     80:            return(objc_entryPoints);
                     81: 
                     82:        /*
                     83:         * Determine the area to vm_protect() for writing the code.
                     84:         */
                     85:        min = 0xffffffff;
                     86:        max = 0;
                     87:        for(i = 0; objc_exitPoints[i] != 0; i++){
                     88:            if(objc_exitPoints[i] < min)
                     89:                min = objc_exitPoints[i];
                     90:            if(objc_exitPoints[i] > max)
                     91:                max = objc_exitPoints[i];
                     92:        }
                     93:        max += 24;
                     94: 
                     95:        if((r = vm_protect(task_self(), (vm_address_t)min, (vm_size_t)(max-min),
                     96:                           FALSE, VM_PROT_READ | VM_PROT_WRITE |
                     97:                           VM_PROT_EXECUTE)) != KERN_SUCCESS)
                     98:            return(objc_entryPoints);
                     99: 
                    100:        /*
                    101:         * Write in the code to call moncount.
                    102:         */
                    103:        for(i = 0; objc_exitPoints[i] != 0; i++){
                    104:            p = (char *)(objc_exitPoints[i]);
                    105:            /* movel a0,sp@- */
                    106:            *p++ = 0x2f;
                    107:            *p++ = 0x08;
                    108:            /* movel a1,sp@- */
                    109:            *p++ = 0x2f;
                    110:            *p++ = 0x09;
                    111:            /* movel a0,sp@- */
                    112:            *p++ = 0x2f;
                    113:            *p++ = 0x08;
                    114:            /* movel sp@(12),sp@- */
                    115:            *p++ = 0x2f;
                    116:            *p++ = 0x2f;
                    117:            *p++ = 0x00;
                    118:            *p++ = 0x0c;
                    119:            /* jsr      moncount */
                    120:            *p++ = 0x4e;
                    121:            *p++ = 0xb9;
                    122:            *p++ = (moncount_addr >> 24) & 0xff;
                    123:            *p++ = (moncount_addr >> 16) & 0xff;
                    124:            *p++ = (moncount_addr >>  8) & 0xff;
                    125:            *p++ = (moncount_addr) & 0xff;
                    126:            /* addl #8,sp */
                    127:            *p++ = 0x50;
                    128:            *p++ = 0x8f;
                    129:            /* movel sp@+,a1 */
                    130:            *p++ = 0x22;
                    131:            *p++ = 0x5f;
                    132:            /* movel sp@+,a0 */
                    133:            *p++ = 0x20;
                    134:            *p++ = 0x5f;
                    135:            /* jmp a0@ */
                    136:            *p++ = 0x4e;
                    137:            *p++ = 0xd0;
                    138:        }
                    139:        /*
                    140:         * The text cache for the this code now needs to be flushed since
                    141:         * it was just written on so that future calls will get the new
                    142:         * instructions.
                    143:        cache_flush(min, max-min);
                    144:         */
                    145:        asm("trap #2");
                    146: 
                    147:        return(objc_entryPoints);
                    148: }

unix.superglobalmegacorp.com

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