Annotation of os2sdk/startup/chksum.asm, revision 1.1.1.1

1.1       root        1:        TITLE   chksum - _nullcheck routine for C
                      2: ;*** 
                      3: ;chksum.asm - _nullcheck routine for C
                      4: ;
                      5: ;      Copyright (c) 1985-1987, Microsoft Corporation.  All rights reserved.
                      6: ;
                      7: ;Purpose:
                      8: ;      This routine is used to check for assignment through a null pointer.
                      9: ;      Memory at DGROUP:0 is checked for destructive assignments.  This
                     10: ;      routine is not particularly effective in compact and large models.
                     11: ;      A stub may be provoded for this routine without affecting the
                     12: ;      behavior of a correctly written C program.
                     13: ;
                     14: ;*******************************************************************************
                     15: 
                     16: ?DF=           1                       ; this is special for c startup
                     17: include version.inc
                     18: .xlist
                     19: include cmacros.inc
                     20: .list
                     21: 
                     22: createSeg      _TEXT,  code,   word,   public, CODE,   <>
                     23: 
                     24: createSeg      NULL,   null,   para,   public, BEGDATA,DGROUP
                     25: createSeg      _DATA,  data,   word,   public, DATA,   DGROUP
                     26: 
                     27: createSeg      HDR,    nhdr,   byte,   public, MSG,    DGROUP
                     28: createSeg      MSG,    nmsg,   byte,   public, MSG,    DGROUP
                     29: createSeg      PAD,    npad,   byte,   common, MSG,    DGROUP
                     30: createSeg      EPAD,   nepad,  byte,   common, MSG,    DGROUP
                     31: 
                     32: defGrp DGROUP                          ; define DGROUP
                     33: 
                     34: codeOFFSET     equ     offset _TEXT:
                     35: dataOFFSET     equ     offset DGROUP:
                     36: 
                     37: 
                     38: sBegin null
                     39: assumes ds,data
                     40: 
                     41: BIAS=  55h
                     42: 
                     43: chkpt  db      8 dup(0)                ; for null pointer assignment
                     44:        CHKSUM= 1Eh                     ; has to be correct or error
                     45:        db      'MS Run-Time Library - Copyright (c) 1987, Microsoft Corp'
                     46: chkb   db      CHKSUM                  ; checksum byte
                     47:        db      0                       ; leaves al = 0
                     48: chkln=         $ - chkpt               ; length to checksum
                     49: 
                     50: sEnd   null
                     51: 
                     52: sBegin nmsg
                     53: assumes ds,data
                     54:        dw      1
                     55:        db      'R6001',13,10,'- null pointer assignment',13,10,0
                     56: sEnd
                     57: 
                     58: sBegin npad
                     59: assumes ds,data
                     60:        dw      -1
                     61: ; no padding for now;
                     62: ; MAX padding would be
                     63: ;      db      20 dup(0)       
                     64: sEnd
                     65: 
                     66: externP _NMSG_WRITE                    ; pascal calling
                     67: externP _FF_MSGBANNER                  ; pascal calling
                     68: 
                     69: sBegin code
                     70: assumes cs,code
                     71: assumes ds,data
                     72: 
                     73: 
                     74: page
                     75: ;*** 
                     76: ;_nullcheck - check-sum of start of DGROUP segment to detect null-ptr-assignmt.
                     77: ;
                     78: ;Purpose:
                     79: ;      _nullcheck cumulatively xor's all the bytes from ds:0 through 1 past end
                     80: ;      of copyright string, finally xor'ing an arbitrary non-zero constant.
                     81: ;      This is used to check if a null pointer has been written to.
                     82: ;
                     83: ;      This version can be called as many times as the user wants.
                     84: ;      The function returns zero if the checksum is OK.
                     85: ;
                     86: ;      Note that this checksum only detects (DS:0) null pointer assignments
                     87: ;      but not (0:0) null pointer assignments.
                     88: ;
                     89: ;Entry:
                     90: ;      Assumes DS points to the beginning of DGROUP.
                     91: ;
                     92: ;Exit:
                     93: ;      Returns : AX = 0 if no error; AX = 1 if error.
                     94: ;
                     95: ;Uses:
                     96: ;      BX,CX,DX,ES are destroyed.
                     97: ;
                     98: ;Exceptions:
                     99: ;      If _nullcheck check-sum fails, an error message is written
                    100: ;      to standard error, and the routine returns an error code (AX = 1).
                    101: ;
                    102: ;*******************************************************************************
                    103: 
                    104: cProc  _nullcheck,<PUBLIC>,<>
                    105: cBegin nogen                           ; no arguments - so no frame
                    106:        push    si
                    107: 
                    108:        xor     si,si                   ; start at DS:0
                    109:        mov     cx,chkln
                    110:        xor     ah,ah
                    111:        cld
                    112: 
                    113: chkloop:                               ; loop to 1 past end of copyrt. string
                    114:        lodsb
                    115:        xor     ah,al                   ; accumulate xor total in AH
                    116:        loop    chkloop
                    117: 
                    118:        xor     ah,BIAS                 ; XOR out the initial BIAS
                    119:        jz      setzero
                    120: 
                    121:        call    _FF_MSGBANNER           ; (1) "\r\n" to stderr
                    122:                                        ; (2) FORTRAN $DEBUG file/line 
                    123:                                        ;     if _Fline is set (not in C)
                    124:                                        ; (3) "run-time error" banner
                    125:        mov     ax,1                    ; null pointer assignment message no.
                    126:        push    ax
                    127:        call    _NMSG_WRITE             ; write message out
                    128:        mov     ax,1                    ; indicate error occurred
                    129: 
                    130: ;      ax = 0 if the checksum is OK
                    131: 
                    132: setzero:
                    133:        pop     si
                    134:        ret
                    135: 
                    136: cEnd   nogen
                    137: 
                    138: 
                    139: sEnd   code
                    140: 
                    141:        end

unix.superglobalmegacorp.com

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