mem_user.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include "os.h"
  15. void remap_data(void *segment_start, void *segment_end, int w)
  16. {
  17. void *addr;
  18. unsigned long size;
  19. int data, prot;
  20. if(w) prot = PROT_WRITE;
  21. else prot = 0;
  22. prot |= PROT_READ | PROT_EXEC;
  23. size = (unsigned long) segment_end -
  24. (unsigned long) segment_start;
  25. data = create_mem_file(size);
  26. addr = mmap(NULL, size, PROT_WRITE | PROT_READ, MAP_SHARED, data, 0);
  27. if(addr == MAP_FAILED){
  28. perror("mapping new data segment");
  29. exit(1);
  30. }
  31. memcpy(addr, segment_start, size);
  32. if(switcheroo(data, prot, addr, segment_start, size) < 0){
  33. printf("switcheroo failed\n");
  34. exit(1);
  35. }
  36. }
  37. /*
  38. * Overrides for Emacs so that we follow Linus's tabbing style.
  39. * Emacs will notice this stuff at the end of the file and automatically
  40. * adjust the settings for this buffer only. This must remain at the end
  41. * of the file.
  42. * ---------------------------------------------------------------------------
  43. * Local variables:
  44. * c-file-style: "linux"
  45. * End:
  46. */