Skip to content

Commit

Permalink
pmc: Initialise and check the pm_flags field for CONFIGURELOG
Browse files Browse the repository at this point in the history
Whilst the former is not breaking, the latter is, and so this will be
followed by a bump to the pmc major version. This will allow the flags
to actually be usable in future, as otherwise we cannot distinguish
uninitialised stack junk from a deliberately-initialised value.

Reviewed by:	jhb, mhorne
Differential Revision:	https://reviews.freebsd.org/D40049
  • Loading branch information
jrtc27 committed May 30, 2023
1 parent 2071e54 commit 8e63e78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/libpmc/libpmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ pmc_configure_logfile(int fd)
{
struct pmc_op_configurelog cla;

cla.pm_flags = 0;
cla.pm_logfd = fd;
if (PMC_CALL(CONFIGURELOG, &cla) < 0)
return (-1);
Expand Down
6 changes: 6 additions & 0 deletions share/man/man4/hwpmc.4
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ An invalid CPU number was passed in for a
.Dv PMC_OP_GETPMCINFO
operation.
.It Bq Er EINVAL
The
.Ar pm_flags
argument to a
.Dv PMC_OP_CONFIGURELOG
request contained unknown flags.
.It Bq Er EINVAL
A
.Dv PMC_OP_CONFIGURELOG
request to de-configure a log file was issued without a log file
Expand Down
6 changes: 6 additions & 0 deletions sys/dev/hwpmc/hwpmc_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,12 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
break;
}

/* No flags currently implemented */
if (cl.pm_flags != 0) {
error = EINVAL;
break;
}

/* mark this process as owning a log file */
p = td->td_proc;
if ((po = pmc_find_owner_descriptor(p)) == NULL)
Expand Down

0 comments on commit 8e63e78

Please sign in to comment.