xref: /minix3/external/gpl3/gcc/files/gcov-minix-fs-wrapper.h (revision d19d7d58aa5cd1165eefe1a0d807c8afe282db62)
1*d19d7d58SLionel Sambuc /* This header makes it possible to redefine system calls to the
2*d19d7d58SLionel Sambuc  * file system. This way, minix servers can re-route the data
3*d19d7d58SLionel Sambuc  * that libgcov tries to send to the file system. This is
4*d19d7d58SLionel Sambuc  * necessary, because the servers can't access the file system
5*d19d7d58SLionel Sambuc  * directly. Instead, they will copy the data to a helping user
6*d19d7d58SLionel Sambuc  * space process, which will call the file system for them.
7*d19d7d58SLionel Sambuc  * For more information, see the <minix/gcov.h> header file.
8*d19d7d58SLionel Sambuc  */
9*d19d7d58SLionel Sambuc 
10*d19d7d58SLionel Sambuc #include <stdio.h>
11*d19d7d58SLionel Sambuc #include <unistd.h>
12*d19d7d58SLionel Sambuc #include <sys/types.h>
13*d19d7d58SLionel Sambuc 
14*d19d7d58SLionel Sambuc 
15*d19d7d58SLionel Sambuc /* These function pointers initially point to the standard system library
16*d19d7d58SLionel Sambuc  * functions (fopen, etc). All calls to these system library functions are
17*d19d7d58SLionel Sambuc  * then redefined to calls to these function pointers. Because the pointers
18*d19d7d58SLionel Sambuc  * still point to the original functions, all functionality is unchanged.
19*d19d7d58SLionel Sambuc  * Therefore, libgcov won't act differently when linked to applications.
20*d19d7d58SLionel Sambuc  * But, when these pointers are redefined by code within the minix servers,
21*d19d7d58SLionel Sambuc  * the file system calls get replaced by other functionality.
22*d19d7d58SLionel Sambuc  */
23*d19d7d58SLionel Sambuc 
24*d19d7d58SLionel Sambuc #define fopen(...)  _gcov_fopen(__VA_ARGS__)
25*d19d7d58SLionel Sambuc #define fread(...)  _gcov_fread(__VA_ARGS__)
26*d19d7d58SLionel Sambuc #define fwrite(...) _gcov_fwrite(__VA_ARGS__)
27*d19d7d58SLionel Sambuc #define fclose(...) _gcov_fclose(__VA_ARGS__)
28*d19d7d58SLionel Sambuc #define fseek(...)  _gcov_fseek(__VA_ARGS__)
29*d19d7d58SLionel Sambuc #define getenv(...) _gcov_getenv(__VA_ARGS__)
30*d19d7d58SLionel Sambuc 
31*d19d7d58SLionel Sambuc 
32*d19d7d58SLionel Sambuc /* wrapper to make it possible to disable gcov_exit on a process exit (for mfs) */
33*d19d7d58SLionel Sambuc 
34*d19d7d58SLionel Sambuc int do_gcov_exit = 1;
35*d19d7d58SLionel Sambuc 
gcov_exit_wrapper(void)36*d19d7d58SLionel Sambuc void gcov_exit_wrapper(void){
37*d19d7d58SLionel Sambuc 	if(do_gcov_exit)
38*d19d7d58SLionel Sambuc 		gcov_exit();
39*d19d7d58SLionel Sambuc }
40