Example: eq3.c

up: index
prev: eq2.c
next: eq4.c

    #include <stdio.h>
    #include <stdint.h>
    #include "capprint.h"
    
    void f(int x)
    {
        fprintf(stderr,"real_f(%d)\n", x);
    }
    
    int x;
    
    int main()
    {
        void (*fp)(int) = &f;
        int *ip = &x;
    
        uintptr_t uif = (uintptr_t)fp;
        uintptr_t uix = (uintptr_t)ip;
    
        fprintf(stderr,"Function pointer %" PTR_FMT "\n", sptr((void*)fp));
        fprintf(stderr,"Global pointer %" PTR_FMT "\n", sptr((void*)uix));
    
        fprintf(stderr,"Compare %s\n",
                (uif == uix)? "equal":"not equal"
        ); //is that guaranteed to be FALSE?
    
    }

Experimental data (what does this mean?)

cerberus-cheri-no-pnvi
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia-no-pnvi
 Function pointer (@disabled, 0x100000386 [rxR,0x100000386-0x100000388] (sentry))
Global pointer (@disabled, 0xfffffff8 [rwRW,0xfffffff8-0xfffffffc])
Compare not equal
 
cerberus-cheri
cerberus-cheri-revocation
cerberus-cheri-cornucopia
 Function pointer (@empty, 0x100000386 [rxR,0x100000386-0x100000388] (sentry))
Global pointer (@0, 0xfffffff8 [rwRW,0xfffffff8-0xfffffffc])
Compare not equal
 
clang-riscv-O3-bounds-subobject-safe Function pointer 0x1020cc [rxR,0x100000-0x104640] (sentry,capmode)
Global pointer 0x104620 [rwRW,0x104620-0x104624]
Compare not equal
 
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe
 Function pointer 0x1020aa [rxR,0x100000-0x104640] (sentry,capmode)
Global pointer 0x104630 [rwRW,0x104630-0x104634]
Compare not equal
 
clang-riscv-O3-bounds-conservative Function pointer 0x1020b6 [rxR,0x100000-0x104600] (sentry,capmode)
Global pointer 0x1045e0 [rwRW,0x1045e0-0x1045e4]
Compare not equal
 
clang-riscv-O0-bounds-conservative
clang-riscv-O0-bounds-references-only
 Function pointer 0x10208a [rxR,0x100000-0x104600] (sentry,capmode)
Global pointer 0x1045e0 [rwRW,0x1045e0-0x1045e4]
Compare not equal
 
clang-morello-O3-bounds-subobject-safe Function pointer 0x1110a1 [rxR,0x100000-0x131700] (sentry)
Global pointer 0x1316e0 [rwRW,0x1316e0-0x1316e4]
Compare not equal
 
clang-morello-O0-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
 Function pointer 0x110ee1 [rxR,0x100000-0x131500] (sentry)
Global pointer 0x1314e0 [rwRW,0x1314e0-0x1314e4]
Compare not equal
 
clang-morello-O3-bounds-conservative Function pointer 0x1110d1 [rxR,0x100000-0x131700] (sentry)
Global pointer 0x1316e0 [rwRW,0x1316e0-0x1316e4]
Compare not equal
 
clang-morello-O0-bounds-conservative
clang-morello-O0-bounds-references-only
 Function pointer 0x110ec1 [rxR,0x100000-0x1314c0] (sentry)
Global pointer 0x1314a0 [rwRW,0x1314a0-0x1314a4]
Compare not equal
 
gcc-morello-O3 tests/cheri/eq3.c: In function 'main':
tests/cheri/eq3.c:20:60: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
20 | fprintf(stderr,"Function pointer %" PTR_FMT "\n", sptr((void*)fp));
| ^
Function pointer 0x403061 [rxRE,0x400000-0x427300] (sentry)
Global pointer 0x429510 [rwRW,0x429510-0x429514]
Compare not equal
 
gcc-morello-O0 tests/cheri/eq3.c: In function 'main':
tests/cheri/eq3.c:20:60: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
20 | fprintf(stderr,"Function pointer %" PTR_FMT "\n", sptr((void*)fp));
| ^
Function pointer 0x403885 [rxRE,0x400000-0x427800] (sentry)
Global pointer 0x429a10 [rwRW,0x429a10-0x429a14]
Compare not equal