etc/services - sync with NetBSD-8
[minix.git] / minix / servers / vfs / gcov.c
blob82c62dcebf819eb24641b92bca09473c14242a93
2 #include <string.h>
4 #include "fs.h"
5 #include "file.h"
7 /*===========================================================================*
8 * do_gcov_flush *
9 *===========================================================================*/
10 int do_gcov_flush(void)
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).
18 char label[LABEL_MAX];
19 vir_bytes labeladdr, buf;
20 size_t labellen, size;
21 endpoint_t endpt;
22 cp_grant_id_t grantid;
23 int r;
24 message m;
27 * Something as sensitive as system service coverage information must be
28 * call to the target service, and so it is not impossible to deadlock the
29 * system with this call.
31 if (!super_user) return(EPERM);
33 labeladdr = job_m_in.m_lc_vfs_gcov.label;
34 labellen = job_m_in.m_lc_vfs_gcov.labellen;
35 buf = job_m_in.m_lc_vfs_gcov.buf;
36 size = job_m_in.m_lc_vfs_gcov.buflen;
38 /* Retrieve and look up the target label. */
39 if (labellen >= sizeof(label))
40 return EINVAL;
41 if ((r = sys_datacopy_wrapper(who_e, labeladdr, SELF, (vir_bytes)label,
42 labellen)) != OK)
43 return r;
44 label[labellen - 1] = '\0';
46 if ((r = ds_retrieve_label_endpt(label, &endpt)) != OK)
47 return r;
49 /* Hack: init is the only non-system process with a valid label. */
50 if (endpt == INIT_PROC_NR)
51 return ENOENT;
53 /* Grant target process to requestor's buffer. */
54 if ((grantid = cpf_grant_magic(endpt, who_e, buf, size, CPF_WRITE)) < 0) {
55 printf("VFS: gcov_flush: grant failed\n");
56 return(ENOMEM);
59 if (endpt == VFS_PROC_NR) {
60 /* Request is for VFS itself. */
61 r = gcov_flush(VFS_PROC_NR, grantid, size);
62 } else {
63 /* Perform generic GCOV request. */
64 memset(&m, 0, sizeof(m));
65 m.m_vfs_lsys_gcov.grant = grantid;
66 m.m_vfs_lsys_gcov.size = size;
67 r = _taskcall(endpt, COMMON_REQ_GCOV_DATA, &m);
70 cpf_revoke(grantid);
72 return(r);