From 56147c03698b1c7eb48808e05513b911d00a6847 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 1 Aug 2021 11:49:15 +0100 Subject: [PATCH] Solaris/Illumos build implementation proposal. --- Makefile | 4 ++++ display.c | 23 +++++++++++++++++++++++ honggfuzz.c | 2 +- libhfcommon/log.c | 17 +++++++++++++++++ libhfcommon/log.h | 6 ++++++ posix/arch.c | 12 +++++++----- report.c | 2 +- sanitizers.c | 4 ++-- socketfuzzer.c | 4 ++-- subproc.c | 2 +- 10 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 13a0a74d..2c2e55e2 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,10 @@ else ARCH_CFLAGS := -Wno-initializer-overrides \ -Wno-unknown-warning-option -Wno-unknown-pragmas ARCH_LDFLAGS := -L/usr/local/lib -lm + ifeq ($(OS),SunOS) + ARCH_CFLAGS += -D_POSIX_C_SOURCE=200809L -D__EXTENSIONS__=1 + ARCH_LDFLAGS += -lkstat -lsocket -lnsl + endif ifneq ($(OS),OpenBSD) ARCH_LDFLAGS += -lrt endif diff --git a/display.c b/display.c index 6636cc73..2de46805 100644 --- a/display.c +++ b/display.c @@ -39,6 +39,10 @@ #include #endif +#if defined(__sun) +#include +#endif + #if defined(__APPLE__) #include #include @@ -163,6 +167,25 @@ static unsigned getCpuUse(int numCpus) { systemT += cpuData[CP_SYS] * ticks; idleT += cpuData[CP_IDLE] * ticks; } +#elif defined(__sun) + kstat_ctl_t *kctl = kstat_open(); + for (int i = 0; i < numCpus; i++) { + kstat_named_t *data; + kstat_t *cpu = kstat_lookup(kctl, "cpu", i, NULL); + if (!cpu) { + LOG_W("kstat_lookup('cpu_info') != 0"); + continue; + } + kstat_read(kctl, cpu, NULL); + data = kstat_data_lookup(cpu, "cpu_ticks_user"); + userT += data->value.ui64; + data = kstat_data_lookup(cpu, "cpu_ticks_kernel"); + systemT += data->value.ui64; + data = kstat_data_lookup(cpu, "cpu_ticks_idle"); + idleT += data->value.ui64; + } + + kstat_close(kctl); #else host_cpu_load_info_data_t avg; mach_msg_type_number_t num = HOST_CPU_LOAD_INFO_COUNT; diff --git a/honggfuzz.c b/honggfuzz.c index 49d10e73..380cf149 100644 --- a/honggfuzz.c +++ b/honggfuzz.c @@ -101,7 +101,7 @@ static void setupRLimits(void) { LOG_E("RLIMIT_NOFILE max limit < 1024 (%zu). Expect troubles!", (size_t)rlim.rlim_max); return; } - rlim.rlim_cur = MIN(1024, rlim.rlim_max); // we don't need more + rlim.rlim_cur = HF_MIN(1024, rlim.rlim_max); // we don't need more if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) { PLOG_E("Couldn't setrlimit(RLIMIT_NOFILE, cur=%zu/max=%zu)", (size_t)rlim.rlim_cur, (size_t)rlim.rlim_max); diff --git a/libhfcommon/log.c b/libhfcommon/log.c index 4858f6b6..7a1ddcaa 100644 --- a/libhfcommon/log.c +++ b/libhfcommon/log.c @@ -181,3 +181,20 @@ int logFd(void) { enum llevel_t logGetLevel(void) { return hf_log_level; } + +#if defined(__sun) +void dprintf(int fd, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vdprintf(fd, fmt, ap); + va_end(ap); +} + +int vdprintf(int fd, const char *fmt, va_list ap) { + FILE fp = { + ._magic = (unsigned char )fd, + ._flag = _IOREAD, + }; + return vfprintf(&fp, fmt, ap); +} +#endif diff --git a/libhfcommon/log.h b/libhfcommon/log.h index dc75e0a4..6d2f3b2e 100644 --- a/libhfcommon/log.h +++ b/libhfcommon/log.h @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef _HF_ARCH_DARWIN #pragma push_macro("DEBUG") @@ -97,6 +98,11 @@ extern pthread_mutex_t* logMutexGet(void); void logMutexReset(void); +#if defined(__sun) +void dprintf(int fd, const char *, ...); +int vdprintf(int fd, const char *, va_list); +#endif + #ifdef _HF_ARCH_DARWIN #pragma pop_macro("DEBUG") #endif diff --git a/posix/arch.c b/posix/arch.c index c6090b0f..bf950fe1 100644 --- a/posix/arch.c +++ b/posix/arch.c @@ -32,7 +32,9 @@ #include #include #include +#if !defined(__sun) #include +#endif #include #include #include @@ -93,7 +95,7 @@ static void arch_analyzeSignal(run_t* run, pid_t pid, int status) { * Boring, the process just exited */ if (WIFEXITED(status)) { - LOG_D("Process (pid %d) exited normally with status %d", pid, WEXITSTATUS(status)); + LOG_D("Process (pid %d) exited normally with status %d", (int)pid, WEXITSTATUS(status)); return; } @@ -102,12 +104,12 @@ static void arch_analyzeSignal(run_t* run, pid_t pid, int status) { */ if (!WIFSIGNALED(status)) { LOG_E("Process (pid %d) exited with the following status %d, please report that as a bug", - pid, status); + (int)pid, status); return; } int termsig = WTERMSIG(status); - LOG_D("Process (pid %d) killed by signal %d '%s'", pid, termsig, strsignal(termsig)); + LOG_D("Process (pid %d) killed by signal %d '%s'", (int)pid, termsig, strsignal(termsig)); if (!arch_sigs[termsig].important) { LOG_D("It's not that important signal, skipping"); return; @@ -150,7 +152,7 @@ static void arch_analyzeSignal(run_t* run, pid_t pid, int status) { snprintf(run->crashFileName, sizeof(run->crashFileName), "%s/%s.PC.%" PRIx64 ".STACK.%" PRIx64 ".ADDR.%" PRIx64 ".%s.%d.%s", run->global->io.crashDir, util_sigName(termsig), pc, run->backtrace, crashAddr, - localtmstr, pid, run->global->io.fileExtn); + localtmstr, (int)pid, run->global->io.fileExtn); } if (files_exists(run->crashFileName)) { @@ -210,7 +212,7 @@ static bool arch_checkWait(run_t* run) { PLOG_F("waitpid() failed"); } - LOG_D("pid=%d returned with status: %s", pid, subproc_StatusToStr(status)); + LOG_D("pid=%d returned with status: %s", (int)pid, subproc_StatusToStr(status)); arch_analyzeSignal(run, pid, status); diff --git a/report.c b/report.c index a7f6396e..2e38d50c 100644 --- a/report.c +++ b/report.c @@ -136,7 +136,7 @@ void report_appendReport(pid_t pid, run_t* run, funcs_t* funcs, size_t funcCnt, util_ssnprintf(run->report, sizeof(run->report), "DESCRIPTION: %s\n", description); util_ssnprintf(run->report, sizeof(run->report), "ORIG_FNAME: %s\n", run->dynfile->path); util_ssnprintf(run->report, sizeof(run->report), "FUZZ_FNAME: %s\n", run->crashFileName); - util_ssnprintf(run->report, sizeof(run->report), "PID: %d\n", pid); + util_ssnprintf(run->report, sizeof(run->report), "PID: %d\n", (int)pid); util_ssnprintf( run->report, sizeof(run->report), "SIGNAL: %s (%d)\n", util_sigName(signo), signo); util_ssnprintf(run->report, sizeof(run->report), "PC: 0x%" PRIx64 "\n", pc); diff --git a/sanitizers.c b/sanitizers.c index 302b6267..20246c0b 100644 --- a/sanitizers.c +++ b/sanitizers.c @@ -132,7 +132,7 @@ size_t sanitizers_parseReport(run_t* run, pid_t pid, funcs_t* funcs, uint64_t* p /* Under Linux the crash is seen in TID, but the sanitizer report is created for PID */ pid = sanitizers_PidForTid(pid); snprintf( - crashReport, sizeof(crashReport), "%s/%s.%d", run->global->io.workDir, kLOGPREFIX, pid); + crashReport, sizeof(crashReport), "%s/%s.%d", run->global->io.workDir, kLOGPREFIX, (int)pid); FILE* fReport = fopen(crashReport, "rb"); if (fReport == NULL) { @@ -169,7 +169,7 @@ size_t sanitizers_parseReport(run_t* run, pid_t pid, funcs_t* funcs, uint64_t* p if (reportpid != pid) { LOG_W( "SAN report found in '%s', but its PID:%d is different from the needed PID:%d", - crashReport, reportpid, pid); + crashReport, reportpid, (int)pid); break; } headerFound = true; diff --git a/socketfuzzer.c b/socketfuzzer.c index 53f1d810..25b91885 100644 --- a/socketfuzzer.c +++ b/socketfuzzer.c @@ -117,7 +117,7 @@ bool setupSocketFuzzer(honggfuzz_t* run) { socklen_t t; struct sockaddr_un local, remote; char socketPath[512]; - snprintf(socketPath, sizeof(socketPath), "/tmp/honggfuzz_socket.%i", getpid()); + snprintf(socketPath, sizeof(socketPath), "/tmp/honggfuzz_socket.%i", (int)getpid()); if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { perror("socket"); @@ -154,6 +154,6 @@ bool setupSocketFuzzer(honggfuzz_t* run) { void cleanupSocketFuzzer() { char socketPath[512]; - snprintf(socketPath, sizeof(socketPath), "/tmp/honggfuzz_socket.%i", getpid()); + snprintf(socketPath, sizeof(socketPath), "/tmp/honggfuzz_socket.%i", (int)getpid()); unlink(socketPath); } diff --git a/subproc.c b/subproc.c index d6cfca3b..69c5a4a4 100644 --- a/subproc.c +++ b/subproc.c @@ -519,7 +519,7 @@ void subproc_checkTimeLimit(run_t* run) { if (run->tmOutSignaled && (diffUSecs > ((run->global->timing.tmOut + 1) * 1000000))) { /* Has this instance been already signaled due to timeout? Just, SIGKILL it */ - LOG_W("pid=%d has already been signaled due to timeout. Killing it with SIGKILL", run->pid); + LOG_W("pid=%d has already been signaled due to timeout. Killing it with SIGKILL", (int)run->pid); kill(run->pid, SIGKILL); return; }