[MPlayer-dev-eng] Re: amd64 -sws 0 fix (iow: playing with NX bit)

Trent Piepho xyzzy at speakeasy.org
Tue Jan 25 00:23:22 CET 2005


On Mon, 24 Jan 2005, Aurelien Jacobs wrote:
> Hum... did you had a look at my mmap patch ?
> It also check PAGESIZE to ensure that only funnyCode and nothing more
> Maybe it's not useful ? I don't know if mmap only alloc full pages or

If you just made the max funny code size a multiple of the pagesize, like
PAGESIZE*4 or 10001/PAGESIZE*PAGESIZE+PAGESIZE then you could just ignore mmap
alignment from then on.

> Moreover, we also can't assume that we have mmap so we need an
> alternative way to do it. That's why I think it's not simpler.

If you have NX and mprotect, then can't you assume mmap too?  If you don't
have NX, then you don't have to worry about mprotect or alignment.

> That's pretty ugly :-(
> maybe we should use posix_memalign instead ?
> Or we should provide an alternative implementation for memalign, but
> that seem pretty hard (if we want to be able to free()).

memaligning portably is a bitch.  If you use memalign, you can't free the
memory afterwards portably.  glibc can do it, but isn't not required. 
posix_memalign memory can be freed afterward, but not all systems have
posix_memalign.  

You can implement your own aligned memory routine on top of a system malloc,
but you can't free the aligned pointer with free, you need to create your own
free function, and use it.  Of course your free function will probably not
work when passed non-aligned memory that was allocated with just malloc, so
now you need to keep track of aligned-malloced and normal-malloced memory to
use the correct free function.

Usually what people do it just give up, and say you need posix_memalign or a
memalign that supports free, or tough, you don't get aligned memory.




More information about the MPlayer-dev-eng mailing list