FFI: FFI-Callbacks-mt.18.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

FFI: FFI-Callbacks-mt.18.mcz

commits-2
Marcel Taeumel uploaded a new version of FFI-Callbacks to project FFI:
http://source.squeak.org/FFI/FFI-Callbacks-mt.18.mcz

==================== Summary ====================

Name: FFI-Callbacks-mt.18
Author: mt
Time: 23 May 2021, 4:03:13.688158 pm
UUID: fcb16553-c424-d646-b58f-dc47277ed808
Ancestors: FFI-Callbacks-mt.17

Use #abiSend: for callback init.

=============== Diff against FFI-Callbacks-mt.17 ===============

Item was changed:
  ----- Method: FFICallback>>init__ccall (in category 'initialization - thunk prepare') -----
  init__ccall
  "Initialize the receiver with a __ccall thunk."
 
+ FFIPlatformDescription current abiSend: #'init_ccall' to: self.!
- FFICallback methodsDo: [:method |
- (method selector beginsWith: 'init__ccall') ifTrue: [
- (method hasPragma: #init) ifTrue: [
- (method pragmaAt: #abi:)
- ifNotNil: [:pragma | (pragma argumentAt: 1) = abi
- ifTrue: [^ self executeMethod: method]]]]].
-
- self error: 'Could not initialize thunk for current ABI: ', abi.!

Item was changed:
  ----- Method: FFICallback>>init__ccall_ARM32 (in category 'initialization - thunk prepare') -----
  init__ccall_ARM32
+ <abi: #ARM32> <init_ccall>
- <abi: #ARM32> <init>
  "Initialize the receiver with a __ccall thunk.  The thunk calls thunkEntry in the IA32ABI plugin,
  whose source is in platforms/Cross/plugins/IA32ABI/arm32abicc.c.  thunkEntry is the entry point
  for Callbacks. The objective of the thunk is to call thunkEntry with all arguments to the call of the
  thunk (registers and stack) as well as a pointer to the thunk itself.  thunkEntry is as follows:
 
  long long
  thunkEntry(long r0, long r1, long r2, long r3,
             double d0, double d1, double d2, double d3,
             double d4, double d5, double d6, double d7,
             void *thunkpPlus16, sqIntptr_t *stackp)
 
  thunkEntry then collects the various arguments (thunk, integer register arguments, floating-point
  register arguments, stack pointer) in a VMCallbackContext and invokes the callback via invokeCallbackContext:."
 
  "0x0 <thunk+0>: mov     r12, sp ; 0xe1a0c00d
    0x4 <thunk+4>: sub     sp, sp, #16 ; 0xe24dd010
    0x8 <thunk+8>: str     pc, [sp, #0] ; 0xe58df000 N.B. passes thunk+16; thunkEntry compensates
    0xc <thunk+12>: str     r12, [sp,#4] ; 0xe58dc004
    0x10 <thunk+16>: str     lr, [sp, #12] ; 0xe58de00c
    0x14 <thunk+20>: ldr     r12, [pc, #8] ; 0xe59fc008
    0x18 <thunk+24>: blx     r12 ; 0xe12fff3c
    0x1c <thunk+28>: add     sp, sp, #12 ; 0xe28dd00c
    0x20 <thunk+32>: ldr     pc, [sp], #4!! ; 0xe49df004 ; pop     {pc}
    0x24 <thunk+36>:     .word thunkEntry"
  self flag: #hidden. "mt: How is the thunk's handle stored to lookup this instance upon callback later?"
  thunk getHandle
  unsignedLongAt:   1 put: 16re1a0c00d;
  unsignedLongAt:   5 put: 16re24dd010;
  unsignedLongAt:   9 put: 16re58df000;
  unsignedLongAt: 13 put: 16re58dc004;
  unsignedLongAt: 17 put: 16re58de00c;
  unsignedLongAt: 21 put: 16re59fc008;
  unsignedLongAt: 25 put: 16re12fff3c;
  unsignedLongAt: 29 put: 16re28dd00c;
  unsignedLongAt: 33 put: 16re49df004;
  pointerAt: 37 put: self thunkEntryAddress length: 4.!

Item was changed:
  ----- Method: FFICallback>>init__ccall_ARM64 (in category 'initialization - thunk prepare') -----
  init__ccall_ARM64
+ <abi: #ARM64> <init_ccall>
- <abi: #ARM64> <init>
  "Initialize the receiver with a __ccall thunk.  The thunk calls thunkEntry in the Alien/IA32ABI plugin,
  whose source is in platforms/Cross/plugins/IA32ABI/arm64abicc.c.  thunkEntry is the entry point
  for Callbacks. The objective of the thunk is to call thunkEntry with all arguments to the call of the
  thunk (registers and stack) as well as a pointer to the thunk itself.  thunkEntry is as follows:
 
  long long
  thunkEntry(long x0, long x1, long x2, long x3,
        long x4, long x5, long x6, long x7,
        double d0, double d1, double d2, double d3,
        double d4, double d5, double d6, double d7,
        void *thunkpPlus16, sqIntptr_t *stackp)
 
  thunkEntry then collects the various arguments (thunk, integer register arguments, floating-point
  register arguments, stack pointer) in a VMCallbackContext and invokes the callback via invokeCallbackContext:."
 
  self shouldBeImplemented
 
  "self newCCall"!

Item was changed:
  ----- Method: FFICallback>>init__ccall_IA32 (in category 'initialization - thunk prepare') -----
  init__ccall_IA32
+ <abi: #IA32> <init_ccall>
- <abi: #IA32> <init>
  "Initialize the receiver with a __ccall thunk.  The thunk calls thunkEntry in the IA32ABI plugin,
  whose source is in platforms/Cross/plugins/IA32ABI/x64win64abicc.c.  thunkEntry is the entry point
  for Callbacks. The objective of the thunk is to call thunkEntry with all arguments to the call of the
  thunk (registers and stack) as well as a pointer to the thunk itself.  thunkEntry is as follows:
 
  long
  thunkEntry(void *thunkp, sqIntptr_t *stackp)
 
  thunkEntry then collects the various arguments (thunk, stack pointer) in a VMCallbackContext and
  invokes the callback via invokeCallbackContext:."
 
  "thunk: push   %esp 0x54 0xa1905454
  thunk+01: push   %esp 0x54
  thunk+02: nop   0x90
  thunk+03: mov    $thunkEntry,%eax 0xb8 0x00 0x00 0x00 0x00 0x00000000 - entry
  thunk+08: nop   0x90 0x68909090
  thunk+09: nop   0x90
  thunk+10: nop   0x90
  thunk+11: push   $thunk 0x68 0x00 0x00 0x00 0x00 0x00000000 - thunk
  thunk+16: call   *%eax 0xff 0xd0 0xc483d0ff
  thunk+18: add    $0xC,%esp 0x83 0xc4 0x0C 0x9090c30C
  thunk+21: ret 0xc3
  thunk+22: nop 0x90
  thunk+23: nop 0x90"
  thunk getHandle
  unsignedLongAt:  1 put: 16rB8905454;
  pointerAt: 5 put: self thunkEntryAddress length: 4;
  unsignedLongAt:  9 put: 16r68909090;
  pointerAt: 13 put: thunk getHandle length: 4;
  unsignedLongAt: 17 put: 16rC483D0FF;
  unsignedLongAt: 21 put: 16r9090C30C!

Item was changed:
  ----- Method: FFICallback>>init__ccall_X64 (in category 'initialization - thunk prepare') -----
  init__ccall_X64
+ <abi: #X64> <init_ccall>
- <abi: #X64> <init>
  "Initialize the receiver with a __ccall thunk.  The thunk calls thunkEntry in the IA32ABI plugin,
  whose source is in platforms/Cross/plugins/IA32ABI/x64sysvabicc.c.  thunkEntry is the entry point
  for Callbacks. The objective of the thunk is to call thunkEntry with all arguments to the call of the
  thunk (registers and stack) as well as a pointer to the thunk itself.  thunkEntry is as follows:
 
  long
  thunkEntry(long a0, long a1, long a2, long a3, long a4, long a5,
             double d0, double d1, double d2, double d3,
             double d4, double d5, double d6, double d7,
             void *thunkp, sqIntptr_t *stackp)
 
  thunkEntry then collects the various arguments (thunk, integer register arguments, floating-point
  register arguments, stack pointer) in a VMCallbackContext and invokes the callback via invokeCallbackContext:."
 
  "thunk+0x0: pushq  %rsp 54
  thunk+0x1: pushq  %rsp 54
  thunk+0x4: movabsq $thunk, %rax 48 b8 b0..b7 eight bytes of thunk address a.k.a. handle
  thunk+0xc: pushq  %rax 50
  thunk+0xd: movabsq $thunkEntry, %rax 48 b8 b0..b7 eight bytes of the thunkEntry address
  thunk+0x17: callq  *%rax ff d0
  thunk+0x19: addq   $0x18, %rsp 48 83 c4 18
  thunk+0x1d: retq c3
  thunk+0x1e: nop 90
  thunk+0x1f: nop 90"
  thunk getHandle
  unsignedLongAt:  1 put: 16rb8485454;
  pointerAt:  5 put: thunk getHandle length: 8;
  unsignedLongAt: 13 put: 16r00b84850; "00 is the first byte of the 64-bit constant the movabsq/0x48 opcode moves"
  pointerAt: 16 put: self thunkEntryAddress length: 8;
  unsignedByteAt: 24 put: 16rff;
  unsignedLongAt: 25 put: 16rc48348d0;
  unsignedLongAt: 29 put: 16r9090c318.!

Item was changed:
  ----- Method: FFICallback>>init__ccall_X64Win64 (in category 'initialization - thunk prepare') -----
  init__ccall_X64Win64
+ <abi: #X64Win64> <init_ccall>
- <abi: #X64Win64> <init>
  "Initialize the receiver with a __ccall thunk.  The thunk calls thunkEntry in the IA32ABI plugin,
  whose source is in platforms/Cross/plugins/IA32ABI/x64win64abicc.c.  thunkEntry is the entry point
  for Callbacks. The objective of the thunk is to call thunkEntry with all arguments to the call of the
  thunk (registers and stack) as well as a pointer to the thunk itself.  thunkEntry is as follows:
 
  long long
  thunkEntry(long long rcx, long long rdx,
        long long r8, long long r9,
  void *thunkp, sqIntptr_t *stackp)
 
  thunkEntry then collects the various arguments (thunk, integer register arguments, stack pointer)
  in a VMCallbackContext and invokes the callback via invokeCallbackContext:."
 
  "thunk+0x0: pushq  %rsp 54
  thunk+0x1: pushq  %rsp 54
  thunk+0x4: movabsq $thunk, %rax 48 b8 b0..b7 eight bytes of thunk address a.k.a. addressField
  thunk+0xc: pushq  %rax 50
  thunk+0xd: subq   $0x20, %rsp 48 83 c4 e0 (this is addq -20 since the immediate is signed extended)
  thunk+0x11: movabsq $thunkEntry, %rax 48 b8 b0..b7 eight bytes of the thunkEntry address
  thunk+0x1b: callq  *%rax ff d0
  thunk+0x1d: addq   $0x38, %rsp 48 83 c4 38
  thunk+0x21: retq c3
  thunk+0x22: nop 90
  thunk+0x23: nop 90"
  thunk getHandle
  unsignedLongAt:  1 put: 16rb8485454;
  pointerAt:  5 put: thunk getHandle length: 8;
  unsignedLongAt: 13 put: 16rc4834850;
  unsignedLongAt: 17 put: 16r00b848e0; "00 is the first byte of the 64-bit constant the movabsq/0x48 opcode moves"
  pointerAt: 20 put: self thunkEntryAddress length: 8;
  unsignedByteAt: 28 put: 16rff;
  unsignedLongAt: 29 put: 16rc48348d0;
  unsignedLongAt: 33 put: 16r9090c338.!

Item was changed:
  ----- Method: FFICallback>>init__stdcall: (in category 'initialization - thunk prepare') -----
  init__stdcall: numBytes
  "Initialize the receiver with a __stdcall thunk with numBytes argument bytes."
 
+ FFIPlatformDescription current abiSend: #'init_stdcall' to: self with: numBytes.!
- FFICallback methodsDo: [:method |
- (method selector beginsWith: 'init__stdcall') ifTrue: [
- (method hasPragma: #init) ifTrue: [
- (method pragmaAt: #abi:)
- ifNotNil: [:pragma | (pragma argumentAt: 1) = abi
- ifTrue: [^ self with: numBytes executeMethod: method]]]]].
-
- self error: 'Could not initialize thunk for current ABI: ', abi.!

Item was changed:
  ----- Method: FFICallback>>init__stdcall_IA32: (in category 'initialization - thunk prepare') -----
  init__stdcall_IA32: numBytes
+ <abi: #IA32> <init_stdcall>
- <abi: #IA32> <init>
  "Initialize the receiver with a __stdcall thunk with numBytes argument bytes. (See #init__ccall_IA32 for more info)"
  "thunk: push   %esp 0x54 0xa1905454
  thunk+01: push   %esp 0x54
  thunk+02: nop   0x90
  thunk+03: mov    $thunkEntry,%eax 0xb8 0x00 0x00 0x00 0x00 0x00000000 - entry
  thunk+08: nop   0x90 0x68909090
  thunk+09: nop   0x90
  thunk+10: nop   0x90
  thunk+11: push   $thunk 0x68 0x00 0x00 0x00 0x00 0x00000000 - thunk
  thunk+16: call   *%eax 0xff 0xd0 0xc483d0ff
  thunk+18: add    $0xC,%esp 0x83 0xc4 0x0C 0xBYTSc20C
  thunk+21: ret    $bytes 0xc2 0xBY 0xTS"
 
  thunk getHandle
  unsignedLongAt:  1 put: 16rB8905454;
  pointerAt: 5 put: self thunkEntryAddress length: 4;
  unsignedLongAt:  9 put: 16r68909090;
  pointerAt: 13 put: thunk getHandle length: 4;
  unsignedLongAt:  17 put: 16rC483D0FF;
  unsignedShortAt: 21 put: 16rC20C;
  unsignedShortAt: 23 put: numBytes.!