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