summaryrefslogtreecommitdiff
path: root/hieronymus
diff options
context:
space:
mode:
authorneal <neal>2008-06-29 19:45:04 +0000
committerneal <neal>2008-06-29 19:45:04 +0000
commita43a424d8301fd58566a6087e3ae715cfc4f965d (patch)
treeacb1b04f5de91e978b3bc7ea57d50b4d7764de08 /hieronymus
parentb80a1c88a925afa8de0c6fd2b70d7bdecc15750e (diff)
libc-parts/
2008-06-29 Neal H. Walfield <neal@gnu.org> * md5.h: New file from glibc 2.7. * md5.c: Likewise. * Makefile.am (common_sources): Add md5.h and md5.c. hieronymus/ 2008-06-29 Neal H. Walfield <neal@gnu.org> * hieronymus.c: Include <md5.h>. (struct module): Add field md5sum. (main): Calculate the md5 digest for the binary. Compare it to the hash calculated at compile time. If they don't match, panic. * Makefile.am (md5sum): New function. (tovar): New function. (modules.h): Use it. Generate an md5 digest for the binary.
Diffstat (limited to 'hieronymus')
-rw-r--r--hieronymus/ChangeLog10
-rw-r--r--hieronymus/Makefile.am37
-rw-r--r--hieronymus/hieronymus.c28
3 files changed, 61 insertions, 14 deletions
diff --git a/hieronymus/ChangeLog b/hieronymus/ChangeLog
index 5b43c1e..a97ed58 100644
--- a/hieronymus/ChangeLog
+++ b/hieronymus/ChangeLog
@@ -1,5 +1,15 @@
2008-06-29 Neal H. Walfield <neal@gnu.org>
+ * hieronymus.c: Include <md5.h>.
+ (struct module): Add field md5sum.
+ (main): Calculate the md5 digest for the binary. Compare it to
+ the hash calculated at compile time. If they don't match, panic.
+ * Makefile.am (md5sum): New function.
+ (tovar): New function.
+ (modules.h): Use it. Generate an md5 digest for the binary.
+
+2008-06-29 Neal H. Walfield <neal@gnu.org>
+
* hieronymus.c (struct module): Add field delay.
(do_gather_stats): Don't initialize EPOCH here...
(main): ... but here. After loading all the modules, free the
diff --git a/hieronymus/Makefile.am b/hieronymus/Makefile.am
index 9121b3c..9608b7c 100644
--- a/hieronymus/Makefile.am
+++ b/hieronymus/Makefile.am
@@ -33,30 +33,45 @@ hieronymus_SOURCES = hieronymus.c modules.h
# delay (in seconds) at which to start the module. Each component is
# separated by a !
modules = ruth!1!100
-#modules = activity-distribution!1!100
ruth_commandline = "-D 3"
+#modules = activity-distribution!1!100
+#modules = gcbench!1!100!5 gcbench2!1!100!20 gcbench3!1!200!0 gcbench4!1!200!10
+
# List of directories relative to the top of the build tree to search
# for binaries.
module_paths = ruth benchmarks
files = $(foreach module,$(modules),$(firstword $(subst !, ,$(module))))
+find_binary = \
+ $(firstword \
+ $(wildcard \
+ $(addsuffix /$(1),$(addprefix $(top_builddir)/,$(module_paths)))) \
+ $(1):not_found)
+
+md5sum = \
+ $(shell md5sum $(call find_binary,$(1)) | awk '{ printf $$1 }' \
+ | sed 's/\([0-9a-f]\{2\}\)/0x\1, /g')
+
+tovar = $(subst -,_,$(firstword $(subst !, ,$(1))))
+
modules.h: $(addsuffix .S, $(files)) Makefile
echo ' \
$(foreach module,$(subst -,_,$(modules)), \
- extern char $(firstword $(subst !, ,$(module)))_start; \
- extern char $(firstword $(subst !, ,$(module)))_end;) \
+ extern char $(call tovar,$(module))_start; \
+ extern char $(call tovar,$(module))_end;) \
struct module modules[] = { \
- $(foreach module,$(subst -,_,$(modules)), \
+ $(foreach module,$(modules), \
{ \
- STRINGIFY ( $(firstword $(subst !, ,$(module))) ), \
+ "$(firstword $(subst !, ,$(module)))", \
$(wordlist 2, 2, $(subst !, ,$(module))), \
$(wordlist 3, 3, $(subst !, ,$(module))), \
$(wordlist 4, 4, $(subst !, ,$(module))) + 0, \
- $($(firstword $(subst !, ,$(module)))_commandline) "",\
- &$(firstword $(subst !, ,$(module)))_start, \
- &$(firstword $(subst !, ,$(module)))_end \
+ $($(call tovar,$(module))_commandline) "", \
+ &$(call tovar,$(module))_start, \
+ &$(call tovar,$(module))_end, \
+ { $(call md5sum,$(firstword $(subst !, ,$(module)))) }\
}, \
) \
};' > $@
@@ -65,12 +80,6 @@ modules.h: $(addsuffix .S, $(files)) Makefile
hieronymus.c: modules.h
-find_binary = \
- $(firstword \
- $(wildcard \
- $(addsuffix /$(1),$(addprefix $(top_builddir)/,$(module_paths)))) \
- $(1):not_found)
-
binaries = $(foreach file,$(files),$(call find_binary,$(file)))
$(addsuffix .S, $(files)): %.S: module.S $(binaries) Makefile
diff --git a/hieronymus/hieronymus.c b/hieronymus/hieronymus.c
index f5d3e94..e7ad638 100644
--- a/hieronymus/hieronymus.c
+++ b/hieronymus/hieronymus.c
@@ -31,6 +31,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <md5.h>
#define STRINGIFY_(id) #id
#define STRINGIFY(id) STRINGIFY_(id)
@@ -45,6 +46,8 @@ struct module
const char *commandline;
char *start;
char *end;
+
+ unsigned char md5sum[16];
};
#include "modules.h"
@@ -214,6 +217,31 @@ main (int argc, char *argv[])
addr_t thread[module_count];
for (i = 0; i < module_count; i ++)
{
+ struct md5_ctx ctx;
+ unsigned char result[16];
+
+ md5_init_ctx (&ctx);
+ md5_process_bytes (modules[i].start,
+ modules[i].end - modules[i].start,
+ &ctx);
+ md5_finish_ctx (&ctx, result);
+
+ if (memcmp (result, modules[i].md5sum, 16) != 0)
+ {
+ int j;
+ printf ("Expected md5 hash: ");
+ for (j = 0; j < 16; j ++)
+ printf ("%x%x", modules[i].md5sum[j] & 0x15,
+ modules[i].md5sum[j] >> 4);
+
+ printf ("\nGot: ");
+ for (j = 0; j < 16; j ++)
+ printf ("%x%x", result[j] & 0x15, result[j] >> 4);
+ printf ("\n");
+
+ panic ("Binary %s corrupted!", modules[i].name);
+ }
+
const char *argv[] = { modules[i].name, modules[i].commandline, NULL };
const char *env[] = { NULL };
thread[i] = process_spawn (activities[i],