forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwasi-system-compat.h
More file actions
103 lines (82 loc) Β· 2.53 KB
/
wasi-system-compat.h
File metadata and controls
103 lines (82 loc) Β· 2.53 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef WASI_SYSTEM_COMPAT_H_
#define WASI_SYSTEM_COMPAT_H_
// This file provides system-specific compatibility for WASI builds
// Include this before any system calls in Node.js source files
#ifdef __wasi__
#include <sys/types.h>
#include <stdint.h>
#include <limits.h>
#include <vector>
#include <unordered_map>
// Check if we need to include sys/resource.h or define our own types
#include <sys/resource.h>
// If sys/resource.h doesn't provide these, define them
#ifndef RLIM_INFINITY
#define RLIM_INFINITY ((rlim_t)-1)
#endif
// Resource limit definitions missing in WASI
#ifndef RLIMIT_NOFILE
#define RLIMIT_NOFILE 7 // Maximum number of open file descriptors
#endif
// Network service flags missing in WASI
#ifndef NI_NUMERICSERV
#define NI_NUMERICSERV 0x08 // Don't resolve service names
#endif
// The WASI SDK now provides getrlimit and setrlimit in sys/resource.h
// so we don't need stub implementations
// Filesystem compatibility for C++17 features
#ifdef __cplusplus
#include <string>
#include <vector>
// Note: std::filesystem is provided by WASI SDK
// Don't redefine it here to avoid conflicts
#endif // __cplusplus
// Platform-specific timestamp function
inline double SystemClockTimeMillis() {
// Simple timestamp implementation for WASI
// In real WASI environments, you would use the WASI clock API
// For now, return a monotonic counter
static double counter = 0.0;
return counter += 1.0;
}
// cppgc::HeapStatistics extensions for missing members
namespace cppgc {
// Forward declarations to fix ordering issues
class ObjectStatsEntry;
class PageStatistics;
class SpaceStatistics;
class PageStatistics {
public:
size_t physical_size_bytes;
size_t used_size_bytes;
size_t committed_size_bytes;
size_t resident_size_bytes;
std::vector<ObjectStatsEntry> object_statistics;
};
// FreeListStats for SpaceStatistics
struct FreeListStats {
std::vector<size_t> bucket_size;
std::vector<size_t> free_count;
std::vector<size_t> free_size;
};
class SpaceStatistics {
public:
const char* name;
size_t physical_size_bytes;
size_t used_size_bytes;
size_t committed_size_bytes;
size_t resident_size_bytes;
std::vector<PageStatistics> page_stats;
FreeListStats free_list_stats;
};
// HeapStatistics extension - only define if not already defined
#ifndef CPPGC_HEAP_STATISTICS_DEFINED
#define CPPGC_HEAP_STATISTICS_DEFINED
#endif
} // namespace cppgc
// v8::HeapStatistics extensions
namespace v8 {
// Extension classes can be added here if needed
} // namespace v8
#endif // __wasi__
#endif // WASI_SYSTEM_COMPAT_H_