xref: /minix3/minix/servers/vfs/gcov.c (revision 3956ee9eeda988648c3f2092c7d31faa0a0e7294)
1 
2 #include "fs.h"
3 #include "file.h"
4 
5 int gcov_flush(cp_grant_id_t grantid, size_t size );
6 
7 /*===========================================================================*
8  *				do_gcov_flush				*
9  *===========================================================================*/
10 int do_gcov_flush()
11 {
12 /* A userland tool has requested the gcov data from another
13  * process (possibly vfs itself). Grant the target process
14  * access to the supplied buffer, and perform the call that
15  * makes the target copy its buffer to the caller (incl vfs
16  * itself).
17  */
18   struct fproc *rfp;
19   ssize_t size;
20   cp_grant_id_t grantid;
21   int r, n;
22   pid_t target;
23   message m;
24   vir_bytes buf;
25 
26   size = job_m_in.m_lc_vfs_gcov.buff_sz;
27   target = job_m_in.m_lc_vfs_gcov.pid;
28   buf = job_m_in.m_lc_vfs_gcov.buff_p;
29 
30   /* If the wrong process is sent to, the system hangs; so make this root-only.
31    */
32 
33   if (!super_user) return(EPERM);
34 
35   /* Find target gcov process. */
36   for(n = 0; n < NR_PROCS; n++) {
37 	if(fproc[n].fp_endpoint != NONE && fproc[n].fp_pid == target)
38 		 break;
39   }
40   if(n >= NR_PROCS) {
41 	printf("VFS: gcov process %d not found\n", target);
42 	return(ESRCH);
43   }
44   rfp = &fproc[n];
45 
46   /* Grant target process to requestor's buffer. */
47   if ((grantid = cpf_grant_magic(rfp->fp_endpoint, who_e, buf,
48 				 size, CPF_WRITE)) < 0) {
49 	printf("VFS: gcov_flush: grant failed\n");
50 	return(ENOMEM);
51   }
52 
53   if (rfp->fp_endpoint == VFS_PROC_NR) {
54 	/* Request is for VFS itself. */
55 	r = gcov_flush(grantid, size);
56   } else {
57 	/* Perform generic GCOV request. */
58 	m.m_lc_vfs_gcov.grant = grantid;
59 	m.m_lc_vfs_gcov.buff_sz = size;
60 	r = _taskcall(rfp->fp_endpoint, COMMON_REQ_GCOV_DATA, &m);
61   }
62 
63   cpf_revoke(grantid);
64 
65   return(r);
66 }
67