I'm looking for WP options/model that could allow me to prove basic C memory manipulations like :
memcpy : I've tried to prove this simple code :
struct header_src{ char t1; char t2; char t3; char t4; }; struct header_dest{ short t1; short t2; }; /*@ requires 0<=n<=UINT_MAX; @ requires \valid(dest); @ requires \valid_read(src); @ assigns (dest)[0..n-1] \from (src)[0..n-1]; @ assigns \result \from dest; @ ensures dest[0..n] == src[0..n]; @ ensures \result == dest; */ void* Frama_C_memcpy(char *dest, const char *src, uint32_t n); int main(void) { struct header_src p_header_src; struct header_dest p_header_dest; p_header_src.t1 = 'e'; p_header_src.t2 = 'b'; p_header_src.t3 = 'c'; p_header_src.t4 = 'd'; p_header_dest.t1 = 0x0000; p_header_dest.t2 = 0x0000; //@ assert \valid(&p_header_dest); Frama_C_memcpy((char*)&p_header_dest, (char*)&p_header_src, sizeof(struct header_src)); //@ assert p_header_dest.t1 == 0x6265; //@ assert p_header_dest.t2 == 0x6463; }
but the two last assert weren't verified by WP (with default prover Alt-Ergo). It can be proved thanks to Value analysis, but I mostly want to be able to prove the code not using abstract interpretation.
Cast pointer to int : Since I'm programming embedded code, I want to be able to specify something like:
#define MEMORY_ADDR 0x08000000 #define SOME_SIZE 10 struct some_struct { uint8_t field1[SOME_SIZE]; uint32_t field2[SOME_SIZE]; } // [...] // some function body { struct some_struct *p = (some_struct*)MEMORY_ADDR; if(p == NULL) { // Handle error } else { // Do something } // } body end
I've looked a little bit at WP's documentation and it seems that the version of frama-c that I use (Magnesium-20151002) has several memory model (Hoare, Typed , +cast, +ref, ...) but none of the given example were proved with any of the model above. It is explicitly said in the documentation that Typed model does not handle pointer-to-int casts. I've a lot of trouble to understand what's really going on under the hood with each wp-model. It would really help me if I was able to verify at least post-conditions of the memcpy function.
Plus, I have seen this issue about void pointer that apparently are not very well handled by WP at least in the Magnesium version. I didn't tried another version of frama-c yet, but I think that newer version handle void pointer in a better way.
Thank you very much in advance for your suggestions !