libfoedus-core
FOEDUS Core Library
protected_boundary.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_ASSORTED_PROTECTED_BOUNDARY_HPP_
19 #define FOEDUS_ASSORTED_PROTECTED_BOUNDARY_HPP_
20 
21 #include <stdint.h>
22 
23 #include <algorithm>
24 #include <cstring>
25 #include <string>
26 
27 #include "foedus/assert_nd.hpp"
28 #include "foedus/error_code.hpp"
29 
30 namespace foedus {
31 namespace assorted {
32 
33 const uint64_t kProtectedBoundaryMagicWord = 0x42a6292680d7ce36ULL;
34 
57  enum Constants {
58  kByteSize = 1 << 12,
61  };
62 
64  uint64_t data_[kWordCount];
65 
75 
83 
88  void reset(const std::string& boundary_name) {
89  uint16_t copy_len = std::min<uint64_t>(boundary_name.length(), kMaxBoundaryNameLength);
90  boundary_name.copy(boundary_name_, copy_len, 0);
91  if (copy_len < kMaxBoundaryNameLength) {
92  std::memset(boundary_name_ + copy_len, 0, kMaxBoundaryNameLength- copy_len);
93  }
94  for (uint32_t i = 0; i < kWordCount; ++i) {
95  data_[i] = kProtectedBoundaryMagicWord;
96  }
97  }
98 
103  void assert_boundary() const {
104  for (uint32_t i = 0; i < kWordCount; ++i) {
105  ASSERT_ND(data_[i] == kProtectedBoundaryMagicWord);
106  }
107  }
108 
109  std::string get_boundary_name() const {
110  uint16_t len;
111  for (len = 0; len < kMaxBoundaryNameLength; ++len) {
112  if (boundary_name_[len] == 0) {
113  break;
114  }
115  }
116  ASSERT_ND(len < kMaxBoundaryNameLength);
117  return std::string(boundary_name_, len);
118  }
119 };
120 
121 } // namespace assorted
122 } // namespace foedus
123 
124 #endif // FOEDUS_ASSORTED_PROTECTED_BOUNDARY_HPP_
A 4kb dummy data placed between separate memory regions so that we can check if/where a bogus memory ...
void reset(const std::string &boundary_name)
Fills the block with magic words.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
char boundary_name_[kMaxBoundaryNameLength]
const uint64_t kProtectedBoundaryMagicWord
void assert_boundary() const
Called at shutdown to check whether these boundaries were not accessed.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
ErrorCode release_protect()
Removes all access restrictions via mprotect().
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
ErrorCode acquire_protect()
Puts a strict access prohibition via mprotect().