blob: 8e55cd5d3d07230bb5d98d5a5113fd6b707cec8a [file] [log] [blame]
Paolo 'Blaisorblade' Giarrusso60b27372005-06-21 17:16:25 -07001/*
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 Bergmann5f4c6bc2006-10-02 02:18:37 -07008#include <sys/syscall.h>
Paolo 'Blaisorblade' Giarrusso60b27372005-06-21 17:16:25 -07009
Paolo 'Blaisorblade' Giarrusso60b27372005-06-21 17:16:25 -070010int switcheroo(int fd, int prot, void *from, void *to, int size)
11{
Arnd Bergmann5f4c6bc2006-10-02 02:18:37 -070012 if (syscall(__NR_munmap, to, size) < 0){
Paolo 'Blaisorblade' Giarrusso60b27372005-06-21 17:16:25 -070013 return(-1);
14 }
Arnd Bergmann5f4c6bc2006-10-02 02:18:37 -070015 if (syscall(__NR_mmap2, to, size, prot, MAP_SHARED | MAP_FIXED, fd, 0) == (void*) -1 ){
Paolo 'Blaisorblade' Giarrusso60b27372005-06-21 17:16:25 -070016 return(-1);
17 }
Arnd Bergmann5f4c6bc2006-10-02 02:18:37 -070018 if (syscall(__NR_munmap, from, size) < 0){
Paolo 'Blaisorblade' Giarrusso60b27372005-06-21 17:16:25 -070019 return(-1);
20 }
21 return(0);
22}