Skip to content

Commit

Permalink
attempting to fix riscv32 waitpid
Browse files Browse the repository at this point in the history
  • Loading branch information
oriansj committed Feb 7, 2022
1 parent 08a6615 commit b774c03
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions riscv32/linux/unistd.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,42 +77,43 @@ int waitid(int idtype, int id, struct siginfo_t *infop, int options, void *rusag

void* calloc(int count, int size);
void free(void* l);
struct siginfo_t *__waitpid_info;
int waitpid(int pid, int* status_ptr, int options)
{
struct siginfo_t *info = calloc(1, sizeof(struct siginfo_t));
int r = waitid(P_PID, pid, info, options|WEXITED, NULL);
if(r < 0)
{
return r;
}
if((info->si_pid != 0) && (status_ptr != NULL))
if(NULL == __waitpid_info) __waitpid_info = calloc(1, sizeof(struct siginfo_t));
int r = waitid(P_PID, pid, __waitpid_info, options|WEXITED, NULL);

if(__waitpid_info->si_pid != 0)
{
int sw = 0;
if(info->si_code == CLD_EXITED)
if(__waitpid_info->si_code == CLD_EXITED)
{
sw = (info->si_status & 0xff) << 8;
sw = (__waitpid_info->si_status & 0xff) << 8;
}
else if(info->si_code == CLD_KILLED)
else if(__waitpid_info->si_code == CLD_KILLED)
{
sw = info->si_status & 0x7f;
sw = __waitpid_info->si_status & 0x7f;
}
else if(info->si_code == CLD_DUMPED)
else if(__waitpid_info->si_code == CLD_DUMPED)
{
sw = (info->si_status & 0x7f) | 0x80;
sw = (__waitpid_info->si_status & 0x7f) | 0x80;
}
else if(info->si_code == CLD_CONTINUED)
else if(__waitpid_info->si_code == CLD_CONTINUED)
{
sw = 0xffff;
}
else if(info->si_code == CLD_STOPPED || info->si_code == CLD_TRAPPED)
else if(__waitpid_info->si_code == CLD_STOPPED || __waitpid_info->si_code == CLD_TRAPPED)
{
sw = ((info->si_status & 0xff) << 8) + 0x7f;
sw = ((__waitpid_info->si_status & 0xff) << 8) + 0x7f;
}
*status_ptr = sw;
if(status_ptr != NULL) *status_ptr = sw;
}
int rval = info->si_pid;
free(info);
int rval = __waitpid_info->si_pid;

if(r < 0)
{
return r;
}
return rval;
}

Expand Down

0 comments on commit b774c03

Please sign in to comment.