about summary refs log tree commit diff
path: root/src/libstd/uv_ll.rs
blob: 0f52664a8155cd278009cb3e6d758371164f6c1a (plain)
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
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
#[doc = "
Low-level bindings to the libuv library.

This module contains a set of direct, 'bare-metal' wrappers around
the libuv C-API.

Also contained herein are a set of rust records that map, in
approximate memory-size, to the libuv data structures. The record
implementations are adjusted, per-platform, to match their respective
representations.

There are also a collection of helper functions to ease interacting
with the low-level API (such as a function to return the latest
libuv error as a rust-formatted string).

As new functionality, existant in uv.h, is added to the rust stdlib,
the mappings should be added in this module.

This module's implementation will hopefully be, eventually, replaced
with per-platform, generated source files from rust-bindgen.
"];

// libuv struct mappings
type uv_ip4_addr = {
    ip: [u8],
    port: int
};
type uv_ip6_addr = uv_ip4_addr;

enum uv_handle_type {
    UNKNOWN_HANDLE = 0,
    UV_TCP,
    UV_UDP,
    UV_NAMED_PIPE,
    UV_TTY,
    UV_FILE,
    UV_TIMER,
    UV_PREPARE,
    UV_CHECK,
    UV_IDLE,
    UV_ASYNC,
    UV_ARES_TASK,
    UV_ARES_EVENT,
    UV_PROCESS,
    UV_FS_EVENT
}

type handle_type = libc::c_uint;

type uv_handle_fields = {
   loop_handle: *libc::c_void,
   type_: handle_type,
   close_cb: *u8,
   mut data: *libc::c_void,
};

// unix size: 8
type uv_err_t = {
    code: libc::c_int,
    sys_errno_: libc::c_int
};

// don't create one of these directly. instead,
// count on it appearing in libuv callbacks or embedded
// in other types as a pointer to be used in other
// operations (so mostly treat it as opaque, once you
// have it in this form..)
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "win32")]
type uv_stream_t = {
    fields: uv_handle_fields
};

// 64bit unix size: 272
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
type uv_tcp_t = {
    fields: uv_handle_fields,
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8, a10: *u8, a11: *u8,
    a12: *u8, a13: *u8, a14: *u8, a15: *u8,
    a16: *u8, a17: *u8, a18: *u8, a19: *u8,
    a20: *u8, a21: *u8, a22: *u8, a23: *u8,
    a24: *u8, a25: *u8, a26: *u8, a27: *u8,
    a28: *u8,
    a30: uv_tcp_t_32bit_unix_riders
};
// 32bit unix size: 328 (164)
#[cfg(target_arch="x86_64")]
type uv_tcp_t_32bit_unix_riders = {
    a29: *u8
};
#[cfg(target_arch="x86")]
type uv_tcp_t_32bit_unix_riders = {
    a29: *u8, a30: *u8, a31: *u8,
    a32: *u8, a33: *u8, a34: *u8,
    a35: *u8, a36: *u8
};

// 32bit win32 size: 240 (120)
#[cfg(target_os = "win32")]
type uv_tcp_t = {
    fields: uv_handle_fields,
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8, a10: *u8, a11: *u8,
    a12: *u8, a13: *u8, a14: *u8, a15: *u8,
    a16: *u8, a17: *u8, a18: *u8, a19: *u8,
    a20: *u8, a21: *u8, a22: *u8, a23: *u8,
    a24: *u8, a25: *u8
};

// unix size: 48
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
type uv_connect_t = {
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8
};
// win32 size: 88 (44)
#[cfg(target_os = "win32")]
type uv_connect_t = {
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8, a10: *u8
};

// unix size: 16
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "win32")]
type uv_buf_t = {
    base: *u8,
    len: libc::size_t
};
// no gen stub method.. should create
// it via uv::direct::buf_init()

// unix size: 144
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
type uv_write_t = {
    fields: uv_handle_fields,
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8, a10: *u8, a11: *u8,
    a12: *u8,
    a14: uv_write_t_32bit_unix_riders
};
#[cfg(target_arch="x86_64")]
type uv_write_t_32bit_unix_riders = {
    a13: *u8
};
#[cfg(target_arch="x86")]
type uv_write_t_32bit_unix_riders = {
    a13: *u8, a14: *u8
};
// win32 size: 136 (68)
#[cfg(target_os = "win32")]
type uv_write_t = {
    fields: uv_handle_fields,
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8, a10: *u8, a11: *u8,
    a12: *u8
};
// 64bit unix size: 120
// 32bit unix size: 152 (76)
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
type uv_async_t = {
    fields: uv_handle_fields,
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8,
    a11: uv_async_t_32bit_unix_riders
};
#[cfg(target_arch="x86_64")]
type uv_async_t_32bit_unix_riders = {
    a10: *u8
};
#[cfg(target_arch="x86")]
type uv_async_t_32bit_unix_riders = {
    a10: *u8, a11: *u8, a12: *u8, a13: *u8
};
// win32 size 132 (68)
#[cfg(target_os = "win32")]
type uv_async_t = {
    fields: uv_handle_fields,
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8, a10: *u8, a11: *u8,
    a12: *u8
};

// 64bit unix size: 128
// 32bit unix size: 84
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
type uv_timer_t = {
    fields: uv_handle_fields,
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8,
    a11: uv_timer_t_32bit_unix_riders
};
#[cfg(target_arch="x86_64")]
type uv_timer_t_32bit_unix_riders = {
    a10: *u8, a11: *u8
};
#[cfg(target_arch="x86")]
type uv_timer_t_32bit_unix_riders = {
    a10: *u8, a11: *u8, a12: *u8, a13: *u8,
    a14: *u8, a15: *u8, a16: *u8
};
// win32 size: 64
#[cfg(target_os = "win32")]
type uv_timer_t = {
    fields: uv_handle_fields,
    a00: *u8, a01: *u8, a02: *u8, a03: *u8,
    a04: *u8, a05: *u8, a06: *u8, a07: *u8,
    a08: *u8, a09: *u8, a10: *u8, a11: *u8
};

// unix size: 16
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "win32")]
type sockaddr_in = {
    mut sin_family: u16,
    mut sin_port: u16,
    mut sin_addr: u32, // in_addr: this is an opaque, per-platform struct
    mut sin_zero: (u8, u8, u8, u8, u8, u8, u8, u8)
};

// unix size: 28 .. make due w/ 32
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "win32")]
type sockaddr_in6 = {
    a0: *u8, a1: *u8,
    a2: *u8, a3: *u8
};

mod uv_ll_struct_stubgen {
    fn gen_stub_uv_tcp_t() -> uv_tcp_t {
        ret gen_stub_os();
        #[cfg(target_os = "linux")]
        #[cfg(target_os = "macos")]
        #[cfg(target_os = "freebsd")]
        fn gen_stub_os() -> uv_tcp_t {
            ret gen_stub_arch();
            #[cfg(target_arch="x86_64")]
            fn gen_stub_arch() -> uv_tcp_t {
                ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                                close_cb: ptr::null(),
                                mut data: ptr::null() },
                    a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                    a03: 0 as *u8,
                    a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                    a07: 0 as *u8,
                    a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
                    a11: 0 as *u8,
                    a12: 0 as *u8, a13: 0 as *u8, a14: 0 as *u8,
                    a15: 0 as *u8,
                    a16: 0 as *u8, a17: 0 as *u8, a18: 0 as *u8,
                    a19: 0 as *u8,
                    a20: 0 as *u8, a21: 0 as *u8, a22: 0 as *u8,
                    a23: 0 as *u8,
                    a24: 0 as *u8, a25: 0 as *u8, a26: 0 as *u8,
                    a27: 0 as *u8,
                    a28: 0 as *u8,
                    a30: {
                        a29: 0 as *u8
                    }
                };
            }
            #[cfg(target_arch="x86")]
            fn gen_stub_arch() -> uv_tcp_t {
                ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                                close_cb: ptr::null(),
                                mut data: ptr::null() },
                    a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                    a03: 0 as *u8,
                    a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                    a07: 0 as *u8,
                    a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
                    a11: 0 as *u8,
                    a12: 0 as *u8, a13: 0 as *u8, a14: 0 as *u8,
                    a15: 0 as *u8,
                    a16: 0 as *u8, a17: 0 as *u8, a18: 0 as *u8,
                    a19: 0 as *u8,
                    a20: 0 as *u8, a21: 0 as *u8, a22: 0 as *u8,
                    a23: 0 as *u8,
                    a24: 0 as *u8, a25: 0 as *u8, a26: 0 as *u8,
                    a27: 0 as *u8,
                    a28: 0 as *u8,
                    a30: {
                        a29: 0 as *u8, a30: 0 as *u8, a31: 0 as *u8,
                        a32: 0 as *u8, a33: 0 as *u8, a34: 0 as *u8,
                        a35: 0 as *u8, a36: 0 as *u8
                    }
                };
            }
        }
        #[cfg(target_os = "win32")]
        fn gen_stub_os() -> uv_tcp_t {
            ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                            close_cb: ptr::null(),
                            mut data: ptr::null() },
                a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                a03: 0 as *u8,
                a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                a07: 0 as *u8,
                a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
                a11: 0 as *u8,
                a12: 0 as *u8, a13: 0 as *u8, a14: 0 as *u8,
                a15: 0 as *u8,
                a16: 0 as *u8, a17: 0 as *u8, a18: 0 as *u8,
                a19: 0 as *u8,
                a20: 0 as *u8, a21: 0 as *u8, a22: 0 as *u8,
                a23: 0 as *u8,
                a24: 0 as *u8, a25: 0 as *u8
            };
        }
    }
    #[cfg(target_os = "linux")]
    #[cfg(target_os = "macos")]
    #[cfg(target_os = "freebsd")]
    fn gen_stub_uv_connect_t() -> uv_connect_t {
        ret {
            a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
            a03: 0 as *u8,
            a04: 0 as *u8, a05: 0 as *u8
        };
    }
    #[cfg(target_os = "win32")]
    fn gen_stub_uv_connect_t() -> uv_connect_t {
        ret {
            a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
            a03: 0 as *u8,
            a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
            a07: 0 as *u8,
            a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8
        };
    }
    #[cfg(target_os = "linux")]
    #[cfg(target_os = "macos")]
    #[cfg(target_os = "freebsd")]
    fn gen_stub_uv_async_t() -> uv_async_t {
        ret gen_stub_arch();
        #[cfg(target_arch = "x86_64")]
        fn gen_stub_arch() -> uv_async_t {
            ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                            close_cb: ptr::null(),
                            mut data: ptr::null() },
                a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                a03: 0 as *u8,
                a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                a07: 0 as *u8,
                a08: 0 as *u8, a09: 0 as *u8,
                a11: {
                    a10: 0 as *u8
                }
            };
        }
        #[cfg(target_arch = "x86")]
        fn gen_stub_arch() -> uv_async_t {
            ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                            close_cb: ptr::null(),
                            mut data: ptr::null() },
                a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                a03: 0 as *u8,
                a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                a07: 0 as *u8,
                a08: 0 as *u8, a09: 0 as *u8,
                a11: {
                    a10: 0 as *u8, a11: 0 as *u8,
                    a12: 0 as *u8, a13: 0 as *u8
                }
            };
        }
    }
    #[cfg(target_os = "win32")]
    fn gen_stub_uv_async_t() -> uv_async_t {
        ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                        close_cb: ptr::null(),
                        mut data: ptr::null() },
            a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
            a03: 0 as *u8,
            a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
            a07: 0 as *u8,
            a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
            a11: 0 as *u8,
            a12: 0 as *u8
        };
    }
    #[cfg(target_os = "linux")]
    #[cfg(target_os = "macos")]
    #[cfg(target_os = "freebsd")]
    fn gen_stub_uv_timer_t() -> uv_timer_t {
        ret gen_stub_arch();
        #[cfg(target_arch = "x86_64")]
        fn gen_stub_arch() -> uv_timer_t {
            ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                            close_cb: ptr::null(),
                            mut data: ptr::null() },
                a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                a03: 0 as *u8,
                a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                a07: 0 as *u8,
                a08: 0 as *u8, a09: 0 as *u8,
                a11: {
                    a10: 0 as *u8, a11: 0 as *u8
                }
            };
        }
        #[cfg(target_arch = "x86")]
        fn gen_stub_arch() -> uv_timer_t {
            ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                            close_cb: ptr::null(),
                            mut data: ptr::null() },
                a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                a03: 0 as *u8,
                a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                a07: 0 as *u8,
                a08: 0 as *u8, a09: 0 as *u8,
                a11: {
                    a10: 0 as *u8, a11: 0 as *u8,
                    a12: 0 as *u8, a13: 0 as *u8,
                    a14: 0 as *u8, a15: 0 as *u8,
                    a16: 0 as *u8
                }
            };
        }
    }
    #[cfg(target_os = "win32")]
    fn gen_stub_uv_timer_t() -> uv_timer_t {
        ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                        close_cb: ptr::null(),
                        mut data: ptr::null() },
            a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
            a03: 0 as *u8,
            a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
            a07: 0 as *u8,
            a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
            a11: 0 as *u8
        };
    }
    #[cfg(target_os = "linux")]
    #[cfg(target_os = "macos")]
    #[cfg(target_os = "freebsd")]
    fn gen_stub_uv_write_t() -> uv_write_t {
        ret gen_stub_arch();
        #[cfg(target_arch="x86_64")]
        fn gen_stub_arch() -> uv_write_t {
            ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                            close_cb: ptr::null(),
                            mut data: ptr::null() },
                a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                a03: 0 as *u8,
                a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                a07: 0 as *u8,
                a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
                a11: 0 as *u8,
                a12: 0 as *u8, a14: { a13: 0 as *u8 }
            };
        }
        #[cfg(target_arch="x86")]
        fn gen_stub_arch() -> uv_write_t {
            ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                            close_cb: ptr::null(),
                            mut data: ptr::null() },
                a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
                a03: 0 as *u8,
                a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
                a07: 0 as *u8,
                a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
                a11: 0 as *u8,
                a12: 0 as *u8, a14: { a13: 0 as *u8, a14: 0 as *u8 }
            };
        }
    }
    #[cfg(target_os = "win32")]
    fn gen_stub_uv_write_t() -> uv_write_t {
        ret { fields: { loop_handle: ptr::null(), type_: 0u32,
                        close_cb: ptr::null(),
                        mut data: ptr::null() },
            a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
            a03: 0 as *u8,
            a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
            a07: 0 as *u8,
            a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8,
            a11: 0 as *u8,
            a12: 0 as *u8
        };
    }
}

#[nolink]
native mod rustrt {
    fn rust_uv_loop_new() -> *libc::c_void;
    fn rust_uv_loop_delete(lp: *libc::c_void);
    fn rust_uv_run(loop_handle: *libc::c_void);
    fn rust_uv_close(handle: *libc::c_void, cb: *u8);
    fn rust_uv_async_send(handle: *uv_async_t);
    fn rust_uv_async_init(loop_handle: *libc::c_void,
                          async_handle: *uv_async_t,
                          cb: *u8) -> libc::c_int;
    fn rust_uv_tcp_init(
        loop_handle: *libc::c_void,
        handle_ptr: *uv_tcp_t) -> libc::c_int;
    // FIXME ref #2604 .. ?
    fn rust_uv_buf_init(out_buf: *uv_buf_t, base: *u8,
                        len: libc::size_t);
    fn rust_uv_last_error(loop_handle: *libc::c_void) -> uv_err_t;
    // FIXME ref #2064
    fn rust_uv_strerror(err: *uv_err_t) -> *libc::c_char;
    // FIXME ref #2064
    fn rust_uv_err_name(err: *uv_err_t) -> *libc::c_char;
    fn rust_uv_ip4_addr(ip: *u8, port: libc::c_int)
        -> sockaddr_in;
    // FIXME ref #2064
    fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t,
                           tcp_handle_ptr: *uv_tcp_t,
                           ++after_cb: *u8,
                           ++addr: *sockaddr_in) -> libc::c_int;
    // FIXME ref 2064
    fn rust_uv_tcp_bind(tcp_server: *uv_tcp_t,
                        ++addr: *sockaddr_in) -> libc::c_int;
    fn rust_uv_listen(stream: *libc::c_void, backlog: libc::c_int,
                      cb: *u8) -> libc::c_int;
    fn rust_uv_accept(server: *libc::c_void, client: *libc::c_void)
        -> libc::c_int;
    fn rust_uv_write(req: *libc::c_void, stream: *libc::c_void,
             ++buf_in: *uv_buf_t, buf_cnt: libc::c_int,
             cb: *u8) -> libc::c_int;
    fn rust_uv_read_start(stream: *libc::c_void, on_alloc: *u8,
                          on_read: *u8) -> libc::c_int;
    fn rust_uv_read_stop(stream: *libc::c_void) -> libc::c_int;
    fn rust_uv_timer_init(loop_handle: *libc::c_void,
                          timer_handle: *uv_timer_t) -> libc::c_int;
    fn rust_uv_timer_start(
        timer_handle: *uv_timer_t,
        cb: *u8,
        timeout: libc::c_uint,
        repeat: libc::c_uint) -> libc::c_int;
    fn rust_uv_timer_stop(handle: *uv_timer_t) -> libc::c_int;

    // data accessors/helpers for rust-mapped uv structs
    fn rust_uv_malloc_buf_base_of(sug_size: libc::size_t) -> *u8;
    fn rust_uv_free_base_of_buf(++buf: uv_buf_t);
    fn rust_uv_get_stream_handle_from_connect_req(
        connect_req: *uv_connect_t)
        -> *uv_stream_t;
    fn rust_uv_get_stream_handle_from_write_req(
        write_req: *uv_write_t)
        -> *uv_stream_t;
    fn rust_uv_get_loop_for_uv_handle(handle: *libc::c_void)
        -> *libc::c_void;
    fn rust_uv_get_data_for_uv_loop(loop_ptr: *libc::c_void) -> *libc::c_void;
    fn rust_uv_set_data_for_uv_loop(loop_ptr: *libc::c_void,
                                    data: *libc::c_void);
    fn rust_uv_get_data_for_uv_handle(handle: *libc::c_void)
        -> *libc::c_void;
    fn rust_uv_set_data_for_uv_handle(handle: *libc::c_void,
                                      data: *libc::c_void);
    fn rust_uv_get_data_for_req(req: *libc::c_void) -> *libc::c_void;
    fn rust_uv_set_data_for_req(req: *libc::c_void,
                                data: *libc::c_void);
    fn rust_uv_get_base_from_buf(++buf: uv_buf_t) -> *u8;
    fn rust_uv_get_len_from_buf(++buf: uv_buf_t) -> libc::size_t;
}

unsafe fn loop_new() -> *libc::c_void {
    ret rustrt::rust_uv_loop_new();
}

unsafe fn loop_delete(loop_handle: *libc::c_void) {
    rustrt::rust_uv_loop_delete(loop_handle);
}

unsafe fn run(loop_handle: *libc::c_void) {
    rustrt::rust_uv_run(loop_handle);
}

unsafe fn close<T>(handle: *T, cb: *u8) {
    rustrt::rust_uv_close(handle as *libc::c_void, cb);
}

unsafe fn tcp_init(loop_handle: *libc::c_void, handle: *uv_tcp_t)
    -> libc::c_int {
    ret rustrt::rust_uv_tcp_init(loop_handle, handle);
}
// FIXME ref #2064
unsafe fn tcp_connect(connect_ptr: *uv_connect_t,
                      tcp_handle_ptr: *uv_tcp_t,
                      addr_ptr: *sockaddr_in,
                      ++after_connect_cb: *u8)
-> libc::c_int {
    let address = *addr_ptr;
    log(debug, #fmt("b4 native tcp_connect--addr port: %u cb: %u",
                     address.sin_port as uint, after_connect_cb as uint));
    ret rustrt::rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr,
                                after_connect_cb, addr_ptr);
}
// FIXME ref #2064
unsafe fn tcp_bind(tcp_server_ptr: *uv_tcp_t,
                   addr_ptr: *sockaddr_in) -> libc::c_int {
    ret rustrt::rust_uv_tcp_bind(tcp_server_ptr,
                                 addr_ptr);
}

unsafe fn listen(stream: *libc::c_void, backlog: libc::c_int,
                 cb: *u8) -> libc::c_int {
    ret rustrt::rust_uv_listen(stream, backlog, cb);
}

unsafe fn accept(server: *libc::c_void, client: *libc::c_void)
    -> libc::c_int {
    ret rustrt::rust_uv_accept(server, client);
}

unsafe fn write(req: *libc::c_void, stream: *libc::c_void,
         buf_in: *[uv_buf_t], cb: *u8) -> libc::c_int {
    let buf_ptr = vec::unsafe::to_ptr(*buf_in);
    let buf_cnt = vec::len(*buf_in) as i32;
    ret rustrt::rust_uv_write(req, stream, buf_ptr, buf_cnt, cb);
}
unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8,
                     on_read: *u8) -> libc::c_int {
    ret rustrt::rust_uv_read_start(stream as *libc::c_void,
                                   on_alloc, on_read);
}

unsafe fn read_stop(stream: *uv_stream_t) -> libc::c_int {
    ret rustrt::rust_uv_read_stop(stream as *libc::c_void);
}

unsafe fn last_error(loop_handle: *libc::c_void) -> uv_err_t {
    ret rustrt::rust_uv_last_error(loop_handle);
}

unsafe fn strerror(err: *uv_err_t) -> *libc::c_char {
    ret rustrt::rust_uv_strerror(err);
}
unsafe fn err_name(err: *uv_err_t) -> *libc::c_char {
    ret rustrt::rust_uv_err_name(err);
}

unsafe fn async_init(loop_handle: *libc::c_void,
                     async_handle: *uv_async_t,
                     cb: *u8) -> libc::c_int {
    ret rustrt::rust_uv_async_init(loop_handle,
                                   async_handle,
                                   cb);
}

unsafe fn async_send(async_handle: *uv_async_t) {
    ret rustrt::rust_uv_async_send(async_handle);
}
unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
    let out_buf = { base: ptr::null(), len: 0 as libc::size_t };
    let out_buf_ptr = ptr::addr_of(out_buf);
    log(debug, #fmt("ll::buf_init - input %u len %u out_buf: %u",
                     input as uint,
                     len as uint,
                     out_buf_ptr as uint));
    // yuck :/
    rustrt::rust_uv_buf_init(out_buf_ptr, input, len);
    //let result = rustrt::rust_uv_buf_init_2(input, len);
    log(debug, "after rust_uv_buf_init");
    let res_base = get_base_from_buf(out_buf);
    let res_len = get_len_from_buf(out_buf);
    //let res_base = get_base_from_buf(result);
    log(debug, #fmt("ll::buf_init - result %u len %u",
                     res_base as uint,
                     res_len as uint));
    ret out_buf;
    //ret result;
}
unsafe fn ip4_addr(ip: str, port: int)
-> sockaddr_in {
    let mut addr_vec = str::bytes(ip);
    addr_vec += [0u8]; // add null terminator
    let addr_vec_ptr = vec::unsafe::to_ptr(addr_vec);
    let ip_back = str::from_bytes(addr_vec);
    log(debug, #fmt("vec val: '%s' length: %u",
                     ip_back, vec::len(addr_vec)));
    ret rustrt::rust_uv_ip4_addr(addr_vec_ptr,
                                 port as libc::c_int);
}

unsafe fn timer_init(loop_ptr: *libc::c_void,
                     timer_ptr: *uv_timer_t) -> libc::c_int {
    ret rustrt::rust_uv_timer_init(loop_ptr, timer_ptr);
}
unsafe fn timer_start(timer_ptr: *uv_timer_t, cb: *u8, timeout: uint,
                      repeat: uint) -> libc::c_int {
    ret rustrt::rust_uv_timer_start(timer_ptr, cb, timeout as libc::c_uint,
                                    repeat as libc::c_uint);
}
unsafe fn timer_stop(timer_ptr: *uv_timer_t) -> libc::c_int {
    ret rustrt::rust_uv_timer_stop(timer_ptr);
}

// libuv struct initializers
unsafe fn tcp_t() -> uv_tcp_t {
    ret uv_ll_struct_stubgen::gen_stub_uv_tcp_t();
}
unsafe fn connect_t() -> uv_connect_t {
    ret uv_ll_struct_stubgen::gen_stub_uv_connect_t();
}
unsafe fn write_t() -> uv_write_t {
    ret uv_ll_struct_stubgen::gen_stub_uv_write_t();
}
unsafe fn async_t() -> uv_async_t {
    ret uv_ll_struct_stubgen::gen_stub_uv_async_t();
}
unsafe fn timer_t() -> uv_timer_t {
    ret uv_ll_struct_stubgen::gen_stub_uv_timer_t();
}

// data access helpers
unsafe fn get_loop_for_uv_handle<T>(handle: *T)
    -> *libc::c_void {
    ret rustrt::rust_uv_get_loop_for_uv_handle(handle as *libc::c_void);
}
unsafe fn get_stream_handle_from_connect_req(connect: *uv_connect_t)
    -> *uv_stream_t {
    ret rustrt::rust_uv_get_stream_handle_from_connect_req(
        connect);
}
unsafe fn get_stream_handle_from_write_req(
    write_req: *uv_write_t)
    -> *uv_stream_t {
    ret rustrt::rust_uv_get_stream_handle_from_write_req(
        write_req);
}
unsafe fn get_data_for_uv_loop(loop_ptr: *libc::c_void) -> *libc::c_void {
    rustrt::rust_uv_get_data_for_uv_loop(loop_ptr)
}
unsafe fn set_data_for_uv_loop(loop_ptr: *libc::c_void, data: *libc::c_void) {
    rustrt::rust_uv_set_data_for_uv_loop(loop_ptr, data);
}
unsafe fn get_data_for_uv_handle<T>(handle: *T) -> *libc::c_void {
    ret rustrt::rust_uv_get_data_for_uv_handle(handle as *libc::c_void);
}
unsafe fn set_data_for_uv_handle<T, U>(handle: *T,
                    data: *U) {
    rustrt::rust_uv_set_data_for_uv_handle(handle as *libc::c_void,
                                           data as *libc::c_void);
}
unsafe fn get_data_for_req(req: *libc::c_void) -> *libc::c_void {
    ret rustrt::rust_uv_get_data_for_req(req);
}
unsafe fn set_data_for_req(req: *libc::c_void,
                    data: *libc::c_void) {
    rustrt::rust_uv_set_data_for_req(req, data);
}
unsafe fn get_base_from_buf(buf: uv_buf_t) -> *u8 {
    ret rustrt::rust_uv_get_base_from_buf(buf);
}
unsafe fn get_len_from_buf(buf: uv_buf_t) -> libc::size_t {
    ret rustrt::rust_uv_get_len_from_buf(buf);
}
unsafe fn malloc_buf_base_of(suggested_size: libc::size_t)
    -> *u8 {
    ret rustrt::rust_uv_malloc_buf_base_of(suggested_size);
}
unsafe fn free_base_of_buf(buf: uv_buf_t) {
    rustrt::rust_uv_free_base_of_buf(buf);
}

unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> str {
    let err = last_error(uv_loop);
    let err_ptr = ptr::addr_of(err);
    let err_name = str::unsafe::from_c_str(err_name(err_ptr));
    let err_msg = str::unsafe::from_c_str(strerror(err_ptr));
    ret #fmt("LIBUV ERROR: name: %s msg: %s",
                    err_name, err_msg);
}