AssetManager instances are created by zygote and passed to all its
children so that they don't have to individually open
frameworks-res.apk. This creates a problem for determining the current
file offset when using lseek() on those files, because you can't
guarantee the cross-process locking of a mutex. Luckily, Linux
implements pread() to get around this suckiness.
The problem is that only Linux implements this, so we have to keep the
old locking for use on host builds with aapt and friends. aapt doesn't
have this same problem of sharing file descriptors across forked
processes, so we can keep the local AutoMutex to protect accesses of
those files.
Change-Id: Ibe9f11499a53fe345f50fbaea438815ec0fd363e
There is apparently still a race upon reading the entry Local File
Header that can't be tracked down, so move the LFH check inside the
mutex-protected block so we can call lseek again to see where we are
when we log an error.
Also, close() can fail so use TEMP_FAILURE_RETRY on it so we don't
unwittingly leak file descriptors when Mean Mr. EINTR comes a-knocking.
Change-Id: I753abad0bd882fe28f7281c406fa76f64393ef4c
Since we switched to seeking to the LFH to verify its existence instead
of a huge mmap of the file, we have to guarantee that another seek
doesn't happen before we finish our read on the LFH.
Change-Id: If8135d9cb6f2f5cc4db734eafa4f6b5f6269c62a
This reverts commit 52b8235238fb4d8cf141020cc1ae33880929dc3f.
munmap() on a region that overlaps something else (e.g, the ZIP Central
Directory in this case) unmaps those other regions as well making the
ZipFileRO class unhappy. Revert this for now until we can have FileMap
deal with this craziness.
Some assets are failing to read from ZIP files. This adds a bit more
debugging to figure out what's going on.
Change-Id: Id90e10546c54c85069a34478fbc28bc2523bda5d
In the success case, the 65kB scanBuf was not freed!
Also, get rid of annoying complaints about ssize_t from printf in error
cases.
Change-Id: If154ac19bf47637f898b4ec8c8e27c9a073a7b81
Change the way zip archives are handled. This is necessary to deal with
very large (~1GB) APK files, for which our current approach of mapping
the entire file falls over.
We now do the classic scavenger hunt for the End Of Central Directory
magic on a buffer of data read from the file, instead of a memory-mapped
section. We use what we find to create a map that covers the Central
Directory only.
If the caller is interested in unpacking the file contents, we have to
do an additional file read to discover the size of the Local File Header
section so we can skip past it.
This is based on Change I745fb15abb in the dalvik tree. Both
implementations share a common ancestry, but the cost of unifying them
outweighs the benefits of wrapping C calls.
Change-Id: Iddacb50fe913917c2845708a530872d65fdbe620