Merge pull request #90 from jiangyy/native-exit
native,platform: exit gracefully when smp=1
This commit is contained in:
commit
7e484d8af8
|
@ -19,7 +19,7 @@ static int event_thread(void *args) {
|
|||
while (1) {
|
||||
SDL_WaitEvent(&event);
|
||||
switch (event.type) {
|
||||
case SDL_QUIT: exit(0); break;
|
||||
case SDL_QUIT: _halt(0);
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#include <stdatomic.h>
|
||||
#include "platform.h"
|
||||
|
||||
int __am_mpe_init = 0;
|
||||
|
||||
int _mpe_init(void (*entry)()) {
|
||||
__am_mpe_init = 1;
|
||||
for (int i = 1; i < _ncpu(); i++) {
|
||||
if (fork() == 0) {
|
||||
thiscpu->cpuid = i;
|
||||
|
|
|
@ -155,25 +155,17 @@ static void init_platform() {
|
|||
assert(__am_pgsize > 0 && __am_pgsize % sys_pgsz == 0);
|
||||
|
||||
const char *args = getenv("mainargs");
|
||||
exit(main(args ? args : "")); // call main here!
|
||||
_halt(main(args ? args : "")); // call main here!
|
||||
}
|
||||
|
||||
static void exit_platform() __attribute__((destructor));
|
||||
static void exit_platform() {
|
||||
printf("%s\n", __func__);
|
||||
kill(0, SIGKILL);
|
||||
void __am_exit_platform(int code) {
|
||||
int ret = shm_unlink(pmem_shm_file);
|
||||
printf("Unlink pmem_shm_file %s\n", (ret == 0 ? "successfully" : "fail"));
|
||||
|
||||
int ret = munmap(pmem, PMEM_SIZE);
|
||||
assert(ret == 0);
|
||||
close(pmem_fd);
|
||||
ret = shm_unlink(pmem_shm_file);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = munmap(thiscpu, sizeof(*thiscpu));
|
||||
assert(ret == 0);
|
||||
|
||||
ret = munmap(TRAP_PAGE_START, sys_pgsz);
|
||||
assert(ret == 0);
|
||||
// let Linux clean up other resource
|
||||
extern int __am_mpe_init;
|
||||
if (__am_mpe_init && _ncpu() > 1) kill(0, SIGKILL);
|
||||
exit(code);
|
||||
}
|
||||
|
||||
void __am_shm_mmap(void *va, void *pa, int prot) {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include <am.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern void __am_platform_dummy();
|
||||
void __am_platform_dummy();
|
||||
void __am_exit_platform(int code);
|
||||
|
||||
void _trm_init() {
|
||||
__am_platform_dummy();
|
||||
}
|
||||
|
@ -13,7 +14,9 @@ void _putc(char ch) {
|
|||
|
||||
void _halt(int code) {
|
||||
printf("Exit (%d)\n", code);
|
||||
exit(code);
|
||||
__am_exit_platform(code);
|
||||
printf("Should not reach here!\n");
|
||||
while (1);
|
||||
}
|
||||
|
||||
_Area _heap = {};
|
||||
|
|
Loading…
Reference in New Issue