This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
mlock in libc
- From: James A Morrison <ja2morri at student dot math dot uwaterloo dot ca>
- To: libc-alpha at sources dot redhat dot com
- Date: Sun, 3 Nov 2002 11:29:33 -0500 (EST)
- Subject: mlock in libc
Hi,
I was looking at why gpg fails to build on the Hurd. I discovered mlock
is what is broken. The problem arises when the actual protection on the
memory is less relaxed than the protection passed to vm_wire. What does work
is using VM_PROT_DEFAULT, because memory allocated with malloc seems to use
VM_PROT_DEFAULT. However, I think the best solution is to call vm_region
and actually get the proper permissions for the pages.
Here are a couple of patches that checks vm_region and acts more like
wire_segment_internal in [hurd]/libshouldbeinlibc. The first patch relaxes
the permissions on the memory region to max_protection so that the wired
region can have its protections relaxed to that level at any time. The
second does not because perhaps something could write to a read-only part
of memory between the calls to vm_protect.
2002-11-03 James Morrison <ja2morri@uwaterloo.ca>
* sysdeps/mach/hurd/mlock.c (mlock): Get the actual protections on a
region of memory before wiring it.
Index: mlock.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/mach/hurd/mlock.c,v
retrieving revision 1.2
diff -u -r1.2 mlock.c
--- mlock.c 6 Jul 2001 04:55:57 -0000 1.2
+++ mlock.c 3 Nov 2002 16:18:09 -0000
@@ -39,8 +39,19 @@
page = trunc_page ((vm_address_t) addr);
len = round_page ((vm_address_t) addr + len) - page;
- err = __vm_wire (hostpriv, __mach_task_self (), page, len,
- VM_PROT_ALL); /* XXX ? */
+ {
+ vm_prot_t cur, max;
+ vm_inherit_t inher;
+ boolean_t shared;
+ mach_port_t obj;
+ vm_offset_t offs;
+
+ __vm_region (mach_task_self (), &page, &len, &cur, &max, &inher, &shared,
+ &obj, &offs);
+ __vm_protect (mach_task_self (), page, len, 0, max);
+ err = __vm_wire (hostpriv, __mach_task_self (), page, len, max);
+ __vm_protect (mach_task_self (), page, len, 0, cur);
+ }
__mach_port_deallocate (__mach_task_self (), hostpriv);
return err ? __hurd_fail (err) : 0;
Index: mlock.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/mach/hurd/mlock.c,v
retrieving revision 1.2
diff -u -r1.2 mlock.c
--- mlock.c 6 Jul 2001 04:55:57 -0000 1.2
+++ mlock.c 3 Nov 2002 16:25:44 -0000
@@ -39,8 +39,18 @@
page = trunc_page ((vm_address_t) addr);
len = round_page ((vm_address_t) addr + len) - page;
- err = __vm_wire (hostpriv, __mach_task_self (), page, len,
- VM_PROT_ALL); /* XXX ? */
+ {
+ vm_prot_t cur, max;
+ vm_inherit_t inher;
+ boolean_t shared;
+ mach_port_t obj;
+ vm_offset_t offs;
+
+ __vm_region (mach_task_self (), &page, &len, &cur, &max, &inher, &shared,
+ &obj, &offs);
+ err = __vm_wire (hostpriv, __mach_task_self (), page, len, max);
+ __mach_port_deallocate (mach_task_self (), obj);
+ }
__mach_port_deallocate (__mach_task_self (), hostpriv);
return err ? __hurd_fail (err) : 0;