-
Notifications
You must be signed in to change notification settings - Fork 1
/
bqc.h
3247 lines (3145 loc) · 95 KB
/
bqc.h
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
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef BQC_H
#define BQC_H
#ifdef __GNUC__
#define PASTE3_(x,y,z) x##y##z
#define PASTE3(x,y,z) PASTE3_(x,y,z)
#define GCCVER PASTE3(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
#endif
#if 1 //architecture ports
#include <linux/unistd.h>
//to add a new arch:
//
//to get the gcc register syntax (sp, %sp, $sp, :sp) see:
//https://github.com/gcc-mirror/gcc/tree/master/gcc/config/<arch>/<arch>.h
//if you have a working compiler try `echo|gcc -E -dM - |grep REGISTER_PREFIX`
//then prepend its value to "sp"
//to figure out syscalls see
//https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/patch/?id=f5738ceed46782aea7663d62cb6398eb05fc4ce0
//note: kernel devs removed _syscall()s without documenting alternatives
//if you are lucky, your architecture may be in the 2.6.18 unistd.h
//set up architecture dependent stuff
// #define ARCH_DATA "sp", "syscall","callnum","ret","arg1","arg2","arg3","arg4","arg5","arg6","arg7","memory",...
#ifdef __x86_64__
#define ARCH_DATA "rsp","syscall", "rax","rax","rdi","rsi","rdx","r10","r8", "r9", "0", "rcx","r11","memory"
//TODO x32 as subset
enum {
__NR_
};
#elif defined (__i386__)
#define ARCH_DATA "esp","int $128","eax","eax","ebx","ecx","edx","esi","edi","ebp","0", "memory"
#elif defined (__aarch64__)
#define ARCH_DATA "sp","svc 0", "x8", "x0", "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x9", "x10", "x11", "x12", "x13","x14", "x15", "x16", "x17", "x18", "memory"
#elif defined (__arm__)
#define ARCH_DATA "sp","swi 0x0", "r7", "r0", "r0", "r1", "r2", "r3", "r4", "r5", "r6", "memory"
#elif defined (__alpha__) //* also returns error on $19 */
//#define ARCH_DATA "sp","syscall", "v0", "v0", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "memory"
/* older way */
//#define ARCH_DATA "sp","callsys # %0 %1 %2 %3 %4 %5 %6 %7 %8", "$0", "$0","$16","$17","$18","$19","$20","$21", "$22","$23","$24","$25","$27","$28","$1","$2","$3","$4","$5","$6","$7","$8","memory"
#elif defined (__alpha__) //stack pointer called "sp", but located @ "r28"
//#define ARCH_DATA "sp",
#elif defined (__avr32__)
//#define ARCH_DATA "__SP_L__","scall",
#elif defined __bfin
//#define ARCH_DATA "SP","excpt 0x0","P0", "R0", "R0", "R1", "R2", "R3", "R4", "R5", "R6", /* more clobbers?*/ "memory"
#elif defined (__TMS320C6X__) || defined (_TMS320C6X) //c6x
//#define ARCH_DATA "B15",
#elif defined (__CR__) || defined (__CR16__) || defined (__CR16C__)
//#define ARCH_DATA "B15",
#elif defined __cris__
//#define ARCH_DATA "sp","break 13","r9","r10","r10","r11","r12","r13","mof","srp",0,"memory"
#elif defined (__epiphany__)
//#define ARCH_DATA "sp",
#elif defined (fr30)
//#define ARCH_DATA "sp",
#elif defined (__frv__) //sp is "gr1"
//#define ARCH_DATA "sp",
#elif defined (__FT32__)
//#define ARCH_DATA "$sp",
#elif defined(__H8300SX__) || defined(__H8300S__) || defined(__H8300H__) || defined(__H8300__) //sp is "r7"
//#define ARCH_DATA "sp",
#elif defined(__hppa__) || defined(__hppa)
//#define ARCH_DATA "%usp","ble 0x100(%sr2,%r0)","%r20","%r28","%r26","%r25","%r24","%r23","%r22","%r21","0", ,"r1","r2","r20","r29","r31","memory"
//#define ARCH_DATA "r30","ble 0x100(%sr2, %r0)","r20","r26","r25","r24","r23","r22","r21","0","0", memory","r1","r2","r20","r29","r31"
#elif defined(__ia64__) /* has 2 returns */ //sp is "r12"
//#define ARCH_DATA "sp","break 0x100000","r15","r10/r8","out0","out1","out2","out3","out4","out5","0", "memory"
#elif defined(__iq2000__)
//#define ARCH_DATA "%29",
#elif defined(__lm32__)
//#define ARCH_DATA "sp",
#elif defined(__m32c__)
//#define ARCH_DATA "sp",
#elif defined(__M32R__) || defined(__m32r__) //sp is "r15"
//#define ARCH_DATA "sp",
#elif defined(__m68k__)
//#define ARCH_DATA "sp","trap #0","d0","d0","d1","d2","d3","d4","d5", "0", "a0","d0","d1","a0","memory"
//#define ARCH_DATA "%sp","trap &0","%d0","%d0","%d1","%d2","%d3","%d4","%d5","0",%a0","%d0","%d1","%a0","memory"
#elif defined(__mcore__) || defined(__MCORE__) //sp is "r0"
//#define ARCH_DATA "sp",
#elif defined(__MEP__) || defined(__MeP__) || defined(mep) //$sp is "$15" also aliased as "sp"
//#define ARCH_DATA "$sp",
#elif defined(__microblaze__)
//#define ARCH_DATA "r1","brki r14, 0x8","r12","r3","r5","r6","r7","r8","r9","r10","0","memory","r4"
#elif defined(__mips64__)
//#define ARCH_DATA "$sp","syscall","$v0","$v0","$a0","$a1","$a2","$a3","$a4","$a5","$a6","$a7","$at","$t0","$t1","$t2","$t3","$t4","$t5","$t6","$t7","$t8","$t9","$hi","$lo","memory"
#elif defined(__mips__) || defined (_mips)
//#define ARCH_DATA "$sp","syscall","$v0","$v0","$a0","$a1","$a2","$a3","$a4","$a5","$a6", "$a7","$at","$t0","$t1","$t2","$t3","$t4","$t5","$t6","$t7","$t8","$t9","$hi","$lo","memory"
#elif defined(__mmix__) || defined (__MMIX__) //sp is "$254" also aliased as ":sp"
//#define ARCH_DATA "sp",
#elif defined(__MN10300__) || defined (__mn10300__)
//#define ARCH_DATA "sp",
#elif defined(moxie) || defined (MOXIE)
//#define ARCH_DATA "$sp",
#elif defined(__MSP430__)
//#define ARCH_DATA "R1",
#elif defined(__nds32__) //sp is $r31
//#define ARCH_DATA "$sp",
#elif defined(__nios2_arch__) || defined(nios2) || defined(NIOS2) //sp is r27
//#define ARCH_DATA "sp",
#elif defined(__nvptx__) //sp is regnum which would correspond to "%hr1" which is list as %outargs
//#define ARCH_DATA "%outargs",
#elif defined(__or1k__) //clobbers unused would-be arg registers
//#define ARCH_DATA ???,"l.sys 1","r11","r11","r3","r4","r5","r6","r7","r8","0", memory","r12","r13","r15","r17","r19","r21","r23","r25","r27","r29","r31"
#elif defined(pdp11) //sp is r6
//#define ARCH_DATA "sp",
#elif defined(__powerpc64__)
//#define ARCH_DATA ???,"sc","r0","r0","r3","r4","r5","r6","r7","r8","0","memory","cr0","ctr","r8","r9","r10","r11","r12"
#elif defined(__powerpc__)
//#define ARCH_DATA ???,"sc","r0","r0","r3","r4","r5","r6","r7","r8","0","memory","cr0","ctr","r8","r9","r10","r11","r12"
#elif defined(__RL78__) //sp would be r32, but not aliased
//#define ARCH_DATA "sp",
#elif defined(__RX__) //sp ~= r0
//#define ARCH_DATA "sp",
#elif defined(__s390x__)
//#define ARCH_DATA "r15","svc 0","r1","r2","r2","r3","r4","r5","r6","r7","0","memory"
#elif defined (__s390__)
//#define ARCH_DATA "r15"," svc %b1\n"
#elif defined __sh__
//#define ARCH_DATA "r15","trapa #","r3", "r0", "r4", "r5", "r6", "r7", "r0", "r1", "0", "memory"
#elif defined(__sparc64__) || defined(__sparcv9) || defined(__sparcv9__) || defined(__sparc_v9__) || defined(__arch64__) //sp is %o6
//#define ARCH_DATA "%sp","t 0x6d", "%g1","%o0","%o0","%o1","%o2","%o3","%o4","%o5", "0", "memory"
#elif defined (__sparc__) || defined (__sparclet__) || defined (__sparclite__) || defined (__sparclite8x__) || defined (__supersparc__) || defined(__sparc_v8__) //sp is %o6
//#define ARCH_DATA "%sp","t 0x10", "%g1","%o0","%o0","%o1","%o2","%o3","%o4","%o5", "0", "memory"
#elif defined (__spu__)
//#define ARCH_DATA "$sp",
#elif defined (xstormy16) //sp is r15
//#define ARCH_DATA "sp",
#elif defined (__tilegx__) || defined (__tilepro__) //sp is r54
//#define ARCH_DATA "sp",
#elif defined(__v850__)
//sp is r3
//#define ARCH_DATA "sp",
#elif defined(__vax__) //sp is r14
//#define ARCH_DATA "sp",
#elif defined(__VISIUM__) //sp is r23
//#define ARCH_DATA "sp",
#elif defined __xtensa__
//#define ARCH_DATA ???,syscall,a2,a2??,a6,a3,a4,a5,a8,a9,0,"memory"
#else
#error architecture not supported by bQc
#endif
//Crap should have been: SP,PRE6-1,SYSCALL,POST1-6,RET2,RET,NUM,ARG1-ARG6,CLOBBERS
//ex. x86
// #define ARCH "esp","","","","","","","int $128","","","","","","", \
// 0,NA,"eax","eax","ebx","ecx","edx","esi","edi","ebp", "memory"
//ex. arch
// #define ARCH "sp","","","","","","","callsys # %0 %1 %2"," %3"," %4"," %5"," %6"," %7"," %8", \
// 1,"$19","$0", "$0","$16","$17","$18","$19","$20","$21", "$22","$23","$24","$25","$27","$28","$1","$2","$3","$4","$5","$6","$7","$8","memory"
// The syscall pre and post strings get concatenated together as needed
// This would be for architectures that change the syscall string according to # of args
// arch uses: (((((callsys # %0) %1) %2) %3) %4) %5)
// while other architectures may need additional prefix instructions (mov, etc...)
#endif
#if 1 //constants
#define AF_AAL5 8
#define AF_APPLETALK 5
#define AF_AX25 3
#define AF_BRIDGE 7
#define AF_INET 2
#define AF_INET6 10
#define AF_IPX 4
#define AF_MAX 12
#define AF_NETROM 6
#define AF_UNIX 1
#define AF_UNSPEC 0
#define AF_X25 9
#define __ARCH_SI_PREAMBLE_SIZE (3 * sizeof(int))
#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(int) * 2 + sizeof(sigval_t))
#define ASK_VGA 0xfffd
#define B0 0000000
#define B1000000 0010010
#define B110 0000003
#define B1152000 0010011
#define B115200 0010002
#define B1200 0000011
#define B134 0000004
#define B1500000 0010012
#define B150 0000005
#define B1800 0000012
#define B19200 0000016
#define B2000000 0010013
#define B200 0000006
#define B230400 0010003
#define B2400 0000013
#define B2500000 0010014
#define B3000000 0010015
#define B300 0000007
#define B3500000 0010016
#define B38400 0000017
#define B4000000 0010017
#define B460800 0010004
#define B4800 0000014
#define B50 0000001
#define B500000 0010005
#define B576000 0010006
#define B57600 0010001
#define B600 0000010
#define B75 0000002
#define B921600 0010007
#define B9600 0000015
#define BOTHER 0010000
#define BRKINT 0000002
#define BS0 0000000
#define BS1 0020000
#define BSDLY 0020000
#define BUS_ADRALN (__SI_FAULT|1)
#define BUS_ADRERR (__SI_FAULT|2)
#define BUS_MCEERR_AO (__SI_FAULT|5)
#define BUS_MCEERR_AR (__SI_FAULT|4)
#define BUS_OBJERR (__SI_FAULT|3)
#define CAN_USE_HEAP 128
#define CBAUD 0010017
#define CBAUDEX 0010000
#define CIBAUD 002003600000
#define CLD_CONTINUED (__SI_CHLD|6)
#define CLD_DUMPED (__SI_CHLD|3)
#define CLD_EXITED (__SI_CHLD|1)
#define CLD_KILLED (__SI_CHLD|2)
#define CLD_STOPPED (__SI_CHLD|5)
#define CLD_TRAPPED (__SI_CHLD|4)
#define CLOCAL 0004000
#define CLONE_CHILD_CLEARTID 0x00200000
#define CLONE_CHILD_SETTID 0x01000000
#define CLONE_DETACHED 0x00400000
#define CLONE_FILES 0x00000400
#define CLONE_FS 0x00000200
#define CLONE_IO 0x80000000
#define CLONE_NEWIPC 0x08000000
#define CLONE_NEWNET 0x40000000
#define CLONE_NEWNS 0x00020000
#define CLONE_NEWPID 0x20000000
#define CLONE_NEWUSER 0x10000000
#define CLONE_NEWUTS 0x04000000
#define CLONE_PARENT 0x00008000
#define CLONE_PARENT_SETTID 0x00100000
#define CLONE_PTRACE 0x00002000
#define CLONE_SETTLS 0x00080000
#define CLONE_SIGHAND 0x00000800
#define CLONE_SYSVSEM 0x00040000
#define CLONE_THREAD 0x00010000
#define CLONE_UNTRACED 0x00800000
#define CLONE_VFORK 0x00004000
#define CLONE_VM 0x00000100
#define CMSPAR 010000000000
#define COMMAND_LINE_SIZE 512
#define CR0 0000000
#define CR1 0001000
#define CR2 0002000
#define CR3 0003000
#define CRDLY 0003000
#define CREAD 0000200
#define CRTSCTS 020000000000
#define CS5 0000000
#define CS6 0000020
#define CS7 0000040
#define CS8 0000060
#define CSIGNAL 0x000000ff
#define CSIZE 0000060
#define CSTOPB 0000100
#define E2BIG 7
#define EACCES 13
#define EADDRINUSE 98
#define EADDRNOTAVAIL 99
#define EADV 68
#define EAFNOSUPPORT 97
#define EAGAIN 11
#define EALREADY 114
#define EBADE 52
#define EBADF 9
#define EBADFD 77
#define EBADMSG 74
#define EBADR 53
#define EBADRQC 56
#define EBADSLT 57
#define EBFONT 59
#define EBUSY 16
#define ECANCELED 125
#define ECHILD 10
#define ECHO 0000010
#define ECHOCTL 0001000
#define ECHOE 0000020
#define ECHOK 0000040
#define ECHOKE 0004000
#define ECHONL 0000100
#define ECHOPRT 0002000
#define ECHRNG 44
#define ECOMM 70
#define ECONNABORTED 103
#define ECONNREFUSED 111
#define ECONNRESET 104
#define EDEADLK 35
#define EDEADLOCK EDEADLK
#define EDESTADDRREQ 89
#define EDOM 33
#define EDOTDOT 73
#define EDQUOT 122
#define EEXIST 17
#define EFAULT 14
#define EFBIG 27
#define EHOSTDOWN 112
#define EHOSTUNREACH 113
#define EHWPOISON 133
#define EIDRM 43
#define EILSEQ 84
#define EINPROGRESS 115
#define EINTR 4
#define EINVAL 22
#define EIO 5
#define EISCONN 106
#define EISDIR 21
#define EISNAM 120
#define EKEYEXPIRED 127
#define EKEYREJECTED 129
#define EKEYREVOKED 128
#define EL2HLT 51
#define EL2NSYNC 45
#define EL3HLT 46
#define EL3RST 47
#define ELAST 134
#define ELIBACC 79
#define ELIBBAD 80
#define ELIBEXEC 83
#define ELIBMAX 82
#define ELIBSCN 81
#define ELNRNG 48
#define ELOOP 40
#define EMEDIUMTYPE 124
#define EMFILE 24
#define EMLINK 31
#define EMSGSIZE 90
#define EMULTIHOP 72
#define ENAMETOOLONG 36
#define ENAVAIL 119
#define ENETDOWN 100
#define ENETRESET 102
#define ENETUNREACH 101
#define ENFILE 23
#define ENOANO 55
#define ENOBUFS 105
#define ENOCSI 50
#define ENODATA 61
#define ENODEV 19
#define ENOENT 2
#define ENOEXEC 8
#define ENOKEY 126
#define ENOLCK 37
#define ENOLINK 67
#define ENOMEDIUM 123
#define ENOMEM 12
#define ENOMSG 42
#define ENONET 64
#define ENOPKG 65
#define ENOPROTOOPT 92
#define ENOSPC 28
#define ENOSR 63
#define ENOSTR 60
#define ENOSYS 38
#define ENOTBLK 15
#define ENOTCONN 107
#define ENOTDIR 20
#define ENOTEMPTY 39
#define ENOTNAM 118
#define ENOTRECOVERABLE 131
#define ENOTSOCK 88
#define ENOTSUP EOPNOTSUPP
#define ENOTTY 25
#define ENOTUNIQ 76
#define ENXIO 6
#define EOPNOTSUPP 95
#define EOVERFLOW 75
#define EOWNERDEAD 130
#define EPERM 1
#define EPFNOSUPPORT 96
#define EPIPE 32
#define EPROTO 71
#define EPROTONOSUPPORT 93
#define EPROTOTYPE 91
#define ERANGE 34
#define EREMCHG 78
#define EREMOTE 66
#define EREMOTEIO 121
#define ERESTART 85
#define ERFKILL 132
#define EROFS 30
#define ESHUTDOWN 108
#define ESOCKTNOSUPPORT 94
#define ESPIPE 29
#define ESRCH 3
#define ESRMNT 69
#define ESTALE 116
#define ESTRPIPE 86
#define ETIME 62
#define ETIMEDOUT 110
#define ETOOMANYREFS 109
#define ETXTBSY 26
#define EUCLEAN 117
#define EUNATCH 49
#define EUSERS 87
#define EWOULDBLOCK EAGAIN
#define EXDEV 18
#define EXEC_PAGESIZE 4096
#define EXFULL 54
#define EXTA B19200
#define EXTB B38400
#define EXTENDED_VGA 0xfffe
#define EXTPROC 0200000
#define FASYNC 00020000
#define FD_CLOEXEC 1
#define F_DUPFD 0
#define F_EXLCK 4
#define FF0 0000000
#define FF1 0100000
#define FFDLY 0100000
#define F_GETFD 1
#define F_GETFL 3
#define F_GETLK 5
#define F_GETLK64 12
#define F_GETOWN 9
#define F_GETOWNER_UIDS 17
#define F_GETOWN_EX 16
#define F_GETSIG 11
#define FIOASYNC 0x5452
#define FIOCLEX 0x5451
#define FIOGETOWN 0x8903
#define FIONBIO 0x5421
#define FIONCLEX 0x5450
#define FIONREAD 0x541B
#define FIOQSIZE 0x5460
#define FIOSETOWN 0x8901
#define F_LINUX_SPECIFIC_BASE 1024
#define FLUSHO 0010000
#define F_OWNER_PGRP 2
#define F_OWNER_PID 1
#define F_OWNER_TID 0
#define FPE_FLTDIV (__SI_FAULT|3)
#define FPE_FLTINV (__SI_FAULT|7)
#define FPE_FLTOVF (__SI_FAULT|4)
#define FPE_FLTRES (__SI_FAULT|6)
#define FPE_FLTSUB (__SI_FAULT|8)
#define FPE_FLTUND (__SI_FAULT|5)
#define FPE_INTDIV (__SI_FAULT|1)
#define FPE_INTOVF (__SI_FAULT|2)
#define F_RDLCK 0
#define F_SETFD 2
#define F_SETFL 4
#define F_SETLK 6
#define F_SETLK64 13
#define F_SETLKW64 14
#define F_SETLKW 7
#define F_SETOWN 8
#define F_SETOWN_EX 15
#define F_SETSIG 10
#define F_SHLCK 8
#define F_UNLCK 2
#define F_WRLCK 1
#define HUPCL 0002000
#define HZ 100
#define IBSHIFT 16
#define ICANON 0000002
#define ICRNL 0000400
#define IEXTEN 0100000
#define IGNBRK 0000001
#define IGNCR 0000200
#define IGNPAR 0000004
#define ILL_BADSTK (__SI_FAULT|8)
#define ILL_COPROC (__SI_FAULT|7)
#define ILL_ILLADR (__SI_FAULT|3)
#define ILL_ILLOPC (__SI_FAULT|1)
#define ILL_ILLOPN (__SI_FAULT|2)
#define ILL_ILLTRP (__SI_FAULT|4)
#define ILL_PRVOPC (__SI_FAULT|5)
#define ILL_PRVREG (__SI_FAULT|6)
#define IMAXBEL 0020000
#define INLCR 0000100
#define INPCK 0000020
#define _IOC_DIRBITS 2
#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
#define _IOC_NONE 0U
#define _IOC_NRBITS 8
#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
#define _IOC_NRSHIFT 0
#define _IOC_READ 2U
#define _IOC_SIZEBITS 14
#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
#define _IOC_TYPEBITS 8
#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
#define _IOC_WRITE 1U
#define IPPROTO_AH 51
#define IPPROTO_BEETPH 94
#define IPPROTO_COMP 108
#define IPPROTO_DCCP 33
#define IPPROTO_EGP 8
#define IPPROTO_ENCAP 98
#define IPPROTO_ESP 50
#define IPPROTO_GRE 47
#define IPPROTO_ICMP 1
#define IPPROTO_IDP 22
#define IPPROTO_IGMP 2
#define IPPROTO_IP 0
#define IPPROTO_IPIP 4
#define IPPROTO_IPV6 41
#define IPPROTO_MAX =256
#define IPPROTO_MTP 92
#define IPPROTO_PIM 103
#define IPPROTO_PUP 12
#define IPPROTO_RAW 255
#define IPPROTO_RSVP 46
#define IPPROTO_SCTP 132
#define IPPROTO_TCP 6
#define IPPROTO_TP 29
#define IPPROTO_UDP 17
#define IPPROTO_UDPLITE 136
#define ISIG 0000001
#define ISTRIP 0000040
#define IUCLC 0001000
#define IUTF8 0040000
#define IXANY 0004000
#define IXOFF 0010000
#define IXON 0002000
#define KEEP_SEGMENTS 64
#define LOADED_HIGH = 1
#define LOCK_EX 2
#define LOCK_MAND 32
#define LOCK_NB 4
#define LOCK_READ 64
#define LOCK_RW 192
#define LOCK_SH 1
#define LOCK_UN 8
#define LOCK_WRITE 128
#define MADV_DODUMP 17
#define MADV_DOFORK 11
#define MADV_DONTDUMP 16
#define MADV_DONTFORK 10
#define MADV_DONTNEED 4
#define MADV_HUGEPAGE 14
#define MADV_HWPOISON 100
#define MADV_MERGEABLE 12
#define MADV_NOHUGEPAGE 15
#define MADV_NORMAL 0
#define MADV_RANDOM 1
#define MADV_REMOVE 9
#define MADV_SEQUENTIAL 2
#define MADV_SOFT_OFFLINE 101
#define MADV_UNMERGEABLE 13
#define MADV_WILLNEED 3
#define MAP_ANONYMOUS 0x20
#define MAP_FILE 0
#define MAP_FIXED 0x10
#define MAP_HUGE_MASK 0x3f
#define MAP_HUGE_SHIFT 26
#define MAP_PRIVATE 0x02
#define MAP_SHARED 0x01
#define MAP_TYPE 0x0f
#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
#define MAP_UNINITIALIZED 0x4000000
#else
#define MAP_UNINITIALIZED 0x0
#endif
#define MAXHOSTNAMELEN 64
#define MS_ASYNC 1
#define MS_INVALIDATE 2
#define MS_SYNC 4
#define NCC 8
#define NCCS 32
#define NL0 0000000
#define NL1 0000400
#define NLDLY 0000400
#define NOFLSH 0000200
#define NOGROUP (-1)
#define NORMAL_VGA 0xffff
#define NSIGBUS 5
#define NSIGCHLD 6
#define NSIGFPE 8
#define NSIGILL 8
#define NSIGPOLL 6
#define NSIGSEGV 2
#define NSIGSYS 1
#define NSIGTRAP 4
#define O_ACCMODE 00000003
#define O_APPEND 00002000
#define O_CLOEXEC 02000000
#define O_CREAT 00000100
#define OCRNL 0000010
#define O_DIRECT 00040000
#define O_DIRECTORY 00200000
#define O_DSYNC 00010000
#define O_EXCL 00000200
#define OFDEL 0000200
#define OFILL 0000100
#define O_LARGEFILE 00100000
#define OLCUC 0000002
#define O_NDELAY 00004000
#define ONLCR 0000004
#define ONLRET 0000040
#define O_NOATIME 01000000
#define ONOCR 0000020
#define O_NOCTTY 00000400
#define O_NOFOLLOW 00400000
#define O_NONBLOCK 00004000
#define O_PATH 010000000
#define OPOST 0000001
#define O_RDONLY 00000000
#define O_RDWR 00000002
#define __O_SYNC 04000000
#define __O_TMPFILE 020000000
#define O_TMPFILE 020200000
#define O_TMPFILE_MASK =020200100
#define O_TRUNC 00001000
#define O_WRONLY 00000001
#define PAGE_SIZE 4096
#define P_ALL 0
#define PARENB 0000400
#define PARMRK 0000010
#define PARODD 0001000
#define PENDIN 0040000
#define PF_AAL5 AF_AAL5
#define PF_APPLETALK AF_APPLETALK
#define PF_AX25 AF_AX25
#define PF_BRIDGE AF_BRIDGE
#define PF_INET6 AF_INET6
#define PF_INET AF_INET
#define PF_IPX AF_IPX
#define PF_MAX AF_MAX
#define PF_NETROM AF_NETROM
#define PF_UNIX AF_UNIX
#define PF_UNSPEC AF_UNSPEC
#define PF_X25 AF_X25
#define POLL_BUSY_LOOP 0x8000
#define POLLERR 0x0008
#define POLL_ERR (__SI_POLL|4)
#define POLLFREE 0x4000
#define POLLHUP 0x0010
#define POLL_HUP (__SI_POLL|6)
#define POLLIN 0x0001
#define POLL_IN (__SI_POLL|1)
#define POLLMSG 0x0400
#define POLL_MSG (__SI_POLL|3)
#define POLLNVAL 0x0020
#define POLLOUT 0x0004
#define POLL_OUT (__SI_POLL|2)
#define POLLPRI 0x0002
#define POLL_PRI (__SI_POLL|5)
#define POLLRDBAND 0x0080
#define POLLRDHUP 0x2000
#define POLLRDNORM 0x0040
#define POLLREMOVE 0x1000
#define POLLWRBAND 0x0200
#define POLLWRNORM 0x0100
#define P_PGID 2
#define P_PID 1
#define PROT_EXEC 0x4
#define PROT_GROWSDOWN 0x01000000
#define PROT_GROWSUP 0x02000000
#define PROT_NONE 0x0
#define PROT_READ 0x1
#define PROT_SEM 0x8
#define PROT_WRITE 0x2
#define QUIET_FLAG 32
#define RAMDISK_IMAGE_START_MASK 0x07FF
#define RAMDISK_LOAD_FLAG 0x4000
#define RAMDISK_PROMPT_FLAG 0x8000
#define RLIM_INFINITY (~0UL)
#define RLIMIT_AS 9
#define RLIMIT_CORE 4
#define RLIMIT_CPU 0
#define RLIMIT_DATA 2
#define RLIMIT_FSIZE 1
#define RLIMIT_LOCKS 10
#define RLIMIT_MEMLOCK 8
#define RLIMIT_MSGQUEUE 12
#define RLIMIT_NICE 13
#define RLIMIT_NOFILE 7
#define RLIMIT_NPROC 6
#define RLIMIT_RSS 5
#define RLIMIT_RTPRIO 14
#define RLIMIT_RTTIME 15
#define RLIMIT_SIGPENDING 11
#define RLIMIT_STACK 3
#define RLIM_NLIMITS 16
#define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
#define SCM_TIMESTAMP SO_TIMESTAMP
#define SCM_WIFI_STATUS SO_WIFI_STATUS
#define SEGV_ACCERR (__SI_FAULT|2)
#define SEGV_MAPERR (__SI_FAULT|1)
#define SETUP_DTB 2
#define SETUP_E820_EXT 1
#define SETUP_NONE 0
#define SETUP_PCI 3
#define SHMLBA PAGE_SIZE
#define SI_ASYNCIO -4
#define __SI_CHLD 0
#define SI_DETHREAD -7
#define __SI_FAULT 0
#define SIGEV_MAX_SIZE 64
#define SIGEV_NONE 1
#define SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE - __ARCH_SIGEV_PREAMBLE_SIZE) / sizeof(int))
#define SIGEV_SIGNAL 0
#define SIGEV_THREAD 2
#define SIGEV_THREAD_ID 4
#define SI_KERNEL 0x80
#define __SI_KILL 0
#define __SI_MESGQ 0
#define SI_MESGQ -3
#define SI_MAX_SIZE 128
#define SIOCATMARK 0x8905
#define SIOCGPGRP 0x8904
#define SIOCGSTAMP 0x8906
#define SIOCGSTAMPNS 0x8907
#define SIOCSPGRP 0x8902
#define SI_PAD_SIZE ((SI_MAX_SIZE - __ARCH_SI_PREAMBLE_SIZE) / sizeof(int))
#define __SI_POLL 0
#define SI_QUEUE -1
#define __SI_RT 0
#define SI_SIGIO -5
#define __SI_SYS 0
#define __SI_TIMER 0
#define SI_TIMER -2
#define SI_TKILL -6
#define SI_USER 0
#define SO_ACCEPTCONN 30
#define SO_ATTACH_FILTER 26
#define SO_BINDTODEVICE 25
#define SO_BROADCAST 6
#define SO_BSDCOMPAT 14
#define SO_BUSY_POLL 46
#define SOCK_DGRAM 2
#define SOCK_RAW 3
#define SOCK_RDM 4
#define SOCK_SEQPACKET 5
#define SOCK_STREAM 1
#define SO_DEBUG 1
#define SO_DETACH_FILTER 27
#define SO_DOMAIN 39
#define SO_DONTROUTE 5
#define SO_ERROR 4
#define SO_GET_FILTER SO_ATTACH_FILTER
#define SO_KEEPALIVE 9
#define SO_LINGER 13
#define SO_LOCK_FILTER 44
#define SOL_SOCKET 1
#define SO_MARK 36
#define SO_NO_CHECK 11
#define SO_NOFCS 43
#define SO_OOBINLINE 10
#define SO_PASSCRED 16
#define SO_PASSSEC 34
#define SO_PEEK_OFF 42
#define SO_PEERCRED 17
#define SO_PEERNAME 28
#define SO_PEERSEC 31
#define SO_PRIORITY 12
#define SO_PROTOCOL 38
#define SO_RCVBUF 8
#define SO_RCVBUFFORCE 33
#define SO_RCVLOWAT 18
#define SO_RCVTIMEO 20
#define SO_REUSEADDR 2
#define SO_REUSEPORT 15
#define SO_RXQ_OVFL 40
#define SO_SECURITY_AUTHENTICATION 22
#define SO_SECURITY_ENCRYPTION_NETWORK 24
#define SO_SECURITY_ENCRYPTION_TRANSPORT 23
#define SO_SELECT_ERR_QUEUE 45
#define SO_SNDBUF 7
#define SO_SNDBUFFORCE 32
#define SO_SNDLOWAT 19
#define SO_SNDTIMEO 21
#define SO_TIMESTAMP 29
#define SO_TIMESTAMPING 37
#define SO_TIMESTAMPNS 35
#define SO_TYPE 3
#define SO_WIFI_STATUS 41
#define _STK_LIM_MAX RLIM_INFINITY
#define SYS_SECCOMP (__SI_SYS|1)
#define TAB0 0000000
#define TAB1 0004000
#define TAB2 0010000
#define TAB3 0014000
#define TABDLY 0014000
#define TCFLSH 0x540B
#define TCGETA 0x5405
#define TCGETS 0x5401
#define TCGETS2 _IOR('T' 0x2A struct termios2)
#define TCGETX 0x5432
#define TCIFLUSH 0
#define TCIOFF 2
#define TCIOFLUSH 2
#define TCION 3
#define TCOFLUSH 1
#define TCOOFF 0
#define TCOON 1
#define TCSADRAIN 1
#define TCSAFLUSH 2
#define TCSANOW 0
#define TCSBRK 0x5409
#define TCSBRKP 0x5425
#define TCSETA 0x5406
#define TCSETAF 0x5408
#define TCSETAW 0x5407
#define TCSETS 0x5402
#define TCSETS2 _IOW('T' 0x2B struct termios2)
#define TCSETSF 0x5404
#define TCSETSF2 _IOW('T' 0x2D struct termios2)
#define TCSETSW 0x5403
#define TCSETSW2 _IOW('T' 0x2C struct termios2)
#define TCSETX 0x5433
#define TCSETXF 0x5434
#define TCSETXW 0x5435
#define TCXONC 0x540A
#define TIOCCBRK 0x5428
#define TIOCCONS 0x541D
#define TIOCEXCL 0x540C
#define TIOCGDEV _IOR('T' 0x32 unsigned int)
#define TIOCGETD 0x5424
#define TIOCGEXCL _IOR('T' 0x40 int)
#define TIOCGICOUNT 0x545D
#define TIOCGLCKTRMIOS 0x5456
#define TIOCGPGRP 0x540F
#define TIOCGPKT _IOR('T' 0x38 int)
#define TIOCGPTLCK _IOR('T' 0x39 int)
#define TIOCGPTN _IOR('T' 0x30 unsigned int)
#define TIOCGRS485 0x542E
#define TIOCGSERIAL 0x541E
#define TIOCGSID 0x5429
#define TIOCGSOFTCAR 0x5419
#define TIOCGWINSZ 0x5413
#define TIOCINQ FIONREAD
#define TIOCLINUX 0x541C
#define TIOCMBIC 0x5417
#define TIOCMBIS 0x5416
#define TIOCM_CAR 0x040
#define TIOCM_CD TIOCM_CAR
#define TIOCM_CTS 0x020
#define TIOCM_DSR 0x100
#define TIOCM_DTR 0x002
#define TIOCMGET 0x5415
#define TIOCMIWAIT 0x545C
#define TIOCM_LE 0x001
#define TIOCM_LOOP 0x8000
#define TIOCM_OUT1 0x2000
#define TIOCM_OUT2 0x4000
#define TIOCM_RI TIOCM_RNG
#define TIOCM_RNG 0x080
#define TIOCM_RTS 0x004
#define TIOCMSET 0x5418
#define TIOCM_SR 0x010
#define TIOCM_ST 0x008
#define TIOCNOTTY 0x5422
#define TIOCNXCL 0x540D
#define TIOCOUTQ 0x5411
#define TIOCPKT 0x5420
#define TIOCSBRK 0x5427
#define TIOCSCTTY 0x540E
#define TIOCSERCONFIG 0x5453
#define TIOCSERGETLSR 0x5459
#define TIOCSERGETMULTI 0x545A
#define TIOCSERGSTRUCT 0x5458
#define TIOCSERGWILD 0x5454
#define TIOCSERSETMULTI 0x545B
#define TIOCSERSWILD 0x5455
#define TIOCSETD 0x5423
#define TIOCSIG _IOW('T' 0x36 int)
#define TIOCSLCKTRMIOS 0x5457
#define TIOCSPGRP 0x5410
#define TIOCSPTLCK _IOW('T' 0x31 int)
#define TIOCSRS485 0x542F
#define TIOCSSERIAL 0x541F
#define TIOCSSOFTCAR 0x541A
#define TIOCSTI 0x5412
#define TIOCSWINSZ 0x5414
#define TIOCVHANGUP 0x5437
#define TOSTOP 0000400
#define TRAP_BRANCH (__SI_FAULT|3)
#define TRAP_BRKPT (__SI_FAULT|1)
#define TRAP_HWBKPT (__SI_FAULT|4)
#define TRAP_TRACE (__SI_FAULT|2)
#define VDISCARD 13
#define VEOF 4
#define VEOL 11
#define VEOL2 16
#define VERASE 2
#define VINTR 0
#define VKILL 3
#define VLNEXT 15
#define VMIN 6
#define VQUIT 1
#define VREPRINT 12
#define VSTART 8
#define VSTOP 9
#define VSUSP 10
#define VSWTC 7
#define VT0 0000000
#define VT1 0040000
#define VTDLY 0040000
#define VTIME 5
#define VWERASE 14
#define __WALL 0x40000000
#define __WCLONE 0x80000000
#define WCONTINUED 0x00000008
#define WEXITED 0x00000004
#define WNOHANG 0x00000001
#define __WNOTHREAD 0x20000000
#define WNOWAIT 0x01000000
#define WSTOPPED WUNTRACED
#define WUNTRACED 0x00000002
#define X86_NR_SUBARCHS 5
#define X86_SUBARCH_CE4100 4
#define X86_SUBARCH_LGUEST 1
#define X86_SUBARCH_MRST 3
#define X86_SUBARCH_PC 0
#define X86_SUBARCH_XEN 2
#define XCASE 0000004
#define XLF_CAN_BE_LOADED_ABOVE_4G 2
#define XLF_EFI_HANDOVER_32 4
#define XLF_EFI_HANDOVER_64 8
#define XLF_KERNEL_64 1
#define XTABS 0014000
#endif
#if 1 //macros
#ifndef NULL
#define NULL ((void *)0)
#endif
#define CHAR_BIT __CHAR_BIT__ //__CHAR_BIT__ is passed by the compiler
#if __BITS_PER_LONG != 64
#define IFBITSPERLONGNEQ64(...) __VA_ARGS__
#define IFBITSPERLONGEQ64(...)
#else
#define IFBITSPERLONGNEQ64(...)
#define IFBITSPERLONGEQ64(...) __VA_ARGS__
#endif
#ifndef __ARCH_SI_ATTRIBUTES
#define __ARCH_SI_ATTRIBUTES
#endif
#define get_avphys_pages() sysconf(_SC_AVPHYS_PAGES)
#define get_nprocs() sysconf(_SC_NPROCESSORS_ONLN)
#define get_nprocs_conf() sysconf(_SC_NPROCESSORS_CONF)
#define get_phys_pages() sysconf(_SC_PHYS_PAGES)
#define ROL(x,y) (x<<y)|(x>>((sizeof(x)*CHAR_BIT) -y))
#define ROR(x,y) (x>>y)|(x<<((sizeof(x)*CHAR_BIT) -y))
#define SI_FROMUSER(siptr) ((siptr)->si_code <= 0),
#define SI_FROMKERNEL(siptr) ((siptr)->si_code > 0),
#define _IOC(d,t,n,sz) (((d) << _IOC_DIRSHIFT) | ((t) << _IOC_TYPESHIFT) | \
((n) << _IOC_NRSHIFT) | ((sz) << _IOC_SIZESHIFT))
#define _IOC_TYPECHECK(t) (sizeof(t))
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOR_BAD(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
#define _IOW_BAD(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
#define _IOWR_BAD(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
#define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
#define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
#define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
#define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
#define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT)
#define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT)
#define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
#define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT)
#define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
#if __STDC_VERSION__ >= 201103L
#define noreturn _Noreturn
#else
#define noreturn __attribute__((noreturn))
#endif
#endif
#if 1 //syscall macro stuff, TODO - handle multiple returns and extra clobs
#define _P(x, y) x ## y
#define P(x, y) _P(x, y)
#define _H(x,...) x##_(__VA_ARGS__)
#define STACK_POINTER_(sp,...) sp
#define STACK_POINTER _H(STACK_POINTER,ARCH_DATA)
#define SYSCALL_(a,syscall,...) syscall
#define SYSCALL _H(SYSCALL,ARCH_DATA)
#define CALL_NUMBER_(a,b,cnum,...) cnum
#define CALL_NUMBER _H(CALL_NUMBER,ARCH_DATA)
#define RETURN_REGISTER_(a,b,c,ret,...) ret
#define RETURN_REGISTER _H(RETURN_REGISTER,ARCH_DATA)
#define ARG1_(sp,sysc,cnum,ret,a1,...) a1
#define ARG1 _H(ARG1,ARCH_DATA)
#define ARG2_(sp,sysc,cnum,ret,a1,a2,...) a2
#define ARG2 _H(ARG2,ARCH_DATA)
#define ARG3_(sp,sysc,cnum,ret,a1,a2,a3,...) a3
#define ARG3 _H(ARG3,ARCH_DATA)
#define ARG4_(sp,sysc,cnum,ret,a1,a2,a3,a4,...) a4
#define ARG4 _H(ARG4,ARCH_DATA)