| 1 | #include <sys/mman.h> |
| 2 | #include <fcntl.h> |
| 3 | #include <sys/stat.h> |
| 4 | #include "syscall.h" |
| 5 | |
| 6 | const char unsigned *__map_file(const char *pathname, size_t *size) |
| 7 | { |
| 8 | 	struct stat st; |
| 9 | 	const unsigned char *map = MAP_FAILED; |
| 10 | 	int fd = sys_open(pathname, O_RDONLY|O_CLOEXEC|O_NONBLOCK); |
| 11 | 	if (fd < 0) return 0; |
| 12 | 	if (!__fstat(fd, &st)) { |
| 13 | 		map = __mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); |
| 14 | 		*size = st.st_size; |
| 15 | 	} |
| 16 | 	__syscall(SYS_close, fd); |
| 17 | 	return map == MAP_FAILED ? 0 : map; |
| 18 | } |