From 58e32f18c8d2202adba3f2edeb0fc9d51e025b79 Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Mon, 27 Mar 2006 07:02:14 +0000 Subject: More alignment fixes. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9275 a1c6a512-1295-4272-9138-f99709370657 --- apps/tagcache.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'apps/tagcache.c') diff --git a/apps/tagcache.c b/apps/tagcache.c index b485eb4647..0c8a6aaa1d 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -1408,7 +1408,7 @@ static bool allocate_tagcache(void) } /* Load the header. */ - hdr = (struct ramcache_header *)audiobuf; + hdr = (struct ramcache_header *)(((long)audiobuf & ~0x03) + 0x04); memset(hdr, 0, sizeof(struct ramcache_header)); len = sizeof(struct tagcache_header); rc = read(fd, &hdr->h, len); @@ -1424,8 +1424,11 @@ static bool allocate_tagcache(void) hdr->indices = (struct index_entry *)(hdr + 1); - /* Now calculate the required cache size. */ - tagcache_size = hdr->h.datasize + + /** + * Now calculate the required cache size plus + * some extra space for alignment fixes. + */ + tagcache_size = hdr->h.datasize + 128 + sizeof(struct index_entry) * hdr->h.entry_count + sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); logf("tagcache: %d bytes allocated.", tagcache_size); @@ -1523,6 +1526,14 @@ static bool load_tagcache(void) { yield(); fe = (struct tagfile_entry *)p; +#ifdef ROCKBOX_STRICT_ALIGN + /* Make sure the entry is long aligned. */ + if ((long)fe & 0x03) + { + bytesleft -= 4 - ((long)fe & 0x03); + fe = (struct tagfile_entry *)(((long)fe & ~0x03) + 0x04); + } +#endif rc = read(fd, fe, sizeof(struct tagfile_entry)); if (rc != sizeof(struct tagfile_entry)) { -- cgit v1.2.3