Files
mckernel/test/issues/1219/segv_in_sub.c
Masamichi Takagi 11ef2f8092 coredump: Support threads
Change-Id: Id75ade6c87b15abcff5d772d90f77950376a32c1
Refs: #1219
2019-08-09 04:00:15 +00:00

57 lines
959 B
C

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/utsname.h>
#include <memory.h>
#include <sys/mman.h>
#include <sched.h>
#define NUM_THREADS 5
void *thread_fn_nop(void *arg)
{
sleep(10);
}
void *thread_fn_dump(void *arg)
{
int *ptr = NULL;
*ptr = 0xdead;
}
int main(void)
{
pthread_t threads[NUM_THREADS];
int i, j;
int rets[NUM_THREADS];
printf("SEGV in sub thread!!\n");
/* Create threads */
for (i = 0; i < NUM_THREADS; i++) {
if (i == NUM_THREADS - 1) {
/* SEGV thread */
rets[i] = pthread_create(&threads[i], NULL,
thread_fn_dump, NULL);
} else {
rets[i] = pthread_create(&threads[i], NULL,
thread_fn_nop, NULL);
}
if (rets[i] != 0) {
printf("pthread_create: %d\n", rets[i]);
}
}
printf("pthread_create done!! Let's join!!!!\n");
for (j = 0; j < NUM_THREADS; j++) {
pthread_join(threads[j], NULL);
}
printf("All threads are done.\n");
exit(0);
}