Example: intptr10a.c

up: index
prev: intptr10.c
next: intptr11.c

    #include <stdio.h>
    #include <stdint.h>
    #include "capprint.h"
    
    #define ALIGNMENT_BITS 1
    
    int main()
    {
        int n = 42;
        int *p = &n;
    
        fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)p));
        uintptr_t u = (uintptr_t)p;
        u = u >> ALIGNMENT_BITS;
        fprintf(stderr,"After 1st shift: %" PTR_FMT "\n", sptr((void*)u));
        u = u << ALIGNMENT_BITS;
        fprintf(stderr,"After 2nd shift: %" PTR_FMT "\n", sptr((void*)u));
        p = (int*)u;
        fprintf(stderr,"Cast back to int* pointer: %" PTR_FMT "\n", sptr((void*)p));
        fprintf(stderr,"Value %d\n", *p);
    }

Experimental data (what does this mean?)

cerberus-cheri-no-pnvi
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia-no-pnvi
 exit codes: compile 0 / execute 1 Undefined {ub: "UB_CHERI_UndefinedTag", loc: "<20:36--20:38>"}
Original: (@disabled, 0xffffe6d0 [rwRW,0xffffe6d0-0xffffe6d4])
After 1st shift: (@disabled, 0x7ffff368 [?-?] (notag))
After 2nd shift: (@disabled, 0xffffe6d0 [?-?] (notag))
Cast back to int* pointer: (@disabled, 0xffffe6d0 [?-?] (notag))
 
cerberus-cheri
cerberus-cheri-revocation
cerberus-cheri-cornucopia
 exit codes: compile 0 / execute 1 Undefined {ub: "UB_CHERI_UndefinedTag", loc: "<20:36--20:38>"}
Original: (@84, 0xffffe6d0 [rwRW,0xffffe6d0-0xffffe6d4])
After 1st shift: (@empty, 0x7ffff368 [?-?] (notag))
After 2nd shift: (@84, 0xffffe6d0 [?-?] (notag))
Cast back to int* pointer: (@84, 0xffffe6d0 [?-?] (notag))
 
clang-riscv-O3-bounds-subobject-safe exit codes: compile 0 / execute 1
Program received signal SIGPROT, CHERI protection violation.
Capability tag fault caused by register cs4.
0x00000000001021fc in main () at tests/cheri/intptr10a.c:20
20 fprintf(stderr,"Value %d\n", *p);
#0 0x00000000001021fc in main () at tests/cheri/intptr10a.c:20
n = <optimized out>
p = <optimized out>
u = <optimized out>


Original: 0x3fffdfff0c [rwRW,0x3fffdfff0c-0x3fffdfff10]
After 1st shift: 0x1fffefff86 [rwRW,0x1fffefff0c-0x1fffefff10] (invalid)
After 2nd shift: 0x3fffdfff0c [rwRW,0x3fffdfff0c-0x3fffdfff10] (invalid)
Cast back to int* pointer: 0x3fffdfff0c [rwRW,0x3fffdfff0c-0x3fffdfff10] (invalid)
 
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe
 exit codes: compile 0 / execute 1
Program received signal SIGPROT, CHERI protection violation.
Capability tag fault caused by register ca2.
0x000000000010219e in main () at tests/cheri/intptr10a.c:20
20 fprintf(stderr,"Value %d\n", *p);
#0 0x000000000010219e in main () at tests/cheri/intptr10a.c:20
n = 42
p = 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70] (invalid)
u = 278457688228798742455805848211333054316


Original: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70]
After 1st shift: 0x1fffefffb6 [rwRW,0x1fffefff6c-0x1fffefff70] (invalid)
After 2nd shift: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70] (invalid)
Cast back to int* pointer: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70] (invalid)
 
clang-riscv-O3-bounds-conservative exit codes: compile 0 / execute 1
Program received signal SIGPROT, CHERI protection violation.
Capability tag fault caused by register cs4.
0x00000000001021ca in main () at tests/cheri/intptr10a.c:20
20 fprintf(stderr,"Value %d\n", *p);
#0 0x00000000001021ca in main () at tests/cheri/intptr10a.c:20
n = <optimized out>
p = <optimized out>
u = <optimized out>


Original: 0x3fffdfff1c [rwRW,0x3fffdfff1c-0x3fffdfff20]
After 1st shift: 0x1fffefff8e [rwRW,0x1fffefff1c-0x1fffefff20] (invalid)
After 2nd shift: 0x3fffdfff1c [rwRW,0x3fffdfff1c-0x3fffdfff20] (invalid)
Cast back to int* pointer: 0x3fffdfff1c [rwRW,0x3fffdfff1c-0x3fffdfff20] (invalid)
 
clang-riscv-O0-bounds-conservative
clang-riscv-O0-bounds-references-only
 exit codes: compile 0 / execute 1
Program received signal SIGPROT, CHERI protection violation.
Capability tag fault caused by register ca1.
0x000000000010213e in main () at tests/cheri/intptr10a.c:20
20 fprintf(stderr,"Value %d\n", *p);
#0 0x000000000010213e in main () at tests/cheri/intptr10a.c:20
n = 42
p = 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70] (invalid)
u = 278457688228798742455805848211333054316


Original: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70]
After 1st shift: 0x1fffefffb6 [rwRW,0x1fffefff6c-0x1fffefff70] (invalid)
After 2nd shift: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70] (invalid)
Cast back to int* pointer: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70] (invalid)
 
clang-morello-O3-bounds-subobject-safe exit codes: compile 0 / execute 1
Program received signal SIGPROT, CHERI protection violation.
Capability tag fault.
0x0000000000111228 in main () at tests/cheri/intptr10a.c:20
20 fprintf(stderr,"Value %d\n", *p);
#0 0x0000000000111228 in main () at tests/cheri/intptr10a.c:20
n = 42
p = 0xfffffff7feec [rwRW,0xfffffff7feec-0xfffffff7fef0] (invalid)
u = 0xfffffff7feec [rwRW,0xfffffff7feec-0xfffffff7fef0] (invalid)


Original: 0xfffffff7feec [rwRW,0xfffffff7feec-0xfffffff7fef0]
After 1st shift: 0x7ffffffbff76 [rwRW,0x7ffffffbfeec-0x7ffffffbfef0] (invalid)
After 2nd shift: 0xfffffff7feec [rwRW,0xfffffff7feec-0xfffffff7fef0] (invalid)
Cast back to int* pointer: 0xfffffff7feec [rwRW,0xfffffff7feec-0xfffffff7fef0] (invalid)
 
clang-morello-O0-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
 exit codes: compile 0 / execute 1
Program received signal SIGPROT, CHERI protection violation.
Capability tag fault.
0x000000000011101c in main () at tests/cheri/intptr10a.c:20
20 fprintf(stderr,"Value %d\n", *p);
#0 0x000000000011101c in main () at tests/cheri/intptr10a.c:20
n = 42
p = 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60] (invalid)
u = 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60] (invalid)


Original: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
After 1st shift: 0x7ffffffbffae [rwRW,0x7ffffffbff5c-0x7ffffffbff60] (invalid)
After 2nd shift: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60] (invalid)
Cast back to int* pointer: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60] (invalid)
 
clang-morello-O3-bounds-conservative exit codes: compile 0 / execute 1
Program received signal SIGPROT, CHERI protection violation.
Capability tag fault.
main () at tests/cheri/intptr10a.c:20
20 fprintf(stderr,"Value %d\n", *p);
#0 main () at tests/cheri/intptr10a.c:20
n = 42
p = 0xfffffff7ff0c [rwRW,0xfffffff7ff0c-0xfffffff7ff10] (invalid)
u = 0xfffffff7ff0c [rwRW,0xfffffff7ff0c-0xfffffff7ff10] (invalid)


Original: 0xfffffff7ff0c [rwRW,0xfffffff7ff0c-0xfffffff7ff10]
After 1st shift: 0x7ffffffbff86 [rwRW,0x7ffffffbff0c-0x7ffffffbff10] (invalid)
After 2nd shift: 0xfffffff7ff0c [rwRW,0xfffffff7ff0c-0xfffffff7ff10] (invalid)
Cast back to int* pointer: 0xfffffff7ff0c [rwRW,0xfffffff7ff0c-0xfffffff7ff10] (invalid)
 
clang-morello-O0-bounds-conservative
clang-morello-O0-bounds-references-only
 exit codes: compile 0 / execute 1
Program received signal SIGPROT, CHERI protection violation.
Capability tag fault.
0x0000000000110fbc in main () at tests/cheri/intptr10a.c:20
20 fprintf(stderr,"Value %d\n", *p);
#0 0x0000000000110fbc in main () at tests/cheri/intptr10a.c:20
n = 42
p = 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60] (invalid)
u = 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60] (invalid)


Original: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
After 1st shift: 0x7ffffffbffae [rwRW,0x7ffffffbff5c-0x7ffffffbff60] (invalid)
After 2nd shift: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60] (invalid)
Cast back to int* pointer: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60] (invalid)
 
gcc-morello-O3 Original: 0x7fffffdc [rwRW,0x7fffffdc-0x7fffffe0]
After 1st shift: 0x3fffffee [rwRW,0x3fffffdc-0x3fffffe0] (invalid)
After 2nd shift: 0x7fffffdc [rwRW,0x7fffffdc-0x7fffffe0]
Cast back to int* pointer: 0x7fffffdc [rwRW,0x7fffffdc-0x7fffffe0]
Value 42
 
gcc-morello-O0 exit codes: compile 0 / execute 137 Original: 0x7fffffbc [rwRW,0x7fffffbc-0x7fffffc0]
After 1st shift: 0x3fffffde [rwRW,0x3fffffbc-0x3fffffc0] (invalid)
After 2nd shift: 0x7fffffbc [rwRW,0x7fffffbc-0x7fffffc0] (invalid)
Cast back to int* pointer: 0x7fffffbc [rwRW,0x7fffffbc-0x7fffffc0] (invalid)