4 Replies Latest reply on Jun 18, 2019 7:19 PM by TakashiM_61

    Detect stack overflow

    YoIs_1298666

      Hello,

       

      We would like to prepare the detection of stack overflow.

      We will clear the last 4bytes of stack pointer address to 0x00000000 . And  we will detect the stack overlow by reading these 4bytes whether stack pointer has been written.

      How to read/write the last 4bytes

          *(reg32 *)(CYDEV_SRAM_BASE + CYDEV_SRAM_SIZE - CYDEV_STACK_SIZE)

      Is this correct?

       

      for example

      [In case of clearing the last 4bytes of stack pointer to 0x00000000]

              uint32 check_sp_ov;

                       ......

              check_sp_ov = 0x00000000;

              *(reg32 *)(CYDEV_SRAM_BASE + CYDEV_SRAM_SIZE - CYDEV_STACK_SIZE) = check_sp_ov;

       

      [In case of checking the last 4bytes of stack pointer]

              if( *(reg32 *)(CYDEV_SRAM_BASE + CYDEV_SRAM_SIZE - CYDEV_STACK_SIZE) != 0x0)

              {

                     error processing code

              }

       

      Best regards,

      Yocchi