1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #ifndef OS_WINDOWS_GC_Z_ZMAPPER_WINDOWS_HPP
  25 #define OS_WINDOWS_GC_Z_ZMAPPER_WINDOWS_HPP
  26 
  27 #include "memory/allocation.hpp"
  28 #include "utilities/globalDefinitions.hpp"
  29 
  30 #include <Windows.h>
  31 
  32 class ZMapper : public AllStatic {
  33 private:
  34   // Create paging file mapping
  35   static HANDLE create_paging_file_mapping(size_t size);
  36 
  37   // Commit paging file mapping
  38   static bool commit_paging_file_mapping(HANDLE file_handle, uintptr_t file_offset, size_t size);
  39 
  40   // Map a view anywhere without a placeholder
  41   static uintptr_t map_view_no_placeholder(HANDLE file_handle, uintptr_t file_offset, size_t size);
  42 
  43   // Unmap a view without preserving a placeholder
  44   static void unmap_view_no_placeholder(uintptr_t addr, size_t size);
  45 
  46   // Commit memory covering the given virtual address range
  47   static uintptr_t commit(uintptr_t addr, size_t size);
  48 
  49 public:
  50   // Reserve memory with a placeholder
  51   static uintptr_t reserve(uintptr_t addr, size_t size);
  52 
  53   // Unreserve memory
  54   static void unreserve(uintptr_t addr, size_t size);
  55 
  56   // Create and commit paging file mapping
  57   static HANDLE create_and_commit_paging_file_mapping(size_t size);
  58 
  59   // Close paging file mapping
  60   static void close_paging_file_mapping(HANDLE file_handle);
  61 
  62   // Split a placeholder
  63   //
  64   // A view can only replace an entire placeholder, so placeholders need to be
  65   // split and coalesced to be the exact size of the new views.
  66   // [addr, addr + size) needs to be a proper sub-placeholder of an existing
  67   // placeholder.
  68   static void split_placeholder(uintptr_t addr, size_t size);
  69 
  70   // Coalesce a placeholder
  71   //
  72   // [addr, addr + size) is the new placeholder. A sub-placeholder needs to
  73   // exist within that range.
  74   static void coalesce_placeholders(uintptr_t addr, size_t size);
  75 
  76   // Map a view of the file handle and replace the placeholder covering the
  77   // given virtual address range
  78   static void map_view_replace_placeholder(HANDLE file_handle, uintptr_t file_offset, uintptr_t addr, size_t size);
  79 
  80   // Unmap the view and reinstate a placeholder covering the given virtual
  81   // address range
  82   static void unmap_view_preserve_placeholder(uintptr_t addr, size_t size);
  83 };
  84 
  85 #endif // OS_WINDOWS_GC_Z_ZMAPPER_WINDOWS_HPP