Skip to content

Commit

Permalink
Print memrc arch and kernel uname info
Browse files Browse the repository at this point in the history
This should make anlyzing logs easier.
  • Loading branch information
mkozlowski committed Sep 29, 2024
1 parent ef5fc73 commit 51efae2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ endif

PCFLAGS += -Wstrict-prototypes -fno-stack-protector -fpie -nostdlib -ffreestanding -fomit-frame-pointer -Wa,--noexecstack

GIT_VERSION = $(shell (git describe --dirty 2>/dev/null || echo "unknown") | sed 's/^v//')
GIT_VERSION = $(shell (git describe --dirty=+ 2>/dev/null || echo "unknown") | sed 's/^v//')

GOFF = ./gen-offsets.sh

Expand Down Expand Up @@ -143,7 +143,7 @@ $(B)/cpu.o: arch/$(ARCH)/cpu.c
$(CC) $(MCFLAGS) -c $^ -o $@

$(B)/memcr.o: memcr.c $(B)/parasite-blob.h
$(CC) $(MCFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"' -I$(B) -c $< -o $@
$(CC) $(MCFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"' -DARCH_NAME='"$(ARCH)"' -I$(B) -c $< -o $@

$(B)/memcr: $(B)/memcr.o $(B)/cpu.o $(B)/enter.o
$(CC) $(MCFLAGS) $^ $(LDFLAGS) -o $@
Expand Down
15 changes: 14 additions & 1 deletion memcr.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/utsname.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <stdlib.h>
Expand All @@ -65,6 +66,10 @@
#include "arch/enter.h"
#include "parasite-blob.h"

#ifndef ARCH_NAME
#define ARCH_NAME "unknown"
#endif

#define NT_PRSTATUS 1

#define __round_mask(x, y) ((__typeof__(x))((y)-1))
Expand Down Expand Up @@ -2838,7 +2843,15 @@ static int user_interactive_mode(pid_t pid)

static void print_version(void)
{
fprintf(stdout, "[i] memcr version %s\n", GIT_VERSION);
int ret;
struct utsname utsn;
char buf[256] = { 0 };

ret = uname(&utsn);
if (!ret)
snprintf(buf, sizeof(buf), " kernel %s %s", utsn.release, utsn.machine);

fprintf(stdout, "[i] memcr %s %s%s\n", GIT_VERSION, ARCH_NAME, buf);
}

static void usage(const char *name, int status)
Expand Down

0 comments on commit 51efae2

Please sign in to comment.