@@ -180,7 +180,7 @@ procedure GetCodeMem(var ptr: PByte; size: integer);
180
180
page:=VirtualAlloc(nil , PageSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
181
181
{ $ELSE}
182
182
// page := GetMem(PageSize);
183
- page := mmap($10000000 , PageSize, PROT_NONE, MAP_PRIVATE or MAP_ANON, -1 , 0 );
183
+ page := mmap(Pointer( $10000000 ) , PageSize, PROT_NONE, MAP_PRIVATE or MAP_ANON, -1 , 0 );
184
184
mprotect(page, PageSize, PROT_READ or PROT_WRITE or PROT_EXEC);
185
185
{ $ENDIF}
186
186
page^.next:=CodeMemPages;
@@ -505,15 +505,6 @@ function GetCallBack( self: TObject; method: Pointer;
505
505
function GetCallBack ( self: TObject; method: Pointer;
506
506
argnum: Integer; calltype: tcalltype): Pointer;
507
507
const
508
- // Short handling of stdcalls:
509
- S1: array [0 ..14 ] of byte = (
510
- $5A, // 00 pop edx // pop return address
511
- $B8,0 ,0 ,0 ,0 , // 01 mov eax, self
512
- $50 , // 06 push eax
513
- $52 , // 07 push edx // now push return address
514
- // call the real callback
515
- $B8,0 ,0 ,0 ,0 , // 08 mov eax, Method
516
- $FF,$E0); // 13 jmp eax
517
508
518
509
// Handling for ctCDECL:
519
510
C1: array [0 ..5 ] of byte = (
@@ -530,7 +521,7 @@ function GetCallBack( self: TObject; method: Pointer;
530
521
// end;
531
522
532
523
// self parameter
533
- C3: array [0 ..17 ] of byte = (
524
+ C3: array [0 ..19 ] of byte = (
534
525
$B8,0 ,0 ,0 ,0 , // 06+4*s mov eax, self
535
526
$50 , // 11+4*s push eax
536
527
// call the real callback
@@ -539,35 +530,30 @@ function GetCallBack( self: TObject; method: Pointer;
539
530
// clear stack
540
531
$83 ,$C4,0 , // 20+4*s add esp, 4+bytes+align
541
532
$5D, // 23+4*s pop ebp
542
- $C3); // 24+4*s ret
543
-
544
-
533
+ $C2,00 ,00 ); // 24+4*s ret [0]
545
534
546
535
var
547
536
bytes: Word;
548
537
i: Integer;
549
538
P,Q: PByte;
550
539
align : integer;
551
540
begin
552
- if calltype = ctSTDCALL then begin
553
- GetCodeMem(Q,15 );
554
- P := Q;
555
- move(S1,P^,SizeOf(S1));
556
- Inc(P,2 );
557
- move(self,P^,SizeOf(self));
558
- Inc(P,7 );
559
- move(method,P^,SizeOf(method));
560
- { Inc(P,6); End of proc}
561
- end else begin { ctCDECL}
541
+ // On mac FPC ctSTDCALL and ctCDECL are the same
542
+ { $IFDEF FPC}
543
+ { $IFDEF MACOS32}
544
+ calltype := ctCDECL;
545
+ { $ENDIF}
546
+ { $ENDIF}
547
+
562
548
bytes := argnum * 4 ;
563
- align := ($10 - (bytes + 4 { self} + 4 { address} + 4 { push bp} ) and $f) and $f; // align to $10 for Mac compatibility
549
+ align := ($10 - (bytes + 4 { self} + 4 { address} + 4 { push bp} ) and $f) and $f; // align to $10 for Mac compatibility
564
550
565
- GetCodeMem(Q,24 + 4 *argnum);
551
+ GetCodeMem(Q,sizeof(c1)+sizeof(c3)+sizeof(c2) *argnum);
566
552
P := Q;
567
553
move(C1,P^,SizeOf(C1));
568
554
Inc(P,SizeOf(C1)-1 );
569
555
p^ := align;
570
- Inc(P);
556
+ Inc(P);
571
557
for i:=argnum-1 downto 0 do begin
572
558
move(C2,P^,SizeOf(C2));
573
559
Inc(P,2 );
@@ -580,10 +566,19 @@ function GetCallBack( self: TObject; method: Pointer;
580
566
Inc(P,6 );
581
567
move(method,P^,SizeOf(method));
582
568
Inc(P,8 );
583
- P^ := 4 +bytes+align;
584
- { Inc(P,3); End of proc}
585
- end ;
586
- result := Q;
569
+ if calltype = ctCDECL then
570
+ begin
571
+ P^ := 4 +bytes+align;
572
+ end
573
+ else
574
+ begin
575
+ P^ := { 4+} align;
576
+ Inc(P,3 );
577
+ P^ := bytes;
578
+ end ;
579
+
580
+
581
+ result := Q;
587
582
end ;
588
583
{ $ENDIF}
589
584
0 commit comments