summaryrefslogtreecommitdiffstats
path: root/src/uctx.h
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2010-03-10 18:12:02 +0200
committerTimo Teras <timo.teras@iki.fi>2010-03-10 18:12:02 +0200
commit674f1495ab082c8f5a604cbb5a4dadc95b8c7ebb (patch)
treef5fd6a58b2d202057ee7f2df43a4e5d26dd75b01 /src/uctx.h
parent5ef38570315dc68d7ddf8d9475d9a8830528e8a4 (diff)
downloadlibtf-674f1495ab082c8f5a604cbb5a4dadc95b8c7ebb.tar.bz2
libtf-674f1495ab082c8f5a604cbb5a4dadc95b8c7ebb.tar.xz
libtf: fix stack frame creation and valgrind issues
debugging looks now better. there was also some valgrind issues that needed attention.
Diffstat (limited to 'src/uctx.h')
-rw-r--r--src/uctx.h20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/uctx.h b/src/uctx.h
index e27a53c..5eca6be 100644
--- a/src/uctx.h
+++ b/src/uctx.h
@@ -37,15 +37,15 @@ struct tf_uctx {
do { \
unsigned eax, ebx, ecx, edx, esi, edi; \
__asm__ __volatile__ ( \
- "push %%ebp \n" \
"call 1f \n" \
"1: \n" \
"addl $2f-1b, (%%esp) \n" \
+ "push %%ebp \n" \
"movl %%esp, %[prev_sp] \n" \
"movl %[next_sp], %%esp \n" \
+ "pop %%ebp \n" \
"ret \n" \
"2: \n" \
- "pop %%ebp \n" \
: [prev_sp] "=m"(prev->current_sp), \
"=a"(eax), "=b"(ebx), "=c"(ecx), \
"=d"(edx), "=S"(esi), "=D"(edi) \
@@ -101,8 +101,8 @@ tf_uctx_create_embedded(
size_t stack_size,
size_t private_size,
off_t uctx_offset,
- void (*stack_frame_main)(void*), off_t main_argument_offset,
- void (*stack_frame_return)(void))
+ void (*stack_frame_main)(void*, void*),
+ void *main_argument)
{
size_t size = TF_STACK_SIZE;
void *user_data;
@@ -117,20 +117,18 @@ tf_uctx_create_embedded(
/* Create initial stack frame (cdecl convention) */
stack = stack_pointer(stack_base, size);
user_data = stack_push(&stack, TF_ALIGN(private_size, 64));
+ stack_push_ptr(&stack, main_argument);
+ stack_push_ptr(&stack, user_data);
stack_push_ptr(&stack, NULL);
- stack_push_ptr(&stack, NULL);
- stack_push_ptr(&stack, NULL);
- stack_push_ptr(&stack, NULL);
- stack_push_ptr(&stack, user_data + main_argument_offset);
- stack_push_ptr(&stack, stack_frame_return);
- stack_push_ptr(&stack, stack_frame_main);
+ stack_push_ptr(&stack, stack_frame_main); /* eip */
+ stack_push_ptr(&stack, NULL); /* ebp */
uctx = user_data + uctx_offset;
*uctx = (struct tf_uctx) {
.stack_guard = stack_guard(stack_base, size),
.alloc = stack_base,
.current_sp = stack,
- .stack_id = VALGRIND_STACK_REGISTER(stack_base, size),
+ .stack_id = VALGRIND_STACK_REGISTER(stack_base, stack_base+size),
};
*uctx->stack_guard = STACK_GUARD;