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

commits at source.squeak.org commits at source.squeak.org
Tue Apr 19 09:25:31 UTC 2022


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

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

Name: FFI-Callbacks-mt.30
Author: mt
Time: 19 April 2022, 11:25:30.789004 am
UUID: 0278f498-8447-4e48-84db-9c5bf5cae4d3
Ancestors: FFI-Callbacks-mt.29

Fixes callbacks "Bus error" on (macOS) ARM64 platforms.

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

Item was changed:
  ----- Method: FFICallback class>>allocateExecutableBlock (in category 'executable pages') -----
  allocateExecutableBlock
  
+ 	| blockSize newBlock |
- 	| blockSize |
  	blockSize := MaxThunkSize.
- 	ExecutablePagesAccessProtect critical:
- 		[ExecutablePages do:
- 			[:page |
- 			1 to: page size - blockSize by: blockSize do:
- 				[:i|
- 				(page at: i) = 0 ifTrue:
- 					[page at: i put: 1.
- 					 ^ page from: i to: i + blockSize - 1]]]].
  	ExecutablePagesAccessProtect critical: [
+ 		ExecutablePages do: [:page |
+ 			1 to: page size - blockSize by: blockSize do: [:i |
+ 				(page at: i) = 0 ifTrue: [
+ 					newBlock := page from: i to: i + blockSize - 1.
+ 					self markExecutableBlock: newBlock.
+ 					^ newBlock]]]].
+ 	ExecutablePagesAccessProtect critical: [
  		| newPage |
  		newPage := ExecutablePages add: self allocateExecutablePage.
+ 		newBlock := newPage from: 1 to: blockSize.
+ 		self markExecutableBlock: newBlock.
+ 		^ newBlock]!
- 		^ (newPage from: 1 to: blockSize)
- 			at: 1 put: 1; "Mark as allocated."
- 			yourself]!

Item was changed:
  ----- Method: FFICallback class>>allocateExternal (in category 'instance creation') -----
  allocateExternal
  	"Overwritten for custom management of executable pages. Assure compatibility with Alien."
  
  	| instance |
+ 	instance := self fromHandle: self allocateExecutableBlock getHandle.
- 	instance := 	self fromHandle: self allocateExecutableBlock getHandle.
  	AlienStub isAlienLoaded ifTrue: [instance addToAlienThunkTable].
  	^ instance!

Item was added:
+ ----- Method: FFICallback class>>markExecutableBlock: (in category 'executable pages') -----
+ markExecutableBlock: externalData
+ 	"Mark the block of executable memory that is represented by externalData as being used. We do this to allow several subsequent calls to #allocateExecutableBlock without actually writing a thunk in it. NOTE THAT we must use a special primitive to write into executable memory on ARM64 platforms."
+ 
+ 	FFIPlatformDescription current abi == #ARM64
+ 		ifTrue: [self writeExecutableBlockAt: externalData getHandle bytes: #[1]]
+ 		ifFalse: [externalData at: 1 put: 1].!

Item was added:
+ ----- Method: FFICallback class>>zeroExecutableBlock: (in category 'executable pages') -----
+ zeroExecutableBlock: externalObject "< ExternalData | FFICallback>"
+ 	"Variation of #zeroMemory to handle writing into executable memory on ARM64 platforms."
+ 
+ 	FFIPlatformDescription current abi == #ARM64
+ 		ifTrue: [self writeExecutableBlockAt: externalObject getHandle bytes: (ByteArray new: externalObject byteSize)]
+ 		ifFalse: [externalObject getHandle zeroMemory: externalObject byteSize].!

Item was changed:
  ----- Method: FFICallback>>zeroMemory (in category 'initialize-release') -----
  zeroMemory
  
  	ExecutablePagesAccessProtect critical: [
+ 		self class zeroExecutableBlock: self].!
- 		super zeroMemory].!



More information about the Squeak-dev mailing list