shim_vma.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 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 Lesser 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 Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser 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 <list.h>
  27. #include <asm/mman.h>
  28. struct shim_handle;
  29. #define VMA_COMMENT_LEN 16
  30. DEFINE_LIST(shim_vma);
  31. struct shim_vma {
  32. REFTYPE ref_count;
  33. void * addr;
  34. uint64_t length;
  35. int prot;
  36. int flags;
  37. uint64_t offset;
  38. struct shim_handle * file;
  39. LIST_TYPE(shim_vma) list;
  40. char comment[VMA_COMMENT_LEN];
  41. };
  42. /* an additional flag */
  43. #define VMA_UNMAPPED 0x10000000 /* vma is kept for bookkeeping, but the
  44. memory is not actually allocated */
  45. #define VMA_INTERNAL 0x20000000
  46. #define VMA_TAINTED 0x40000000 /* vma has been protected as writeable,
  47. so it has to be checkpointed during
  48. migration */
  49. #define NEED_MIGRATE_MEMORY(vma) \
  50. (((vma)->flags & VMA_TAINTED || !(vma)->file) && \
  51. !((vma)->flags & VMA_UNMAPPED))
  52. #define NEED_MIGRATE_MEMORY_IF_GIPC(vma) \
  53. (!((vma)->flags & VMA_UNMAPPED) && \
  54. !(!(vma)->prot && !((vma)->flags & VMA_TAINTED)) && \
  55. !((vma)->file && ((vma)->flags & MAP_SHARED)))
  56. static inline PAL_FLG PAL_PROT (int prot, int flags)
  57. {
  58. PAL_FLG pal_prot = 0;
  59. if (prot & PROT_READ)
  60. pal_prot |= PAL_PROT_READ;
  61. if (prot & PROT_WRITE)
  62. pal_prot |= PAL_PROT_WRITE;
  63. if (prot & PROT_EXEC)
  64. pal_prot |= PAL_PROT_EXEC;
  65. if (flags & MAP_PRIVATE)
  66. pal_prot |= PAL_PROT_WRITECOPY;
  67. return pal_prot;
  68. }
  69. int init_vma (void);
  70. /* Bookkeeping mmap() system call */
  71. int bkeep_mmap (void * addr, uint64_t length, int prot, int flags,
  72. struct shim_handle * file, uint64_t offset, const char * comment);
  73. /* Bookkeeping munmap() system call */
  74. int bkeep_munmap (void * addr, uint64_t length, const int * flags);
  75. /* Bookkeeping mprotect() system call */
  76. int bkeep_mprotect (void * addr, uint64_t length, int prot, const int * flags);
  77. /* Get vma bookkeeping handle */
  78. void get_vma (struct shim_vma * vma);
  79. void put_vma (struct shim_vma * vma);
  80. int lookup_supervma (const void * addr, uint64_t len, struct shim_vma ** vma);
  81. int lookup_overlap_vma (const void * addr, uint64_t len, struct shim_vma ** vma);
  82. struct shim_vma * next_vma (struct shim_vma * vma);
  83. void * get_unmapped_vma (uint64_t len, int flags);
  84. void * get_unmapped_vma_for_cp (uint64_t len);
  85. int dump_all_vmas (struct shim_thread * thread, char * buf, uint64_t size);
  86. void unmap_all_vmas (void);
  87. /* Debugging */
  88. void debug_print_vma_list (void);
  89. void print_vma_hash (struct shim_vma * vma, void * addr, uint64_t len,
  90. bool force_protect);
  91. /* Constants */
  92. extern unsigned long mem_max_npages;
  93. extern unsigned long brk_max_size;
  94. extern unsigned long sys_stack_size;
  95. #endif /* _SHIM_VMA_H_ */