Jeroen Demeyer on Tue, 18 Oct 2016 10:04:12 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Use PROT_NONE for unused virtual stack memory


On 2016-10-12 23:11, Bill Allombert wrote:
  static void *
  pari_mainstack_malloc(size_t size)
  {
    void *b = mmap(NULL, size, PROT_READ|PROT_WRITE,
-                             MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,-1,0);
+                             MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
    return (b == MAP_FAILED) ? NULL: b;
  }

Is it correct ? It seems to me that we want to use PROT_NONE here as
well, as you do in config/has_mmap.c.

Well, in some sense both PROT_READ|PROT_WRITE as well as PROT_NONE are correct. It just depends what you want.

I chose PROT_READ|PROT_WRITE here to check that it is possible to allocate memory up to size parisizemax. With vm.overcommit=2, this limits parisizemax to the amount of memory that is available at the time of setting parisizemax. I think it's better to fail the allocation early (when setting parisizemax) instead of when actually using the memory.