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

Reimar =?UTF8?Q?D=F6ffinger?= Reimar.Doeffinger at stud.uni-karlsruhe.de
Tue Jan 25 10:22:07 CET 2005

On Mon, Jan 24, 2005 at 08:43:07PM +0100, Aurelien Jacobs wrote:
> On Mon, 24 Jan 2005 15:53:06 +0100
> Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de> wrote:
> > On Mon, Jan 24, 2005 at 03:39:44PM +0100, Aurelien Jacobs wrote:
> > > On Mon, 24 Jan 2005 13:31:05 +0100
> > > Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de> wrote:
> > > > On Mon, Jan 24, 2005 at 03:07:06AM +0100, Aurelien Jacobs wrote:
> > > > > On Fri, 21 Jan 2005 21:40:34 +0100
> > > > > Alex Beregszaszi <alex at fsn.hu> wrote:
> > > > How about just using anonymous mmap instead of malloc+mprotect?
> > > > According to my understandig of its manpage it should work...
> > > 
> > > Right, it works. But I don't like this too much. It less readable and not
> > > really simpler IMHO.
> > 
> > With all that alignment? And you have to find out the page size etc. for
> > the other variant...
> 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 non used end of page can be malloced later ?

mmap always allocates full pages AFAIK, so no need to use or know PAGESIZE there.
Also, the static define PAGESIZE is not really correct IMHO, there are already systems that use different sizes (don't know if MPlayer runs on any of
them though), so you should use getpagesize anyway.

> 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 mprotect you almost certainly have mmap. I am quite certain that there are more systems that have mmap (esp. anonymous) than systems that
have memaligna and mprotect

> > > Do you think this patch is really better or should I stick with my
> > > memalign() version ?
> > 
> > Btw. BSD does not have memalign, as well as other OS (look in config.h
> > it just uses normal malloc then).
> 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()).

libavcodec has, but it is quite a hack...

> Finally what do you think is the best solution ?

I very much prefer the mmap version, it looks much less "hackish" to me. And makes less assumptions. It can even work if the program is not allowed to
change permissions after allocating a memory area (enforcing this might be a good idea security-wise).
One question is open though: what to do when mmap fails... Try with normal malloced memory (i.e. fallback to version when no mmap is available) and
print warning?

Reimar Döffinger

More information about the MPlayer-dev-eng mailing list