unmap.c 575 B

12345678910111213141516171819202122232425
  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. static int errno;
  8. static inline _syscall2(int,munmap,void *,start,size_t,len)
  9. static inline _syscall6(void *,mmap2,void *,addr,size_t,len,int,prot,int,flags,int,fd,off_t,offset)
  10. int switcheroo(int fd, int prot, void *from, void *to, int size)
  11. {
  12. if(munmap(to, size) < 0){
  13. return(-1);
  14. }
  15. if(mmap2(to, size, prot, MAP_SHARED | MAP_FIXED, fd, 0) == (void*) -1 ){
  16. return(-1);
  17. }
  18. if(munmap(from, size) < 0){
  19. return(-1);
  20. }
  21. return(0);
  22. }