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:45

>>5
That's right. It does seem doable, there's a few references to the topic but no solid examples. [2] in the OP is my best lead so far, although the assembly is using indirect jmps (i think absolute ones might be more reliable).

I'm working on a prototype for currying a C int (*fn)(int,int) to an int (*fn)(int), but havn't quite gotten it working yet. Once that's there, the assembly will be pretty general for all of a given calling convention (aiming for cdecl with straight stack parameters, no fpu registers).

Creating a duplicate body of code is probably a lot more work (and way more memory intensive) than an extra jmp. Constant folding is a lot of work to do at runtime, too. One less jmp to mispredict, but much less cache-friendly

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