| 1 |
/* |
| 2 |
* This is a test case for: |
| 3 |
* |
| 4 |
* https://bugzilla.kernel.org/show_bug.cgi?id=219174 |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <dlfcn.h> |
| 8 |
#include <pthread.h> |
| 9 |
#include <stdio.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include <sys/prctl.h> |
| 12 |
#include <sys/psx_syscall.h> |
| 13 |
#include <sys/syscall.h> |
| 14 |
#include <unistd.h> |
| 15 |
|
| 16 |
int main(int argc, char **argv) |
| 17 |
{ |
| 18 |
void *handle = dlopen("./weaver.so", RTLD_NOW); |
| 19 |
if (handle == NULL) { |
| 20 |
perror("no weaver.so loaded"); |
| 21 |
exit(1); |
| 22 |
} |
| 23 |
|
| 24 |
pthread_t (*weaver_thread)(void) = dlsym(handle, "weaver_thread"); |
| 25 |
void (*weaver_setup)(void) = dlsym(handle, "weaver_setup"); |
| 26 |
int (*weaver_waitforit)(int n) = dlsym(handle, "weaver_waitforit"); |
| 27 |
void (*weaver_terminate)(void) = dlsym(handle, "weaver_terminate"); |
| 28 |
|
| 29 |
weaver_setup(); |
| 30 |
|
| 31 |
#define N_THREADS 37 |
| 32 |
long int i; |
| 33 |
pthread_t th[N_THREADS]; |
| 34 |
for (i = 0; i < N_THREADS; i++) { |
| 35 |
if (psx_syscall6(SYS_prctl, PR_SET_KEEPCAPS, i&1, 0, 0, 0, 0) != 0) { |
| 36 |
perror((i&1) ? "failed to set keep-caps" : |
| 37 |
"failed to reset keep-caps"); |
| 38 |
exit(1); |
| 39 |
} |
| 40 |
th[i] = weaver_thread(); |
| 41 |
int got = weaver_waitforit(i+1); |
| 42 |
int want = (i&1) ? (3*(i+1)) : (2*(i+1)); |
| 43 |
printf("for %ld weaver.so launched threads, total=%d, wanted=%d\n", |
| 44 |
i+1, got, want); |
| 45 |
if (got != want) { |
| 46 |
printf("FAILED\n"); |
| 47 |
exit(1); |
| 48 |
} |
| 49 |
} |
| 50 |
weaver_terminate(); |
| 51 |
for (i = 0; i < N_THREADS; i++) { |
| 52 |
pthread_join(th[i], NULL); |
| 53 |
} |
| 54 |
printf("PASSED\n"); |
| 55 |
exit(0); |
| 56 |
} |