Hello All,
I'd like to bring this to your attention and review, hopefully to spawn some constructive discussions. The code was a result of experiments I've been doing lately concering some new idea not especially related to WINE.
To quote myself from http://wiki.winehq.org/UnalignedMmap:
---- Large majority of PE executables have sections that are page-aligned in memory but not in the PE file image. Linux's mmap() doesn't support mappings that are not aligned to page boundries with regard to file offsets. Currently it forces wineserver to fake mmap() by allocating anonymous pages and using read() to load the sections.
In dlls/ntdll/virtual.c, comment above map_file_into_view() says: "Linux kernels before 2.4.x can support non page-aligned offsets, as long as the offset is aligned to the filesystem block size. This is a big performance gain so we want to take advantage of it."
These days are long gone, we are now using Linux 2.6, and it doesn't support unaligned mmap().
Enter upmfs. This simple kernel module exports this function to userspace using '/proc':
* int mmap_offset(int fd, unsigned long offset);
Given an fd and an offset, a new fd is returned. Using mmap() on that new fd, the mapping will be aligned with the given offset, which can be smaller than PAGE_SIZE.
A wineserver implementation can check the existance of that module in the kernel (i.e "/proc/upmfs/interface" exists) and use its functionality. ----
The code for the upmfs source package is attached to this post.