15 #include "../libelf_compat.h"
18 libelf_mmap(void *addr
, size_t len
, int prot
, int flags
, int fd
, off_t offset
)
20 void *p
; /* malloc'ed pointer */
23 if ((addr
!= NULL
) || (flags
!= MAP_PRIVATE
) || (prot
!= PROT_READ
)) {
24 LIBELF_SET_ERROR(ARGUMENT
, 0);
29 * Fall back to malloc+read.
32 bufsize
= 1024 * 1024;
33 while (/*CONSTCOND*/true) {
34 void *newp
= realloc(p
, bufsize
);
39 LIBELF_SET_ERROR(RESOURCE
, 0);
43 rsz
= pread(fd
, p
, bufsize
, 0);
46 LIBELF_SET_ERROR(IO
, errno
);
48 } else if ((size_t) rsz
> bufsize
) {
50 LIBELF_SET_ERROR(IO
, EIO
); /* XXX */
52 } else if ((size_t) rsz
< bufsize
) {
54 * try to shrink the buffer.
56 newp
= realloc(p
, (size_t) rsz
);
69 libelf_munmap(void *addr
, size_t len
)