shim_vma.h 4.0 KB

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