~ubuntu-branches/ubuntu/precise/eglibc/precise

« back to all changes in this revision

Viewing changes to debian/patches/any/local-nscd-NO_MAPPING.diff

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2011-10-04 17:48:26 UTC
  • mfrom: (216.1.23 oneiric)
  • Revision ID: package-import@ubuntu.com-20111004174826-2cyb9ewn3ucymlsx
Tags: 2.13-20ubuntu5
libc6-dev: Don't break the current {gnat,gcj}-4.4-base versons. LP: #853688.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Description: Fix thread locking for __nscd_get_mapping
2
 
 This patch should solve occasional chromium-browser crashes,
3
 
 and other possibly-related (ktorrent?) crashes from thread
4
 
 corruption in __nscd_get_mapping.
5
 
Author: Jeff Law <law@redhat.com>
6
 
Bug: http://sourceware.org/bugzilla/show_bug.cgi?id=13594
7
 
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/chromium-browser/+bug/929219
8
 
 
9
 
diff -rup c/nscd/nscd_gethst_r.c d/nscd/nscd_gethst_r.c
10
 
--- c/nscd/nscd_gethst_r.c      2012-01-01 05:16:32.000000000 -0700
11
 
+++ d/nscd/nscd_gethst_r.c      2012-03-28 10:45:51.546600822 -0600
12
 
@@ -101,9 +101,27 @@ libc_freeres_fn (hst_map_free)
13
 
 uint32_t
14
 
 __nscd_get_nl_timestamp (void)
15
 
 {
16
 
+  uint32_t retval;
17
 
   if (__nss_not_use_nscd_hosts != 0)
18
 
     return 0;
19
 
 
20
 
+  int cnt = 0;
21
 
+  /* __nscd_get_mapping can change hst_map_handle.mapped to NO_MAPPING.
22
 
+   However, __nscd_get_mapping assumes the prior value was not NO_MAPPING.
23
 
+   Thus we have to acquire the lock to prevent this thread from changing
24
 
+   hst_map_handle.mapped to NO_MAPPING while another thread is inside
25
 
+    __nscd_get_mapping.  */
26
 
+  while (__builtin_expect
27
 
+        (atomic_compare_and_exchange_val_acq (&__hst_map_handle.lock,
28
 
+                                              1, 0) != 0, 0))
29
 
+    {
30
 
+      // XXX Best number of rounds?
31
 
+      if (__builtin_expect (++cnt > 5, 0))
32
 
+       return 0;
33
 
+
34
 
+      atomic_delay ();
35
 
+    }
36
 
+
37
 
   struct mapped_database *map = __hst_map_handle.mapped;
38
 
 
39
 
   if (map == NULL
40
 
@@ -113,9 +131,14 @@ __nscd_get_nl_timestamp (void)
41
 
     map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped);
42
 
 
43
 
   if (map == NO_MAPPING)
44
 
-    return 0;
45
 
+    retval =  0;
46
 
+  else
47
 
+    retval =  map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
48
 
+
49
 
+  /* Release the lock.  */
50
 
+  __hst_map_handle.lock = 0;
51
 
 
52
 
-  return map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
53
 
+  return retval;
54
 
 }
55
 
 
56