@@ -52,31 +52,41 @@ void *result;
5252 /* adjust stack pointer to be 16 byte (4 quad) aligned with
5353 * room for call args
5454 * since the call instruction, 5 quads have
55- * been pushed (ip, bp, bx, si, di), need extra 3 quads
55+ * been pushed (ip, bp, bx, si, di), need extra 3 quads (0xa)
5656 * for alignment, which fits our three quad call args.
57+ * Add another 16 (0x10) bytes, so that we can pass to the callbacks
58+ * a 16 byte boundary that lies above the pushed arguments
59+ * so that the call arguments of the functions aren't clobbered
60+ * by memory transfer.
5761 */
58- "subl $12 , %%esp\n"
62+ "subl $0x1a , %%esp\n"
5963 "movl %[cb], %%esi\n" /* save 'callback' for later */
6064 "movl %[ctx], %%edi\n" /* save 'context' for later */
6165
62- /* first call */
63- "movl %%esp, 8(%%esp)\n" /* arg 2 sp */
66+ /* first call */
67+ "leal 0x10(%%esp), %%ebx\n" /* arg 2 adjusted sp (also in nv. reg) */
68+ "movl %%ebx, 8(%%esp)\n"
6469 "movl $0, 4(%%esp)\n" /* arg 1 opcode STACKMAN_OP_SAVE */
6570 "movl %%edi, 0(%%esp)\n" /* arg 0 context */
6671 "call *%%esi\n"
6772
68- /* restore esp */
69- "movl %%eax, %%esp\n"
73+ /* restore esp, re-adding shadow space */
74+ "leal -0x10(%%eax), %%esp\n"
75+
76+ /* and adjust ebp with difference between new and old */
77+ "subl %%ebx, %%eax\n"
78+ "addl %%eax, %%ebp\n"
7079
7180 /* second call */
72- "movl %%eax, 8(%%esp)\n" /* arg 2 sp */
81+ "leal 0x10(%%esp), %%eax\n" /* arg 2 sp */
82+ "movl %%eax, 8(%%esp)\n"
7383 "movl $1, 4(%%esp)\n" /* arg 1 opcode STACKMAN_OP_RESTORE */
7484 "movl %%edi, 0(%%esp)\n" /* arg 0 context */
7585 "call *%%esi\n"
7686
7787 "movl %%eax, %[result]\n"
7888
79- "addl $12 , %%esp\n"
89+ "addl $0x1a , %%esp\n"
8090 : [result ] "=r" (result ) /* output variables */
8191 : [cb ] "r" (callback ), /* input variables */
8292 [ctx ] "r" (context )
0 commit comments