forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmman.h
More file actions
83 lines (68 loc) · 1.7 KB
/
mman.h
File metadata and controls
83 lines (68 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
// This file ensures that mman.h compatible functions are defined in the global
// namespace for windows and posix environments.
#pragma once
#include <executorch/runtime/platform/compiler.h>
#include <sys/stat.h>
#include <cstdint>
#ifndef _WIN32
#include <sys/mman.h>
#include <unistd.h>
ET_INLINE size_t get_os_page_size() {
return sysconf(_SC_PAGESIZE);
}
/**
* Platform-specific file stat function.
*/
ET_INLINE int get_file_stat(int fd, size_t* out_size) {
struct stat st;
int err = ::fstat(fd, &st);
if (err >= 0) {
*out_size = static_cast<size_t>(st.st_size);
}
return err;
}
/**
* Platform-specific mmap offset type conversion.
*/
ET_INLINE off_t get_mmap_offset(size_t offset) {
return static_cast<off_t>(offset);
}
#else
#define NOMINMAX
#include <windows.h>
#undef NOMINMAX
#include <io.h>
#include <executorch/extension/data_loader/mman_windows.h>
ET_INLINE long get_os_page_size() {
SYSTEM_INFO si;
GetSystemInfo(&si);
long pagesize = si.dwAllocationGranularity > si.dwPageSize
? si.dwAllocationGranularity
: si.dwPageSize;
return pagesize;
}
/**
* Platform-specific file stat function.
*/
ET_INLINE int get_file_stat(int fd, size_t* out_size) {
struct _stat64 st;
int err = ::_fstat64(fd, &st);
if (err >= 0) {
*out_size = static_cast<size_t>(st.st_size);
}
return err;
}
/**
* Platform-specific mmap offset type conversion.
*/
ET_INLINE uint64_t get_mmap_offset(size_t offset) {
return static_cast<uint64_t>(offset);
}
#endif