• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #include <stdio.h>
3 
4 
5 #define COMPILER_BARRIER  __asm__ __volatile("":::"cc","memory")
6 
7 /* force the kernel to map in 15k below SP, so we can safely poke
8    around there. */
make_below_sp_safe(void)9 __attribute__((noinline)) void make_below_sp_safe ( void )
10 {
11    const int N = 15000;
12    unsigned char a[N];
13    int i;
14 
15    for (i = 0; i < N; i++) {
16       a[i] = i & 0xFF;
17    }
18 
19    COMPILER_BARRIER;
20 
21    unsigned int r = 0;
22    for (i = 0; i < N; i++) {
23       r = (r << 1) | (r >> 31);
24       r ^= (unsigned int)a[i];
25    }
26    fprintf(stderr, "Checksum: %08x\n", r);
27 }
28 
29 
main(void)30 int main ( void )
31 {
32    make_below_sp_safe();
33 
34    unsigned int res;
35    __asm__ __volatile__("movl -8192(%%rsp), %0"
36                         : "=r"(res) : : "memory","cc");
37    fprintf(stderr, "Got %08x\n", res);
38    return 0;
39 }
40