Subversion Repositories Kolibri OS

Rev

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

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