home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SOURCE / STARTUP / CHKSUM.AS_ / CHKSUM.AS
Encoding:
Text File  |  1993-02-08  |  3.2 KB  |  141 lines

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