diff options
| author | Drahflow <drahflow@gmx.de> | 2015-05-07 17:44:52 +0200 |
|---|---|---|
| committer | Drahflow <drahflow@gmx.de> | 2015-05-07 17:44:52 +0200 |
| commit | 44319ab55f3dfa7360ad06ee2455cfbe6184807d (patch) | |
| tree | 389df44fa43e0138b5553c4765c9ed9ed1b7cd30 /elymas | |
| parent | 838371f7e95b5d9dc44752e2c2b1b77e6faa9670 (diff) | |
Wrap callbacks
Diffstat (limited to 'elymas')
| -rw-r--r-- | elymas/lib/sys/so.ey | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/elymas/lib/sys/so.ey b/elymas/lib/sys/so.ey index 1cd6688..295456e 100644 --- a/elymas/lib/sys/so.ey +++ b/elymas/lib/sys/so.ey @@ -1,5 +1,7 @@ # Freeze into ELF binary which requires libc (for dlsym and dlopen). +# FIXME: also have r13 backup, because coroutines + < sys .linux "+" via sys .asm "::" via @@ -156,6 +158,7 @@ # 1 -> argument specification string # "iis" == foo(int, int, char *) # p: pointer argument + # c: callback argument (create suitable callbacks using wrapCallback) # i: integer argument (of any width) # f: float argument # d: double argument @@ -225,6 +228,16 @@ nextIntegerStorage ] } + { t 0 "c" * eq }' { + [ + useIntegerStorage ==reg + 8 /r15 :subqImm8Reg + reg /r15 :movqRegMem # keep the GC away + 24 reg reg :movqMemDisp8Reg + 16 reg :addqImm8Reg + nextIntegerStorage + ] + } { t 0 "d" * eq }' { [[ useFloatStorage ==reg @@ -482,6 +495,41 @@ ] [ ] ::createFunction } /wrapFunction deffd + { ==rets ==args ==func + [ + /rbx :pushqReg + /rbp :pushqReg + /r12 :pushqReg + /r13 :pushqReg + /r14 :pushqReg + /r15 :pushqReg + + r15backup rawContentAddress /rax :movqImmReg + /rax /r15 :movqMemReg + + func ::rawAddress /rax :movqImmReg + /rax :pushqReg + # FIXME: push arguments on stack + + "*" | ::rawCodeAddress /rax :movqImmReg + /rax :callqReg + + # FIXME: grab return values from stack + + r15backup rawContentAddress /rax :movqImmReg + /r15 /rax :movqRegMem + + /r15 :popqReg + /r14 :popqReg + /r13 :popqReg + /r12 :popqReg + /rbp :popqReg + /rbx :popqReg + + :retn + ] [ func ::rawAddress ] ::createFunction + } /wrapCallback deffd + { "\0" cat } [ /rbx :popqReg |
