Ejemplo n.º 1
0
void verifyNoTags(int seed, long *aa, int length) {
	srand(seed);
	int i;
	for(i=0;i<length;i++) {
		long randomValue = rand();
		unsigned char randomTag = rand() & TAG_MASK;
//		printf("[%d] = %ld, tag %d\n", i, aa[i], (unsigned char)load_tag(&aa[i]));
		assert(aa[i] == randomValue);
		assert((unsigned char)load_tag(&aa[i]) == 0);
	}
}
Ejemplo n.º 2
0
void verify(int seed, long *aa, int length) {
	srand(seed);
	int i;
//	printf("Verify with tags:\n");
//	dump(aa, length);
	for(i=0;i<length;i++) {
		long randomValue = rand();
		unsigned char randomTag = rand() & TAG_MASK;
		assert(aa[i] == randomValue);
		assert((unsigned char)load_tag(&aa[i]) == randomTag);
	}
}
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;
}
Ejemplo n.º 5
0
Archivo: cover.c Proyecto: rbong/jmc
// internal functions
SDL_Surface *load_embedded (const char *file)
{
    if (file == NULL)
        return NULL;

    if (access (file, F_OK) == -1)
    {
        fprintf (stderr,"%s: file '%s' does not exist\n", prog, file);
        return NULL;
    }
    if (access (file, R_OK) == -1)
    {
        fprintf (stderr,"%s: file '%s' cannot be read\n", prog, file);
        return NULL;
    }

    ID3v2_tag *tag = load_tag  (file);

    if (tag == NULL)
    {
        return NULL;
    }

    ID3v2_frame *frame = tag_get_album_cover (tag);

    if (frame == NULL)
    {
        free_tag (tag);
        return NULL;
    }

    ID3v2_frame_apic_content *album_content = parse_apic_frame_content (frame);

    if (album_content == NULL)
    {
        free_tag  (tag);
        return NULL;
    }

    SDL_Surface *sur =
        load_img_sdl (album_content->data, album_content->picture_size);
    free_tag (tag);
    free_apic_content (album_content);
    return sur;
}
Ejemplo n.º 6
0
static char *
generate_title(const char *fn, WavpackContext *ctx)
{
    static char *displaytitle = NULL;
    ape_tag tag;
    TitleInput *ti;

    ti = (TitleInput *) g_malloc0(sizeof(TitleInput));
    ti->__size = XMMS_TITLEINPUT_SIZE;
    ti->__version = XMMS_TITLEINPUT_VERSION;

    ti->file_name = g_strdup(g_basename(fn));
    ti->file_ext = "wv";

    load_tag(&tag, ctx);

    // xmms doesn't support unicode...
    ti->track_name = convertUTF8toLocale(tag.title);
    ti->performer = convertUTF8toLocale(tag.artist);
    ti->album_name = convertUTF8toLocale(tag.album);
    ti->date = convertUTF8toLocale(tag.year);
    ti->track_number = atoi(tag.track);
    if (ti->track_number < 0)
        ti->track_number = 0;
    ti->year = atoi(tag.year);
    if (ti->year < 0)
        ti->year = 0;
    ti->genre = convertUTF8toLocale(tag.genre);
    ti->comment = convertUTF8toLocale(tag.comment);

    displaytitle = xmms_get_titlestring(xmms_get_gentitle_format(), ti);
    if (!displaytitle || *displaytitle == '\0'
            || (strlen(tag.title) == 0 && strlen(tag.artist) == 0))
        displaytitle = ti->file_name;
    g_free(ti->track_name);
    g_free(ti->performer);
    g_free(ti->album_name);
    g_free(ti->genre);
    g_free(ti->comment);
    g_free(ti);

    return displaytitle;
}
Ejemplo n.º 7
0
int com_load_tag(char *arg) {
  int res = load_tag(arg);
  if (res == 0)
    printf("Successfully loaded tag from: %s\n", arg);
  return 0;
}
Ejemplo n.º 8
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");
}
Ejemplo n.º 9
0
void dump(long *aa, int length) {
	int i;
	for(i=0;i<length;i++) {
		printf("[%d] = %ld, tag %d\n", i, aa[i], (unsigned char)load_tag(&aa[i]));
	}
}
Ejemplo n.º 10
0
int main(int argc, char **argv) {
	printf("Testing memcpy/memmove with function pointers for array size ");
	printf("%d", ARRAY_SIZE);
#ifdef NO_TAGS
	printf(" (no tags)");
#endif
#ifdef FAKE_TAGS
	printf(" (fake tags)");
#endif
	printf("...\n");
	Object *p = createEvilObject();
	fillArray(p);
	printf("Calling function on original object...\n");
#ifndef NO_TAGS
	printf("Tag on p function pointer is %d\n", (int)load_tag(&(p->fn)));
	assert(load_tag(&(p->fn)) == __RISCV_TAG_CLEAN_FPTR);
#endif
	p->fn();
	Object *q = copyObject(p);
	checkArray(q);
	printf("Calling function on memcpy'ed copy of object...\n");
#ifndef NO_TAGS
	printf("Tag on p function pointer is %d\n", (int)load_tag(&(p->fn)));
	assert(load_tag(&(p->fn)) == __RISCV_TAG_CLEAN_FPTR);
	printf("Tag on q function pointer is %d\n", (int)load_tag(&(q->fn)));
	assert(load_tag(&(q->fn)) == __RISCV_TAG_CLEAN_FPTR);
#endif
	q->fn();
	Object *r = moveObject(p);
	checkArray(r);
	printf("Calling function on memmove'ed copy of object...\n");
#ifndef NO_TAGS
	printf("Tag on p function pointer is %d\n", (int)load_tag(&(p->fn)));
	assert(load_tag(&(p->fn)) == __RISCV_TAG_CLEAN_FPTR);
	printf("Tag on q function pointer is %d\n", (int)load_tag(&(q->fn)));
	assert(load_tag(&(q->fn)) == __RISCV_TAG_CLEAN_FPTR);
	printf("Tag on r function pointer is %d\n", (int)load_tag(&(r->fn)));
	assert(load_tag(&(r->fn)) == __RISCV_TAG_CLEAN_FPTR);
#endif
	r->fn();
	printf("Success!\n");
	deleteObject(p);
	deleteObject(q);
	deleteObject(r);
	return 0;
}