koffi 1.1.1 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CMakeLists.txt +13 -7
  2. package/README.md +15 -26
  3. package/build/qemu/1.1.4/koffi_darwin_x64.tar.gz +0 -0
  4. package/build/qemu/1.1.4/koffi_freebsd_arm64.tar.gz +0 -0
  5. package/build/qemu/1.1.4/koffi_freebsd_ia32.tar.gz +0 -0
  6. package/build/qemu/1.1.4/koffi_freebsd_x64.tar.gz +0 -0
  7. package/build/qemu/1.1.4/koffi_linux_arm.tar.gz +0 -0
  8. package/build/qemu/1.1.4/koffi_linux_arm64.tar.gz +0 -0
  9. package/build/qemu/1.1.4/koffi_linux_ia32.tar.gz +0 -0
  10. package/build/qemu/1.1.4/koffi_linux_riscv64.tar.gz +0 -0
  11. package/build/qemu/1.1.4/koffi_linux_x64.tar.gz +0 -0
  12. package/build/qemu/1.1.4/koffi_openbsd_ia32.tar.gz +0 -0
  13. package/build/qemu/1.1.4/koffi_openbsd_x64.tar.gz +0 -0
  14. package/build/qemu/1.1.4/koffi_win32_ia32.tar.gz +0 -0
  15. package/build/qemu/1.1.4/koffi_win32_x64.tar.gz +0 -0
  16. package/package.json +2 -2
  17. package/qemu/qemu.js +13 -10
  18. package/qemu/registry/machines.json +138 -3
  19. package/qemu/registry/sha256sum.txt +27 -12
  20. package/src/abi_arm32.cc +29 -16
  21. package/src/abi_arm64.cc +33 -17
  22. package/src/abi_riscv64.cc +468 -0
  23. package/src/abi_riscv64_fwd.S +129 -0
  24. package/src/abi_x64_sysv.cc +9 -10
  25. package/src/abi_x64_win.cc +5 -8
  26. package/src/abi_x86.cc +11 -6
  27. package/src/call.cc +24 -36
  28. package/src/call.hh +14 -24
  29. package/src/ffi.cc +75 -27
  30. package/src/ffi.hh +13 -5
  31. package/src/parser.cc +48 -26
  32. package/src/parser.hh +3 -1
  33. package/src/util.cc +26 -57
  34. package/src/util.hh +17 -1
  35. package/test/CMakeLists.txt +3 -0
  36. package/test/misc.c +34 -0
  37. package/vendor/_patches/glfw_001_fix_openbsd_xlib_soname.patch +145 -0
  38. package/vendor/libcc/libcc.cc +7 -7
  39. package/vendor/libcc/libcc.hh +8 -2
  40. package/vendor/raylib/src/external/glfw/src/egl_context.c +6 -0
  41. package/vendor/raylib/src/external/glfw/src/osmesa_context.c +2 -0
  42. package/vendor/raylib/src/external/glfw/src/vulkan.c +2 -0
  43. package/vendor/raylib/src/external/glfw/src/x11_init.c +20 -0
  44. package/build/qemu/1.1.1/koffi_darwin_x64.tar.gz +0 -0
  45. package/build/qemu/1.1.1/koffi_freebsd_arm64.tar.gz +0 -0
  46. package/build/qemu/1.1.1/koffi_freebsd_ia32.tar.gz +0 -0
  47. package/build/qemu/1.1.1/koffi_freebsd_x64.tar.gz +0 -0
  48. package/build/qemu/1.1.1/koffi_linux_arm.tar.gz +0 -0
  49. package/build/qemu/1.1.1/koffi_linux_arm64.tar.gz +0 -0
  50. package/build/qemu/1.1.1/koffi_linux_ia32.tar.gz +0 -0
  51. package/build/qemu/1.1.1/koffi_linux_x64.tar.gz +0 -0
  52. package/build/qemu/1.1.1/koffi_win32_ia32.tar.gz +0 -0
  53. package/build/qemu/1.1.1/koffi_win32_x64.tar.gz +0 -0
package/src/parser.cc CHANGED
@@ -19,34 +19,29 @@
19
19
 
20
20
  namespace RG {
21
21
 
22
- bool PrototypeParser::Parse(Napi::String proto, FunctionInfo *func)
22
+ bool PrototypeParser::Parse(const char *str, FunctionInfo *out_func)
23
23
  {
24
- if (!proto.IsString()) {
25
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for prototype, expected string", GetValueType(instance, proto));
26
- return false;
27
- }
28
-
29
- std::string hold = proto;
30
-
31
24
  tokens.Clear();
32
25
  offset = 0;
33
26
  valid = true;
34
27
 
35
- Tokenize(hold.c_str());
28
+ Tokenize(str);
36
29
 
37
- func->ret.type = ParseType();
38
- if (func->ret.type->primitive == PrimitiveKind::Array) {
30
+ out_func->ret.type = ParseType();
31
+ if (out_func->ret.type->primitive == PrimitiveKind::Array) {
39
32
  MarkError("You are not allowed to directly return C arrays");
40
33
  return false;
41
34
  }
42
35
  if (Match("__cdecl")) {
43
- func->convention = CallConvention::Cdecl;
36
+ out_func->convention = CallConvention::Cdecl;
44
37
  } else if (Match("__stdcall")) {
45
- func->convention = CallConvention::Stdcall;
38
+ out_func->convention = CallConvention::Stdcall;
46
39
  } else if (Match("__fastcall")) {
47
- func->convention = CallConvention::Fastcall;
40
+ out_func->convention = CallConvention::Fastcall;
41
+ } else if (Match("__thiscall")) {
42
+ out_func->convention = CallConvention::Thiscall;
48
43
  }
49
- func->name = ParseIdentifier();
44
+ out_func->name = ParseIdentifier();
50
45
 
51
46
  Consume("(");
52
47
  if (offset < tokens.len && tokens[offset] != ")") {
@@ -54,7 +49,7 @@ bool PrototypeParser::Parse(Napi::String proto, FunctionInfo *func)
54
49
  ParameterInfo param = {};
55
50
 
56
51
  if (Match("...")) {
57
- func->variadic = true;
52
+ out_func->variadic = true;
58
53
  break;
59
54
  }
60
55
 
@@ -83,18 +78,18 @@ bool PrototypeParser::Parse(Napi::String proto, FunctionInfo *func)
83
78
 
84
79
  offset += (offset < tokens.len && IsIdentifier(tokens[offset]));
85
80
 
86
- if (func->parameters.len >= MaxParameters) {
81
+ if (out_func->parameters.len >= MaxParameters) {
87
82
  MarkError("Functions cannot have more than %1 parameters", MaxParameters);
88
83
  return false;
89
84
  }
90
- if ((param.directions & 2) && ++func->out_parameters >= MaxOutParameters) {
85
+ if ((param.directions & 2) && ++out_func->out_parameters >= MaxOutParameters) {
91
86
  MarkError("Functions cannot have more than out %1 parameters", MaxOutParameters);
92
87
  return false;
93
88
  }
94
89
 
95
- param.offset = func->parameters.len;
90
+ param.offset = out_func->parameters.len;
96
91
 
97
- func->parameters.Append(param);
92
+ out_func->parameters.Append(param);
98
93
 
99
94
  if (offset >= tokens.len || tokens[offset] != ",")
100
95
  break;
@@ -125,6 +120,17 @@ void PrototypeParser::Tokenize(const char *str)
125
120
  Span<const char> tok = MakeSpan(str + i, j - i);
126
121
  tokens.Append(tok);
127
122
 
123
+ i = j - 1;
124
+ } else if (IsAsciiDigit(c)) {
125
+ Size j = i;
126
+ while (str[++j] && IsAsciiDigit(str[j]));
127
+ if (str[j] == '.') {
128
+ while (str[++j] && IsAsciiDigit(str[j]));
129
+ }
130
+
131
+ Span<const char> tok = MakeSpan(str + i, j - i);
132
+ tokens.Append(tok);
133
+
128
134
  i = j - 1;
129
135
  } else if (c == '.' && str[i + 1] == '.' && str[i + 2] == '.') {
130
136
  tokens.Append("...");
@@ -153,9 +159,9 @@ const TypeInfo *PrototypeParser::ParseType()
153
159
  }
154
160
  if (offset == start) {
155
161
  if (offset < tokens.len) {
156
- MarkError("Unexpected token '%1', expected identifier", tokens[offset]);
162
+ MarkError("Unexpected token '%1', expected type", tokens[offset]);
157
163
  } else {
158
- MarkError("Unexpected end of prototype, expected identifier");
164
+ MarkError("Unexpected end of prototype, expected type");
159
165
  }
160
166
  return instance->types_map.FindValue("void", nullptr);
161
167
  }
@@ -165,11 +171,21 @@ const TypeInfo *PrototypeParser::ParseType()
165
171
  }
166
172
  buf.ptr[--buf.len] = 0;
167
173
 
168
- if (TestStr(buf, "char") && indirect) {
169
- buf.RemoveFrom(0);
170
- Fmt(&buf, "string");
174
+ if (indirect) {
175
+ const TypeInfo *type = instance->types_map.FindValue(buf.ptr, nullptr);
176
+ PrimitiveKind primitive = type ? type->primitive : PrimitiveKind::Void;
177
+
178
+ if (primitive == PrimitiveKind::Int8 || primitive == PrimitiveKind::UInt8) {
179
+ buf.RemoveFrom(0);
180
+ Fmt(&buf, "string");
181
+
182
+ indirect--;
183
+ } else if (primitive == PrimitiveKind::Int16 || primitive == PrimitiveKind::UInt16) {
184
+ buf.RemoveFrom(0);
185
+ Fmt(&buf, "string16");
171
186
 
172
- indirect--;
187
+ indirect--;
188
+ }
173
189
  }
174
190
 
175
191
  while (buf.len) {
@@ -250,4 +266,10 @@ bool PrototypeParser::IsIdentifier(Span<const char> tok) const
250
266
  return IsAsciiAlpha(tok[0]) || tok[0] == '_';
251
267
  }
252
268
 
269
+ bool ParsePrototype(Napi::Env env, const char *str, FunctionInfo *out_func)
270
+ {
271
+ PrototypeParser parser(env);
272
+ return parser.Parse(str, out_func);
273
+ }
274
+
253
275
  }
package/src/parser.hh CHANGED
@@ -36,7 +36,7 @@ class PrototypeParser {
36
36
  public:
37
37
  PrototypeParser(Napi::Env env) : env(env), instance(env.GetInstanceData<InstanceData>()) {}
38
38
 
39
- bool Parse(Napi::String proto, FunctionInfo *func);
39
+ bool Parse(const char *str, FunctionInfo *out_func);
40
40
 
41
41
  private:
42
42
  void Tokenize(const char *str);
@@ -60,4 +60,6 @@ private:
60
60
  }
61
61
  };
62
62
 
63
+ bool ParsePrototype(Napi::Env env, const char *str, FunctionInfo *out_func);
64
+
63
65
  }
package/src/util.cc CHANGED
@@ -126,76 +126,45 @@ bool CheckValueTag(const InstanceData *instance, Napi::Value value, const void *
126
126
  return match;
127
127
  }
128
128
 
129
- class HfaAnalyser {
130
- uint32_t primitives;
131
- Size count;
132
-
133
- public:
134
- bool Analyse(const TypeInfo *type, int min, int max);
135
-
136
- private:
137
- void AnalyseStruct(const TypeInfo *type);
138
- void AnalyseArray(const TypeInfo *type);
139
- };
140
-
141
- bool HfaAnalyser::Analyse(const TypeInfo *type, int min, int max)
129
+ static int AnalyseFlatRec(const TypeInfo *type, int offset, int count, FunctionRef<void(const TypeInfo *type, int offset, int count)> func)
142
130
  {
143
- primitives = 0;
144
- count = 0;
145
-
146
131
  if (type->primitive == PrimitiveKind::Record) {
147
- AnalyseStruct(type);
132
+ for (int i = 0; i < count; i++) {
133
+ for (const RecordMember &member: type->members) {
134
+ offset = AnalyseFlatRec(member.type, offset, 1, func);
135
+ }
136
+ }
148
137
  } else if (type->primitive == PrimitiveKind::Array) {
149
- AnalyseArray(type);
138
+ count *= type->size / type->ref->size;
139
+ offset = AnalyseFlatRec(type->ref, offset, count, func);
150
140
  } else {
151
- return false;
141
+ func(type, offset, count);
142
+ offset += count;
152
143
  }
153
144
 
154
- bool hfa = (count >= min && count <= max && PopCount(primitives) == 1);
155
- return hfa;
145
+ return offset;
156
146
  }
157
147
 
158
- void HfaAnalyser::AnalyseStruct(const TypeInfo *type)
148
+ int AnalyseFlat(const TypeInfo *type, FunctionRef<void(const TypeInfo *type, int offset, int count)> func)
159
149
  {
160
- RG_ASSERT(type->primitive == PrimitiveKind::Record);
161
-
162
- for (const RecordMember &member: type->members) {
163
- if (member.type->primitive == PrimitiveKind::Record) {
164
- AnalyseStruct(member.type);
165
- } else if (member.type->primitive == PrimitiveKind::Array) {
166
- AnalyseArray(member.type);
167
- } else if (member.type->primitive == PrimitiveKind::Float32 ||
168
- member.type->primitive == PrimitiveKind::Float64) {
169
- primitives |= 1u << (int)member.type->primitive;
170
- count++;
171
- } else {
172
- primitives = UINT_MAX;
173
- return;
174
- }
175
- }
150
+ return AnalyseFlatRec(type, 0, 1, func);
176
151
  }
177
152
 
178
- void HfaAnalyser::AnalyseArray(const TypeInfo *type)
153
+ int IsHFA(const TypeInfo *type, int min, int max)
179
154
  {
180
- RG_ASSERT(type->primitive == PrimitiveKind::Array);
181
-
182
- if (type->ref->primitive == PrimitiveKind::Record) {
183
- AnalyseStruct(type->ref);
184
- } else if (type->ref->primitive == PrimitiveKind::Array) {
185
- AnalyseArray(type->ref);
186
- } else if (type->ref->primitive == PrimitiveKind::Float32 ||
187
- type->ref->primitive == PrimitiveKind::Float64) {
188
- primitives |= 1u << (int)type->ref->primitive;
189
- count += type->size / type->ref->size;;
190
- } else {
191
- primitives = UINT_MAX;
192
- }
193
- }
155
+ uint32_t primitives = 0;
156
+ int count = 0;
194
157
 
195
- bool IsHFA(const TypeInfo *type, int min, int max)
196
- {
197
- HfaAnalyser analyser;
198
- return analyser.Analyse(type, min, max);
158
+ count = AnalyseFlat(type, [&](const TypeInfo *type, int, int) {
159
+ if (IsFloat(type)) {
160
+ primitives |= 1u << (int)type->primitive;
161
+ } else {
162
+ primitives = UINT32_MAX;
163
+ }
164
+ });
165
+
166
+ bool hfa = (count >= min && count <= max && PopCount(primitives) == 1);
167
+ return hfa ? count : 0;
199
168
  }
200
169
 
201
170
  }
package/src/util.hh CHANGED
@@ -53,6 +53,20 @@ static inline T *AlignDown(T *ptr, Size align)
53
53
  return (T *)aligned;
54
54
  }
55
55
 
56
+ static inline bool IsInteger(const TypeInfo *type)
57
+ {
58
+ bool integer = ((int)type->primitive >= (int)PrimitiveKind::Int8 &&
59
+ (int)type->primitive <= (int)PrimitiveKind::UInt64);
60
+ return integer;
61
+ }
62
+
63
+ static inline bool IsFloat(const TypeInfo *type)
64
+ {
65
+ bool fp = (type->primitive == PrimitiveKind::Float32 ||
66
+ type->primitive == PrimitiveKind::Float64);
67
+ return fp;
68
+ }
69
+
56
70
  const TypeInfo *ResolveType(const InstanceData *instance, Napi::Value value, int *out_directions = nullptr);
57
71
  const TypeInfo *GetPointerType(InstanceData *instance, const TypeInfo *type);
58
72
 
@@ -89,6 +103,8 @@ T CopyNumber(const Napi::Value &value)
89
103
  RG_UNREACHABLE();
90
104
  }
91
105
 
92
- bool IsHFA(const TypeInfo *type, int min, int max);
106
+ int AnalyseFlat(const TypeInfo *type, FunctionRef<void(const TypeInfo *type, int offset, int count)> func);
107
+
108
+ int IsHFA(const TypeInfo *type, int min, int max);
93
109
 
94
110
  }
@@ -42,6 +42,9 @@ else()
42
42
  -Wno-unused-function -Wno-missing-field-initializers
43
43
  -Wno-unused-value -Wno-implicit-fallthrough -Wno-stringop-overflow
44
44
  -Wno-unused-result)
45
+ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
46
+ target_compile_options(raylib PRIVATE -Wno-unknown-warning-option)
47
+ endif()
45
48
  endif()
46
49
 
47
50
  if(WIN32)
package/test/misc.c CHANGED
@@ -75,6 +75,15 @@ typedef struct Double3 {
75
75
  } s;
76
76
  } Double3;
77
77
 
78
+ typedef struct FloatInt {
79
+ float f;
80
+ int i;
81
+ } FloatInt;
82
+ typedef struct IntFloat {
83
+ int i;
84
+ float f;
85
+ } IntFloat;
86
+
78
87
  typedef struct IJK1 { int8_t i; int8_t j; int8_t k; } IJK1;
79
88
  typedef struct IJK4 { int32_t i; int32_t j; int32_t k; } IJK4;
80
89
  typedef struct IJK8 { int64_t i; int64_t j; int64_t k; } IJK8;
@@ -188,6 +197,11 @@ EXPORT Float2 PackFloat2(float a, float b, Float2 *out)
188
197
  return ret;
189
198
  }
190
199
 
200
+ EXPORT Float2 ThroughFloat2(Float2 f2)
201
+ {
202
+ return f2;
203
+ }
204
+
191
205
  EXPORT Float3 PackFloat3(float a, float b, float c, Float3 *out)
192
206
  {
193
207
  Float3 ret;
@@ -228,6 +242,26 @@ EXPORT Double3 PackDouble3(double a, double b, double c, Double3 *out)
228
242
  return ret;
229
243
  }
230
244
 
245
+ EXPORT IntFloat ReverseFloatInt(FloatInt sfi)
246
+ {
247
+ IntFloat sif;
248
+
249
+ sif.i = (int)sfi.f;
250
+ sif.f = (float)sfi.i;
251
+
252
+ return sif;
253
+ }
254
+
255
+ EXPORT FloatInt ReverseIntFloat(IntFloat sif)
256
+ {
257
+ FloatInt sfi;
258
+
259
+ sfi.i = (int)sif.f;
260
+ sfi.f = (float)sif.i;
261
+
262
+ return sfi;
263
+ }
264
+
231
265
  EXPORT int64_t ConcatenateToInt1(int8_t a, int8_t b, int8_t c, int8_t d, int8_t e, int8_t f,
232
266
  int8_t g, int8_t h, int8_t i, int8_t j, int8_t k, int8_t l)
233
267
  {
@@ -0,0 +1,145 @@
1
+ diff --git a/koffi/vendor/raylib/src/external/glfw/src/egl_context.c b/koffi/vendor/raylib/src/external/glfw/src/egl_context.c
2
+ index 975c67be..4edd3dac 100644
3
+ --- a/koffi/vendor/raylib/src/external/glfw/src/egl_context.c
4
+ +++ b/koffi/vendor/raylib/src/external/glfw/src/egl_context.c
5
+ @@ -316,6 +316,8 @@ GLFWbool _glfwInitEGL(void)
6
+ "libEGL.dylib",
7
+ #elif defined(__CYGWIN__)
8
+ "libEGL-1.so",
9
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
10
+ + "libEGL.so",
11
+ #else
12
+ "libEGL.so.1",
13
+ #endif
14
+ @@ -686,6 +688,8 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
15
+ "libGLES_CM.dll",
16
+ #elif defined(_GLFW_COCOA)
17
+ "libGLESv1_CM.dylib",
18
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
19
+ + "libGLESv1_CM.so",
20
+ #else
21
+ "libGLESv1_CM.so.1",
22
+ "libGLES_CM.so.1",
23
+ @@ -703,6 +707,8 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
24
+ "libGLESv2.dylib",
25
+ #elif defined(__CYGWIN__)
26
+ "libGLESv2-2.so",
27
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
28
+ + "libGLESv2.so",
29
+ #else
30
+ "libGLESv2.so.2",
31
+ #endif
32
+ diff --git a/koffi/vendor/raylib/src/external/glfw/src/osmesa_context.c b/koffi/vendor/raylib/src/external/glfw/src/osmesa_context.c
33
+ index 70e8675b..62c31678 100644
34
+ --- a/koffi/vendor/raylib/src/external/glfw/src/osmesa_context.c
35
+ +++ b/koffi/vendor/raylib/src/external/glfw/src/osmesa_context.c
36
+ @@ -124,6 +124,8 @@ GLFWbool _glfwInitOSMesa(void)
37
+ "libOSMesa.8.dylib",
38
+ #elif defined(__CYGWIN__)
39
+ "libOSMesa-8.so",
40
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
41
+ + "libOSMesa.so",
42
+ #else
43
+ "libOSMesa.so.8",
44
+ "libOSMesa.so.6",
45
+ diff --git a/koffi/vendor/raylib/src/external/glfw/src/vulkan.c b/koffi/vendor/raylib/src/external/glfw/src/vulkan.c
46
+ index b5340520..7eb4fdf0 100644
47
+ --- a/koffi/vendor/raylib/src/external/glfw/src/vulkan.c
48
+ +++ b/koffi/vendor/raylib/src/external/glfw/src/vulkan.c
49
+ @@ -59,6 +59,8 @@ GLFWbool _glfwInitVulkan(int mode)
50
+ _glfw.vk.handle = _glfw_dlopen("libvulkan.1.dylib");
51
+ if (!_glfw.vk.handle)
52
+ _glfw.vk.handle = _glfwLoadLocalVulkanLoaderNS();
53
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
54
+ + _glfw.vk.handle = _glfw_dlopen("libvulkan.so");
55
+ #else
56
+ _glfw.vk.handle = _glfw_dlopen("libvulkan.so.1");
57
+ #endif
58
+ diff --git a/koffi/vendor/raylib/src/external/glfw/src/x11_init.c b/koffi/vendor/raylib/src/external/glfw/src/x11_init.c
59
+ index fc9ac427..c2233f56 100644
60
+ --- a/koffi/vendor/raylib/src/external/glfw/src/x11_init.c
61
+ +++ b/koffi/vendor/raylib/src/external/glfw/src/x11_init.c
62
+ @@ -601,7 +601,11 @@ static void detectEWMH(void)
63
+ //
64
+ static GLFWbool initExtensions(void)
65
+ {
66
+ +#if defined(__OpenBSD__) || defined(__NetBSD__)
67
+ + _glfw.x11.vidmode.handle = _glfw_dlopen("libXxf86vm.so");
68
+ +#else
69
+ _glfw.x11.vidmode.handle = _glfw_dlopen("libXxf86vm.so.1");
70
+ +#endif
71
+ if (_glfw.x11.vidmode.handle)
72
+ {
73
+ _glfw.x11.vidmode.QueryExtension = (PFN_XF86VidModeQueryExtension)
74
+ @@ -621,6 +625,8 @@ static GLFWbool initExtensions(void)
75
+
76
+ #if defined(__CYGWIN__)
77
+ _glfw.x11.xi.handle = _glfw_dlopen("libXi-6.so");
78
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
79
+ + _glfw.x11.xi.handle = _glfw_dlopen("libXi.so");
80
+ #else
81
+ _glfw.x11.xi.handle = _glfw_dlopen("libXi.so.6");
82
+ #endif
83
+ @@ -651,6 +657,8 @@ static GLFWbool initExtensions(void)
84
+
85
+ #if defined(__CYGWIN__)
86
+ _glfw.x11.randr.handle = _glfw_dlopen("libXrandr-2.so");
87
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
88
+ + _glfw.x11.randr.handle = _glfw_dlopen("libXrandr.so");
89
+ #else
90
+ _glfw.x11.randr.handle = _glfw_dlopen("libXrandr.so.2");
91
+ #endif
92
+ @@ -743,6 +751,8 @@ static GLFWbool initExtensions(void)
93
+
94
+ #if defined(__CYGWIN__)
95
+ _glfw.x11.xcursor.handle = _glfw_dlopen("libXcursor-1.so");
96
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
97
+ + _glfw.x11.xcursor.handle = _glfw_dlopen("libXcursor.so");
98
+ #else
99
+ _glfw.x11.xcursor.handle = _glfw_dlopen("libXcursor.so.1");
100
+ #endif
101
+ @@ -764,6 +774,8 @@ static GLFWbool initExtensions(void)
102
+
103
+ #if defined(__CYGWIN__)
104
+ _glfw.x11.xinerama.handle = _glfw_dlopen("libXinerama-1.so");
105
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
106
+ + _glfw.x11.xinerama.handle = _glfw_dlopen("libXinerama.so");
107
+ #else
108
+ _glfw.x11.xinerama.handle = _glfw_dlopen("libXinerama.so.1");
109
+ #endif
110
+ @@ -817,6 +829,8 @@ static GLFWbool initExtensions(void)
111
+ {
112
+ #if defined(__CYGWIN__)
113
+ _glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb-1.so");
114
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
115
+ + _glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb.so");
116
+ #else
117
+ _glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb.so.1");
118
+ #endif
119
+ @@ -830,6 +844,8 @@ static GLFWbool initExtensions(void)
120
+
121
+ #if defined(__CYGWIN__)
122
+ _glfw.x11.xrender.handle = _glfw_dlopen("libXrender-1.so");
123
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
124
+ + _glfw.x11.xrender.handle = _glfw_dlopen("libXrender.so");
125
+ #else
126
+ _glfw.x11.xrender.handle = _glfw_dlopen("libXrender.so.1");
127
+ #endif
128
+ @@ -857,6 +873,8 @@ static GLFWbool initExtensions(void)
129
+
130
+ #if defined(__CYGWIN__)
131
+ _glfw.x11.xshape.handle = _glfw_dlopen("libXext-6.so");
132
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
133
+ + _glfw.x11.xshape.handle = _glfw_dlopen("libXext.so");
134
+ #else
135
+ _glfw.x11.xshape.handle = _glfw_dlopen("libXext.so.6");
136
+ #endif
137
+ @@ -1120,6 +1138,8 @@ int _glfwPlatformInit(void)
138
+
139
+ #if defined(__CYGWIN__)
140
+ _glfw.x11.xlib.handle = _glfw_dlopen("libX11-6.so");
141
+ +#elif defined(__OpenBSD__) || defined(__NetBSD__)
142
+ + _glfw.x11.xlib.handle = _glfw_dlopen("libX11.so");
143
+ #else
144
+ _glfw.x11.xlib.handle = _glfw_dlopen("libX11.so.6");
145
+ #endif
@@ -3745,7 +3745,7 @@ static std::atomic_bool flag_interrupt = false;
3745
3745
  static std::atomic_bool explicit_interrupt = false;
3746
3746
  static int interrupt_pfd[2] = {-1, -1};
3747
3747
 
3748
- static void SetSignalHandler(int signal, struct sigaction *prev, void (*func)(int))
3748
+ void SetSignalHandler(int signal, void (*func)(int), struct sigaction *prev)
3749
3749
  {
3750
3750
  struct sigaction action = {};
3751
3751
 
@@ -3786,10 +3786,10 @@ RG_INIT(SetupDefaultHandlers)
3786
3786
  int ret = setpgid(0, 0);
3787
3787
  RG_ASSERT(!ret);
3788
3788
 
3789
- SetSignalHandler(SIGINT, nullptr, DefaultSignalHandler);
3790
- SetSignalHandler(SIGTERM, nullptr, DefaultSignalHandler);
3791
- SetSignalHandler(SIGHUP, nullptr, DefaultSignalHandler);
3792
- SetSignalHandler(SIGPIPE, nullptr, [](int) {});
3789
+ SetSignalHandler(SIGINT, DefaultSignalHandler);
3790
+ SetSignalHandler(SIGTERM, DefaultSignalHandler);
3791
+ SetSignalHandler(SIGHUP, DefaultSignalHandler);
3792
+ SetSignalHandler(SIGPIPE, [](int) {});
3793
3793
  }
3794
3794
 
3795
3795
  RG_EXIT(TerminateChildren)
@@ -3797,7 +3797,7 @@ RG_EXIT(TerminateChildren)
3797
3797
  pid_t pid = getpid();
3798
3798
  RG_ASSERT(pid > 1);
3799
3799
 
3800
- SetSignalHandler(SIGTERM, nullptr, [](int) {});
3800
+ SetSignalHandler(SIGTERM, [](int) {});
3801
3801
  kill(-pid, SIGTERM);
3802
3802
  }
3803
3803
 
@@ -4168,7 +4168,7 @@ WaitForResult WaitForInterrupt(int64_t timeout)
4168
4168
  static std::atomic_bool message = false;
4169
4169
 
4170
4170
  flag_interrupt = true;
4171
- SetSignalHandler(SIGUSR1, nullptr, [](int) { message = true; });
4171
+ SetSignalHandler(SIGUSR1, [](int) { message = true; });
4172
4172
 
4173
4173
  if (timeout >= 0) {
4174
4174
  struct timespec ts;
@@ -35,7 +35,7 @@
35
35
  #include <utility>
36
36
  #if defined(_WIN32)
37
37
  #include <intrin.h>
38
- #elif !defined(__APPLE__) && (!defined(__linux__) || defined(__GLIBC__))
38
+ #elif !defined(__APPLE__) && (!defined(__linux__) || defined(__GLIBC__)) && __has_include(<ucontext.h>)
39
39
  #define RG_FIBER_USE_UCONTEXT
40
40
  #include <ucontext.h>
41
41
  #else
@@ -54,6 +54,7 @@
54
54
  #pragma intrinsic(__rdtsc)
55
55
  #endif
56
56
 
57
+ struct sigaction;
57
58
  struct BrotliEncoderStateStruct;
58
59
 
59
60
  namespace RG {
@@ -93,7 +94,7 @@ extern "C" const char *FelixTarget;
93
94
  extern "C" const char *FelixVersion;
94
95
  extern "C" const char *FelixCompiler;
95
96
 
96
- #if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__)
97
+ #if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || __riscv_xlen == 64
97
98
  typedef int64_t Size;
98
99
  #define RG_SIZE_MAX INT64_MAX
99
100
  #elif defined(_WIN32) || defined(__APPLE__) || defined(__unix__)
@@ -115,6 +116,7 @@ extern "C" const char *FelixCompiler;
115
116
  #if ULLONG_MAX != 0xFFFFFFFFFFFFFFFFull
116
117
  #error This code base is not designed to support non-64-bits long long types
117
118
  #endif
119
+ static_assert(sizeof(double) == 8, "This code base is not designed to support single-precision double floats");
118
120
 
119
121
  #define RG_STRINGIFY_(a) #a
120
122
  #define RG_STRINGIFY(a) RG_STRINGIFY_(a)
@@ -195,6 +197,8 @@ extern "C" void AssertMessage(const char *filename, int line, const char *cond);
195
197
  #define RG_DEBUG_BREAK() __asm__ __volatile__(".inst 0xd4200000")
196
198
  #elif defined(__arm__)
197
199
  #define RG_DEBUG_BREAK() __asm__ __volatile__(".inst 0xe7f001f0")
200
+ #elif defined(__riscv)
201
+ #define RG_DEBUG_BREAK() __asm__ __volatile__("ebreak")
198
202
  #endif
199
203
 
200
204
  #define RG_CRITICAL(Cond, ...) \
@@ -3929,6 +3933,8 @@ enum class PipeMode {
3929
3933
  bool CreateOverlappedPipe(bool overlap0, bool overlap1, PipeMode mode, void *out_handles[2]); // HANDLE
3930
3934
  void CloseHandleSafe(void **handle_ptr); // HANDLE
3931
3935
  #else
3936
+ void SetSignalHandler(int signal, void (*func)(int), struct sigaction *prev = nullptr);
3937
+
3932
3938
  bool CreatePipe(int pfd[2]);
3933
3939
  void CloseDescriptorSafe(int *fd_ptr);
3934
3940
  #endif
@@ -316,6 +316,8 @@ GLFWbool _glfwInitEGL(void)
316
316
  "libEGL.dylib",
317
317
  #elif defined(__CYGWIN__)
318
318
  "libEGL-1.so",
319
+ #elif defined(__OpenBSD__) || defined(__NetBSD__)
320
+ "libEGL.so",
319
321
  #else
320
322
  "libEGL.so.1",
321
323
  #endif
@@ -686,6 +688,8 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
686
688
  "libGLES_CM.dll",
687
689
  #elif defined(_GLFW_COCOA)
688
690
  "libGLESv1_CM.dylib",
691
+ #elif defined(__OpenBSD__) || defined(__NetBSD__)
692
+ "libGLESv1_CM.so",
689
693
  #else
690
694
  "libGLESv1_CM.so.1",
691
695
  "libGLES_CM.so.1",
@@ -703,6 +707,8 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
703
707
  "libGLESv2.dylib",
704
708
  #elif defined(__CYGWIN__)
705
709
  "libGLESv2-2.so",
710
+ #elif defined(__OpenBSD__) || defined(__NetBSD__)
711
+ "libGLESv2.so",
706
712
  #else
707
713
  "libGLESv2.so.2",
708
714
  #endif
@@ -124,6 +124,8 @@ GLFWbool _glfwInitOSMesa(void)
124
124
  "libOSMesa.8.dylib",
125
125
  #elif defined(__CYGWIN__)
126
126
  "libOSMesa-8.so",
127
+ #elif defined(__OpenBSD__) || defined(__NetBSD__)
128
+ "libOSMesa.so",
127
129
  #else
128
130
  "libOSMesa.so.8",
129
131
  "libOSMesa.so.6",
@@ -59,6 +59,8 @@ GLFWbool _glfwInitVulkan(int mode)
59
59
  _glfw.vk.handle = _glfw_dlopen("libvulkan.1.dylib");
60
60
  if (!_glfw.vk.handle)
61
61
  _glfw.vk.handle = _glfwLoadLocalVulkanLoaderNS();
62
+ #elif defined(__OpenBSD__) || defined(__NetBSD__)
63
+ _glfw.vk.handle = _glfw_dlopen("libvulkan.so");
62
64
  #else
63
65
  _glfw.vk.handle = _glfw_dlopen("libvulkan.so.1");
64
66
  #endif