Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward application exit status to host #55

Closed
7 tasks done
edubart opened this issue May 29, 2023 · 1 comment
Closed
7 tasks done

Forward application exit status to host #55

edubart opened this issue May 29, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@edubart
Copy link
Contributor

edubart commented May 29, 2023

Context

An application running inside the virtual machine can exit with an error status when it fails or crashes. We should start exposing this exit status to be readable by the host after the machine is halted, so the host is able to determine if the guest machine finished its application with success or failure.

Possible solutions

We need to edit our init script so it captures the exit status of the application and saves this exit status in a machine CSR before halting. The first obvious solution would be creating a new poweroff utility that halts the machine while saving the exit status.

@edubart edubart added the enhancement New feature or request label May 29, 2023
@edubart edubart moved this to Todo in Machine Emulator SDK May 30, 2023
@mpolitzer mpolitzer self-assigned this Jul 24, 2023
@mpolitzer
Copy link
Contributor

Retrieved from Chat archives:


Regarding the exit status / return code for applications:

OpenSBI would require a patch to pass one of the registers into sbi_system_reset

https://github.com/cartesi/opensbi/blob/5ef1484038f287106fe9706c02d0f45f31df6914/lib/sbi/sbi_ecall_legacy.c#L110

Linux accepts a string when the reboot syscall is invoked with: LINUX_REBOOT_CMD_RESTART2, could be a way to extract the status code of applications.
It would need a patch to arch/riscv/kernel/reset.c:machine_restart to remove the infinite loop and pass something useful down to sbi_shutdown.

https://github.com/cartesi/linux/blob/d40b7543be1650576bc0672f868218a8a73ade30/arch/riscv/kernel/sbi.c#L101C6-L101C18
https://github.com/cartesi/linux/blob/d40b7543be1650576bc0672f868218a8a73ade30/arch/riscv/kernel/reset.c#L18

Then we could do something like this to get the string into the kernel:

#include<unistd.h>
#include<syscall.h>
#include<linux/reboot.h>

int main(int argc, char *argv[]) {
    syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, argv[1]);
}
[   18.488384] reboot: Restarting system with command 'bye'

@edubart edubart removed their assignment Jul 25, 2023
@mpolitzer mpolitzer moved this from Todo to PR Available in Machine Emulator SDK Aug 28, 2023
@github-project-automation github-project-automation bot moved this from PR Available to Done in Machine Emulator SDK Dec 1, 2023
@vfusco vfusco added this to the v0.16.0 milestone Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants