handle some errors properly so avoid exit() during initialization. this fixes issue #237

This commit is contained in:
Nguyen Anh Quynh
2015-11-12 01:43:41 +08:00
parent 116d96692d
commit 2f297bdd3a
38 changed files with 203 additions and 125 deletions

View File

@ -29,8 +29,8 @@
static void error_exit(int err, const char *msg)
{
fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
abort();
// fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
// abort();
}
void qemu_mutex_init(QemuMutex *mutex)
@ -389,7 +389,7 @@ void qemu_event_wait(QemuEvent *ev)
}
}
void qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name,
int qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name,
void *(*start_routine)(void*),
void *arg, int mode)
{
@ -397,20 +397,16 @@ void qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *na
int err;
pthread_attr_t attr;
#if 0
static int count = 0;
count++;
printf(">>> create thread %u\n", count);
#endif
err = pthread_attr_init(&attr);
if (err) {
error_exit(err, __func__);
return -1;
}
if (mode == QEMU_THREAD_DETACHED) {
err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (err) {
error_exit(err, __func__);
return -1;
}
}
@ -418,12 +414,16 @@ void qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *na
sigfillset(&set);
pthread_sigmask(SIG_SETMASK, &set, &oldset);
err = pthread_create(&thread->thread, &attr, start_routine, arg);
if (err)
if (err) {
error_exit(err, __func__);
return -1;
}
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
pthread_attr_destroy(&attr);
return 0;
}
void qemu_thread_get_self(struct uc_struct *uc, QemuThread *thread)

View File

@ -27,7 +27,7 @@ static void error_exit(int err, const char *msg)
NULL, err, 0, (LPTSTR)&pstr, 2, NULL);
fprintf(stderr, "qemu: %s: %s\n", msg, pstr);
LocalFree(pstr);
abort();
//abort();
}
void qemu_mutex_init(QemuMutex *mutex)
@ -326,7 +326,7 @@ void *qemu_thread_join(QemuThread *thread)
return ret;
}
void qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name,
int qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name,
void *(*start_routine)(void *),
void *arg, int mode)
{
@ -350,9 +350,13 @@ void qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *na
data, 0, &thread->tid);
if (!hThread) {
error_exit(GetLastError(), __func__);
return -1;
}
CloseHandle(hThread);
thread->data = (mode == QEMU_THREAD_DETACHED) ? NULL : data;
return 0;
}
void qemu_thread_get_self(struct uc_struct *uc, QemuThread *thread)