File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -406,6 +406,51 @@ inline void *valloc(__CPROVER_size_t malloc_size)
406406 return malloc (malloc_size );
407407}
408408
409+ /* FUNCTION: posix_memalign */
410+
411+ #ifndef __CPROVER_ERRNO_H_INCLUDED
412+ #include <errno.h>
413+ #define __CPROVER_ERRNO_H_INCLUDED
414+ #endif
415+
416+ #undef posix_memalign
417+
418+ inline void * malloc (__CPROVER_size_t malloc_size );
419+ inline int
420+ posix_memalign (void * * ptr , __CPROVER_size_t alignment , __CPROVER_size_t size )
421+ {
422+ __CPROVER_HIDE :;
423+
424+ __CPROVER_size_t multiplier = alignment / sizeof (void * );
425+ // Modeling the posix_memalign checks on alignment.
426+ if (
427+ alignment % sizeof (void * ) != 0 || ((multiplier ) & (multiplier - 1 )) != 0 ||
428+ alignment == 0 )
429+ {
430+ return EINVAL ;
431+ }
432+ // The address of the allocated memory is supposed to be aligned with
433+ // alignment. As cbmc doesn't model address alignment,
434+ // assuming MALLOC_ALIGNMENT = MAX_INT_VALUE seems fair.
435+ // As _mid_memalign simplifies for alignment <= MALLOC_ALIGNMENT
436+ // to a malloc call, it should be sound, if we do it too.
437+
438+ // The originial posix_memalign check on the pointer is:
439+
440+ // void *tmp = malloc(size);
441+ // if(tmp != NULL){
442+ // *ptr = tmp;
443+ // return 0;
444+ // }
445+ // return ENOMEM;
446+
447+ // As _CPROVER_allocate used in malloc never returns null,
448+ // this check is not applicable and can be simplified:
449+
450+ * ptr = malloc (size );
451+ return 0 ;
452+ }
453+
409454/* FUNCTION: random */
410455
411456long __VERIFIER_nondet_long ();
You can’t perform that action at this time.
0 commit comments