aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/cloudabi/cloudabi_vdso_x86_64.c
blob: a493d716bb52d6cc9429b80fec1016061c0b2c8f (plain) (blame)
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
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
// Copyright (c) 2016 Nuxi (https://nuxi.nl/) and contributors.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// This file is automatically generated. Do not edit.
//
// Source: https://github.com/NuxiNL/cloudabi

#include <cloudabi_types.h>

cloudabi_errno_t cloudabi_sys_clock_res_get(cloudabi_clockid_t clock_id,
                                            cloudabi_timestamp_t *resolution) {
  register uint64_t reg_rax asm("rax") = 0;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)clock_id;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi)
      : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  if (okay) {
    *resolution = (cloudabi_timestamp_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_clock_time_get(cloudabi_clockid_t clock_id,
                                             cloudabi_timestamp_t precision,
                                             cloudabi_timestamp_t *time) {
  register uint64_t reg_rax asm("rax") = 1;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)clock_id;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)precision;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
      : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  if (okay) {
    *time = (cloudabi_timestamp_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_condvar_signal(_Atomic(cloudabi_condvar_t) *
                                                 condvar,
                                             cloudabi_scope_t scope,
                                             cloudabi_nthreads_t nwaiters) {
  register uint64_t reg_rax asm("rax") = 2;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)condvar;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)scope;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)nwaiters;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_close(cloudabi_fd_t fd) {
  register uint64_t reg_rax asm("rax") = 3;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_create1(cloudabi_filetype_t type,
                                         cloudabi_fd_t *fd) {
  register uint64_t reg_rax asm("rax") = 4;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)type;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi)
      : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  if (okay) {
    *fd = (cloudabi_fd_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_create2(cloudabi_filetype_t type,
                                         cloudabi_fd_t *fd1,
                                         cloudabi_fd_t *fd2) {
  register uint64_t reg_rax asm("rax") = 5;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)type;
  register uint64_t reg_rdx asm("rdx");
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax), "=r"(reg_rdx)
      : "r"(reg_rax), "r"(reg_rdi)
      : "memory", "rcx", "r8", "r9", "r10", "r11");
  if (okay) {
    *fd1 = (cloudabi_fd_t)reg_rax;
    *fd2 = (cloudabi_fd_t)reg_rdx;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_datasync(cloudabi_fd_t fd) {
  register uint64_t reg_rax asm("rax") = 6;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_dup(cloudabi_fd_t from, cloudabi_fd_t *fd) {
  register uint64_t reg_rax asm("rax") = 7;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)from;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi)
      : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  if (okay) {
    *fd = (cloudabi_fd_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_pread(cloudabi_fd_t fd,
                                       const cloudabi_iovec_t *iov,
                                       size_t iovcnt,
                                       cloudabi_filesize_t offset,
                                       size_t *nread) {
  register uint64_t reg_rax asm("rax") = 8;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)iov;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)iovcnt;
  register uint64_t reg_r10 asm("r10") = (uint64_t)offset;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx), "r"(reg_r10)
      : "memory", "rcx", "r8", "r9", "r11");
  if (okay) {
    *nread = (size_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_pwrite(cloudabi_fd_t fd,
                                        const cloudabi_ciovec_t *iov,
                                        size_t iovcnt,
                                        cloudabi_filesize_t offset,
                                        size_t *nwritten) {
  register uint64_t reg_rax asm("rax") = 9;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)iov;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)iovcnt;
  register uint64_t reg_r10 asm("r10") = (uint64_t)offset;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx), "r"(reg_r10)
      : "memory", "rcx", "r8", "r9", "r11");
  if (okay) {
    *nwritten = (size_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_read(cloudabi_fd_t fd,
                                      const cloudabi_iovec_t *iov,
                                      size_t iovcnt, size_t *nread) {
  register uint64_t reg_rax asm("rax") = 10;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)iov;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)iovcnt;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
      : "memory", "rcx", "r8", "r9", "r10", "r11");
  if (okay) {
    *nread = (size_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_replace(cloudabi_fd_t from, cloudabi_fd_t to) {
  register uint64_t reg_rax asm("rax") = 11;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)from;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)to;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_seek(cloudabi_fd_t fd,
                                      cloudabi_filedelta_t offset,
                                      cloudabi_whence_t whence,
                                      cloudabi_filesize_t *newoffset) {
  register uint64_t reg_rax asm("rax") = 12;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)offset;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)whence;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
      : "memory", "rcx", "r8", "r9", "r10", "r11");
  if (okay) {
    *newoffset = (cloudabi_filesize_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_stat_get(cloudabi_fd_t fd,
                                          cloudabi_fdstat_t *buf) {
  register uint64_t reg_rax asm("rax") = 13;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)buf;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_stat_put(cloudabi_fd_t fd,
                                          const cloudabi_fdstat_t *buf,
                                          cloudabi_fdsflags_t flags) {
  register uint64_t reg_rax asm("rax") = 14;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)buf;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)flags;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_sync(cloudabi_fd_t fd) {
  register uint64_t reg_rax asm("rax") = 15;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_fd_write(cloudabi_fd_t fd,
                                       const cloudabi_ciovec_t *iov,
                                       size_t iovcnt, size_t *nwritten) {
  register uint64_t reg_rax asm("rax") = 16;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)iov;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)iovcnt;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
      : "memory", "rcx", "r8", "r9", "r10", "r11");
  if (okay) {
    *nwritten = (size_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_advise(cloudabi_fd_t fd,
                                          cloudabi_filesize_t offset,
                                          cloudabi_filesize_t len,
                                          cloudabi_advice_t advice) {
  register uint64_t reg_rax asm("rax") = 17;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)offset;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)len;
  register uint64_t reg_r10 asm("r10") = (uint64_t)advice;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10)
               : "memory", "rcx", "r8", "r9", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_allocate(cloudabi_fd_t fd,
                                            cloudabi_filesize_t offset,
                                            cloudabi_filesize_t len) {
  register uint64_t reg_rax asm("rax") = 18;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)offset;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)len;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_create(cloudabi_fd_t fd, const char *path,
                                          size_t pathlen,
                                          cloudabi_filetype_t type) {
  register uint64_t reg_rax asm("rax") = 19;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)path;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)pathlen;
  register uint64_t reg_r10 asm("r10") = (uint64_t)type;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10)
               : "memory", "rcx", "r8", "r9", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_link(cloudabi_lookup_t fd1,
                                        const char *path1, size_t path1len,
                                        cloudabi_fd_t fd2, const char *path2,
                                        size_t path2len) {
  register uint64_t reg_rax asm("rax") = 20;
  register uint64_t reg_rdi asm("rdi") = *(uint64_t *)&fd1;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)path1;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)path1len;
  register uint64_t reg_r10 asm("r10") = (uint64_t)fd2;
  register uint64_t reg_r8 asm("r8") = (uint64_t)path2;
  register uint64_t reg_r9 asm("r9") = (uint64_t)path2len;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10), "r"(reg_r8), "r"(reg_r9)
               : "memory", "rcx", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_open(cloudabi_lookup_t dirfd,
                                        const char *path, size_t pathlen,
                                        cloudabi_oflags_t oflags,
                                        const cloudabi_fdstat_t *fds,
                                        cloudabi_fd_t *fd) {
  register uint64_t reg_rax asm("rax") = 21;
  register uint64_t reg_rdi asm("rdi") = *(uint64_t *)&dirfd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)path;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)pathlen;
  register uint64_t reg_r10 asm("r10") = (uint64_t)oflags;
  register uint64_t reg_r8 asm("r8") = (uint64_t)fds;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx), "r"(reg_r10),
        "r"(reg_r8)
      : "memory", "rcx", "r9", "r11");
  if (okay) {
    *fd = (cloudabi_fd_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_readdir(cloudabi_fd_t fd, void *buf,
                                           size_t nbyte,
                                           cloudabi_dircookie_t cookie,
                                           size_t *bufused) {
  register uint64_t reg_rax asm("rax") = 22;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)buf;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)nbyte;
  register uint64_t reg_r10 asm("r10") = (uint64_t)cookie;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx), "r"(reg_r10)
      : "memory", "rcx", "r8", "r9", "r11");
  if (okay) {
    *bufused = (size_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_readlink(cloudabi_fd_t fd, const char *path,
                                            size_t pathlen, char *buf,
                                            size_t bufsize, size_t *bufused) {
  register uint64_t reg_rax asm("rax") = 23;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)path;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)pathlen;
  register uint64_t reg_r10 asm("r10") = (uint64_t)buf;
  register uint64_t reg_r8 asm("r8") = (uint64_t)bufsize;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx), "r"(reg_r10),
        "r"(reg_r8)
      : "memory", "rcx", "r9", "r11");
  if (okay) {
    *bufused = (size_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_rename(cloudabi_fd_t oldfd, const char *old,
                                          size_t oldlen, cloudabi_fd_t newfd,
                                          const char *new, size_t newlen) {
  register uint64_t reg_rax asm("rax") = 24;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)oldfd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)old;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)oldlen;
  register uint64_t reg_r10 asm("r10") = (uint64_t)newfd;
  register uint64_t reg_r8 asm("r8") = (uint64_t) new;
  register uint64_t reg_r9 asm("r9") = (uint64_t)newlen;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10), "r"(reg_r8), "r"(reg_r9)
               : "memory", "rcx", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_stat_fget(cloudabi_fd_t fd,
                                             cloudabi_filestat_t *buf) {
  register uint64_t reg_rax asm("rax") = 25;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)buf;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_stat_fput(cloudabi_fd_t fd,
                                             const cloudabi_filestat_t *buf,
                                             cloudabi_fsflags_t flags) {
  register uint64_t reg_rax asm("rax") = 26;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)buf;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)flags;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_stat_get(cloudabi_lookup_t fd,
                                            const char *path, size_t pathlen,
                                            cloudabi_filestat_t *buf) {
  register uint64_t reg_rax asm("rax") = 27;
  register uint64_t reg_rdi asm("rdi") = *(uint64_t *)&fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)path;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)pathlen;
  register uint64_t reg_r10 asm("r10") = (uint64_t)buf;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10)
               : "memory", "rcx", "r8", "r9", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_stat_put(cloudabi_lookup_t fd,
                                            const char *path, size_t pathlen,
                                            const cloudabi_filestat_t *buf,
                                            cloudabi_fsflags_t flags) {
  register uint64_t reg_rax asm("rax") = 28;
  register uint64_t reg_rdi asm("rdi") = *(uint64_t *)&fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)path;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)pathlen;
  register uint64_t reg_r10 asm("r10") = (uint64_t)buf;
  register uint64_t reg_r8 asm("r8") = (uint64_t)flags;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10), "r"(reg_r8)
               : "memory", "rcx", "r9", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_symlink(const char *path1, size_t path1len,
                                           cloudabi_fd_t fd, const char *path2,
                                           size_t path2len) {
  register uint64_t reg_rax asm("rax") = 29;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)path1;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)path1len;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)fd;
  register uint64_t reg_r10 asm("r10") = (uint64_t)path2;
  register uint64_t reg_r8 asm("r8") = (uint64_t)path2len;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10), "r"(reg_r8)
               : "memory", "rcx", "r9", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_file_unlink(cloudabi_fd_t fd, const char *path,
                                          size_t pathlen,
                                          cloudabi_ulflags_t flags) {
  register uint64_t reg_rax asm("rax") = 30;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)path;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)pathlen;
  register uint64_t reg_r10 asm("r10") = (uint64_t)flags;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10)
               : "memory", "rcx", "r8", "r9", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_lock_unlock(_Atomic(cloudabi_lock_t) * lock,
                                          cloudabi_scope_t scope) {
  register uint64_t reg_rax asm("rax") = 31;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)lock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)scope;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_mem_advise(void *addr, size_t len,
                                         cloudabi_advice_t advice) {
  register uint64_t reg_rax asm("rax") = 32;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)addr;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)len;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)advice;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_mem_lock(const void *addr, size_t len) {
  register uint64_t reg_rax asm("rax") = 33;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)addr;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)len;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_mem_map(void *addr, size_t len,
                                      cloudabi_mprot_t prot,
                                      cloudabi_mflags_t flags, cloudabi_fd_t fd,
                                      cloudabi_filesize_t off, void **mem) {
  register uint64_t reg_rax asm("rax") = 34;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)addr;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)len;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)prot;
  register uint64_t reg_r10 asm("r10") = (uint64_t)flags;
  register uint64_t reg_r8 asm("r8") = (uint64_t)fd;
  register uint64_t reg_r9 asm("r9") = (uint64_t)off;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx), "r"(reg_r10),
        "r"(reg_r8), "r"(reg_r9)
      : "memory", "rcx", "r11");
  if (okay) {
    *mem = (void *)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_mem_protect(void *addr, size_t len,
                                          cloudabi_mprot_t prot) {
  register uint64_t reg_rax asm("rax") = 35;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)addr;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)len;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)prot;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_mem_sync(void *addr, size_t len,
                                       cloudabi_msflags_t flags) {
  register uint64_t reg_rax asm("rax") = 36;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)addr;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)len;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)flags;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_mem_unlock(const void *addr, size_t len) {
  register uint64_t reg_rax asm("rax") = 37;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)addr;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)len;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_mem_unmap(void *addr, size_t len) {
  register uint64_t reg_rax asm("rax") = 38;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)addr;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)len;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_poll(const cloudabi_subscription_t *in,
                                   cloudabi_event_t *out, size_t nsubscriptions,
                                   size_t *nevents) {
  register uint64_t reg_rax asm("rax") = 39;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)in;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)out;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)nsubscriptions;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
      : "memory", "rcx", "r8", "r9", "r10", "r11");
  if (okay) {
    *nevents = (size_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_poll_fd(cloudabi_fd_t fd,
                                      const cloudabi_subscription_t *in,
                                      size_t nin, cloudabi_event_t *out,
                                      size_t nout,
                                      const cloudabi_subscription_t *timeout,
                                      size_t *nevents) {
  register uint64_t reg_rax asm("rax") = 40;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)in;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)nin;
  register uint64_t reg_r10 asm("r10") = (uint64_t)out;
  register uint64_t reg_r8 asm("r8") = (uint64_t)nout;
  register uint64_t reg_r9 asm("r9") = (uint64_t)timeout;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx), "r"(reg_r10),
        "r"(reg_r8), "r"(reg_r9)
      : "memory", "rcx", "r11");
  if (okay) {
    *nevents = (size_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_proc_exec(cloudabi_fd_t fd, const void *data,
                                        size_t datalen,
                                        const cloudabi_fd_t *fds,
                                        size_t fdslen) {
  register uint64_t reg_rax asm("rax") = 41;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)fd;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)data;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)datalen;
  register uint64_t reg_r10 asm("r10") = (uint64_t)fds;
  register uint64_t reg_r8 asm("r8") = (uint64_t)fdslen;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10), "r"(reg_r8)
               : "memory", "rcx", "r9", "r11");
  return reg_rax;
}

_Noreturn void cloudabi_sys_proc_exit(cloudabi_exitcode_t rval) {
  register uint64_t reg_rax asm("rax") = 42;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)rval;
  asm volatile("\tsyscall\n"
               :
               : "r"(reg_rax), "r"(reg_rdi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  for (;;)
    ;
}

cloudabi_errno_t cloudabi_sys_proc_fork(cloudabi_fd_t *fd,
                                        cloudabi_tid_t *tid) {
  register uint64_t reg_rax asm("rax") = 43;
  register uint64_t reg_rdx asm("rdx");
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax), "=r"(reg_rdx)
      : "r"(reg_rax)
      : "memory", "rcx", "r8", "r9", "r10", "r11");
  if (okay) {
    *fd = (cloudabi_fd_t)reg_rax;
    *tid = (cloudabi_tid_t)reg_rdx;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_proc_raise(cloudabi_signal_t sig) {
  register uint64_t reg_rax asm("rax") = 44;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sig;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_random_get(void *buf, size_t nbyte) {
  register uint64_t reg_rax asm("rax") = 45;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)buf;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)nbyte;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_sock_accept(cloudabi_fd_t sock,
                                          cloudabi_sockstat_t *buf,
                                          cloudabi_fd_t *conn) {
  register uint64_t reg_rax asm("rax") = 46;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)buf;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
      : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  if (okay) {
    *conn = (cloudabi_fd_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_sock_bind(cloudabi_fd_t sock, cloudabi_fd_t fd,
                                        const char *path, size_t pathlen) {
  register uint64_t reg_rax asm("rax") = 47;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)fd;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)path;
  register uint64_t reg_r10 asm("r10") = (uint64_t)pathlen;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10)
               : "memory", "rcx", "r8", "r9", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_sock_connect(cloudabi_fd_t sock, cloudabi_fd_t fd,
                                           const char *path, size_t pathlen) {
  register uint64_t reg_rax asm("rax") = 48;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)fd;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)path;
  register uint64_t reg_r10 asm("r10") = (uint64_t)pathlen;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx),
                 "r"(reg_r10)
               : "memory", "rcx", "r8", "r9", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_sock_listen(cloudabi_fd_t sock,
                                          cloudabi_backlog_t backlog) {
  register uint64_t reg_rax asm("rax") = 49;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)backlog;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_sock_recv(cloudabi_fd_t sock,
                                        const cloudabi_recv_in_t *in,
                                        cloudabi_recv_out_t *out) {
  register uint64_t reg_rax asm("rax") = 50;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)in;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)out;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_sock_send(cloudabi_fd_t sock,
                                        const cloudabi_send_in_t *in,
                                        cloudabi_send_out_t *out) {
  register uint64_t reg_rax asm("rax") = 51;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)in;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)out;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_sock_shutdown(cloudabi_fd_t sock,
                                            cloudabi_sdflags_t how) {
  register uint64_t reg_rax asm("rax") = 52;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)how;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_sock_stat_get(cloudabi_fd_t sock,
                                            cloudabi_sockstat_t *buf,
                                            cloudabi_ssflags_t flags) {
  register uint64_t reg_rax asm("rax") = 53;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)sock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)buf;
  register uint64_t reg_rdx asm("rdx") = (uint64_t)flags;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi), "r"(reg_rdx)
               : "memory", "rcx", "r8", "r9", "r10", "r11");
  return reg_rax;
}

cloudabi_errno_t cloudabi_sys_thread_create(cloudabi_threadattr_t *attr,
                                            cloudabi_tid_t *tid) {
  register uint64_t reg_rax asm("rax") = 54;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)attr;
  register char okay;
  asm volatile(
      "\tsyscall\n"
      "\tsetnc %0\n"
      : "=r"(okay), "=r"(reg_rax)
      : "r"(reg_rax), "r"(reg_rdi)
      : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  if (okay) {
    *tid = (cloudabi_tid_t)reg_rax;
    return 0;
  }
  return reg_rax;
}

_Noreturn void cloudabi_sys_thread_exit(_Atomic(cloudabi_lock_t) * lock,
                                        cloudabi_scope_t scope) {
  register uint64_t reg_rax asm("rax") = 55;
  register uint64_t reg_rdi asm("rdi") = (uint64_t)lock;
  register uint64_t reg_rsi asm("rsi") = (uint64_t)scope;
  asm volatile("\tsyscall\n"
               :
               : "r"(reg_rax), "r"(reg_rdi), "r"(reg_rsi)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  for (;;)
    ;
}

cloudabi_errno_t cloudabi_sys_thread_yield(void) {
  register uint64_t reg_rax asm("rax") = 56;
  asm volatile("\tsyscall\n"
               : "=r"(reg_rax)
               : "r"(reg_rax)
               : "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  return reg_rax;
}