| 1 |
|
|---|
| 2 | For implementing malloc:
|
|---|
| 3 |
|
|---|
| 4 | Add sizeof expression in model.
|
|---|
| 5 | Semantics: get the dynamic type and evaluate the sizeof that
|
|---|
| 6 | using some well-known formulas. Add things to the path condition
|
|---|
| 7 | as a side effect, like sizes are greater than 0, or 1, or
|
|---|
| 8 | whatever.
|
|---|
| 9 |
|
|---|
| 10 | Add a MallocStatement to the model. Example
|
|---|
| 11 | (double*)malloc(&h, sizeof(double)*10).
|
|---|
| 12 | - int getMallocId();
|
|---|
| 13 | - Expression getHeapPointerExpression(); // &h
|
|---|
| 14 | - Type getStaticElementType(); // double
|
|---|
| 15 | - SymbolicType getDynamicObjectType(); // symbolic array of double
|
|---|
| 16 | - Expression getSizeExpression(); // sizeof(double)*10
|
|---|
| 17 | - SymbolicExpression getUndefinedObject(); // symbolic constant UNDEFINED
|
|---|
| 18 | // of type array of double
|
|---|
| 19 |
|
|---|
| 20 | During model building, count the malloc statements as they are
|
|---|
| 21 | encountered and assign each a unique ID.
|
|---|
| 22 |
|
|---|
| 23 | Complete the $heap type:
|
|---|
| 24 | For each i, you have the static CIVL type T_i and the
|
|---|
| 25 | __malloc__ function. Compute the most general symbolic
|
|---|
| 26 | type t_i by translating t_i and using incomplete types
|
|---|
| 27 | for arrays. Store t_i in the malloc call object.
|
|---|
| 28 | let $heap be the symbolic type which is the tuple type
|
|---|
| 29 |
|
|---|
| 30 | [array of array of t1,
|
|---|
| 31 | array of array of t2,
|
|---|
| 32 | array of array of t3, ...]
|
|---|
| 33 |
|
|---|
| 34 | Initial value:
|
|---|
| 35 |
|
|---|
| 36 | [array of length 0, array of length 0, ...]
|
|---|
| 37 |
|
|---|
| 38 | Semantics:
|
|---|
| 39 | to execute a malloc statement with malloc index i:
|
|---|
| 40 | let h be the result of evaluating the heap argument. *h is a tuple.
|
|---|
| 41 | (*h).i is a concrete array. Let l be its concrete length.
|
|---|
| 42 | create a new symbolic constant whose name is a function of
|
|---|
| 43 | the pid, dynamic scope id, heap variable ID, index i, and
|
|---|
| 44 | l. The type of this new symbolic constant is array of t_i
|
|---|
| 45 | of length arg/sizeof(t+i), where arg is the result of evaluating
|
|---|
| 46 | the size argument. Check that it evenly divides, and log
|
|---|
| 47 | an error if it might not. Now append this symbolic constant
|
|---|
| 48 | to the concrete array. [Really need a method in SARL to do this.]
|
|---|
| 49 | Anyway, since it is concrete, get its sequence and append on to that.
|
|---|
| 50 | Return the reference with tree:
|
|---|
| 51 | - ref to heap (h)
|
|---|
| 52 | - tuple component ref (i)
|
|---|
| 53 | - array element reference (l)
|
|---|
| 54 | - array element reference (0)
|
|---|
| 55 | which is a reference to the first element of the newly allocated
|
|---|
| 56 | array.
|
|---|
| 57 |
|
|---|
| 58 | free: sets the value in the heap array to some symbolic constant
|
|---|
| 59 | UNDEFINED of type array of t_i.
|
|---|
| 60 |
|
|---|
| 61 | Canonicalization: map
|
|---|
| 62 | Ref[h,i,l,0] -> Ref[h,i,l',0]
|
|---|
| 63 | H_p_s_v_i_l -> H_p_s_v_i_l' (symbolic constants)
|
|---|
| 64 | Perform substitution on the state
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | ---
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | Think about moving more stuff into model factory, like pointer value
|
|---|
| 71 | manipulation
|
|---|
| 72 |
|
|---|
| 73 | better printing of model
|
|---|
| 74 |
|
|---|
| 75 | better printing of states during execution
|
|---|