shim_vma.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 OSCAR lab, Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * shim_vma.h
  17. *
  18. * Definitions of types and functions for VMA bookkeeping.
  19. */
  20. #ifndef _SHIM_VMA_H_
  21. #define _SHIM_VMA_H_
  22. #include <shim_types.h>
  23. #include <shim_defs.h>
  24. #include <shim_handle.h>
  25. #include <pal.h>
  26. #include <linux_list.h>
  27. struct shim_handle;
  28. #define VMA_COMMENT_LEN 16
  29. struct shim_vma {
  30. REFTYPE ref_count;
  31. void * addr;
  32. size_t length;
  33. int prot;
  34. int flags;
  35. int offset;
  36. struct shim_handle * file;
  37. struct list_head list;
  38. size_t received;
  39. char comment[VMA_COMMENT_LEN];
  40. };
  41. /* an additional flag */
  42. #define VMA_UNMAPPED 0x10000000 /* vma is kept for bookkeeping, but the
  43. memory is not actually allocated */
  44. #define VMA_INTERNAL 0x20000000
  45. #define VMA_TAINTED 0x40000000 /* vma has been protected as writeable,
  46. so it has to be checkpointed during
  47. migration */
  48. #define NEED_MIGRATE_MEMORY(vma) \
  49. (((vma)->flags & VMA_TAINTED || !(vma)->file) && \
  50. !((vma)->flags & VMA_UNMAPPED))
  51. int init_vma (void);
  52. /* Bookkeeping mmap() system call */
  53. int bkeep_mmap (void * addr, size_t length, int prot, int flags,
  54. struct shim_handle * file, int offset,
  55. const char * comment);
  56. /* Bookkeeping munmap() system call */
  57. int bkeep_munmap (void * addr, size_t length, const int * flags);
  58. /* Bookkeeping mprotect() system call */
  59. int bkeep_mprotect (void * addr, size_t length, int prot, const int * flags);
  60. /* Get vma bookkeeping handle */
  61. void get_vma (struct shim_vma * vma);
  62. void put_vma (struct shim_vma * vma);
  63. int lookup_supervma (const void * addr, size_t len, struct shim_vma ** vma);
  64. int lookup_overlap_vma (const void * addr, size_t len, struct shim_vma ** vma);
  65. struct shim_vma * next_vma (struct shim_vma * vma);
  66. void * get_unmapped_vma (size_t len, int flags);
  67. int dump_all_vmas (struct shim_thread * thread, char * buf, size_t size);
  68. void unmap_all_vmas (void);
  69. /* Debugging */
  70. void debug_print_vma_list (void);
  71. void print_vma_hash (struct shim_vma * vma, void * addr, int len,
  72. bool force_protect);
  73. /* Constants */
  74. extern unsigned long mem_max_npages;
  75. extern unsigned long brk_max_size;
  76. extern unsigned long sys_stack_size;
  77. #endif /* _SHIM_VMA_H_ */