[haiku-commits] Re: BRANCH pdziepak-github.aslr - src/system/kernel/vm headers/os/kernel

  • From: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 26 Feb 2013 15:38:08 +0100

Am 25/02/2013 23:00, schrieb pdziepak-github.aslr:
+/* http://graphics.stanford.edu/~seander/bithacks.html */
+static int
+log2(uint32_t v)

The scheduler is already using its own random function; maybe it makes sense to put that all into some utility code. Besides that, we keep the methods in declaration order, and keep class methods together; IOW that helper functions should go to some place before the class methods.

+#ifdef B_HAIKU_64_BIT
+const addr_t VMUserAddressSpace::kMaxRandomize                 =  
0x8000000000ul;
+const addr_t VMUserAddressSpace::kMaxInitialRandomize  = 0x20000000000ul;
+#else
+const addr_t VMUserAddressSpace::kMaxRandomize                 =  0x800000ul;
+const addr_t VMUserAddressSpace::kMaxInitialRandomize  = 0x2000000ul;
+#endif

Constants and definitions go to the top of the file, not intermixed with functions.

+addr_t
+VMUserAddressSpace::_RandomizeAddress(addr_t start, addr_t end, bool initial)
+{
+       const int rand_shift = log2(RAND_MAX) + 1;

rand_shift -> randShift. Constants usually get a 'k' prefix.

+       int shift = 0;
+
+       if (start == end)
+               return start;

That check should come first; variables should be declared immediately before they are used.

+       random %= range;
+       random &= ~0xffful;

That looks like you wanted to write ~addr_t(B_PAGE_SIZE - 1) instead.

+       if (addressSpec == B_RAND_BASE_ADDRESS) {
+               originalStart = start;
+               start = _RandomizeAddress(start, end - size, true);
+       }
+
        start = ROUNDUP(start, alignment);

I don't see where you change the size requirements of areas with a randomized start pointer - it might need a page more.

Bye,
   Axel.


Other related posts: