[squeak-dev] FFI: FFI-Callbacks-mt.26.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Aug 12 09:21:11 UTC 2021


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

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

Name: FFI-Callbacks-mt.26
Author: mt
Time: 12 August 2021, 11:21:11.185222 am
UUID: 7a80cde1-f678-084c-9a81-5ec72cb442e3
Ancestors: FFI-Callbacks-mt.25

Ports callback support for ARM64v8 from Alien project.

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

Item was added:
+ ----- Method: AlienStub class>>alienClass (in category 'class initialization') -----
+ alienClass
+ 
+ 	^ Smalltalk specialObjectsArray at: 53!

Item was added:
+ ----- Method: AlienStub class>>atAddress:dataSize: (in category 'instance creation') -----
+ atAddress: address "<Integer>" dataSize: dataByteSize "<Integer>" "^<Alien>"
+ 
+ 	^ self new
+ 		sizeFieldPut: dataByteSize asInteger abs negated;
+ 		addressFieldPut: address;
+ 		yourself!

Item was changed:
  ----- Method: AlienStub class>>isAlienLoaded (in category 'class initialization') -----
  isAlienLoaded
  
  	self flag: #alienCompatibility.
+ 	^ self alienClass ~~ self!
- 	^ (Smalltalk specialObjectsArray at: 53) ~~ self!

Item was changed:
  ----- Method: AlienStub class>>unload (in category 'class initialization') -----
  unload
  
  	Smalltalk removeFromStartUpList: self.
  	
+ 	self isAlienLoaded ifFalse: [
- 	(Smalltalk specialObjectsArray at: 53) == self ifTrue: [
  		Smalltalk specialObjectsArray at: 53 put: nil].!

Item was added:
+ ----- Method: AlienStub>>replaceFrom:to:with:startingAt: (in category 'primitives-accessing') -----
+ replaceFrom: start "<Integer>" to: stop "<Integer>" with: replacement "<Alien | indexableByteSubclass>" startingAt: repStart "<Integer>" "^<self>"
+ 	"N.B. on platforms where executable memory cannot be written to unless flipped out of
+ 	 executability, this primitive, and only this primitive, will contain code to identify an attempt
+ 	 to write to one of the executable pages allocated via primAllocateExecutablePage, and
+ 	 will flip protections appropriately around the replacement write."
+ 	<primitive: 'primAlienReplace' module: 'IA32ABI' error: errorCode>
+ 	^self primitiveFailed!

Item was added:
+ ----- Method: FFICallback class>>writeExecutableBlockAt:bytes: (in category 'executable pages') -----
+ writeExecutableBlockAt: handle bytes: bytes
+ 	"See #allocateExecutableBlock."
+ 	
+ 	| alien |
+ 	self flag: #alienCompatibility.
+ 	alien := AlienStub alienClass
+ 		atAddress: handle asInteger
+ 		dataSize: bytes size.
+ 	
+ 	alien replaceFrom: 1 to: bytes size with: bytes startingAt: 1.!

Item was changed:
  ----- Method: FFICallback>>init__ccall_ARM64 (in category 'private') -----
  init__ccall_ARM64
  	<abi: #ARM64> <init_ccall>
  	"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:."
  
+ 	| bytes |
+ 	bytes := #["0		mov	x16, sp"			16rF0 16r03 16r00 16r91
+ 				"4		sub	sp, sp, #0x20"			16rFF 16r83 16r00 16rD1
+ 				"8		stp	x16, x30, [sp, #0x8]"	16rF0 16rFB 16r00 16rA9
+ 				"c		bl		0x10"				16r01 16r00 16r00 16r94
+ 				"10		str		x30, [sp]"			16rFE 16r03 16r00 16rF9
+ 				"14		ldr		x16, #0x14"		16rB0 16r00 16r00 16r58
+ 				"18		blr		x16	"				16r00 16r02 16r3F 16rD6
+ 				 "1C	ldr		x30, [sp, #0x16]"	16rFE 16r0B 16r40 16rF9
+ 				 "20	add		sp, sp, #0x20"		16rFF 16r83 16r00 16r91
+ 				 "24	ret"							16rC0 16r03 16r5F 16rD6
+ 													0 0 0 0 0 0 0 0] copy.
+ 	bytes type: #uint64_t at: 41 put: self primThunkEntryAddress.
+ 	self class writeExecutableBlockAt: handle "thunk" bytes: bytes.
+ 	
- 	self shouldBeImplemented
- 
  	"self newCCall"!

Item was changed:
  ----- Method: FFICallbackConstants class>>initialize (in category 'class initialization') -----
  initialize
  	"
  	self initialize.
  	"
  
  	"Callback return types. See vmCallback.h"
  	ResultTypeWord := 1.
  	ResultTypeWord64 := 2.
  	ResultTypeDouble := 3.
  	ResultTypeStruct := 4.
  	
  	"See FFICallbackThunk initialize & initializeStdcall:; must be big enough for the largest thunk created"
+ 	MaxThunkSize := 48.!
- 	MaxThunkSize := 40.!

Item was added:
+ (PackageInfo named: 'FFI-Callbacks') postscript: '"MaxThunkSize increased from 40 to 48 bytes."
+ FFICallbackConstants initialize.
+ FFICallback defineFields.'!



More information about the Squeak-dev mailing list