Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Machine-code/Smalltalk/machine-code-1.st
Normal file
17
Task/Machine-code/Smalltalk/machine-code-1.st
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
!ExternalBytes class methods!
|
||||
|
||||
mapExecutableBytes:size
|
||||
%{
|
||||
# include <sys/mman.h>
|
||||
|
||||
void *mem;
|
||||
OBJ retVal;
|
||||
int nBytes = __intVal(size);
|
||||
|
||||
mem = mmap(nil, nBytes, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0);
|
||||
if (mem != MAP_FAILED) {
|
||||
RETURN( __MKEXTERNALBYTES_N(mem, nBytes));
|
||||
}
|
||||
%}.
|
||||
self primitiveFailed
|
||||
! !
|
||||
21
Task/Machine-code/Smalltalk/machine-code-2.st
Normal file
21
Task/Machine-code/Smalltalk/machine-code-2.st
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
OperatingSystem getCPUType = #'x86' ifTrue:[
|
||||
code := #[0x8B 0x44 0x24 0x04 0x03 0x44 0x24 0x08 0xC3].
|
||||
] ifFalse:[
|
||||
self error:'unsupported cpu'
|
||||
].
|
||||
|
||||
handle := ExternalBytes mapExecutableBytes:100.
|
||||
handle replaceFrom:1 with:code.
|
||||
|
||||
" dump it (debugging only)... "
|
||||
e'code at {handle address hexPrintString} is:' printCR.
|
||||
(handle copyFrom:1 to:50) asByteArray hexPrintString printCR.
|
||||
|
||||
" create an ExternalFunction for it "
|
||||
func := ExternalLibraryFunction new code:handle address.
|
||||
func name:'unnamed' module:nil returnType:#int argumentTypes:#(int int).
|
||||
func beCallTypeC.
|
||||
func printCR.
|
||||
|
||||
" now call it "
|
||||
result := func invokeWithArguments:{10 . 20}
|
||||
Loading…
Add table
Add a link
Reference in a new issue