Paolo 'Blaisorblade' Giarrusso | 60b2737 | 2005-06-21 17:16:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) |
| 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
| 6 | #include <linux/mman.h> |
| 7 | #include <asm/unistd.h> |
Arnd Bergmann | 5f4c6bc | 2006-10-02 02:18:37 -0700 | [diff] [blame] | 8 | #include <sys/syscall.h> |
Paolo 'Blaisorblade' Giarrusso | 60b2737 | 2005-06-21 17:16:25 -0700 | [diff] [blame] | 9 | |
Paolo 'Blaisorblade' Giarrusso | 60b2737 | 2005-06-21 17:16:25 -0700 | [diff] [blame] | 10 | int switcheroo(int fd, int prot, void *from, void *to, int size) |
| 11 | { |
Arnd Bergmann | 5f4c6bc | 2006-10-02 02:18:37 -0700 | [diff] [blame] | 12 | if (syscall(__NR_munmap, to, size) < 0){ |
Paolo 'Blaisorblade' Giarrusso | 60b2737 | 2005-06-21 17:16:25 -0700 | [diff] [blame] | 13 | return(-1); |
| 14 | } |
Arnd Bergmann | 5f4c6bc | 2006-10-02 02:18:37 -0700 | [diff] [blame] | 15 | if (syscall(__NR_mmap2, to, size, prot, MAP_SHARED | MAP_FIXED, fd, 0) == (void*) -1 ){ |
Paolo 'Blaisorblade' Giarrusso | 60b2737 | 2005-06-21 17:16:25 -0700 | [diff] [blame] | 16 | return(-1); |
| 17 | } |
Arnd Bergmann | 5f4c6bc | 2006-10-02 02:18:37 -0700 | [diff] [blame] | 18 | if (syscall(__NR_munmap, from, size) < 0){ |
Paolo 'Blaisorblade' Giarrusso | 60b2737 | 2005-06-21 17:16:25 -0700 | [diff] [blame] | 19 | return(-1); |
| 20 | } |
| 21 | return(0); |
| 22 | } |