mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 18:56:29 +00:00
parent
789d908cee
commit
cde542c37c
@ -1189,11 +1189,23 @@ void *Libc::Vfs_plugin::mmap(void *addr_in, ::size_t length, int prot, int flags
|
||||
return (void *)-1;
|
||||
}
|
||||
|
||||
if (::pread(fd->libc_fd, addr, length, offset) < 0) {
|
||||
Genode::error("mmap could not obtain file content");
|
||||
::munmap(addr, length);
|
||||
errno = EACCES;
|
||||
return (void *)-1;
|
||||
/* copy variables for complete read */
|
||||
size_t read_remain = length;
|
||||
size_t read_offset = offset;
|
||||
char *read_addr = (char *)addr;
|
||||
|
||||
while (read_remain > 0) {
|
||||
ssize_t length_read = ::pread(fd->libc_fd, read_addr, read_remain, read_offset);
|
||||
if (length_read < 0) { /* error */
|
||||
Genode::error("mmap could not obtain file content");
|
||||
::munmap(addr, length);
|
||||
errno = EACCES;
|
||||
return (void *)-1;
|
||||
} else if (length_read == 0) /* EOF */
|
||||
break; /* done (length can legally be greater than the file length) */
|
||||
read_remain -= length_read;
|
||||
read_offset += length_read;
|
||||
read_addr += length_read;
|
||||
}
|
||||
|
||||
return addr;
|
||||
|
Loading…
Reference in New Issue
Block a user