void clean(long *aa, int length) { int i; for(i=0;i<length;i++,aa++) { store_tag(aa, 0); *aa = 0; } }
void dcache_inv_all() { int i; for(i = 0; i < 8192; i += 64) { store_tag(i, 0, 0); __builtin_allegrex_cache(0x13, i); __builtin_allegrex_cache(0x11, i); } }
int fill_entry_struct(struct Entry *entry, const struct Rc *rc, const struct Options *opt) { unsigned int i; assert(entry); assert(rc); assert(opt); /* * Get information about the environment; hostname, current directory, * login name and tty. * * Fixme: Add check so this and the session info thing are run only * once. Only has some effect if creating many UUIDs. */ entry->host = get_hostname(rc); if (!entry->host) { myerror("fill_entry_struct(): Cannot get hostname"); return EXIT_FAILURE; } if (!valid_hostname(entry->host)) { myerror("fill_entry_struct(): Got invalid hostname: \"%s\"", entry->host); return EXIT_FAILURE; } entry->cwd = getpath(); entry->user = get_username(); entry->tty = get_tty(); /* * Store tags and comment in entry. */ for (i = 0; i < MAX_TAGS && opt->tag[i]; i++) if (store_tag(entry, opt->tag[i]) == EXIT_FAILURE) return EXIT_FAILURE; if (opt->comment) { entry->txt = process_comment_option(opt->comment); if (!entry->txt) return EXIT_FAILURE; } /* * Store session information from the environment variable. */ if (get_sess_info(entry) == EXIT_FAILURE) { free(entry->txt); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char **argv) { printf("Calling function\n"); #ifdef FAKE_TAGS store_tag(&mutableFN, __RISCV_TAG_CLEAN_FPTR); #endif #ifndef NO_TAGS assert(load_tag(&mutableFN) == __RISCV_TAG_CLEAN_FPTR); #endif mutableFN(); printf("Changing function pointer\n"); mutableFN = evil; #ifdef FAKE_TAGS store_tag(&mutableFN, __RISCV_TAG_CLEAN_FPTR); #endif #ifndef NO_TAGS assert(load_tag(&mutableFN) == __RISCV_TAG_CLEAN_FPTR); #endif printf("Calling new function\n"); mutableFN(); printf("Success!\n"); return 0; }
int main(int argc, char **argv) { printf("Calling function\n"); #ifdef FAKE_TAGS store_tag(&mutableFN, __RISCV_TAG_CLEAN_FPTR); #endif #ifndef NO_TAGS assert(load_tag(&mutableFN) == __RISCV_TAG_CLEAN_FPTR); #endif mutableFN(); printf("Changing function pointer\n"); void **p = (void**) &mutableFN; void *f = (void*) evil; *p = f; #ifndef NO_TAGS printf("Tag is now %ld\n", load_tag(&mutableFN)); // assert(load_tag(&mutableFN) == 0); #endif printf("This should fail...\n"); mutableFN(); printf("Called evil function, failure!\n"); return 0; }
int main(int argc, char **argv) { printf("Doing random tag test with length %d tag mask %d\n", LENGTH, TAG_MASK); long *a = malloc(sizeof(long)*(LENGTH+2)); long *b = malloc(sizeof(long)*(LENGTH+2)); printf("Allocated space\n"); store_tag(&a[0], __RISCV_TAG_INVALID); store_tag(&b[0], __RISCV_TAG_INVALID); printf("Added bumpers at start\n"); store_tag(&a[LENGTH+1], __RISCV_TAG_INVALID); store_tag(&b[LENGTH+1], __RISCV_TAG_INVALID); printf("Added bumpers at end\n"); long *aa = &a[1]; long *bb = &b[1]; int seed = rand(); srand(seed); int i; printf("Setting up...\n"); for(i=0;i<LENGTH;i++) { long randomValue = rand(); char randomTag = rand() & TAG_MASK; aa[i] = randomValue; store_tag(&aa[i], randomTag); // printf("[%d] = %ld, tag %d\n", i, randomValue, randomTag); } // Should copy tags. printf("Calling memcpy\n"); memcpy(bb, aa, LENGTH * sizeof(long)); verify(seed, aa, LENGTH); verify(seed, bb, LENGTH); clean(bb, LENGTH); printf("Calling memmove\n"); memmove(bb, aa, LENGTH * sizeof(long)); verify(seed, aa, LENGTH); verify(seed, bb, LENGTH); clean(bb, LENGTH); printf("Calling __riscv_memcpy_tagged\n"); // printf("aa:\n"); // dump(aa, LENGTH); // printf("bb:\n"); // dump(bb, LENGTH); __riscv_memcpy_tagged(bb, aa, LENGTH * sizeof(long)); // printf("After __riscv_memcpy_tagged:\n"); // printf("aa:\n"); // dump(aa, LENGTH); // printf("bb:\n"); // dump(bb, LENGTH); verify(seed, aa, LENGTH); verify(seed, bb, LENGTH); clean(bb, LENGTH); printf("Calling __riscv_memmove_tagged\n"); __riscv_memmove_tagged(bb, aa, LENGTH * sizeof(long)); verify(seed, aa, LENGTH); verify(seed, bb, LENGTH); clean(bb, LENGTH); printf("Calling __riscv_memcpy_no_tags\n"); __riscv_memcpy_no_tags(bb, aa, LENGTH * sizeof(long)); verify(seed, aa, LENGTH); verifyNoTags(seed, bb, LENGTH); printf("Calling __riscv_memmove_no_tags\n"); __riscv_memmove_no_tags(bb, aa, LENGTH * sizeof(long)); verify(seed, aa, LENGTH); verifyNoTags(seed, bb, LENGTH); memmove(bb, aa, LENGTH * sizeof(long)); #if LENGTH > 1 printf("Moving forward with memmove in-place by one slot...\n"); memmove(&bb[1], &bb[0], (LENGTH-1) * sizeof(long)); verify(seed, &bb[1], LENGTH-1); verify(seed, &bb[0], 1); printf("Cleaning...\n"); memmove(bb, aa, LENGTH * sizeof(long)); verify(seed, aa, LENGTH); verify(seed, bb, LENGTH); printf("Moving backwards with memmove in-place by one slot...\n"); memmove(&bb[0], &bb[1], (LENGTH-1)*sizeof(long)); verify(seed, aa, LENGTH); assert(bb[LENGTH-1] == aa[LENGTH-1]); assert(load_tag(&bb[LENGTH-1]) == load_tag(&aa[LENGTH-1])); // for(i=0;i<LENGTH-1;i++) { // printf("bb[%d] = %ld, tag %d should be %ld, tag %d\n", i, bb[i], // (unsigned char)load_tag(&bb[i]), aa[i+1], // (unsigned char)load_tag(&aa[i+1])); // } for(i=0;i<LENGTH-1;i++) { assert(bb[i] == aa[i+1]); assert(load_tag(&bb[i]) == load_tag(&aa[i+1])); } #endif /* LENGTH > 1 */ clean(a, LENGTH+2); clean(b, LENGTH+2); printf("Success!\n"); }