MCPcopy Create free account
hub / github.com/catboost/catboost / Map

Method Map

util/system/filemap.cpp:221–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219 }
220
221 inline TMapResult Map(i64 offset, size_t size) {
222 assert(File_.IsOpen());
223
224 if (offset > Length_) {
225 ythrow yexception() << "Can't map something at offset " << offset << " of '" << DbgName_ << "' with length " << Length_;
226 }
227
228 if (offset + (i64)size > Length_) {
229 ythrow yexception() << "Can't map " << (unsigned long)size << " bytes at offset " << offset << " of '" << DbgName_ << "' with length " << Length_;
230 }
231
232 TMapResult result;
233
234 i64 base = DownToGranularity(offset);
235 result.Head = (i32)(offset - base);
236 size += result.Head;
237
238#if defined(_win_)
239 result.Ptr = MapViewOfFile(Mapping_,
240 (Mode_ & oAccessMask) == oRdOnly ? FILE_MAP_READ : (Mode_ & oAccessMask) == oCopyOnWr ? FILE_MAP_COPY
241 : FILE_MAP_WRITE,
242 Hi32(base), Lo32(base), size);
243#else
244 #if defined(_unix_)
245 if (Mode_ & oNotGreedy) {
246 #endif
247 result.Ptr = mmap((caddr_t) nullptr, size, ModeToMmapProt(Mode_), ModeToMmapFlags(Mode_), File_.GetHandle(), base);
248
249 if (result.Ptr == MAP_FAILED) {
250 result.Ptr = nullptr;
251 }
252 #if defined(_unix_)
253 } else {
254 result.Ptr = PtrStart_ ? static_cast<caddr_t>(PtrStart_) + base : nullptr;
255 }
256 #endif
257#endif
258 if (result.Ptr != nullptr || size == 0) { // allow map of size 0
259 result.Size = size;
260 } else {
261 ythrow yexception() << "Can't map " << (unsigned long)size << " bytes at offset " << offset << " of '" << DbgName_ << "': " << LastSystemErrorText();
262 }
263 NSan::Unpoison(result.Ptr, result.Size);
264 if (Mode_ & oPrecharge) {
265 NPrivate::Precharge(result.Ptr, result.Size, 0, result.Size);
266 }
267
268 return result;
269 }
270
271#if defined(_win_)
272 inline bool Unmap(void* ptr, size_t) {

Callers

nothing calls this directly

Calls 9

DownToGranularityFunction · 0.85
Hi32Function · 0.85
Lo32Function · 0.85
ModeToMmapProtFunction · 0.85
ModeToMmapFlagsFunction · 0.85
UnpoisonFunction · 0.85
LastSystemErrorTextFunction · 0.70
IsOpenMethod · 0.45
GetHandleMethod · 0.45

Tested by

no test coverage detected