Skip to content

Commit

Permalink
Merge pull request #8269 from tautschnig/features/mmap64
Browse files Browse the repository at this point in the history
C library: add mmap64
  • Loading branch information
tautschnig authored Apr 30, 2024
2 parents 04a4a51 + 4725692 commit facb34d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
57 changes: 39 additions & 18 deletions src/ansi-c/library/mman.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# endif

__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
void *mmap64(void *, __CPROVER_size_t, int, int, int, off_t);

void *mmap(
void *addr,
Expand All @@ -29,24 +30,7 @@ void *mmap(
int fd,
off_t offset)
{
(void)prot;
(void)fd;
(void)offset;

if(
addr == 0 ||
(__VERIFIER_nondet___CPROVER_bool() && (flags & MAP_FIXED) == 0))
{
if(flags & MAP_ANONYMOUS && (flags & MAP_UNINITIALIZED) == 0)
return __CPROVER_allocate(length, 1);
else
return __CPROVER_allocate(length, 0);
}
else
{
__CPROVER_allocated_memory((__CPROVER_size_t)addr, length);
return addr;
}
return mmap64(addr, length, prot, flags, fd, offset);
}

#endif
Expand All @@ -73,6 +57,7 @@ void *mmap(
# endif

__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
void *mmap64(void *, __CPROVER_size_t, int, int, int, off_t);

void *_mmap(
void *addr,
Expand All @@ -81,6 +66,42 @@ void *_mmap(
int flags,
int fd,
off_t offset)
{
return mmap64(addr, length, prot, flags, fd, offset);
}

#endif

/* FUNCTION: mmap64 */

#ifndef _WIN32

# ifndef __CPROVER_SYS_MMAN_H_INCLUDED
# include <sys/mman.h>
# define __CPROVER_SYS_MMAN_H_INCLUDED
# endif

# ifndef MAP_FIXED
# define MAP_FIXED 0
# endif

# ifndef MAP_ANONYMOUS
# define MAP_ANONYMOUS 0
# endif

# ifndef MAP_UNINITIALIZED
# define MAP_UNINITIALIZED 0
# endif

__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);

void *mmap64(
void *addr,
__CPROVER_size_t length,
int prot,
int flags,
int fd,
off_t offset)
{
(void)prot;
(void)fd;
Expand Down
1 change: 1 addition & 0 deletions src/ansi-c/library_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ perl -p -i -e 's/^__builtin_alloca\n//' __functions # alloca-01
perl -p -i -e 's/^fclose_cleanup\n//' __functions # fopen
perl -p -i -e 's/^fopen64\n//' __functions # fopen
perl -p -i -e 's/^freopen64\n//' __functions # freopen
perl -p -i -e 's/^mmap64\n//' __functions # mmap
perl -p -i -e 's/^munmap\n//' __functions # mmap-01
perl -p -i -e 's/^__fgets_chk\n//' __functions # fgets-01/__fgets_chk.desc
perl -p -i -e 's/^__fprintf_chk\n//' __functions # fprintf-01/__fprintf_chk.desc
Expand Down

0 comments on commit facb34d

Please sign in to comment.