Example: modptr6.c

up: index
prev: modptr5.c
next: modptr7.c

    #include <stdio.h>
    #include "capprint.h"
    
    void func(int x) { }
    
    int main(void)
    {
        void (*fptr)(int) = &func;
        fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)fptr));
        unsigned char *p = (unsigned char*) &fptr;
        p[0] = 42;
        fprintf(stderr,"Modified: %" PTR_FMT "\n", sptr((void*)fptr));
    }

Experimental data (what does this mean?)

cerberus-cheri-no-pnvi
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia-no-pnvi
 Original: (@disabled, 0x100000386 [rxR,0x100000386-0x100000388] (sentry))
Modified: (@disabled, 0x10000032a [rxR,0x100000386-0x100000388] (notag,sentry))
 
cerberus-cheri
cerberus-cheri-revocation
cerberus-cheri-cornucopia
 Original: (@empty, 0x100000386 [rxR,0x100000386-0x100000388] (sentry))
Modified: (@empty, 0x10000032a [rxR,0x100000386-0x100000388] (notag,sentry))
 
clang-riscv-O3-bounds-subobject-safe Original: 0x101fd4 [rxR,0x100000-0x104480] (sentry,capmode)
Modified: 0x101f2a [rxR,0x100000-0x104480] (invalid,sentry,capmode)
 
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe
 Original: 0x101fb2 [rxR,0x100000-0x104440] (sentry,capmode)
Modified: 0x101f2a [rxR,0x100000-0x104440] (invalid,sentry,capmode)
 
clang-riscv-O3-bounds-conservative Original: 0x101fee [rxR,0x100000-0x1044a0] (sentry,capmode)
Modified: 0x101f2a [rxR,0x100000-0x1044a0] (invalid,sentry,capmode)
 
clang-riscv-O0-bounds-conservative
clang-riscv-O0-bounds-references-only
 Original: 0x101f92 [rxR,0x100000-0x104400] (sentry,capmode)
Modified: 0x101f2a [rxR,0x100000-0x104400] (invalid,sentry,capmode)
 
clang-morello-O3-bounds-subobject-safe Original: 0x111001 [rxR,0x100000-0x131580] (sentry)
Modified: 0x11102a [rxR,0x100000-0x131580] (invalid,sentry)
 
clang-morello-O0-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
 Original: 0x110e31 [rxR,0x100000-0x131380] (sentry)
Modified: 0x110e2a [rxR,0x100000-0x131380] (invalid,sentry)
 
clang-morello-O3-bounds-conservative Original: 0x111041 [rxR,0x100000-0x1315c0] (sentry)
Modified: 0x11102a [rxR,0x100000-0x1315c0] (invalid,sentry)
 
clang-morello-O0-bounds-conservative
clang-morello-O0-bounds-references-only
 Original: 0x110e11 [rxR,0x100000-0x131340] (sentry)
Modified: 0x110e2a [rxR,0x100000-0x131340] (invalid,sentry)
 
gcc-morello-O3 tests/cheri/modptr6.c: In function 'main':
tests/cheri/modptr6.c:9:53: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
9 | fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)fptr));
| ^
tests/cheri/modptr6.c:12:53: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
12 | fprintf(stderr,"Modified: %" PTR_FMT "\n", sptr((void*)fptr));
| ^
Original: 0x402fa1 [rxRE,0x400000-0x4271c0] (sentry)
Modified: 0x402f2a [rxRE,0x400000-0x4271c0] (invalid,sentry)
 
gcc-morello-O0 tests/cheri/modptr6.c: In function 'main':
tests/cheri/modptr6.c:9:53: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
9 | fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)fptr));
| ^
tests/cheri/modptr6.c:12:53: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
12 | fprintf(stderr,"Modified: %" PTR_FMT "\n", sptr((void*)fptr));
| ^
Original: 0x403805 [rxRE,0x400000-0x427640] (sentry)
Modified: 0x40382a [rxRE,0x400000-0x427640] (invalid,sentry)