From 95ac23754bb20c6998d8b02dd4c7eb80e9ff8e9f Mon Sep 17 00:00:00 2001 From: Benjamin Levy Date: Tue, 2 Jul 2024 14:56:03 -0400 Subject: [PATCH] Page-in strings with macro --- nvram.c | 10 +++++----- strings.c | 11 +++++------ strings.h | 4 +++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/nvram.c b/nvram.c index d9fdddd..31af7f8 100644 --- a/nvram.c +++ b/nvram.c @@ -126,7 +126,7 @@ int nvram_clear(void) { // Clear is really a bunch of unsets rv = igloo_hypercall2(110, (unsigned long)path, strlen(path)); while (rv == 1) { - igloo_page_in_str(path); + PAGE_IN(path); rv = igloo_hypercall2(110, (unsigned long)path, strlen(path)); } } @@ -285,7 +285,7 @@ int nvram_get_buf(const char *key, char *buf, size_t sz) { rv = igloo_hypercall2(107, (unsigned long)path, strlen(path)); while (rv == 1) { - igloo_page_in_str(path); + PAGE_IN(path); rv = igloo_hypercall2(107, (unsigned long)path, strlen(path)); } @@ -308,7 +308,7 @@ int nvram_get_buf(const char *key, char *buf, size_t sz) { // success rv = igloo_hypercall2(108, (unsigned long)path, strlen(path)); while (rv == 1) { - igloo_page_in_str(path); + PAGE_IN(path); rv = igloo_hypercall2(108, (unsigned long)path, strlen(path)); } } @@ -469,7 +469,7 @@ int nvram_set(const char *key, const char *val) { rv = igloo_hypercall2(109, (unsigned long)path, (unsigned long)val); while (rv == 1) { - igloo_page_in_str(path); + PAGE_IN(path); rv = igloo_hypercall2(109, (unsigned long)path, (unsigned long)val); } @@ -544,7 +544,7 @@ int nvram_unset(const char *key) { rv = igloo_hypercall2(110, (unsigned long)path, strlen(path)); while (rv == 1) { - igloo_page_in_str(path); + PAGE_IN(path); rv = igloo_hypercall2(110, (unsigned long)path, strlen(path)); } diff --git a/strings.c b/strings.c index 9a7101f..c210215 100644 --- a/strings.c +++ b/strings.c @@ -14,9 +14,8 @@ typedef struct { const char* value; } match; -void igloo_page_in_str(const char *s) { - volatile const char *p = s; - while (*p++); +void igloo_page_in_str(volatile const char *s) { + while (*s++); } void log_match(match m) { @@ -35,7 +34,7 @@ void log_match(match m) { int rv = igloo_hypercall2(cmd, (unsigned long)m.value, minimal_strlen(m.value)); while (rv == 1) { - igloo_page_in_str(m.value); + PAGE_IN(m.value); rv = igloo_hypercall2(cmd, (unsigned long)m.value, minimal_strlen(m.value)); } } @@ -126,8 +125,8 @@ char *strstr(const char *haystack, const char *needle) { // Hypercall returns -1 on read fail. If no hypercall is available we'd get a different reval // so we wouldn't infinite loop. Hopefully. while (rv == 1) { - igloo_page_in_str(haystack); - igloo_page_in_str(needle); + PAGE_IN(haystack); + PAGE_IN(needle); rv = igloo_hypercall2(104, (unsigned long)haystack, (unsigned long)needle); } diff --git a/strings.h b/strings.h index 5f6a4af..9f14b8a 100644 --- a/strings.h +++ b/strings.h @@ -4,10 +4,12 @@ #include "hypercall.h" #include +#define PAGE_IN(s) igloo_page_in_str((volatile const char *)(s)) + #define TARGET_VALUE "DYNVALDYNVALDYNVAL" extern char **environ; -void igloo_page_in_str(const char *s); +void igloo_page_in_str(volatile const char *s); size_t minimal_strlen(const char *s); int minimal_strncmp(short do_log, size_t n, const char *s1, const char *s2); int minimal_strcmp(const char *s1, const char *s2, short do_log);