Example: memcpy2.c

up: index
prev: memcpy1.c
next: memcpy3.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <cheriintrin.h>
    #include "capprint.h"
    
    void f(int x)
    {
        fprintf(stderr,"%d\n", x);
    }
    
    int main()
    {
        void (*p0)(int) = &f;
        void (**p1)(int) = malloc(sizeof(void (*)(int)));
        memcpy(p1,&p0,sizeof(int*));
    
        fprintf(stderr,"Original %" PTR_FMT "\n", sptr((void*)p0));
        fprintf(stderr,"Copy %" PTR_FMT "\n", sptr((void*)*p1));
    
        fprintf(stderr,"Pointers are %s\n",
                cheri_is_equal_exact(p0,*p1)?"exactly equal":"not equal");
        
        (**p1)(42);
    }

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))
Copy (@disabled, 0x100000386 [rxR,0x100000386-0x100000388] (sentry))
Pointers are exactly equal
42
 
cerberus-cheri
cerberus-cheri-revocation
cerberus-cheri-cornucopia
 Original (@empty, 0x100000386 [rxR,0x100000386-0x100000388] (sentry))
Copy (@empty, 0x100000386 [rxR,0x100000386-0x100000388] (sentry))
Pointers are exactly equal
42
 
clang-riscv-O3-bounds-subobject-safe Original 0x102094 [rxR,0x100000-0x104600] (sentry,capmode)
Copy 0x102094 [rxR,0x100000-0x104600] (sentry,capmode)
Pointers are exactly equal
42
 
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe
 Original 0x102072 [rxR,0x100000-0x104600] (sentry,capmode)
Copy 0x102072 [rxR,0x100000-0x104600] (sentry,capmode)
Pointers are exactly equal
42
 
clang-riscv-O3-bounds-conservative Original 0x1020b6 [rxR,0x100000-0x104620] (sentry,capmode)
Copy 0x1020b6 [rxR,0x100000-0x104620] (sentry,capmode)
Pointers are exactly equal
42
 
clang-riscv-O0-bounds-conservative
clang-riscv-O0-bounds-references-only
 Original 0x102052 [rxR,0x100000-0x1045c0] (sentry,capmode)
Copy 0x102052 [rxR,0x100000-0x1045c0] (sentry,capmode)
Pointers are exactly equal
42
 
clang-morello-O3-bounds-subobject-safe Original 0x111081 [rxR,0x100000-0x1316c0] (sentry)
Copy 0x111081 [rxR,0x100000-0x1316c0] (sentry)
Pointers are exactly equal
42
 
clang-morello-O0-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
 Original 0x110ec1 [rxR,0x100000-0x131500] (sentry)
Copy 0x110ec1 [rxR,0x100000-0x131500] (sentry)
Pointers are exactly equal
42
 
clang-morello-O3-bounds-conservative Original 0x1110d1 [rxR,0x100000-0x131700] (sentry)
Copy 0x1110d1 [rxR,0x100000-0x131700] (sentry)
Pointers are exactly equal
42
 
clang-morello-O0-bounds-conservative
clang-morello-O0-bounds-references-only
 Original 0x110ea1 [rxR,0x100000-0x1314c0] (sentry)
Copy 0x110ea1 [rxR,0x100000-0x1314c0] (sentry)
Pointers are exactly equal
42
 
gcc-morello-O3 tests/cheri/memcpy2.c: In function 'main':
tests/cheri/memcpy2.c:18:52: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
18 | fprintf(stderr,"Original %" PTR_FMT "\n", sptr((void*)p0));
| ^
tests/cheri/memcpy2.c:19:48: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
19 | fprintf(stderr,"Copy %" PTR_FMT "\n", sptr((void*)*p1));
| ^
Original 0x403061 [rxRE,0x400000-0x427300] (sentry)
Copy 0x403061 [rxRE,0x400000-0x427300] (sentry)
Pointers are exactly equal
42
 
gcc-morello-O0 tests/cheri/memcpy2.c: In function 'main':
tests/cheri/memcpy2.c:18:52: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
18 | fprintf(stderr,"Original %" PTR_FMT "\n", sptr((void*)p0));
| ^
tests/cheri/memcpy2.c:19:48: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
19 | fprintf(stderr,"Copy %" PTR_FMT "\n", sptr((void*)*p1));
| ^
Original 0x403885 [rxRE,0x400000-0x427800] (sentry)
Copy 0x403885 [rxRE,0x400000-0x427800] (sentry)
Pointers are exactly equal
42