ffi 1.16.3 → 1.17.1

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 (96) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +51 -0
  4. data/Gemfile +9 -2
  5. data/README.md +1 -1
  6. data/Rakefile +18 -6
  7. data/ext/ffi_c/AbstractMemory.c +39 -38
  8. data/ext/ffi_c/ArrayType.c +2 -2
  9. data/ext/ffi_c/Buffer.c +4 -4
  10. data/ext/ffi_c/Call.c +12 -6
  11. data/ext/ffi_c/Call.h +3 -2
  12. data/ext/ffi_c/DynamicLibrary.c +2 -2
  13. data/ext/ffi_c/Function.c +52 -34
  14. data/ext/ffi_c/FunctionInfo.c +1 -1
  15. data/ext/ffi_c/LastError.c +4 -4
  16. data/ext/ffi_c/MemoryPointer.c +2 -2
  17. data/ext/ffi_c/Pointer.c +14 -11
  18. data/ext/ffi_c/Struct.c +11 -4
  19. data/ext/ffi_c/StructLayout.c +13 -13
  20. data/ext/ffi_c/Type.c +17 -16
  21. data/ext/ffi_c/Types.c +7 -1
  22. data/ext/ffi_c/Types.h +0 -1
  23. data/ext/ffi_c/Variadic.c +6 -3
  24. data/ext/ffi_c/libffi/.allow-ai-service +0 -0
  25. data/ext/ffi_c/libffi/.github/workflows/build.yml +34 -15
  26. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +2 -1
  27. data/ext/ffi_c/libffi/LICENSE +1 -1
  28. data/ext/ffi_c/libffi/README.md +10 -5
  29. data/ext/ffi_c/libffi/configure +1254 -940
  30. data/ext/ffi_c/libffi/configure.ac +2 -2
  31. data/ext/ffi_c/libffi/configure.host +1 -1
  32. data/ext/ffi_c/libffi/doc/libffi.texi +1 -1
  33. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  34. data/ext/ffi_c/libffi/fficonfig.h.in +6 -6
  35. data/ext/ffi_c/libffi/include/ffi.h.in +2 -11
  36. data/ext/ffi_c/libffi/include/ffi_common.h +4 -2
  37. data/ext/ffi_c/libffi/libffi.map.in +5 -0
  38. data/ext/ffi_c/libffi/libtool-version +1 -1
  39. data/ext/ffi_c/libffi/ltmain.sh +8 -20
  40. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +1 -1
  41. data/ext/ffi_c/libffi/src/aarch64/ffi.c +26 -13
  42. data/ext/ffi_c/libffi/src/aarch64/sysv.S +198 -46
  43. data/ext/ffi_c/libffi/src/closures.c +3 -3
  44. data/ext/ffi_c/libffi/src/debug.c +2 -2
  45. data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
  46. data/ext/ffi_c/libffi/src/loongarch64/ffi.c +3 -0
  47. data/ext/ffi_c/libffi/src/mips/ffi.c +12 -4
  48. data/ext/ffi_c/libffi/src/mips/n32.S +65 -14
  49. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +36 -24
  50. data/ext/ffi_c/libffi/src/sparc/ffi64.c +7 -1
  51. data/ext/ffi_c/libffi/src/tramp.c +1 -1
  52. data/ext/ffi_c/libffi/src/types.c +4 -6
  53. data/ext/ffi_c/libffi/src/wasm32/ffi.c +13 -0
  54. data/ext/ffi_c/libffi/src/x86/ffiw64.c +1 -1
  55. data/ext/ffi_c/libffi/testsuite/Makefile.am +79 -127
  56. data/ext/ffi_c/libffi/testsuite/Makefile.in +79 -127
  57. data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +6 -0
  58. data/ext/ffi_c/libffi/testsuite/libffi.call/callback.c +99 -0
  59. data/ext/ffi_c/libffi/testsuite/libffi.call/callback2.c +108 -0
  60. data/ext/ffi_c/libffi/testsuite/libffi.call/callback3.c +114 -0
  61. data/ext/ffi_c/libffi/testsuite/libffi.call/callback4.c +119 -0
  62. data/ext/ffi_c/libffi.darwin.mk +2 -2
  63. data/lib/ffi/autopointer.rb +1 -9
  64. data/lib/ffi/dynamic_library.rb +34 -5
  65. data/lib/ffi/enum.rb +0 -1
  66. data/lib/ffi/ffi.rb +59 -0
  67. data/lib/ffi/function.rb +1 -1
  68. data/lib/ffi/io.rb +2 -2
  69. data/lib/ffi/library.rb +23 -23
  70. data/lib/ffi/platform/aarch64-linux/types.conf +74 -3
  71. data/lib/ffi/pointer.rb +6 -6
  72. data/lib/ffi/struct.rb +4 -4
  73. data/lib/ffi/struct_layout.rb +2 -2
  74. data/lib/ffi/struct_layout_builder.rb +8 -8
  75. data/lib/ffi/types.rb +51 -49
  76. data/lib/ffi/version.rb +1 -1
  77. data/sig/ffi/abstract_memory.rbs +165 -0
  78. data/sig/ffi/auto_pointer.rbs +26 -0
  79. data/sig/ffi/buffer.rbs +18 -0
  80. data/sig/ffi/data_converter.rbs +10 -0
  81. data/sig/ffi/dynamic_library.rbs +9 -0
  82. data/sig/ffi/enum.rbs +38 -0
  83. data/sig/ffi/function.rbs +39 -0
  84. data/sig/ffi/library.rbs +42 -0
  85. data/sig/ffi/native_type.rbs +86 -0
  86. data/sig/ffi/pointer.rbs +42 -0
  87. data/sig/ffi/struct.rbs +76 -0
  88. data/sig/ffi/struct_by_reference.rbs +11 -0
  89. data/sig/ffi/struct_by_value.rbs +7 -0
  90. data/sig/ffi/struct_layout.rbs +9 -0
  91. data/sig/ffi/struct_layout_builder.rbs +5 -0
  92. data/sig/ffi/type.rbs +39 -0
  93. data/sig/ffi.rbs +26 -0
  94. data.tar.gz.sig +0 -0
  95. metadata +37 -18
  96. metadata.gz.sig +0 -0
@@ -64,6 +64,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
64
64
  #define PTR_SIZE 8
65
65
  #endif
66
66
 
67
+ #define BTI_C hint #34
68
+ #define BTI_J hint #36
69
+ /*
70
+ * The ELF Notes section needs to indicate if BTI is supported, as the first ELF loaded that doesn't
71
+ * declare this support disables it for memory region containing the loaded library.
72
+ */
73
+ # define GNU_PROPERTY_AARCH64_BTI (1 << 0) /* Has Branch Target Identification */
67
74
  .text
68
75
  .align 4
69
76
 
@@ -84,6 +91,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
84
91
 
85
92
  cfi_startproc
86
93
  CNAME(ffi_call_SYSV):
94
+ BTI_C
87
95
  /* Sign the lr with x1 since that is where it will be stored */
88
96
  SIGN_LR_WITH_REG(x1)
89
97
 
@@ -144,78 +152,142 @@ CNAME(ffi_call_SYSV):
144
152
  /* Save the return value as directed. */
145
153
  adr x5, 0f
146
154
  and w4, w4, #AARCH64_RET_MASK
147
- add x5, x5, x4, lsl #3
155
+ add x5, x5, x4, lsl #4
148
156
  br x5
149
157
 
150
- /* Note that each table entry is 2 insns, and thus 8 bytes.
158
+ /* Note that each table entry is 4 insns, and thus 16 bytes.
151
159
  For integer data, note that we're storing into ffi_arg
152
160
  and therefore we want to extend to 64 bits; these types
153
161
  have two consecutive entries allocated for them. */
154
162
  .align 4
155
- 0: b 99f /* VOID */
163
+ 0: BTI_J /* VOID */
164
+ b 99f
165
+ nop
156
166
  nop
157
- 1: str x0, [x3] /* INT64 */
167
+ 1: BTI_J /* INT64 */
168
+ str x0, [x3]
158
169
  b 99f
159
- 2: stp x0, x1, [x3] /* INT128 */
170
+ nop
171
+ 2: BTI_J /* INT128 */
172
+ stp x0, x1, [x3]
160
173
  b 99f
174
+ nop
161
175
  3: brk #1000 /* UNUSED */
162
176
  b 99f
177
+ nop
178
+ nop
163
179
  4: brk #1000 /* UNUSED */
164
180
  b 99f
181
+ nop
182
+ nop
165
183
  5: brk #1000 /* UNUSED */
166
184
  b 99f
185
+ nop
186
+ nop
167
187
  6: brk #1000 /* UNUSED */
168
188
  b 99f
189
+ nop
190
+ nop
169
191
  7: brk #1000 /* UNUSED */
170
192
  b 99f
171
- 8: st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3] /* S4 */
193
+ nop
194
+ nop
195
+ 8: BTI_J /* S4 */
196
+ st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3]
172
197
  b 99f
173
- 9: st3 { v0.s, v1.s, v2.s }[0], [x3] /* S3 */
198
+ nop
199
+ 9: BTI_J /* S3 */
200
+ st3 { v0.s, v1.s, v2.s }[0], [x3]
174
201
  b 99f
175
- 10: stp s0, s1, [x3] /* S2 */
202
+ nop
203
+ 10: BTI_J /* S2 */
204
+ stp s0, s1, [x3]
176
205
  b 99f
177
- 11: str s0, [x3] /* S1 */
206
+ nop
207
+ 11: BTI_J
208
+ str s0, [x3] /* S1 */
178
209
  b 99f
179
- 12: st4 { v0.d, v1.d, v2.d, v3.d }[0], [x3] /* D4 */
210
+ nop
211
+ 12: BTI_J /* D4 */
212
+ st4 { v0.d, v1.d, v2.d, v3.d }[0], [x3]
180
213
  b 99f
181
- 13: st3 { v0.d, v1.d, v2.d }[0], [x3] /* D3 */
214
+ nop
215
+ 13: BTI_J /* D3 */
216
+ st3 { v0.d, v1.d, v2.d }[0], [x3]
182
217
  b 99f
183
- 14: stp d0, d1, [x3] /* D2 */
218
+ nop
219
+ 14: BTI_J /* D2 */
220
+ stp d0, d1, [x3]
184
221
  b 99f
185
- 15: str d0, [x3] /* D1 */
222
+ nop
223
+ 15: BTI_J /* D1 */
224
+ str d0, [x3]
186
225
  b 99f
187
- 16: str q3, [x3, #48] /* Q4 */
188
226
  nop
189
- 17: str q2, [x3, #32] /* Q3 */
227
+ 16: BTI_J /* Q4 */
228
+ str q3, [x3, #48]
190
229
  nop
191
- 18: stp q0, q1, [x3] /* Q2 */
230
+ nop
231
+ 17: BTI_J /* Q3 */
232
+ str q2, [x3, #32]
233
+ nop
234
+ nop
235
+ 18: BTI_J /* Q2 */
236
+ stp q0, q1, [x3]
192
237
  b 99f
193
- 19: str q0, [x3] /* Q1 */
238
+ nop
239
+ 19: BTI_J /* Q1 */
240
+ str q0, [x3]
194
241
  b 99f
195
- 20: uxtb w0, w0 /* UINT8 */
242
+ nop
243
+ 20: BTI_J /* UINT8 */
244
+ uxtb w0, w0
196
245
  str x0, [x3]
246
+ nop
197
247
  21: b 99f /* reserved */
198
248
  nop
199
- 22: uxth w0, w0 /* UINT16 */
249
+ nop
250
+ nop
251
+ 22: BTI_J /* UINT16 */
252
+ uxth w0, w0
200
253
  str x0, [x3]
254
+ nop
201
255
  23: b 99f /* reserved */
202
256
  nop
203
- 24: mov w0, w0 /* UINT32 */
257
+ nop
258
+ nop
259
+ 24: BTI_J /* UINT32 */
260
+ mov w0, w0
204
261
  str x0, [x3]
262
+ nop
205
263
  25: b 99f /* reserved */
206
264
  nop
207
- 26: sxtb x0, w0 /* SINT8 */
265
+ nop
266
+ nop
267
+ 26: BTI_J /* SINT8 */
268
+ sxtb x0, w0
208
269
  str x0, [x3]
270
+ nop
209
271
  27: b 99f /* reserved */
210
272
  nop
211
- 28: sxth x0, w0 /* SINT16 */
273
+ nop
274
+ nop
275
+ 28: BTI_J /* SINT16 */
276
+ sxth x0, w0
212
277
  str x0, [x3]
278
+ nop
213
279
  29: b 99f /* reserved */
214
280
  nop
215
- 30: sxtw x0, w0 /* SINT32 */
281
+ nop
282
+ nop
283
+ 30: BTI_J /* SINT32 */
284
+ sxtw x0, w0
216
285
  str x0, [x3]
286
+ nop
217
287
  31: b 99f /* reserved */
218
288
  nop
289
+ nop
290
+ nop
219
291
 
220
292
  /* Return now that result has been populated. */
221
293
  99:
@@ -252,6 +324,7 @@ CNAME(ffi_call_SYSV):
252
324
  .align 4
253
325
  CNAME(ffi_closure_SYSV_V):
254
326
  cfi_startproc
327
+ BTI_C
255
328
  SIGN_LR
256
329
  stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
257
330
  cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
@@ -276,6 +349,7 @@ CNAME(ffi_closure_SYSV_V):
276
349
  .align 4
277
350
  cfi_startproc
278
351
  CNAME(ffi_closure_SYSV):
352
+ BTI_C
279
353
  SIGN_LR
280
354
  stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
281
355
  cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
@@ -305,73 +379,135 @@ L(do_closure):
305
379
  /* Load the return value as directed. */
306
380
  adr x1, 0f
307
381
  and w0, w0, #AARCH64_RET_MASK
308
- add x1, x1, x0, lsl #3
382
+ add x1, x1, x0, lsl #4
309
383
  add x3, sp, #16+CALL_CONTEXT_SIZE
310
384
  br x1
311
385
 
312
- /* Note that each table entry is 2 insns, and thus 8 bytes. */
386
+ /* Note that each table entry is 4 insns, and thus 16 bytes. */
313
387
  .align 4
314
- 0: b 99f /* VOID */
388
+ 0: BTI_J /* VOID */
389
+ b 99f
390
+ nop
315
391
  nop
316
- 1: ldr x0, [x3] /* INT64 */
392
+ 1: BTI_J /* INT64 */
393
+ ldr x0, [x3]
317
394
  b 99f
318
- 2: ldp x0, x1, [x3] /* INT128 */
395
+ nop
396
+ 2: BTI_J /* INT128 */
397
+ ldp x0, x1, [x3]
319
398
  b 99f
399
+ nop
320
400
  3: brk #1000 /* UNUSED */
321
401
  nop
402
+ nop
403
+ nop
322
404
  4: brk #1000 /* UNUSED */
323
405
  nop
406
+ nop
407
+ nop
324
408
  5: brk #1000 /* UNUSED */
325
409
  nop
410
+ nop
411
+ nop
326
412
  6: brk #1000 /* UNUSED */
327
413
  nop
414
+ nop
415
+ nop
328
416
  7: brk #1000 /* UNUSED */
329
417
  nop
330
- 8: ldr s3, [x3, #12] /* S4 */
331
418
  nop
332
- 9: ldr s2, [x3, #8] /* S3 */
333
419
  nop
334
- 10: ldp s0, s1, [x3] /* S2 */
420
+ 8: BTI_J /* S4 */
421
+ ldr s3, [x3, #12]
422
+ nop
423
+ nop
424
+ 9: BTI_J /* S3 */
425
+ ldr s2, [x3, #8]
426
+ nop
427
+ nop
428
+ 10: BTI_J /* S2 */
429
+ ldp s0, s1, [x3]
335
430
  b 99f
336
- 11: ldr s0, [x3] /* S1 */
431
+ nop
432
+ 11: BTI_J /* S1 */
433
+ ldr s0, [x3]
337
434
  b 99f
338
- 12: ldr d3, [x3, #24] /* D4 */
339
435
  nop
340
- 13: ldr d2, [x3, #16] /* D3 */
436
+ 12: BTI_J /* D4 */
437
+ ldr d3, [x3, #24]
438
+ nop
439
+ nop
440
+ 13: BTI_J /* D3 */
441
+ ldr d2, [x3, #16]
341
442
  nop
342
- 14: ldp d0, d1, [x3] /* D2 */
443
+ nop
444
+ 14: BTI_J /* D2 */
445
+ ldp d0, d1, [x3]
343
446
  b 99f
344
- 15: ldr d0, [x3] /* D1 */
447
+ nop
448
+ 15: BTI_J /* D1 */
449
+ ldr d0, [x3]
345
450
  b 99f
346
- 16: ldr q3, [x3, #48] /* Q4 */
347
451
  nop
348
- 17: ldr q2, [x3, #32] /* Q3 */
452
+ 16: BTI_J /* Q4 */
453
+ ldr q3, [x3, #48]
349
454
  nop
350
- 18: ldp q0, q1, [x3] /* Q2 */
455
+ nop
456
+ 17: BTI_J /* Q3 */
457
+ ldr q2, [x3, #32]
458
+ nop
459
+ nop
460
+ 18: BTI_J /* Q2 */
461
+ ldp q0, q1, [x3]
351
462
  b 99f
352
- 19: ldr q0, [x3] /* Q1 */
463
+ nop
464
+ 19: BTI_J /* Q1 */
465
+ ldr q0, [x3]
353
466
  b 99f
354
- 20: ldrb w0, [x3, #BE(7)] /* UINT8 */
467
+ nop
468
+ 20: BTI_J /* UINT8 */
469
+ ldrb w0, [x3, #BE(7)]
355
470
  b 99f
471
+ nop
356
472
  21: brk #1000 /* reserved */
357
473
  nop
358
- 22: ldrh w0, [x3, #BE(6)] /* UINT16 */
474
+ nop
475
+ nop
476
+ 22: BTI_J /* UINT16 */
477
+ ldrh w0, [x3, #BE(6)]
359
478
  b 99f
479
+ nop
360
480
  23: brk #1000 /* reserved */
361
481
  nop
362
- 24: ldr w0, [x3, #BE(4)] /* UINT32 */
482
+ nop
483
+ nop
484
+ 24: BTI_J /* UINT32 */
485
+ ldr w0, [x3, #BE(4)]
363
486
  b 99f
487
+ nop
364
488
  25: brk #1000 /* reserved */
365
489
  nop
366
- 26: ldrsb x0, [x3, #BE(7)] /* SINT8 */
490
+ nop
491
+ nop
492
+ 26: BTI_J /* SINT8 */
493
+ ldrsb x0, [x3, #BE(7)]
367
494
  b 99f
495
+ nop
368
496
  27: brk #1000 /* reserved */
369
497
  nop
370
- 28: ldrsh x0, [x3, #BE(6)] /* SINT16 */
498
+ nop
499
+ nop
500
+ 28: BTI_J /* SINT16 */
501
+ ldrsh x0, [x3, #BE(6)]
371
502
  b 99f
503
+ nop
372
504
  29: brk #1000 /* reserved */
373
505
  nop
374
- 30: ldrsw x0, [x3, #BE(4)] /* SINT32 */
506
+ nop
507
+ nop
508
+ 30: BTI_J /* SINT32 */
509
+ ldrsw x0, [x3, #BE(4)]
510
+ nop
375
511
  nop
376
512
  31: /* reserved */
377
513
  99: ldp x29, x30, [sp], #ffi_closure_SYSV_FS
@@ -391,6 +527,7 @@ L(do_closure):
391
527
  #if defined(FFI_EXEC_STATIC_TRAMP)
392
528
  .align 4
393
529
  CNAME(ffi_closure_SYSV_V_alt):
530
+ BTI_C
394
531
  /* See the comments above trampoline_code_table. */
395
532
  ldr x17, [sp, #8] /* Load closure in x17 */
396
533
  add sp, sp, #16 /* Restore the stack */
@@ -405,6 +542,7 @@ CNAME(ffi_closure_SYSV_V_alt):
405
542
 
406
543
  .align 4
407
544
  CNAME(ffi_closure_SYSV_alt):
545
+ BTI_C
408
546
  /* See the comments above trampoline_code_table. */
409
547
  ldr x17, [sp, #8] /* Load closure in x17 */
410
548
  add sp, sp, #16 /* Restore the stack */
@@ -485,6 +623,7 @@ CNAME(ffi_closure_trampoline_table_page):
485
623
  .align 4
486
624
  CNAME(ffi_go_closure_SYSV_V):
487
625
  cfi_startproc
626
+ BTI_C
488
627
  stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
489
628
  cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
490
629
  cfi_rel_offset (x29, 0)
@@ -508,6 +647,7 @@ CNAME(ffi_go_closure_SYSV_V):
508
647
  .align 4
509
648
  cfi_startproc
510
649
  CNAME(ffi_go_closure_SYSV):
650
+ BTI_C
511
651
  stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
512
652
  cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
513
653
  cfi_rel_offset (x29, 0)
@@ -539,5 +679,17 @@ CNAME(ffi_go_closure_SYSV):
539
679
 
540
680
  #if defined __ELF__ && defined __linux__
541
681
  .section .note.GNU-stack,"",%progbits
682
+
683
+ .pushsection .note.gnu.property, "a";
684
+ .balign 8;
685
+ .long 4;
686
+ .long 0x10;
687
+ .long 0x5;
688
+ .asciz "GNU";
689
+ .long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
690
+ .long 4;
691
+ .long GNU_PROPERTY_AARCH64_BTI;
692
+ .long 0;
693
+ .popsection;
542
694
  #endif
543
695
 
@@ -599,7 +599,7 @@ open_temp_exec_file_memfd (const char *name)
599
599
 
600
600
  /* Open a temporary file name, and immediately unlink it. */
601
601
  static int
602
- open_temp_exec_file_name (char *name, int flags)
602
+ open_temp_exec_file_name (char *name, int flags MAYBE_UNUSED)
603
603
  {
604
604
  int fd;
605
605
 
@@ -795,7 +795,7 @@ open_temp_exec_file (void)
795
795
  Failure to allocate the space will cause SIGBUS to be thrown when
796
796
  the mapping is subsequently written to. */
797
797
  static int
798
- allocate_space (int fd, off_t offset, off_t len)
798
+ allocate_space (int fd, off_t len)
799
799
  {
800
800
  static long page_size;
801
801
 
@@ -838,7 +838,7 @@ dlmmap_locked (void *start, size_t length, int prot, int flags, off_t offset)
838
838
 
839
839
  offset = execsize;
840
840
 
841
- if (allocate_space (execfd, offset, length))
841
+ if (allocate_space (execfd, length))
842
842
  return MFAIL;
843
843
 
844
844
  flags &= ~(MAP_PRIVATE | MAP_ANONYMOUS);
@@ -38,7 +38,7 @@ void ffi_stop_here(void)
38
38
 
39
39
  /* This function should only be called via the FFI_ASSERT() macro */
40
40
 
41
- void ffi_assert(char *expr, char *file, int line)
41
+ NORETURN void ffi_assert(const char *expr, const char *file, int line)
42
42
  {
43
43
  fprintf(stderr, "ASSERTION FAILURE: %s at %s:%d\n", expr, file, line);
44
44
  ffi_stop_here();
@@ -47,7 +47,7 @@ void ffi_assert(char *expr, char *file, int line)
47
47
 
48
48
  /* Perform a sanity check on an ffi_type structure */
49
49
 
50
- void ffi_type_test(ffi_type *a, char *file, int line)
50
+ void ffi_type_test(ffi_type *a, const char *file, int line)
51
51
  {
52
52
  FFI_ASSERT_AT(a != NULL, file, line);
53
53
 
@@ -4452,7 +4452,7 @@ struct mallinfo dlmallinfo(void) {
4452
4452
  }
4453
4453
  #endif /* NO_MALLINFO */
4454
4454
 
4455
- void dlmalloc_stats() {
4455
+ void dlmalloc_stats(void) {
4456
4456
  internal_malloc_stats(gm);
4457
4457
  }
4458
4458
 
@@ -28,6 +28,7 @@
28
28
 
29
29
  #include <ffi.h>
30
30
  #include <ffi_common.h>
31
+ #include <tramp.h>
31
32
 
32
33
  #include <stdlib.h>
33
34
  #include <stdint.h>
@@ -58,7 +59,9 @@
58
59
  */
59
60
  typedef struct call_context
60
61
  {
62
+ #if !defined(__loongarch_soft_float)
61
63
  ABI_FLOAT fa[8];
64
+ #endif
62
65
  size_t a[10];
63
66
  } call_context;
64
67
 
@@ -647,9 +647,9 @@ static ffi_status ffi_prep_cif_machdep_int(ffi_cif *cif, unsigned nfixedargs)
647
647
 
648
648
  case FFI_TYPE_POINTER:
649
649
  if (cif->abi == FFI_N32_SOFT_FLOAT || cif->abi == FFI_N32)
650
- cif->flags += FFI_TYPE_UINT32 << (FFI_FLAG_BITS * 8);
650
+ cif->flags += FFI_TYPE_SINT32 << (FFI_FLAG_BITS * 8);
651
651
  else
652
- cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
652
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 8);
653
653
  break;
654
654
 
655
655
  case FFI_TYPE_FLOAT:
@@ -661,7 +661,7 @@ static ffi_status ffi_prep_cif_machdep_int(ffi_cif *cif, unsigned nfixedargs)
661
661
  /* else fall through */
662
662
  case FFI_TYPE_DOUBLE:
663
663
  if (soft_float)
664
- cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
664
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 8);
665
665
  else
666
666
  cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 8);
667
667
  break;
@@ -715,8 +715,16 @@ static ffi_status ffi_prep_cif_machdep_int(ffi_cif *cif, unsigned nfixedargs)
715
715
  }
716
716
  break;
717
717
  }
718
+ case FFI_TYPE_UINT32:
719
+ /* In the N32 or N64 ABI unsigned 32-bit integer should be
720
+ *sign*-extended. */
721
+ cif->flags += FFI_TYPE_SINT32 << (FFI_FLAG_BITS * 8);
722
+ break;
723
+ case FFI_TYPE_SINT64:
724
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 8);
725
+ break;
718
726
  default:
719
- cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
727
+ cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 8);
720
728
  break;
721
729
  }
722
730
  }
@@ -236,19 +236,54 @@ callit:
236
236
  # Shift the return type flag over
237
237
  SRL t6, 8*FFI_FLAG_BITS
238
238
 
239
- beq t6, FFI_TYPE_SINT32, retint
240
- bne t6, FFI_TYPE_INT, retuint32
241
- retint:
239
+ bne t6, FFI_TYPE_UINT64, retsint32
240
+
241
+ retuint64:
242
242
  jal t9
243
243
  REG_L t4, 4*FFI_SIZEOF_ARG($fp)
244
- REG_S v0, 0(t4)
244
+ sd v0, 0(t4)
245
245
  b epilogue
246
246
 
247
- retuint32:
248
- bne t6, FFI_TYPE_UINT32, retfloat
247
+ retsint32:
248
+ bne t6, FFI_TYPE_SINT32, retuint16
249
249
  jal t9
250
250
  REG_L t4, 4*FFI_SIZEOF_ARG($fp)
251
- sw v0, 0(t4)
251
+ sll v0, v0, 0
252
+ sd v0, 0(t4)
253
+ b epilogue
254
+
255
+ retuint16:
256
+ bne t6, FFI_TYPE_UINT16, retsint16
257
+ jal t9
258
+ REG_L t4, 4*FFI_SIZEOF_ARG($fp)
259
+ andi v0, v0, 0xffff
260
+ sd v0, 0(t4)
261
+ b epilogue
262
+
263
+ retsint16:
264
+ bne t6, FFI_TYPE_SINT16, retuint8
265
+ jal t9
266
+ REG_L t4, 4*FFI_SIZEOF_ARG($fp)
267
+ dsll v0, v0, 48
268
+ dsra v0, v0, 48
269
+ sd v0, 0(t4)
270
+ b epilogue
271
+
272
+ retuint8:
273
+ bne t6, FFI_TYPE_UINT8, retsint8
274
+ jal t9
275
+ REG_L t4, 4*FFI_SIZEOF_ARG($fp)
276
+ andi v0, v0, 0xff
277
+ sd v0, 0(t4)
278
+ b epilogue
279
+
280
+ retsint8:
281
+ bne t6, FFI_TYPE_SINT8, retfloat
282
+ jal t9
283
+ REG_L t4, 4*FFI_SIZEOF_ARG($fp)
284
+ sd v0, 0(t4)
285
+ dsll v0, v0, 56
286
+ dsra v0, v0, 56
252
287
  b epilogue
253
288
 
254
289
  retfloat:
@@ -585,19 +620,35 @@ $do_closure:
585
620
 
586
621
  jalr t9
587
622
 
623
+ cls_retuint64:
588
624
  # Return flags are in v0
589
- bne v0, FFI_TYPE_SINT32, cls_retuint32
625
+ bne v0, FFI_TYPE_UINT64, cls_retsint32
626
+ ld v0, V0_OFF2($sp)
627
+ b cls_epilogue
628
+
629
+ cls_retsint32:
630
+ bne v0, FFI_TYPE_SINT32, cls_retsint16
590
631
  lw v0, V0_OFF2($sp)
591
632
  b cls_epilogue
592
633
 
593
- cls_retuint32:
594
- bne v0, FFI_TYPE_UINT32, cls_retint
595
- lwu v0, V0_OFF2($sp)
634
+ cls_retsint16:
635
+ bne v0, FFI_TYPE_SINT16, cls_retuint16
636
+ lh v0, V0_OFF2($sp)
596
637
  b cls_epilogue
597
638
 
598
- cls_retint:
599
- bne v0, FFI_TYPE_INT, cls_retfloat
600
- REG_L v0, V0_OFF2($sp)
639
+ cls_retuint16:
640
+ bne v0, FFI_TYPE_UINT16, cls_retsint8
641
+ lhu v0, V0_OFF2($sp)
642
+ b cls_epilogue
643
+
644
+ cls_retsint8:
645
+ bne v0, FFI_TYPE_SINT8, cls_retuint8
646
+ lb v0, V0_OFF2($sp)
647
+ b cls_epilogue
648
+
649
+ cls_retuint8:
650
+ bne v0, FFI_TYPE_UINT8, cls_retfloat
651
+ lbu v0, V0_OFF2($sp)
601
652
  b cls_epilogue
602
653
 
603
654
  cls_retfloat: