1 // needed to use RTLD_NEXT from dlfcn.h
12 #define ABORT_ON_VIOLATION 1
14 // is set to 'true' when entering the process-callback and to 'false' when
15 // leaving it. When set to 'true', calls to non-realtime functions will
16 // cause warnings/errors.
18 // This assumes there is only 1 thread running at a time, thus introducing
19 // the limitation that jack_interposer is only usable on single-CPU machines
20 // (or machines configured to run the application under test on only 1 CPU).
25 JackProcessCallback real_process_callback
;
27 int fprintf(FILE *stream
, const char *format
, ...)
31 return vfprintf(stream
, format
, ap
);
34 int printf(const char *format
, ...)
38 return vprintf(format
, ap
);
41 int pthread_cond_timedwait(pthread_cond_t
* cond
, pthread_mutex_t
* mutex
, const struct timespec
* abstime
)
43 static int (*func
)(pthread_cond_t
*, pthread_mutex_t
*, const struct timespec
* abstime
);
47 printf("pthread_cond_timedwait() is called while in rt section\n");
48 #if ABORT_ON_VIOLATION
54 //func = (int (*)(pthread_cond_t*, pthread_mutex_t*)) dlsym(RTLD_NEXT, "pthread_cond_wait");
55 // see http://forums.novell.com/novell-product-support-forums/suse-linux-enterprise-server-sles/sles-configure-administer/385705-sles-10-2-java-hung-calling-pthread_cond_timedwait.html
56 func
= (int (*)()) dlvsym(RTLD_NEXT
, "pthread_cond_timedwait", "GLIBC_2.3.2");
59 fprintf(stderr
, "Error dlsym'ing\n");
62 return(func(cond
, mutex
, abstime
));
66 int pthread_cond_wait(pthread_cond_t
* cond
, pthread_mutex_t
* mutex
)
68 static int (*func
)(pthread_cond_t
*, pthread_mutex_t
*);
72 printf("pthread_cond_wait() is called while in rt section\n");
73 #if ABORT_ON_VIOLATION
79 //func = (int (*)(pthread_cond_t*, pthread_mutex_t*)) dlsym(RTLD_NEXT, "pthread_cond_wait");
80 // see http://forums.novell.com/novell-product-support-forums/suse-linux-enterprise-server-sles/sles-configure-administer/385705-sles-10-2-java-hung-calling-pthread_cond_timedwait.html
81 func
= (int (*)(pthread_cond_t
*, pthread_mutex_t
*)) dlvsym(RTLD_NEXT
, "pthread_cond_wait", "GLIBC_2.3.2");
84 fprintf(stderr
, "Error dlsym'ing\n");
87 return(func(cond
, mutex
));
90 int interposed_process_callback(jack_nframes_t nframes
, void* arg
)
96 result
= real_process_callback(nframes
, arg
);
103 int jack_set_process_callback(jack_client_t
* client
,
104 JackProcessCallback process_callback
, void* arg
)
108 static int (*func
)() = NULL
;
112 func
= (int(*)()) dlsym(RTLD_NEXT
, "jack_set_process_callback");
115 fprintf(stderr
, "Error dlsym'ing jack_set_process_callback\n");
119 real_process_callback
= process_callback
;
121 result
= func(client
, interposed_process_callback
, arg
);
123 printf("Result is %d\n", result
);