Groups | Search | Server Info | Login | Register


Groups > comp.os.os2.programmer.porting > #109

Re: VirtualAlloc to DosAllocMem

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!uucp.gnuu.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Date Fri, 08 Jul 2011 22:14:21 +0200
From Heiko Nitzsche <hn-expires-27nov11@arcor.de>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110706 Firefox/5.0 SeaMonkey/2.2
MIME-Version 1.0
Newsgroups comp.os.os2.programmer.porting
Subject Re: VirtualAlloc to DosAllocMem
References <iv5rr7$dqt$1@speranza.aioe.org> <4e176267$0$6545$9b4e6d93@newsspool4.arcor-online.net>
In-Reply-To <4e176267$0$6545$9b4e6d93@newsspool4.arcor-online.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Lines 71
Message-ID <4e176505$0$6554$9b4e6d93@newsspool4.arcor-online.net> (permalink)
Organization Arcor
NNTP-Posting-Date 08 Jul 2011 22:13:57 CEST
NNTP-Posting-Host 549fcf2b.newsspool4.arcor-online.net
X-Trace DXC=^=INde_T@XClU`@c^jLCbJ4IUK<Cl32<A4Fo<]lROoRA8kF<OcfhCOKbHDjlT\cIKLM<kdeV_e3ILOnF@4?GW[2H8h27CNoGN:FllTdhOVM=gC
X-Complaints-To usenet-abuse@arcor.de
Xref x330-a1.tempe.blueboxinc.net comp.os.os2.programmer.porting:109

Show key headers only | View raw


According to the OS/2 TK docs you can even get rid of PAG_READ
when PAG_EXECUTE is set as then PAG_READ is implied. But of
course it doesn't hurt and improves readability if it there ;)
Beware that when querying the memory protection flags, for
executable memory the PAG_READ is not returned since OS/2 Warp
as it implies PAG_READ.

Before accessing the memory it has to be committed with
DosSetMem(..., PAG_DEFAULT | PAG_COMMIT). Potentially
there is another function in the allocator for this.

> Well, I'd propose the following:
>
> static inline DWORD protection(bool writable, bool executable)
> {
> return executable ?
> (writable ? (PAG_EXECUTE | PAG_READ | PAG_WRITE) : (PAG_EXECUTE | PAG_READ) :
> (writable ? ( PAG_READ | PAG_WRITE) : PAG_READ);
> }
>
> You could also write it this way:
>
> static inline DWORD protection(bool writable, bool executable)
> {
> DWORD permissions = PAG_READ; // always readable
> if (writable)
> {
> permissions |= PAG_WRITE; // allow writing
> }
> if (executable)
> {
> permissions |= PAG_EXECUTE; // content may be executed
> }
> return permissions;
> }
>
> And finally
>
> void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable)
> {
> void* result = NULL;
> if (DosAllocMem(&result, bytes, OBJ_ANY | protection(writable, executable)) &&
> DosAllocMem(&result, bytes, protection(writable, executable)))
> {
> CRASH();
> }
> return result;
> }
>
>
>> At that I don't even know what the ? operator does. Any advice?
>
> ? operator is a ternary operator which means simply
>
> value = condition ? value_if_true : value_if_false;
>
> It is a shorter variant of
>
> if (condition)
> {
> value = value_if_true;
> }
> else
> {
> value = value_if_false;
> }
>
> Because of the structure of the operator you can only have single
> operation statements for true and false case.
>
> Hope it helps.

Back to comp.os.os2.programmer.porting | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

VirtualAlloc to DosAllocMem Dave Yeo <dave.r.yeo@gmail.com> - 2011-07-07 19:59 -0700
  Re: VirtualAlloc to DosAllocMem Heiko Nitzsche <hn-expires-27nov11@arcor.de> - 2011-07-08 22:03 +0200
    Re: VirtualAlloc to DosAllocMem Heiko Nitzsche <hn-expires-27nov11@arcor.de> - 2011-07-08 22:14 +0200
      Re: VirtualAlloc to DosAllocMem Dave Yeo <dave.r.yeo@gmail.com> - 2011-07-08 19:39 -0700
        Re: VirtualAlloc to DosAllocMem Dave Yeo <dave.r.yeo@gmail.com> - 2011-07-08 21:57 -0700
    Re: VirtualAlloc to DosAllocMem Paul Ratcliffe <abuse@orac12.clara34.co56.uk78> - 2011-07-08 23:02 +0000
      Re: VirtualAlloc to DosAllocMem "Lars Erdmann" <lars.erdmann@arcor.de> - 2011-07-09 03:46 +0200
        Re: VirtualAlloc to DosAllocMem Paul Ratcliffe <abuse@orac12.clara34.co56.uk78> - 2011-07-09 11:32 +0000
          Re: VirtualAlloc to DosAllocMem Paul Smedley <paulDESPAM@DESPAMMsmedley.id.au> - 2011-07-10 11:39 +0930

csiph-web