Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Currying in C

Name: Anonymous 2012-06-11 3:36

Hi /prog/, what's the standard technique to implement currying / bound function parameters in C (or i386 assembly)? I assume just allocate executable memory, copy in a stub and jmp into it? More elegant suggestions welcome

Are there any implementations of this technique for i386 / x86_64 / ARMv7? I've come across this paper [1] and this forum thread [2] but i havn't quite managed to hack anything together with a VirtualAlloc yet.

_________________________

1. http://asg.unige.ch/site/papers/Dami91a.pdf
2. http://arstechnica.com/civis/viewtopic.php?f=20&t=181415

Name: Anonymous 2012-06-11 4:36

>>4

So you are looking to generate assembly for a function that is equivalent to another function, except that certain values have been bound to a constant? This seems doable. In the most trivial implementation, it could be:


push bound_argument1
push bound_argument2
...
(maybe do some reordering of the arguments on the stack)
...
call bound_function_pointer
ret


You could also create a duplicate body of code for the orginal function, except that certain arguments are bound to constants. And then maybe apply constant folding within the function to optimize it a little.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List