Skip to content

Commit

Permalink
Fix EINVAL returned by E2K_READ_PROCEDURE_STACK_EX sub-function
Browse files Browse the repository at this point in the history
(fix of commit d3f5bdc)

* mach_dep.c [E2K] (GC_get_procedure_stack): Remove assertion that
buf_sz is multiple of word size (because new_size is passed to the
syscall); call E2K_GET_PROCEDURE_STACK_SIZE sub-function of the
syscall right before E2K_READ_PROCEDURE_STACK_EX one to check that
the procedure stack size has not changed since the previous call
of GC_get_procedure_stack(NULL,0); add comment.
  • Loading branch information
ivmai committed Jul 15, 2022
1 parent 713fbad commit 41d41c3
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions mach_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,28 @@
word new_sz;

GC_ASSERT(0 == buf_sz || buf != NULL);
GC_ASSERT(buf_sz % sizeof(word) == 0);
for (;;) {
if (NULL == buf) {
new_sz = 0;
if (syscall(__NR_access_hw_stacks, E2K_GET_PROCEDURE_STACK_SIZE,
NULL, NULL, 0, &new_sz) != -1) {
GC_ASSERT(new_sz > 0 && new_sz % sizeof(word) == 0);
break;
}
} else {
word stack_ofs = 0;

if (syscall(__NR_access_hw_stacks, E2K_READ_PROCEDURE_STACK_EX,
&stack_ofs, buf, buf_sz, NULL) != -1) {
new_sz = buf_sz;
break;
}
word stack_ofs;

new_sz = 0;
if (syscall(__NR_access_hw_stacks, E2K_GET_PROCEDURE_STACK_SIZE,
NULL, NULL, 0, &new_sz) == -1) {
if (errno != EAGAIN)
ABORT_ARG1("Cannot get size of procedure stack",
": errno= %d", errno);
continue;
}
GC_ASSERT(new_sz > 0 && new_sz % sizeof(word) == 0);
if (new_sz > buf_sz)
break;
/* Immediately read the stack right after checking its size. */
stack_ofs = 0;
if (syscall(__NR_access_hw_stacks, E2K_READ_PROCEDURE_STACK_EX,
&stack_ofs, buf, new_sz, NULL) != -1)
break;
if (errno != EAGAIN)
ABORT_ARG2("Cannot read procedure stack",
": buf_sz= %lu, errno= %d", (unsigned long)buf_sz, errno);
": new_sz= %lu, errno= %d", (unsigned long)new_sz, errno);
}
return (size_t)new_sz;
}
Expand Down

0 comments on commit 41d41c3

Please sign in to comment.