home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l291 / 5.ddi / CHKSUM.AS$ / CHKSUM.bin
Encoding:
Text File  |  1989-08-31  |  3.5 KB  |  153 lines

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