shim_vma.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include <asm/mman.h>
  28. struct shim_handle;
  29. #define VMA_COMMENT_LEN 16
  30. struct shim_vma {
  31. REFTYPE ref_count;
  32. void * addr;
  33. size_t length;
  34. int prot;
  35. int flags;
  36. int offset;
  37. struct shim_handle * file;
  38. struct list_head list;
  39. size_t received;
  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. #if 0
  53. #define NEED_MIGRATE_MEMORY_IF_GIPC(vma) \
  54. (!((vma)->flags & VMA_UNMAPPED) && \
  55. !((vma)->file && ((vma)->flags & MAP_SHARED)))
  56. #endif
  57. #define NEED_MIGRATE_MEMORY_IF_GIPC(vma) NEED_MIGRATE_MEMORY((vma))
  58. static inline PAL_FLG PAL_PROT (int prot, int flags)
  59. {
  60. PAL_FLG pal_prot = 0;
  61. if (prot & PROT_READ)
  62. pal_prot |= PAL_PROT_READ;
  63. if (prot & PROT_WRITE)
  64. pal_prot |= PAL_PROT_WRITE;
  65. if (prot & PROT_EXEC)
  66. pal_prot |= PAL_PROT_EXEC;
  67. if (flags & MAP_PRIVATE)
  68. pal_prot |= PAL_PROT_WRITECOPY;
  69. return pal_prot;
  70. }
  71. int init_vma (void);
  72. /* Bookkeeping mmap() system call */
  73. int bkeep_mmap (void * addr, size_t length, int prot, int flags,
  74. struct shim_handle * file, int offset,
  75. const char * comment);
  76. /* Bookkeeping munmap() system call */
  77. int bkeep_munmap (void * addr, size_t length, const int * flags);
  78. /* Bookkeeping mprotect() system call */
  79. int bkeep_mprotect (void * addr, size_t length, int prot, const int * flags);
  80. /* Get vma bookkeeping handle */
  81. void get_vma (struct shim_vma * vma);
  82. void put_vma (struct shim_vma * vma);
  83. int lookup_supervma (const void * addr, size_t len, struct shim_vma ** vma);
  84. int lookup_overlap_vma (const void * addr, size_t len, struct shim_vma ** vma);
  85. struct shim_vma * next_vma (struct shim_vma * vma);
  86. void * get_unmapped_vma (size_t len, int flags);
  87. int dump_all_vmas (struct shim_thread * thread, char * buf, size_t size);
  88. void unmap_all_vmas (void);
  89. /* Debugging */
  90. void debug_print_vma_list (void);
  91. void print_vma_hash (struct shim_vma * vma, void * addr, int len,
  92. bool force_protect);
  93. /* Constants */
  94. extern unsigned long mem_max_npages;
  95. extern unsigned long brk_max_size;
  96. extern unsigned long sys_stack_size;
  97. #endif /* _SHIM_VMA_H_ */