citrun

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

commit 81b2da08ef1265f4a544d10342e5bfa3a6022706
parent fe989f3191597a8593ef32bf56cb465683e92a28
Author: kyle <kyle@0x30.net>
Date:   Sat, 12 Nov 2016 15:44:10 -0700

src: convert runtime to use native instead of fixed width types

Diffstat:
Msrc/rt.c | 25++++++++++++-------------
Msrc/rt.h | 25++++++++++++-------------
Mt/inst_preamble.sh | 25++++++++++++-------------
Mt/rt_header.t | 2+-
Mt/shm.pm | 4++--
Mt/utils.subr | 2+-
6 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/src/rt.c b/src/rt.c @@ -20,7 +20,6 @@ #include <err.h> #include <errno.h> /* EEXIST */ #include <fcntl.h> /* O_CREAT */ -#include <limits.h> /* PATH_MAX */ #include <stddef.h> /* offsetof */ #include <stdlib.h> /* get{env,progname} */ #include <string.h> /* strnlen */ @@ -41,10 +40,10 @@ static size_t shm_len = 0; * Exits on error, returns a pointer to the beginning of the extended memory * region on success. */ -static uint8_t * +static char * shm_extend(int bytes) { - uint8_t *shm; + char *shm; int page_size = getpagesize(); int page_mask = page_size - 1; int aligned_bytes; @@ -74,10 +73,10 @@ shm_extend(int bytes) static void shm_add_header() { - uint8_t *shm; + char *shm; struct citrun_header header = { - "citrun", + "ctrn", citrun_major, citrun_minor }; @@ -86,9 +85,9 @@ shm_add_header() header.pids[1] = getppid(); header.pids[2] = getpgrp(); - strlcpy(header.progname, getprogname(), PATH_MAX); + strlcpy(header.progname, getprogname(), CITRUN_PATH_MAX); - if (getcwd(header.cwd, PATH_MAX) == NULL) + if (getcwd(header.cwd, CITRUN_PATH_MAX) == NULL) err(1, "getcwd"); shm = shm_extend(sizeof(struct citrun_header)); @@ -139,25 +138,25 @@ shm_create() * Exits on failure. */ void -citrun_node_add(uint8_t node_major, uint8_t node_minor, struct citrun_node *n) +citrun_node_add(unsigned int major, unsigned int minor, struct citrun_node *n) { - uint8_t *shm; + char *shm; size_t sz = 0; /* Binary compatibility between versions not guaranteed. */ - if (node_major != citrun_major || node_minor != citrun_minor) + if (major != citrun_major || minor != citrun_minor) errx(1, "libcitrun-%i.%i: incompatible version %i.%i, " "try cleaning and rebuilding your project", - citrun_major, citrun_minor, node_major, node_minor); + citrun_major, citrun_minor, major, minor); if (!init) shm_create(); sz += sizeof(struct citrun_node); - sz += n->size * sizeof(uint64_t); + sz += n->size * sizeof(unsigned long long); shm = shm_extend(sz); memcpy(shm, n, sizeof(struct citrun_node)); - n->data = (uint64_t *)(shm + sizeof(struct citrun_node)); + n->data = (unsigned long long *)(shm + sizeof(struct citrun_node)); } diff --git a/src/rt.h b/src/rt.h @@ -1,20 +1,19 @@ -#include <limits.h> /* PATH_MAX */ -#include <stdint.h> /* uint{64,32,8}_t */ +#define CITRUN_PATH_MAX 1024 struct citrun_header { - char magic[6]; - uint8_t major; - uint8_t minor; - uint32_t pids[3]; - char progname[PATH_MAX]; - char cwd[PATH_MAX]; + char magic[4]; + unsigned int major; + unsigned int minor; + unsigned int pids[3]; + char progname[CITRUN_PATH_MAX]; + char cwd[CITRUN_PATH_MAX]; }; struct citrun_node { - uint32_t size; - const char comp_file_path[PATH_MAX]; - const char abs_file_path[PATH_MAX]; - uint64_t *data; + unsigned int size; + const char comp_file_path[CITRUN_PATH_MAX]; + const char abs_file_path[CITRUN_PATH_MAX]; + unsigned long long *data; }; -void citrun_node_add(uint8_t, uint8_t, struct citrun_node *); +void citrun_node_add(unsigned int, unsigned int, struct citrun_node *); diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh @@ -12,26 +12,25 @@ cat <<EOF > preamble.c.good #ifdef __cplusplus extern "" { #endif -#include <limits.h> /* PATH_MAX */ -#include <stdint.h> /* uint{64,32,8}_t */ +#define CITRUN_PATH_MAX 1024 struct citrun_header { - char magic[6]; - uint8_t major; - uint8_t minor; - uint32_t pids[3]; - char progname[PATH_MAX]; - char cwd[PATH_MAX]; + char magic[4]; + unsigned int major; + unsigned int minor; + unsigned int pids[3]; + char progname[CITRUN_PATH_MAX]; + char cwd[CITRUN_PATH_MAX]; }; struct citrun_node { - uint32_t size; - const char comp_file_path[PATH_MAX]; - const char abs_file_path[PATH_MAX]; - uint64_t *data; + unsigned int size; + const char comp_file_path[CITRUN_PATH_MAX]; + const char abs_file_path[CITRUN_PATH_MAX]; + unsigned long long *data; }; -void citrun_node_add(uint8_t, uint8_t, struct citrun_node *); +void citrun_node_add(unsigned int, unsigned int, struct citrun_node *); static struct citrun_node _citrun = { 1, "", diff --git a/t/rt_header.t b/t/rt_header.t @@ -11,7 +11,7 @@ my $ret = system('t/program/program 1'); is $ret >> 8, 0, "is program exit code 0"; my $shm = t::shm->new(); -is $shm->{magic}, "citrun", "is file magic correct"; +is $shm->{magic}, "ctrn", "is file magic correct"; is $shm->{major}, 0, "is major correct"; is $shm->{minor}, 0, "is minor correct"; diff --git a/t/shm.pm b/t/shm.pm @@ -22,14 +22,14 @@ sub new { ( $self->{magic}, $self->{major}, $self->{minor}, $self->{pids}[0], $self->{pids}[1], $self->{pids}[2], $self->{progname}, $self->{cwd} - ) = unpack("Z6CCLLLZ" . PATH_MAX . "Z" . PATH_MAX, xread($fh, $pagesize)); + ) = unpack("Z4I5Z1024Z1024", xread($fh, $pagesize)); my @translation_units; while (tell $fh < $self->{size}) { my %tu; ($tu{size}, $tu{comp_file_name}, $tu{abs_file_path}) = - unpack("LZ" . PATH_MAX . "Z" . PATH_MAX, xread($fh, 4 + 2 * 1024 + 4 + 8)); + unpack("IZ1024Z1024", xread($fh, 4 + 2 * 1024 + 4 + 8)); $tu{exec_buf_pos} = tell $fh; xread($fh, $tu{size} * 8); diff --git a/t/utils.subr b/t/utils.subr @@ -6,7 +6,7 @@ export CITRUN_TOOLS="`pwd`/src" function strip_preamble { file="${1}" - tail -n +36 $file.citrun > $file.citrun_nohdr + tail -n +35 $file.citrun > $file.citrun_nohdr } function strip_log