[m-rev.] diff: page align MR_zone_hardmax on sparc solaris 10

Peter Ross pro at missioncriticalit.com
Sun Jul 29 21:44:31 AEST 2012


Hi,

Better suggestions for how to fix this problem gladly taken.

The issue is that we ask for a chunk of memory that is a multiple of the
page size, but the pointer to this chunk of memory isn't always page aligned,
thus when we attempt to set the hardmax zone at the end we don't get a
page aligned pointer.



===================================================================


Estimated hours taken: 4
Branches: main, 11.07

runtime/mercury_memory_zones.c:
	It's possible for MR_zone_name to be NULL, in that case set the
	MR_zone_name to be unknown.

	Under Sparc Solaris 10 the MR_zone_hardmax is not always page aligned,
	causing mprotect to fail.  Add an extra term to ensure MR_zone_hardmax
	is page aligned.


Index: runtime/mercury_memory_zones.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory_zones.c,v
retrieving revision 1.47
diff -u -r1.47 mercury_memory_zones.c
--- runtime/mercury_memory_zones.c	22 May 2012 06:58:35 -0000	1.47
+++ runtime/mercury_memory_zones.c	29 Jul 2012 11:31:09 -0000
@@ -810,6 +810,9 @@
         REDZONE_PROT);
     if (res < 0) {
         char buf[2560];
+        if (zone->MR_zone_name == NULL) {
+            zone->MR_zone_name = "unknown";
+        }
         sprintf(buf, "unable to set %s#%" MR_INTEGER_LENGTH_MODIFIER
                 "d redzone\nbase=%p, redzone=%p",
             zone->MR_zone_name, zone->MR_zone_id,
@@ -822,11 +825,16 @@
     ** setup the hardzone
     */
 #if defined(MR_PROTECTPAGE)
-    zone->MR_zone_hardmax = (MR_Word *)((MR_Unsigned)zone->MR_zone_top - MR_page_size);
+    /* The % MR_page_size is to ensure page alignment */
+    zone->MR_zone_hardmax = (MR_Word *)((MR_Unsigned)zone->MR_zone_top -
+            MR_page_size - ((MR_Unsigned) zone->MR_zone_top % MR_page_size));
     res = MR_protect_pages((char *) zone->MR_zone_hardmax, MR_page_size,
         REDZONE_PROT);
     if (res < 0) {
         char buf[2560];
+        if (zone->MR_zone_name == NULL) {
+            zone->MR_zone_name = "unknown";
+        }
         sprintf(buf, "unable to set %s#%" MR_INTEGER_LENGTH_MODIFIER
                 "d hardmax\nbase=%p, hardmax=%p top=%p",
             zone->MR_zone_name, zone->MR_zone_id,

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list