unmap.c 464 B

12345678910111213141516171819202122
  1. /*
  2. * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <linux/mman.h>
  6. #include <asm/unistd.h>
  7. #include <sys/syscall.h>
  8. int switcheroo(int fd, int prot, void *from, void *to, int size)
  9. {
  10. if (syscall(__NR_munmap, to, size) < 0){
  11. return(-1);
  12. }
  13. if (syscall(__NR_mmap, to, size, prot, MAP_SHARED | MAP_FIXED, fd, 0) == (void*) -1){
  14. return(-1);
  15. }
  16. if (syscall(__NR_munmap, from, size) < 0){
  17. return(-1);
  18. }
  19. return(0);
  20. }