forked from ptitSeb/box64
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrappedlibx11.c
More file actions
2786 lines (2585 loc) · 109 KB
/
wrappedlibx11.c
File metadata and controls
2786 lines (2585 loc) · 109 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <dlfcn.h>
#include "wrappedlibs.h"
#include "debug.h"
#include "wrapper32.h"
#include "bridge.h"
#include "librarian/library_private.h"
#include "x64emu.h"
#include "callback.h"
#include "librarian.h"
#include "box32context.h"
#include "emu/x64emu_private.h"
#include "myalign32.h"
#include "elfloader.h"
#include "converter32.h"
#ifdef ANDROID
static const char* libx11Name = "libX11.so";
#else
static const char* libx11Name = "libX11.so.6";
#endif
#define LIBNAME libx11
#include "libtools/my_x11_conv.h"
typedef int (*XErrorHandler)(void *, void *);
void* my32_XSetErrorHandler(x64emu_t* t, XErrorHandler handler);
typedef int (*XIOErrorHandler)(void *);
void* my32_XSetIOErrorHandler(x64emu_t* t, XIOErrorHandler handler);
void* my32_XESetCloseDisplay(x64emu_t* emu, void* display, int32_t extension, void* handler);
typedef int (*WireToEventProc)(void*, void*, void*);
typedef int(*EventHandler) (void*,void*,void*);
int32_t my32_XIfEvent(x64emu_t* emu, void* d,void* ev, EventHandler h, void* arg);
void delShmInfo(my_XShmSegmentInfo_t* a); // edfine in Xext, to remove a saved ShmInfo
typedef void (*vFp_t)(void*);
typedef int (*iFp_t)(void*);
typedef uint32_t (*uFv_t)(void);
typedef int (*iFpp_t)(void*, void*);
typedef int32_t (*iFpl_t)(void*, intptr_t);
typedef int (*iFppp_t)(void*, void*, void*);
typedef uintptr_t (*LFpii_t)(void*, int32_t, int32_t);
typedef int32_t (*iFpiiL_t)(void*, int32_t, int32_t, uintptr_t);
typedef void* (*pFpiiuu_t)(void*, int32_t, int32_t, uint32_t, uint32_t);
#define ADDED_FUNCTIONS() \
GO(XInitThreads, uFv_t) \
GO(XUnlockDisplay, vFp_t)
#include "generated/wrappedlibx11types32.h"
#include "wrappercallback32.h"
#define SUPER() \
GO(0) \
GO(1) \
GO(2) \
GO(3) \
GO(4) \
GO(5) \
GO(6) \
GO(7) \
GO(8) \
GO(9) \
GO(10) \
GO(11) \
GO(12) \
GO(13) \
GO(14) \
GO(15)
// wire_to_event
#define GO(A) \
static uintptr_t my32_wire_to_event_fct_##A = 0; \
static int my32_wire_to_event_##A(void* dpy, void* re, void* event) \
{ \
static my_XEvent_32_t re_s = {0}; \
int ret = (int)RunFunctionFmt(my32_wire_to_event_fct_##A, "ppp", getDisplay(dpy), &re_s, event);\
unconvertXEvent(re, &re_s); \
return ret; \
}
SUPER()
#undef GO
#define GO(A) \
static iFppp_t my32_rev_wire_to_event_fct_##A = NULL; \
static int my32_rev_wire_to_event_##A(void* dpy, void* re, void* event) \
{ \
static my_XEvent_t re_l = {0}; \
int ret = my32_rev_wire_to_event_fct_##A (getDisplay(dpy), &re_l, event); \
convertXEvent(re, &re_l); \
}
SUPER()
#undef GO
static void* findwire_to_eventFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_wire_to_event_fct_##A == (uintptr_t)fct) return my32_wire_to_event_##A;
SUPER()
#undef GO
#define GO(A) if(my32_wire_to_event_fct_##A == 0) {my32_wire_to_event_fct_##A = (uintptr_t)fct; return my32_wire_to_event_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 wire_to_event callback\n");
return NULL;
}
static void* reverse_wire_to_eventFct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_wire_to_event_##A == fct) return (void*)my32_wire_to_event_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_wire_to_event_fct_##A == fct) f = (void*)my32_rev_wire_to_event_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_wire_to_event_fct_##A) {my32_rev_wire_to_event_fct_##A = fct; f = my32_rev_wire_to_event_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, iFppp_32, f, 0, "X11_wire_to_event");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 wire_to_event callback\n");
return fct;
}
// event_to_wire
#define GO(A) \
static uintptr_t my32_event_to_wire_fct_##A = 0; \
static int my32_event_to_wire_##A(void* dpy, void* re, void* event) \
{ \
my_XEvent_32_t re_s = {0}; \
convertXEvent(&re_s, re); \
return (int)RunFunctionFmt(my32_event_to_wire_fct_##A, "ppp", getDisplay(dpy), &re_s, event); \
}
SUPER()
#undef GO
#define GO(A) \
static iFppp_t my32_rev_event_to_wire_fct_##A = NULL; \
static int my32_rev_event_to_wire_##A(void* dpy, void* re, void* event) \
{ \
static my_XEvent_t re_l = {0}; \
unconvertXEvent(&re_l, re); \
return my32_rev_event_to_wire_fct_##A (getDisplay(dpy), &re_l, event); \
}
SUPER()
#undef GO
static void* findevent_to_wireFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_event_to_wire_fct_##A == (uintptr_t)fct) return my32_event_to_wire_##A;
SUPER()
#undef GO
#define GO(A) if(my32_event_to_wire_fct_##A == 0) {my32_event_to_wire_fct_##A = (uintptr_t)fct; return my32_event_to_wire_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 event_to_wire callback\n");
return NULL;
}
static void* reverse_event_to_wireFct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_event_to_wire_##A == fct) return (void*)my32_event_to_wire_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_event_to_wire_fct_##A == fct) f = (void*)my32_rev_event_to_wire_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_event_to_wire_fct_##A) {my32_rev_event_to_wire_fct_##A = fct; f = my32_rev_event_to_wire_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, iFppp_32, f, 0, "X11_event_to_wire");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 event_to_wire callback\n");
return fct;
}
// error_handler
#define GO(A) \
static uintptr_t my32_error_handler_fct_##A = 0; \
static int my32_error_handler_##A(void* dpy, void* error) \
{ \
static my_XErrorEvent_32_t evt = {0}; \
convert_XErrorEvent_to_32(&evt, error); \
printf_log(LOG_DEBUG, "Calling Xerrorhandler(%p, %p), err=%hhu/%hhu/%hhu\n", \
dpy, error, evt.error_code, evt.request_code, evt.minor_code); \
return (int)RunFunctionFmt(my32_error_handler_fct_##A, "pp", FindDisplay(dpy), &evt); \
}
SUPER()
#undef GO
#define GO(A) \
static iFpp_t my32_rev_error_handler_fct_##A = NULL; \
static int my32_rev_error_handler_##A(void* dpy, void* error) \
{ \
my_XErrorEvent_t evt = {0}; \
convert_XErrorEvent_to_64(&evt, error); \
return my32_rev_error_handler_fct_##A (getDisplay(dpy), &evt); \
}
SUPER()
#undef GO
static void* finderror_handlerFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_error_handler_fct_##A == (uintptr_t)fct) return my32_error_handler_##A;
SUPER()
#undef GO
#define GO(A) if(my32_error_handler_fct_##A == 0) {my32_error_handler_fct_##A = (uintptr_t)fct; return my32_error_handler_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 error_handler callback\n");
return NULL;
}
static void* reverse_error_handler_Fct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_error_handler_##A == fct) return (void*)my32_error_handler_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_error_handler_fct_##A == fct) f = (void*)my32_rev_error_handler_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_error_handler_fct_##A) {my32_rev_error_handler_fct_##A = fct; f = my32_rev_error_handler_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, iFpp_32, f, 0, "X11_error_handler");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 error_handler callback\n");
return fct;
}
// ioerror_handler
#define GO(A) \
static uintptr_t my32_ioerror_handler_fct_##A = 0; \
static int my32_ioerror_handler_##A(void* dpy) \
{ \
return (int)RunFunctionFmt(my32_ioerror_handler_fct_##A, "p", FindDisplay(dpy));\
}
SUPER()
#undef GO
#define GO(A) \
static iFp_t my32_rev_ioerror_handler_fct_##A = NULL; \
static int my32_rev_ioerror_handler_##A(void* dpy) \
{ \
return my32_rev_ioerror_handler_fct_##A (getDisplay(dpy)); \
}
SUPER()
#undef GO
static void* findioerror_handlerFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_ioerror_handler_fct_##A == (uintptr_t)fct) return my32_ioerror_handler_##A;
SUPER()
#undef GO
#define GO(A) if(my32_ioerror_handler_fct_##A == 0) {my32_ioerror_handler_fct_##A = (uintptr_t)fct; return my32_ioerror_handler_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 ioerror_handler callback\n");
return NULL;
}
static void* reverse_ioerror_handler_Fct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_ioerror_handler_##A == fct) return (void*)my32_ioerror_handler_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_ioerror_handler_fct_##A == fct) f = (void*)my32_rev_ioerror_handler_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_ioerror_handler_fct_##A) {my32_rev_ioerror_handler_fct_##A = fct; f = my32_rev_ioerror_handler_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, iFp_32, f, 0, "X11_ioerror_handler");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 ioerror_handler callback\n");
return fct;
}
#if 0
// exterror_handler
#define GO(A) \
static uintptr_t my32_exterror_handler_fct_##A = 0; \
static int my32_exterror_handler_##A(void* dpy, void* err, void* codes, int* ret_code) \
{ \
return (int)RunFunctionFmt(my32_exterror_handler_fct_##A, "pppp", dpy, err, codes, ret_code);\
}
SUPER()
#undef GO
static void* findexterror_handlerFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_exterror_handler_fct_##A == (uintptr_t)fct) return my32_exterror_handler_##A;
SUPER()
#undef GO
#define GO(A) if(my32_exterror_handler_fct_##A == 0) {my32_exterror_handler_fct_##A = (uintptr_t)fct; return my32_exterror_handler_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 exterror_handler callback\n");
return NULL;
}
static void* reverse_exterror_handlerFct(library_t* lib, void* fct)
{
if(!fct) return fct;
if(CheckBridged(lib->w.bridge, fct))
return (void*)CheckBridged(lib->w.bridge, fct);
#define GO(A) if(my32_exterror_handler_##A == fct) return (void*)my32_exterror_handler_fct_##A;
SUPER()
#undef GO
return (void*)AddBridge(lib->w.bridge, iFpppp, fct, 0, NULL);
}
#endif
// close_display
#define GO(A) \
static uintptr_t my32_close_display_fct_##A = 0; \
static int my32_close_display_##A(void* dpy, void* codes) \
{ \
return (int)RunFunctionFmt(my32_close_display_fct_##A, "pp", getDisplay(dpy), codes); \
}
SUPER()
#undef GO
static void* findclose_displayFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_close_display_fct_##A == (uintptr_t)fct) return my32_close_display_##A;
SUPER()
#undef GO
#define GO(A) if(my32_close_display_fct_##A == 0) {my32_close_display_fct_##A = (uintptr_t)fct; return my32_close_display_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 close_display callback\n");
return NULL;
}
static void* reverse_close_displayFct(library_t* lib, void* fct)
{
if(!fct) return fct;
if(CheckBridged(lib->w.bridge, fct))
return (void*)CheckBridged(lib->w.bridge, fct);
#define GO(A) if(my32_close_display_##A == fct) return (void*)my32_close_display_fct_##A;
SUPER()
#undef GO
return (void*)AddBridge(lib->w.bridge, iFpp_32, fct, 0, NULL);
}
// register_im
#define GO(A) \
static uintptr_t my32_register_im_fct_##A = 0; \
static void my32_register_im_##A(void* dpy, void* u, void* d) \
{ \
RunFunctionFmt(my32_register_im_fct_##A, "ppp", getDisplay(dpy), u, d); \
}
SUPER()
#undef GO
static void* findregister_imFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_register_im_fct_##A == (uintptr_t)fct) return my32_register_im_##A;
SUPER()
#undef GO
#define GO(A) if(my32_register_im_fct_##A == 0) {my32_register_im_fct_##A = (uintptr_t)fct; return my32_register_im_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 register_im callback\n");
return NULL;
}
static void* reverse_register_imFct(library_t* lib, void* fct)
{
if(!fct) return fct;
if(CheckBridged(lib->w.bridge, fct))
return (void*)CheckBridged(lib->w.bridge, fct);
#define GO(A) if(my32_register_im_##A == fct) return (void*)my32_register_im_fct_##A;
SUPER()
#undef GO
return (void*)AddBridge(lib->w.bridge, iFppp_32, fct, 0, NULL);
}
// XConnectionWatchProc
#define GO(A) \
static uintptr_t my32_XConnectionWatchProc_fct_##A = 0; \
static void my32_XConnectionWatchProc_##A(void* dpy, void* data, int op, void* d) \
{ \
RunFunctionFmt(my32_XConnectionWatchProc_fct_##A, "ppip", FindDisplay(dpy), data, op, d); \
}
SUPER()
#undef GO
static void* findXConnectionWatchProcFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_XConnectionWatchProc_fct_##A == (uintptr_t)fct) return my32_XConnectionWatchProc_##A;
SUPER()
#undef GO
#define GO(A) if(my32_XConnectionWatchProc_fct_##A == 0) {my32_XConnectionWatchProc_fct_##A = (uintptr_t)fct; return my32_XConnectionWatchProc_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 XConnectionWatchProc callback\n");
return NULL;
}
// xifevent
#define GO(A) \
static uintptr_t my32_xifevent_fct_##A = 0; \
static int my32_xifevent_##A(void* dpy, my_XEvent_t* event, void* d) \
{ \
static my_XEvent_32_t evt[16] = {0}; \
static int idx = 0; \
idx=(idx+1)&15; \
convertXEvent(evt+idx, event); \
return RunFunctionFmt(my32_xifevent_fct_##A, "ppp", getDisplay(dpy), evt+idx, d); \
}
SUPER()
#undef GO
static void* findxifeventFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_xifevent_fct_##A == (uintptr_t)fct) return my32_xifevent_##A;
SUPER()
#undef GO
#define GO(A) if(my32_xifevent_fct_##A == 0) {my32_xifevent_fct_##A = (uintptr_t)fct; return my32_xifevent_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 xifevent callback\n");
return NULL;
}
// XInternalAsyncHandler
#define GO(A) \
static uintptr_t my32_XInternalAsyncHandler_fct_##A = 0; \
static int my32_XInternalAsyncHandler_##A(void* dpy, void* rep, void* buf, int len, void* data) \
{ \
return RunFunctionFmt(my32_XInternalAsyncHandler_fct_##A, "pppip", FindDisplay(dpy), rep, buf, len, data); \
}
SUPER()
#undef GO
static void* findXInternalAsyncHandlerFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_XInternalAsyncHandler_fct_##A == (uintptr_t)fct) return my32_XInternalAsyncHandler_##A;
SUPER()
#undef GO
#define GO(A) if(my32_XInternalAsyncHandler_fct_##A == 0) {my32_XInternalAsyncHandler_fct_##A = (uintptr_t)fct; return my32_XInternalAsyncHandler_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 XInternalAsyncHandler callback\n");
return NULL;
}
// XSynchronizeProc
#define GO(A) \
static uintptr_t my32_XSynchronizeProc_fct_##A = 0; \
static int my32_XSynchronizeProc_##A() \
{ \
return (int)RunFunctionFmt(my32_XSynchronizeProc_fct_##A, "");\
}
SUPER()
#undef GO
static void* findXSynchronizeProcFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_XSynchronizeProc_fct_##A == (uintptr_t)fct) return my32_XSynchronizeProc_##A;
SUPER()
#undef GO
#define GO(A) if(my32_XSynchronizeProc_fct_##A == 0) {my32_XSynchronizeProc_fct_##A = (uintptr_t)fct; return my32_XSynchronizeProc_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 XSynchronizeProc callback\n");
return NULL;
}
static void* reverse_XSynchronizeProcFct(library_t* lib, void* fct)
{
if(!fct) return fct;
if(CheckBridged(lib->w.bridge, fct))
return (void*)CheckBridged(lib->w.bridge, fct);
#define GO(A) if(my32_XSynchronizeProc_##A == fct) return (void*)my32_XSynchronizeProc_fct_##A;
SUPER()
#undef GO
return (void*)AddBridge(lib->w.bridge, iFppp_32, fct, 0, NULL);
}
#if 0
// XLockDisplay
#define GO(A) \
static uintptr_t my32_XLockDisplay_fct_##A = 0; \
static void my32_XLockDisplay_##A(void* dpy) \
{ \
RunFunctionFmt(my32_XLockDisplay_fct_##A, "p", dpy); \
}
SUPER()
#undef GO
static void* findXLockDisplayFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_XLockDisplay_fct_##A == (uintptr_t)fct) return my32_XLockDisplay_##A;
SUPER()
#undef GO
#define GO(A) if(my32_XLockDisplay_fct_##A == 0) {my32_XLockDisplay_fct_##A = (uintptr_t)fct; return my32_XLockDisplay_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 XLockDisplay callback\n");
return NULL;
}
// XUnlockDisplay
#define GO(A) \
static uintptr_t my32_XUnlockDisplay_fct_##A = 0; \
static void my32_XUnlockDisplay_##A(void* dpy) \
{ \
RunFunctionFmt(my32_XUnlockDisplay_fct_##A, "p", dpy); \
}
SUPER()
#undef GO
static void* findXUnlockDisplayFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_XUnlockDisplay_fct_##A == (uintptr_t)fct) return my32_XUnlockDisplay_##A;
SUPER()
#undef GO
#define GO(A) if(my32_XUnlockDisplay_fct_##A == 0) {my32_XUnlockDisplay_fct_##A = (uintptr_t)fct; return my32_XUnlockDisplay_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 XUnlockDisplay callback\n");
return NULL;
}
#endif
// async_handler
#define GO(A) \
static uintptr_t my32_async_handler_fct_##A = 0; \
static int my32_async_handler_##A(void* a, void* b, void* c, int d, void* e) \
{ \
return (int)RunFunctionFmt(my32_async_handler_fct_##A, "pppip", FindDisplay(a), b, c, d, e); \
}
SUPER()
#undef GO
static void* find_async_handler_Fct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_async_handler_fct_##A == (uintptr_t)fct) return my32_async_handler_##A;
SUPER()
#undef GO
#define GO(A) if(my32_async_handler_fct_##A == 0) {my32_async_handler_fct_##A = (uintptr_t)fct; return my32_async_handler_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 async_handler callback\n");
return NULL;
}
// XImage function wrappers
// create_image
#define GO(A) \
static uintptr_t my32_create_image_fct_##A = 0; \
static void* my32_create_image_##A(void* a, void* b, uint32_t c, int d, int e, void* f, uint32_t g, uint32_t h, int i, int j) \
{ \
void* ret = (void*)RunFunctionFmt(my32_create_image_fct_##A, "ppuiipuuii", FindDisplay(a), convert_Visual_to_32(a, b), c, d, e, f, g, h, i, j); \
UnwrapXImage(ret, ret); \
return ret; \
} \
static pFXpuiipuuii_t my32_rev_create_image_fct_##A = NULL; \
static void* my32_rev_create_image_##A(void* a, void* b, uint32_t c, int d, int e, void* f, uint32_t g, uint32_t h, int i, int j) \
{ \
void* ret = my32_rev_create_image_fct_##A (getDisplay(a), convert_Visual_to_64(a, b), c, d, e, f, g, h, i, j); \
WrapXImage(ret, ret); \
return ret; \
}
SUPER()
#undef GO
static void* find_create_image_Fct(void* fct)
{
if(!fct) return fct;
void* n_fct = GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_rev_create_image_##A == n_fct) return (void*)my32_rev_create_image_fct_##A;
SUPER()
#undef GO
if(n_fct) return n_fct;
#define GO(A) if(my32_create_image_fct_##A == (uintptr_t)fct) return my32_create_image_##A;
SUPER()
#undef GO
#define GO(A) if(my32_create_image_fct_##A == 0) {my32_create_image_fct_##A = (uintptr_t)fct; return my32_create_image_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 create_image callback\n");
return NULL;
}
static void* reverse_create_image_Fct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_create_image_##A == fct) return (void*)my32_create_image_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_create_image_fct_##A == fct) f = (void*)my32_rev_create_image_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_create_image_fct_##A) {my32_rev_create_image_fct_##A = fct; f = my32_rev_create_image_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, pFXpuiipuuii_32, f, 0, "Ximage_create_image");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 create_image callback\n");
return fct;
}
// destroy_image
#define GO(A) \
static uintptr_t my32_destroy_image_fct_##A = 0; \
static int my32_destroy_image_##A(void* a) \
{ \
void* obdata = ((XImage*)a)->obdata; \
inplace_XImage_shrink(a); \
int ret = (int)RunFunctionFmt(my32_destroy_image_fct_##A, "p", a); \
to_hash_d((uintptr_t)obdata); \
if(obdata) delShmInfo(obdata); \
return ret; \
} \
static iFp_t my32_rev_destroy_image_fct_##A = NULL; \
static int my32_rev_destroy_image_##A(void* a) \
{ \
inplace_XImage_enlarge(a); \
to_hash_d((uintptr_t)((XImage*)a)->obdata); \
void* obdata = ((XImage*)a)->obdata; \
int ret = my32_rev_destroy_image_fct_##A (a); \
if(obdata) delShmInfo(obdata); \
return ret; \
}
SUPER()
#undef GO
static void* find_destroy_image_Fct(void* fct)
{
if(!fct) return fct;
void* n_fct = GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_rev_destroy_image_##A == n_fct) return (void*)my32_rev_destroy_image_fct_##A;
SUPER()
#undef GO
if(n_fct) return n_fct;
#define GO(A) if(my32_destroy_image_fct_##A == (uintptr_t)fct) return my32_destroy_image_##A;
SUPER()
#undef GO
#define GO(A) if(my32_destroy_image_fct_##A == 0) {my32_destroy_image_fct_##A = (uintptr_t)fct; return my32_destroy_image_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for 32bits libX11 destroy_image callback\n");
return NULL;
}
static void* reverse_destroy_image_Fct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_destroy_image_##A == fct) return (void*)my32_destroy_image_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_destroy_image_fct_##A == fct) f = (void*)my32_rev_destroy_image_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_destroy_image_fct_##A) {my32_rev_destroy_image_fct_##A = fct; f = my32_rev_destroy_image_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, iFp_32, f, 0, "Ximage_destroy_image");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 destroy_image callback\n");
return fct;
}
// get_pixel
#define GO(A) \
static uintptr_t my32_get_pixel_fct_##A = 0; \
static unsigned long my32_get_pixel_##A(void* a, int b, int c) \
{ \
inplace_XImage_shrink(a); \
uint32_t ret = RunFunctionFmt(my32_get_pixel_fct_##A, "pii", a, b, c); \
inplace_XImage_enlarge(a); \
return from_ulong(ret); \
} \
static LFpii_t my32_rev_get_pixel_fct_##A = NULL; \
static unsigned long my32_rev_get_pixel_##A(void* a, int b, int c) \
{ \
inplace_XImage_enlarge(a); \
unsigned long ret = my32_rev_get_pixel_fct_##A (a, b, c); \
inplace_XImage_shrink(a); \
return ret; \
}
SUPER()
#undef GO
static void* find_get_pixel_Fct(void* fct)
{
if(!fct) return fct;
void* n_fct = GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_rev_get_pixel_##A == n_fct) return (void*)my32_rev_get_pixel_fct_##A;
SUPER()
#undef GO
if(n_fct) return n_fct;
#define GO(A) if(my32_get_pixel_fct_##A == (uintptr_t)fct) return my32_get_pixel_##A;
SUPER()
#undef GO
#define GO(A) if(my32_get_pixel_fct_##A == 0) {my32_get_pixel_fct_##A = (uintptr_t)fct; return my32_get_pixel_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 get_pixel callback\n");
return NULL;
}
static void* reverse_get_pixel_Fct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_get_pixel_##A == fct) return (void*)my32_get_pixel_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_get_pixel_fct_##A == fct) f = (void*)my32_rev_get_pixel_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_get_pixel_fct_##A) {my32_rev_get_pixel_fct_##A = fct; f = my32_rev_get_pixel_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, LFpii_32, f, 0, "Ximage_get_pixel");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 get_pixel callback\n");
return fct;
}
// put_pixel
#define GO(A) \
static uintptr_t my32_put_pixel_fct_##A = 0; \
static int my32_put_pixel_##A(void* a, int b, int c,unsigned long d) \
{ \
inplace_XImage_shrink(a); \
int ret = (int)RunFunctionFmt(my32_put_pixel_fct_##A, "piiL", a, b, c, d); \
inplace_XImage_enlarge(a); \
return ret; \
} \
static iFpiiL_t my32_rev_put_pixel_fct_##A = NULL; \
static int my32_rev_put_pixel_##A(void* a, int b, int c, ulong_t d) \
{ \
inplace_XImage_enlarge(a); \
int ret = my32_rev_put_pixel_fct_##A (a, b, c, from_ulong(d)); \
inplace_XImage_shrink(a); \
return ret; \
}
SUPER()
#undef GO
static void* find_put_pixel_Fct(void* fct)
{
if(!fct) return fct;
void* n_fct = GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_rev_put_pixel_##A == n_fct) return (void*)my32_rev_put_pixel_fct_##A;
SUPER()
#undef GO
if(n_fct) return n_fct;
#define GO(A) if(my32_put_pixel_fct_##A == (uintptr_t)fct) return my32_put_pixel_##A;
SUPER()
#undef GO
#define GO(A) if(my32_put_pixel_fct_##A == 0) {my32_put_pixel_fct_##A = (uintptr_t)fct; return my32_put_pixel_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 put_pixel callback\n");
return NULL;
}
static void* reverse_put_pixel_Fct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_put_pixel_##A == fct) return (void*)my32_put_pixel_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_put_pixel_fct_##A == fct) f = (void*)my32_rev_put_pixel_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_put_pixel_fct_##A) {my32_rev_put_pixel_fct_##A = fct; f = my32_rev_put_pixel_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, iFpiiL_32, f, 0, "Ximage_put_pixel");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 put_pixel callback\n");
return fct;
}
// sub_image
#define GO(A) \
static uintptr_t my32_sub_image_fct_##A = 0; \
static void* my32_sub_image_##A(void* a, int b, int c, uint32_t d, uint32_t e) \
{ \
inplace_XImage_shrink(a); \
void* ret = (void*)RunFunctionFmt(my32_sub_image_fct_##A, "piiuu", a, b, c, d, e);\
if(ret!=a) UnwrapXImage(ret, ret); \
inplace_XImage_enlarge(a); \
return ret; \
} \
static pFpiiuu_t my32_rev_sub_image_fct_##A = NULL; \
static void* my32_rev_sub_image_##A(void* a, int b, int c, uint32_t d, uint32_t e) \
{ \
inplace_XImage_enlarge(a); \
void* ret = my32_rev_sub_image_fct_##A (a, b, c, d, e); \
if(ret!=a) \
WrapXImage(ret, ret); \
inplace_XImage_shrink(a); \
return ret; \
}
SUPER()
#undef GO
static void* find_sub_image_Fct(void* fct)
{
if(!fct) return fct;
void* n_fct = GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_rev_sub_image_##A == n_fct) return (void*)my32_rev_sub_image_fct_##A;
SUPER()
#undef GO
if(n_fct) return n_fct;
#define GO(A) if(my32_sub_image_fct_##A == (uintptr_t)fct) return my32_sub_image_##A;
SUPER()
#undef GO
#define GO(A) if(my32_sub_image_fct_##A == 0) {my32_sub_image_fct_##A = (uintptr_t)fct; return my32_sub_image_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 sub_image callback\n");
return NULL;
}
static void* reverse_sub_image_Fct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_sub_image_##A == fct) return (void*)my32_sub_image_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_sub_image_fct_##A == fct) f = (void*)my32_rev_sub_image_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_sub_image_fct_##A) {my32_rev_sub_image_fct_##A = fct; f = my32_rev_sub_image_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, pFpiiuu_32, f, 0, "ximage_sub_image");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 sub_image callback\n");
return fct;
}
// add_pixel
#define GO(A) \
static uintptr_t my32_add_pixel_fct_##A = 0; \
static int my32_add_pixel_##A(void* a, long b) \
{ \
inplace_XImage_shrink(a); \
int ret = (int)RunFunctionFmt(my32_add_pixel_fct_##A, "pl", a, b); \
inplace_XImage_enlarge(a); \
return ret; \
} \
static iFpl_t my32_rev_add_pixel_fct_##A = NULL; \
static int my32_rev_add_pixel_##A(void* a, long_t b) \
{ \
inplace_XImage_enlarge(a); \
int ret = my32_rev_add_pixel_fct_##A (a, from_long(b)); \
inplace_XImage_shrink(a); \
return ret; \
}
SUPER()
#undef GO
static void* find_add_pixel_Fct(void* fct)
{
if(!fct) return fct;
void* n_fct = GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my32_rev_add_pixel_##A == n_fct) return (void*)my32_rev_add_pixel_fct_##A;
SUPER()
#undef GO
if(n_fct) return n_fct;
#define GO(A) if(my32_add_pixel_fct_##A == (uintptr_t)fct) return my32_add_pixel_##A;
SUPER()
#undef GO
#define GO(A) if(my32_add_pixel_fct_##A == 0) {my32_add_pixel_fct_##A = (uintptr_t)fct; return my32_add_pixel_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libX11 add_pixel callback\n");
return NULL;
}
static void* reverse_add_pixel_Fct(library_t* lib, void* fct)
{
//Callsed from x86 world -> native world
if(!fct) return fct;
// first check if it's a wrapped function, that could be easy
#define GO(A) if(my32_add_pixel_##A == fct) return (void*)my32_add_pixel_fct_##A;
SUPER()
#undef GO
if(FindElfAddress(my_context, (uintptr_t)fct))
return fct;
// it's a naitve one... so bridge it, but need transform XImage32 to XImage
void* f = NULL;
#define GO(A) if(!f && my32_rev_add_pixel_fct_##A == fct) f = (void*)my32_rev_add_pixel_##A;
SUPER()
#undef GO
#define GO(A) if(!f && !my32_rev_add_pixel_fct_##A) {my32_rev_add_pixel_fct_##A = fct; f = my32_rev_add_pixel_##A;}
SUPER()
#undef GO
if(f)
return (void*)AddCheckBridge(lib->w.bridge, iFpl_32, f, 0, "ximage_add_pixel");
printf_log(LOG_NONE, "Warning, no more slot for reverse 32bits libX11 add_pixel callback\n");
return fct;
}
// end of XImage functions callbacks
#undef SUPER
void* my32_XCreateImage(x64emu_t* emu, void* disp, void* vis, uint32_t depth, int32_t fmt, int32_t off
, void* data, uint32_t w, uint32_t h, int32_t pad, int32_t bpl);
int32_t my32_XInitImage(x64emu_t* emu, void* img);
void* my32_XGetImage(x64emu_t* emu, void* disp, XID drawable, int32_t x, int32_t y
, uint32_t w, uint32_t h, uint32_t plane, int32_t fmt);
int32_t my32_XPutImage(x64emu_t* emu, void* disp, XID drawable, void* gc, void* image
, int32_t src_x, int32_t src_y, int32_t dst_x, int32_t dst_y
, uint32_t w, uint32_t h);
void* my32_XGetSubImage(x64emu_t* emu, void* disp, XID drawable
, int32_t x, int32_t y
, uint32_t w, uint32_t h, XID plane, int32_t fmt
, void* image, int32_t dst_x, int32_t dst_y);
void my32_XDestroyImage(x64emu_t* emu, void* image);
typedef void (*XIMProc)(void*, void*, void*);
typedef int (*XICProc)(void*, void*, void*);
typedef struct {
void* client_data;
XIMProc callback;
} XIMCallback;
typedef struct {
void* client_data;
XICProc callback;
} XICCallback;
#define XNGeometryCallback "geometryCallback"
#define XNDestroyCallback "destroyCallback"
#define XNPreeditStartCallback "preeditStartCallback"
#define XNPreeditDoneCallback "preeditDoneCallback"
#define XNPreeditDrawCallback "preeditDrawCallback"
#define XNPreeditCaretCallback "preeditCaretCallback"
#define XNPreeditStateNotifyCallback "preeditStateNotifyCallback"
#define XNStatusStartCallback "statusStartCallback"
#define XNStatusDoneCallback "statusDoneCallback"
#define XNStatusDrawCallback "statusDrawCallback"
#define XNR6PreeditCallback "r6PreeditCallback"
#define XNStringConversionCallback "stringConversionCallback"
// utility functions
#include "super100.h"
// XNGeometryCallback
#define GO(A) \
static uintptr_t my32_XNGeometryCallback_fct_##A = 0; \
static void my32_XNGeometryCallback_##A(void* a, void* b, void* c) \
{ \
RunFunctionFmt(my32_XNGeometryCallback_fct_##A, "ppp", a, b); \