citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit ce4b3a89afa8757a200a181954a32fb9b4465d3e
parent 5d5833ca3fdab2e0872f1856ad36d327f16e890e
Author: Kyle Milz <milz@0x30.net>
Date:   Fri,  5 Mar 2021 17:03:05 +0000

lib: update #includes and comments

Diffstat:
Mlib/unix.c | 21++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/lib/unix.c b/lib/unix.c @@ -14,16 +14,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/mman.h> /* mmap */ -#include <sys/stat.h> /* S_IRUSR, S_IWUSR, mkdir */ +#include <sys/stat.h> /* S_IRUSR, S_IWUSR */ #include <assert.h> #include <err.h> -#include <errno.h> /* EEXIST */ #include <fcntl.h> /* O_CREAT */ -#include <limits.h> /* PATH_MAX */ -#include <stdlib.h> /* get{env,progname} */ -#include <string.h> /* strl{cpy,cat} */ -#include <unistd.h> /* access, execlp, fork, lseek, get* */ +#include <stdlib.h> /* getprogname */ +#include <string.h> /* strlcpy */ +#include <unistd.h> /* execlp, fork, lseek, get* */ #include "citrun.h" /* struct citrun_header */ #include "os.h" @@ -50,10 +48,10 @@ void * citrun_extend(int fd, size_t req_bytes) { - size_t aligned_bytes; + size_t page_mask, aligned_bytes; off_t len; + int prot; void *mem; - size_t page_mask; page_mask = getpagesize() - 1; aligned_bytes = (req_bytes + page_mask) & ~page_mask; @@ -67,7 +65,8 @@ citrun_extend(int fd, size_t req_bytes) err(1, "ftruncate from %lld to %llu", len, len + aligned_bytes); /* Increase memory mapping length. */ - mem = mmap(NULL, req_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, len); + prot = PROT_READ | PROT_WRITE; + mem = mmap(NULL, req_bytes, prot, MAP_SHARED, fd, len); if (mem == MAP_FAILED) err(1, "mmap %zu bytes @ %llu", req_bytes, len); @@ -100,7 +99,7 @@ citrun_open_fd() * - program name * - current working directory * - * This function doesn't fail. + * This function does not fail. */ void citrun_os_info(struct citrun_header *h) @@ -117,7 +116,7 @@ citrun_os_info(struct citrun_header *h) /* * Tries to exec 'citrun_gl' which must be on the path. - * The instrumented program exits on failure and returns nothing on success. + * If fork() fails, the intstrumented program will also fail. */ void citrun_start_viewer()