Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1.  
  2. .global ___chkstk
  3. .global ___chkstk_ms
  4. .global __alloca
  5.  
  6. .section .text
  7.  
  8. #.def   ___chkstk;      .scl    2;      .type   32;     .endef
  9. #.def ___chkstk_ms;  .scl  2;  .type 32; .endef
  10. #.def __alloca; .scl  2;  .type 32; .endef
  11.  
  12. ___chkstk:
  13. __alloca:
  14.         pushl   %ecx            /* save temp */
  15.         leal    8(%esp), %ecx   /* point past return addr */
  16.         subl    %eax, %ecx
  17.         cmpl    %fs:8, %ecx     # check low stack limit
  18.         jb      1f
  19.  
  20.         movl    %esp, %eax      /* save old stack pointer */
  21.         movl    %ecx, %esp      /* decrement stack */
  22.         movl    (%eax), %ecx    /* recover saved temp */
  23.         movl    4(%eax), %eax   /* recover return address */
  24.  
  25.         /* Push the return value back.  Doing this instead of just
  26.            jumping to %eax preserves the cached call-return stack
  27.            used by most modern processors.  */
  28.         pushl   %eax
  29.         ret
  30. 1:
  31.         int3                    #trap to debugger
  32.         .ascii "Stack overflow"
  33.  
  34.  
  35. ___chkstk_ms:
  36.        pushl  %ecx            /* save temp */
  37.        pushl  %eax
  38.        cmpl $0x1000, %eax     /* > 4k ?*/
  39.        leal 12(%esp), %ecx    /* point past return addr */
  40.        jb 2f
  41.  
  42. 1:
  43.        subl $0x1000, %ecx     /* yes, move pointer down 4k*/
  44.        cmpl %fs:8, %ecx       /* check low stack limit    */
  45.        jb 3f
  46.  
  47.        orl $0x0, (%ecx)       /* probe there */
  48.        subl $0x1000, %eax     /* decrement count */
  49.        cmpl $0x1000, %eax
  50.        ja 1b                  /* and do it again */
  51.  
  52. 2:
  53.        subl %eax, %ecx
  54.        orl $0x0, (%ecx) /* less than 4k, just peek here */
  55.  
  56.        popl %eax
  57.        popl %ecx
  58.        ret
  59. 3:
  60.        int3                    #trap to debugger
  61.        .ascii "Stack overflow"
  62.