----- Original Message -----
From: "Vladimir Lipsky" <[EMAIL PROTECTED]>
To: "perl6-internals" <[EMAIL PROTECTED]>
Sent: Wednesday, December 31, 2003 2:42 AM
Subject: Re: [perl #24769] [PATCH] mem_sys_allocate_executable - initial
draft


> From: "Jonathan Worthington" <[EMAIL PROTECTED]>
>
> > Here is my attempt at a patch for executable memory allocation, which
> makes
>
> +void *
> +mem_alloc_executable(size_t size)
> +{
> + void *ptr = VirtualAlloc(NULL, size, MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
>
> ^^^^^^^^^^^^^^^
>                                                  MEM_RESERVE | MEM_COMMIT
>
> or more preferrable  MEM_RESERVE | MEM_TOP_DOWN | MEM_COMMIT
>
Agree.

> + if (memInfo.RegionSize <= size)
> + {
> +  CopyMemory(newBlock, memblock, memInfo.RegionSize);
> + }
> + else
> + {
> +  CopyMemory(newBlock, memblock, size);
> + }
>
> memInfo.RegionSize is always either greater or equal size. So just
>
> CopyMemory(newBlock, memblock, size);
>
> would be enough
>
I'd disagree here.  realloc allows somebody to resize a block of memory.
Here I am checking the lengths of the old block and the new block.  If they
are asking to enlarge their block of memory, then if we do CopyMemory with
the size of the new block we will be reading into memory that wasn't a part
of the old block, which is a Bad Thing.

> +void
> +mem_free_executable(void *addr)
> +{
> + /* We need to decommit, then release the pages. */
> + VirtualFree(addr, 1, MEM_DECOMMIT); <<<<<<<<<<<<< No need
> + VirtualFree(addr, 0, MEM_RELEASE);
> +}
>
> There is no need to decommit pages if next you release the region.
>
OK.

Provided Leo likes the general gist of my patch, I'll update it with your
suggested changes.  Let me know if you still disagree on the second point.

Thanks, and happy new year to you and everyone for tomorrow,

Jonathan


Reply via email to