CVSROOT:        /cvs
Module name:    src
Changes by:     dera...@cvs.openbsd.org 2025/05/24 00:49:17

Modified files:
        include        : unistd.h 
        sys/sys        : exec.h exec_elf.h gmon.h proc.h systm.h 
        sys/kern       : exec_elf.c init_sysent.c kern_exec.c 
                         kern_exit.c kern_fork.c kern_pledge.c 
                         subr_prof.c syscalls.master 

Log message:
In the old gprof profiling subsystem, the simplistic profil() syscall
told the kernel about the sample buffer, and then the normal exit-time
_mcleanup() would finalize the buffer, open()'ed a file and write out
the details.  This file opening has become increasingly impossible
because of our privsep / privdrop, chroot, setresuid uid-dropping,
pledge, unveil, and other efforts.  So people stopped using gprof.
Programs which needed profiling needed substantial mitigation removal
changes to put them under test.

In the new gprof profiling subsystem, profil() is enhanced to provide more
buffer information to the kernel, as well as better instructions for where
the file should be written.  At normal exit-time mcleanup(), after finalizing
the buffer, the process simply terminates via _exit(2), and the kernel
does all the opening and writing in a safe way.  The file is now deposited
into the starting directory, or into PROFDIR as determined at program start,
with safety issues taken into consideration.

Additional side effecs:
- The monstartup(3) interface will go away, it cannot be supported.
- profil() is now allowed in pledge "stdio", access is decided by the -pg ELF 
note
- gmon.out is renamed to gmon.progname.pid.out, due to pervasive multi-process
privsep practices

prompted originally by job and claudio for use in rpki-client and bgpd
advice from kettenis and claudio

Reply via email to