Skip to content

Commit

Permalink
Page-in strings with macro
Browse files Browse the repository at this point in the history
  • Loading branch information
be32826 committed Jul 2, 2024
1 parent e0e0ec4 commit 95ac237
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions nvram.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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));
}

Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));
}

Expand Down
11 changes: 5 additions & 6 deletions strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include "hypercall.h"
#include <stddef.h>

#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);
Expand Down

0 comments on commit 95ac237

Please sign in to comment.