Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stddef.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/mman.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <errno.h>
- typedef uint32_t (*sumfunc_t)(void);
- sumfunc_t generate(void *buf, size_t bufsize, uint32_t *array, size_t size) ;
- uint32_t array[] = {1, 2, 3, 4, 5};
- size_t size = 5;
- int main() {
- int fd = open("tmp.txt", O_RDWR | O_CREAT | O_TRUNC);
- int ufd = fd;
- for (int i = 0; i < 4096; i++) {
- write(fd, array, 1);
- }
- fd = ufd;
- unsigned char * buf = mmap (NULL, 4096, PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, fd, 0);
- if (buf == MAP_FAILED) {
- printf ("%i\n", errno);
- printf ("error\n");
- return 0;
- }
- uint32_t (*f1)(void) = generate(buf, 4096, array, size);
- printf("%u\n", f1());
- munmap(buf, 4096);
- close(fd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement