or1k: Avoid write outside setjmp buf & shrink buf

Update the offsets used to save registers into the stejmp jmp_buf
structure in order to:

* Avoid writing the supervision register outside the buffer and thus
  clobbering something on the stack. Previously the supervision register
  was written at offset 124 while the buffer was of length 124.

* Shrink the jmp_buf down to the size actually needed, by avoiding holes
  at the locations of omitted registers.
This commit is contained in:
Martin Erik Werner 2019-06-27 10:03:48 +02:00 committed by Corinna Vinschen
parent f96f7bec6b
commit 739e89cbe6
2 changed files with 32 additions and 29 deletions

View File

@ -2,7 +2,10 @@
_BEGIN_STD_C _BEGIN_STD_C
#if defined(__or1k__) || defined(__or1knd__) #if defined(__or1k__) || defined(__or1knd__)
#define _JBLEN 31 /* 32 GPRs - r0 */ /*
* r1, r2, r9, r14, r16 .. r30, SR.
*/
#define _JBLEN 13
#define _JBTYPE unsigned long #define _JBTYPE unsigned long
#endif #endif

View File

@ -29,25 +29,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.type setjmp,@function .type setjmp,@function
setjmp: setjmp:
l.sw 4(r3), r1 l.sw 0(r3), r1
l.sw 8(r3), r2 l.sw 4(r3), r2
/* Skip r3-r8 as they are not preserved across function calls */ /* Skip r3-r8 as they are not preserved across function calls */
l.sw 36(r3), r9 l.sw 8(r3), r9
/* Skip r10 as it's preserved to be used by TLS */ /* Skip r10 as it's preserved to be used by TLS */
/* Skip r11, setjmp always set it to 0 */ /* Skip r11, setjmp always set it to 0 */
/* The following set if registers are preserved across function calls */ /* The following set if registers are preserved across function calls */
l.sw 52(r3), r14 l.sw 12(r3), r14
l.sw 60(r3), r16 l.sw 16(r3), r16
l.sw 68(r3), r18 l.sw 20(r3), r18
l.sw 76(r3), r20 l.sw 24(r3), r20
l.sw 84(r3), r22 l.sw 28(r3), r22
l.sw 92(r3), r24 l.sw 32(r3), r24
l.sw 100(r3), r26 l.sw 36(r3), r26
l.sw 108(r3), r28 l.sw 40(r3), r28
l.sw 116(r3), r30 l.sw 44(r3), r30
/* Save Status Register */ /* Save Status Register */
l.mfspr r13, r0, 17 l.mfspr r13, r0, 17
l.sw 124(r3), r13 l.sw 48(r3), r13
/* Set result register to 0 and jump */ /* Set result register to 0 and jump */
// Different cases for optional delay slot // Different cases for optional delay slot
#if defined(__OR1K_NODELAY__) #if defined(__OR1K_NODELAY__)
@ -77,32 +77,32 @@ longjmp:
/* Load status register */ /* Load status register */
1: 1:
l.lwz r15, 124(r3) l.lwz r15, 48(r3)
l.mtspr r0, r15, 17 l.mtspr r0, r15, 17
l.lwz r1, 4(r3) l.lwz r1, 0(r3)
l.lwz r2, 8(r3) l.lwz r2, 4(r3)
/* Skip r3-r8 as they are not preserved across function calls */ /* Skip r3-r8 as they are not preserved across function calls */
l.lwz r9, 36(r3) l.lwz r9, 8(r3)
/* Skip r11 as it's always set by longjmp */ /* Skip r11 as it's always set by longjmp */
l.lwz r14, 52(r3) l.lwz r14, 12(r3)
l.lwz r16, 60(r3) l.lwz r16, 16(r3)
l.lwz r18, 68(r3) l.lwz r18, 20(r3)
l.lwz r20, 76(r3) l.lwz r20, 24(r3)
l.lwz r22, 84(r3) l.lwz r22, 28(r3)
l.lwz r24, 92(r3) l.lwz r24, 32(r3)
l.lwz r26, 100(r3) l.lwz r26, 36(r3)
l.lwz r28, 108(r3) l.lwz r28, 40(r3)
// Different cases for optional delay slot // Different cases for optional delay slot
#if defined(__OR1K_NODELAY__) #if defined(__OR1K_NODELAY__)
l.lwz r30, 116(r3) l.lwz r30, 44(r3)
l.jr r9 l.jr r9
#elif defined(__OR1K_DELAY__) #elif defined(__OR1K_DELAY__)
l.jr r9 l.jr r9
l.lwz r30, 116(r3) l.lwz r30, 44(r3)
#else #else
l.lwz r30, 116(r3) l.lwz r30, 44(r3)
l.jr r9 l.jr r9
l.nop l.nop
#endif #endif