Both of these questions are pretty easily answered from the original
code you pasted.  You can see that OS::Allocate takes a boolean
parameter, whether the memory should be executable or not.  This is
because code objects live in code space which is executable.  Data
objects live in other spaces which are not executable.

As for the second part of your question, you can easily see the ASSERT
statement verifying the alignment of the returned address.  You can
see OS::AllocateAlignment for the alignment requirements on a
per-platform basis.

On Tue, Jun 23, 2009 at 4:11 PM, AOF<[email protected]> wrote:
>
> Thank you.
> So according to your answer.
> There are two prerequisites relate to memory before running v8.
> 1. the memory should be executable

If OS::Allocate is called with "executable" as true, then yes.

> 2. the memory should have page boundaries of 4k.



> Is that so ?
>
>
>
>
>
>
> On Jun 23, 7:11 pm, Dean McNamee <[email protected]> wrote:
>> You need to be able to control the permission bits on the pages, for
>> example to mark them executable.  This is not something you could do
>> allocating off the heap.  Also, VirtualAlloc allocates full pages on
>> page boundaries (4k).
>>
>> Why would you want to change it?
>>
>>
>>
>> On Tue, Jun 23, 2009 at 12:55 PM, AOF<[email protected]> wrote:
>>
>> > Hello.
>> > I have a question.
>> > Can i replace the function "VirtualAlloc" to the function
>> > "HeapAlloc"in the following code from v8?
>> > If not, why?
>>
>> > void* OS::Allocate(const size_t requested,
>> >                   size_t* allocated,
>> >                   bool executable) {
>> >  // VirtualAlloc rounds allocated size to page size automatically.
>> >  size_t msize = RoundUp(requested, GetPageSize());
>>
>> >  // Windows XP SP2 allows Data Excution Prevention (DEP).
>> >  int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
>> >  LPVOID mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE,
>> > prot);
>> >  if (mbase == NULL) {
>> >    LOG(StringEvent("OS::Allocate", "VirtualAlloc failed"));
>> >    return NULL;
>> >  }
>>
>> >  ASSERT(IsAligned(reinterpret_cast<size_t>(mbase),
>> > OS::AllocateAlignment()));
>>
>> >  *allocated = msize;
>> >  UpdateAllocatedSpaceLimits(mbase, msize);
>> >  return mbase;
>> > }
> >
>

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to