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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
#![allow(non_camel_case_types)]
use crate::{Char, Value};

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct caml_ref_table {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct caml_ephe_ref_table {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct caml_custom_table {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct longjmp_buffer {
    pub _address: u8,
}

pub type backtrace_slot = *mut ::core::ffi::c_void;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct caml_domain_state {
    pub _young_ptr: *mut Value,
    pub _young_limit: *mut Value,
    pub _exception_pointer: *mut Char,
    pub _young_base: *mut ::core::ffi::c_void,
    pub _young_start: *mut Value,
    pub _young_end: *mut Value,
    pub _young_alloc_start: *mut Value,
    pub _young_alloc_end: *mut Value,
    pub _young_alloc_mid: *mut Value,
    pub _young_trigger: *mut Value,
    pub _minor_heap_wsz: usize,
    pub _in_minor_collection: isize,
    pub _extra_heap_resources_minor: f64,
    pub _ref_table: *mut caml_ref_table,
    pub _ephe_ref_table: *mut caml_ephe_ref_table,
    pub _custom_table: *mut caml_custom_table,
    pub _stack_low: *mut Value,
    pub _stack_high: *mut Value,
    pub _stack_threshold: *mut Value,
    pub _extern_sp: *mut Value,
    pub _trapsp: *mut Value,
    pub _trap_barrier: *mut Value,
    pub _external_raise: *mut longjmp_buffer,
    pub _exn_bucket: Value,
    pub _top_of_stack: *mut Char,
    pub _bottom_of_stack: *mut Char,
    pub _last_return_address: usize,
    pub _gc_regs: *mut Value,
    pub _backtrace_active: isize,
    pub _backtrace_pos: isize,
    pub _backtrace_buffer: *mut backtrace_slot,
    pub _backtrace_last_exn: Value,
    pub _compare_unordered: isize,
    pub _requested_major_slice: isize,
    pub _requested_minor_gc: isize,
    pub _local_roots: *mut crate::memory::CamlRootsBlock,
    pub _stat_minor_words: f64,
    pub _stat_promoted_words: f64,
    pub _stat_major_words: f64,
    pub _stat_minor_collections: isize,
    pub _stat_major_collections: isize,
    pub _stat_heap_wsz: isize,
    pub _stat_top_heap_wsz: isize,
    pub _stat_compactions: isize,
    pub _stat_heap_chunks: isize,
}

#[cfg(caml_state)]
extern "C" {

    #[doc(hidden)]
    pub static mut Caml_state: *mut caml_domain_state;
}

#[cfg(not(caml_state))]
extern "C" {

    #[doc(hidden)]
    pub static mut caml_local_roots: *mut crate::memory::CamlRootsBlock;
}

#[cfg(caml_state)]
#[doc(hidden)]
pub unsafe fn local_roots() -> *mut crate::memory::CamlRootsBlock {
    (*Caml_state)._local_roots
}

#[cfg(caml_state)]
#[doc(hidden)]
pub unsafe fn set_local_roots(x: *mut crate::memory::CamlRootsBlock) {
    (*Caml_state)._local_roots = x
}

#[cfg(not(caml_state))]
#[doc(hidden)]
pub unsafe fn local_roots() -> *mut crate::memory::CamlRootsBlock {
    caml_local_roots
}

#[cfg(not(caml_state))]
#[doc(hidden)]
pub unsafe fn set_local_roots(x: *mut crate::memory::CamlRootsBlock) {
    caml_local_roots = x
}

#[test]
fn bindgen_test_layout_caml_domain_state() {
    assert_eq!(
        ::core::mem::size_of::<caml_domain_state>(),
        360usize,
        concat!("Size of: ", stringify!(caml_domain_state))
    );
    assert_eq!(
        ::core::mem::align_of::<caml_domain_state>(),
        8usize,
        concat!("Alignment of ", stringify!(caml_domain_state))
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._young_ptr as *const _ as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_ptr)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._young_limit as *const _ as usize },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_limit)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._exception_pointer as *const _ as usize
        },
        16usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_exception_pointer)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._young_base as *const _ as usize },
        24usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_base)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._young_start as *const _ as usize },
        32usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_start)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._young_end as *const _ as usize },
        40usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_end)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._young_alloc_start as *const _ as usize
        },
        48usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_alloc_start)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._young_alloc_end as *const _ as usize
        },
        56usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_alloc_end)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._young_alloc_mid as *const _ as usize
        },
        64usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_alloc_mid)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._young_trigger as *const _ as usize
        },
        72usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_young_trigger)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._minor_heap_wsz as *const _ as usize
        },
        80usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_minor_heap_wsz)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._in_minor_collection as *const _ as usize
        },
        88usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_in_minor_collection)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._extra_heap_resources_minor as *const _
                as usize
        },
        96usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_extra_heap_resources_minor)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._ref_table as *const _ as usize },
        104usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_ref_table)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._ephe_ref_table as *const _ as usize
        },
        112usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_ephe_ref_table)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._custom_table as *const _ as usize
        },
        120usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_custom_table)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._stack_low as *const _ as usize },
        128usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stack_low)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._stack_high as *const _ as usize },
        136usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stack_high)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stack_threshold as *const _ as usize
        },
        144usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stack_threshold)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._extern_sp as *const _ as usize },
        152usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_extern_sp)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._trapsp as *const _ as usize },
        160usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_trapsp)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._trap_barrier as *const _ as usize
        },
        168usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_trap_barrier)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._external_raise as *const _ as usize
        },
        176usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_external_raise)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._exn_bucket as *const _ as usize },
        184usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_exn_bucket)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._top_of_stack as *const _ as usize
        },
        192usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_top_of_stack)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._bottom_of_stack as *const _ as usize
        },
        200usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_bottom_of_stack)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._last_return_address as *const _ as usize
        },
        208usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_last_return_address)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._gc_regs as *const _ as usize },
        216usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_gc_regs)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._backtrace_active as *const _ as usize
        },
        224usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_backtrace_active)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._backtrace_pos as *const _ as usize
        },
        232usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_backtrace_pos)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._backtrace_buffer as *const _ as usize
        },
        240usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_backtrace_buffer)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._backtrace_last_exn as *const _ as usize
        },
        248usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_backtrace_last_exn)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._compare_unordered as *const _ as usize
        },
        256usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_compare_unordered)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._requested_major_slice as *const _
                as usize
        },
        264usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_requested_major_slice)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._requested_minor_gc as *const _ as usize
        },
        272usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_requested_minor_gc)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<caml_domain_state>()))._local_roots as *const _ as usize },
        280usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_local_roots)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_minor_words as *const _ as usize
        },
        288usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_minor_words)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_promoted_words as *const _ as usize
        },
        296usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_promoted_words)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_major_words as *const _ as usize
        },
        304usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_major_words)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_minor_collections as *const _
                as usize
        },
        312usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_minor_collections)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_major_collections as *const _
                as usize
        },
        320usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_major_collections)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_heap_wsz as *const _ as usize
        },
        328usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_heap_wsz)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_top_heap_wsz as *const _ as usize
        },
        336usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_top_heap_wsz)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_compactions as *const _ as usize
        },
        344usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_compactions)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<caml_domain_state>()))._stat_heap_chunks as *const _ as usize
        },
        352usize,
        concat!(
            "Offset of field: ",
            stringify!(caml_domain_state),
            "::",
            stringify!(_stat_heap_chunks)
        )
    );
}