Skip to content

Commit 3126578

Browse files
committed
fixed #10
1 parent 92ffcf8 commit 3126578

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

shiva.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ shiva_interp_mode(struct shiva_ctx *ctx)
9696
shiva_maps_iterator_t maps_iter;
9797
struct shiva_mmap_entry mmap_entry;
9898
uint8_t *o_stack, *n_stack;
99-
uint64_t o_stack_addr, o_stack_end;
99+
uint64_t o_stack_addr;
100100
size_t copy_len;
101+
uint64_t o_stack_end = 0;
101102

102103
ctx_global = ctx;
103104
shiva_init_lists(ctx);
@@ -124,10 +125,16 @@ shiva_interp_mode(struct shiva_ctx *ctx)
124125

125126
shiva_maps_iterator_init(ctx, &maps_iter);
126127
while (shiva_maps_iterator_next(&maps_iter, &mmap_entry) == SHIVA_ITER_OK) {
127-
if (mmap_entry.mmap_type == SHIVA_MMAP_TYPE_SHIVA) {
128+
if (mmap_entry.mmap_type == SHIVA_MMAP_TYPE_STACK) {
129+
o_stack_end = mmap_entry.base + mmap_entry.len;
130+
shiva_debug("Original stack upper bound: %#lx\n", o_stack_end);
128131
break;
129132
}
130133
}
134+
if (o_stack_end == 0) {
135+
fprintf(stderr, "Unable to find SHIVA_MMAP_TYPE_STACK entry\n");
136+
return false;
137+
}
131138
ctx->shiva.base = mmap_entry.base;
132139
shiva_debug("Setting shiva base: %#lx\n", mmap_entry.base);
133140
/*
@@ -224,17 +231,6 @@ shiva_interp_mode(struct shiva_ctx *ctx)
224231
*/
225232
o_stack = (uint8_t *)rsp;
226233
o_stack_addr = (uint64_t)o_stack;
227-
/*
228-
* XXX BUG XXX
229-
* There is a bug here that occasionally results in a segfault
230-
* later on in the code.
231-
* There are some situations I think where the o_stack_end
232-
* (Which points to the highest stack address) needs to be
233-
* page aligned up one more time. There's not enough room
234-
* being allocated for the stacks copylen in some cases with the
235-
* current code... debug this!
236-
*/
237-
o_stack_end = ELF_PAGEALIGN(o_stack_addr, 0x1000);
238234
copy_len = o_stack_end - o_stack_addr;
239235

240236
shiva_debug("o_stack_addr: %#lx o_stack_end: %#lx\n", o_stack_addr, o_stack_end);

0 commit comments

Comments
 (0)