mem_user.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <string.h>
  9. #include <errno.h>
  10. #include <sys/mman.h>
  11. #include "tt.h"
  12. #include "mem_user.h"
  13. #include "user_util.h"
  14. void remap_data(void *segment_start, void *segment_end, int w)
  15. {
  16. void *addr;
  17. unsigned long size;
  18. int data, prot;
  19. if(w) prot = PROT_WRITE;
  20. else prot = 0;
  21. prot |= PROT_READ | PROT_EXEC;
  22. size = (unsigned long) segment_end -
  23. (unsigned long) segment_start;
  24. data = create_mem_file(size);
  25. addr = mmap(NULL, size, PROT_WRITE | PROT_READ, MAP_SHARED, data, 0);
  26. if(addr == MAP_FAILED){
  27. perror("mapping new data segment");
  28. exit(1);
  29. }
  30. memcpy(addr, segment_start, size);
  31. if(switcheroo(data, prot, addr, segment_start, size) < 0){
  32. printf("switcheroo failed\n");
  33. exit(1);
  34. }
  35. }
  36. /*
  37. * Overrides for Emacs so that we follow Linus's tabbing style.
  38. * Emacs will notice this stuff at the end of the file and automatically
  39. * adjust the settings for this buffer only. This must remain at the end
  40. * of the file.
  41. * ---------------------------------------------------------------------------
  42. * Local variables:
  43. * c-file-style: "linux"
  44. * End:
  45. */