123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
- /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
- /* Copyright (C) 2014 Stony Brook University
- This file is part of Graphene Library OS.
- Graphene Library OS is free software: you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public License
- as published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
- Graphene Library OS is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
- /*
- * shim_vma.h
- *
- * Definitions of types and functions for VMA bookkeeping.
- */
- #ifndef _SHIM_VMA_H_
- #define _SHIM_VMA_H_
- #include <shim_types.h>
- #include <shim_defs.h>
- #include <shim_handle.h>
- #include <pal.h>
- #include <api.h>
- #include <list.h>
- #include <asm/mman.h>
- struct shim_handle;
- #define VMA_COMMENT_LEN 16
- /*
- * struct shim_vma_val is the published version of struct shim_vma
- * (struct shim_vma is defined in bookkeep/shim_vma.c).
- */
- struct shim_vma_val {
- void * addr;
- uint64_t length;
- int prot;
- int flags;
- uint64_t offset;
- struct shim_handle * file;
- char comment[VMA_COMMENT_LEN];
- };
- static inline
- void free_vma_val_array (struct shim_vma_val * vmas, size_t count)
- {
- for (int i = 0 ; i < count ; i++) {
- /* need to release the file handle */
- if (vmas[i].file)
- put_handle(vmas[i].file);
- }
- free(vmas);
- }
- /* an additional flag */
- #define VMA_UNMAPPED 0x10000000 /* vma is kept for bookkeeping, but the
- memory is not actually allocated */
- #define VMA_INTERNAL 0x20000000 /* vma is used internally */
- #define VMA_TAINTED 0x40000000 /* vma has been protected as writeable,
- so it has to be checkpointed during
- migration */
- #define VMA_CP 0x80000000 /* vma is used for dumping checkpoint
- data */
- #define VMA_TYPE(flags) ((flags) & (VMA_INTERNAL | VMA_CP))
- /*
- * We distinguish checkpoint VMAs from user VMAs and other internal VMAs,
- * to prevent corrupting internal data when creating processes.
- */
- #define CP_VMA_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS|VMA_INTERNAL|VMA_CP)
- #define NEED_MIGRATE_MEMORY(vma) \
- (((vma)->flags & VMA_TAINTED || !(vma)->file) && \
- !((vma)->flags & VMA_UNMAPPED))
- #define NEED_MIGRATE_MEMORY_IF_GIPC(vma) \
- (!((vma)->flags & VMA_UNMAPPED) && \
- !(!(vma)->prot && !((vma)->flags & VMA_TAINTED)) && \
- !((vma)->file && ((vma)->flags & MAP_SHARED)))
- static inline PAL_FLG PAL_PROT (int prot, int flags)
- {
- PAL_FLG pal_prot = 0;
- if (prot & PROT_READ)
- pal_prot |= PAL_PROT_READ;
- if (prot & PROT_WRITE)
- pal_prot |= PAL_PROT_WRITE;
- if (prot & PROT_EXEC)
- pal_prot |= PAL_PROT_EXEC;
- if (flags & MAP_PRIVATE)
- pal_prot |= PAL_PROT_WRITECOPY;
- return pal_prot;
- }
- int init_vma (void);
- /* Bookkeeping mmap() system call */
- int bkeep_mmap (void * addr, uint64_t length,
- int prot, int flags,
- struct shim_handle * file, uint64_t offset,
- const char * comment);
- /* Bookkeeping munmap() system call */
- int bkeep_munmap (void * addr, uint64_t length, int flags);
- /* Bookkeeping mprotect() system call */
- int bkeep_mprotect (void * addr, uint64_t length, int prot, int flags);
- /* Looking up VMA that contains [addr, length) */
- int lookup_vma (void * addr, struct shim_vma_val * vma);
- /* Looking up VMA that overlaps with [addr, length) */
- int lookup_overlap_vma (void * addr, uint64_t length,
- struct shim_vma_val * vma);
- /*
- * Looking for an unmapped space and then adding the corresponding bookkeeping
- * (more info in bookkeep/shim_vma.c).
- *
- * Note: the first argument is "top_addr" because the search is top-down.
- */
- void * bkeep_unmapped (void * top_addr, void * bottom_addr, uint64_t length,
- int prot, int flags, struct shim_handle * file,
- uint64_t offset, const char * comment);
- static inline void *
- bkeep_unmapped_any (uint64_t length, int prot, int flags,
- struct shim_handle * file, uint64_t offset,
- const char * comment)
- {
- return bkeep_unmapped(PAL_CB(user_address.end),
- PAL_CB(user_address.start),
- length, prot, flags, file, offset, comment);
- }
- void * bkeep_unmapped_heap (uint64_t length, int prot, int flags,
- struct shim_handle * file, uint64_t offset,
- const char * comment);
- /*
- * Dumping all *non-internal* VMAs into a user-allocated buffer ("max_count" is
- * the maximal number of entries in the buffer). Return number of filled entries
- * if succeeded, or -EOVERFLOW if the buffer is too small.
- */
- int dump_all_vmas (struct shim_vma_val * vmas, size_t max_count);
- /* Debugging */
- void debug_print_vma_list (void);
- /* Constants */
- extern unsigned long brk_max_size;
- extern unsigned long sys_stack_size;
- #endif /* _SHIM_VMA_H_ */
|