aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2014-04-14 16:16:38 -0700
committerChristopher Ferris <cferris@google.com>2014-04-14 18:45:33 -0700
commitf622936d6c5239b3d5ccafdf38189cec8bca55c0 (patch)
treef10d94a89fdcb88c7e72e455913d2fe4939a2d1b
parentd1c383c5bb03420decf5cf789cf14ab144b0720d (diff)
downloadlibunwind-f622936d6c5239b3d5ccafdf38189cec8bca55c0.tar.gz
Make sure that all memory accesses are guarded.
This doesn't protect the fpreg reads completely. It's still possible to have a bad address that has the first part in readable memory and the second part in unreadable memory. Since none of the code android uses uses the fpreg data, this should be okay. Bug: 13946101 Change-Id: I9187b16d0427cbc8af6751cf0b8476ea2d1bfc38
-rw-r--r--include/tdep-aarch64/libunwind_i.h28
-rw-r--r--include/tdep-arm/libunwind_i.h28
-rw-r--r--include/tdep-hppa/libunwind_i.h28
-rw-r--r--include/tdep-mips/libunwind_i.h32
-rw-r--r--include/tdep-sh/libunwind_i.h28
5 files changed, 104 insertions, 40 deletions
diff --git a/include/tdep-aarch64/libunwind_i.h b/include/tdep-aarch64/libunwind_i.h
index 92541596..36250e3f 100644
--- a/include/tdep-aarch64/libunwind_i.h
+++ b/include/tdep-aarch64/libunwind_i.h
@@ -109,37 +109,49 @@ struct cursor
static inline int
dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_readable ((unw_word_t) (uintptr_t) addr))
return -1;
- *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
+
+ *val = *addr;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_writable ((unw_word_t) (uintptr_t) addr))
return -1;
- *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
+
+ *addr = val;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
{
+/* ANDROID support update. */
if (!DWARF_GET_LOC (loc))
return -1;
- *val = *(unw_word_t *) DWARF_GET_LOC (loc);
- return 0;
+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
+ 0, c->as_arg);
+/* End of ANDROID update. */
}
static inline int
dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
{
+/* ANDROID support update. */
if (!DWARF_GET_LOC (loc))
return -1;
- *(unw_word_t *) DWARF_GET_LOC (loc) = val;
- return 0;
+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
+ 1, c->as_arg);
+/* End of ANDROID update. */
}
#else /* !UNW_LOCAL_ONLY */
diff --git a/include/tdep-arm/libunwind_i.h b/include/tdep-arm/libunwind_i.h
index 4577fb8c..1fed4bc5 100644
--- a/include/tdep-arm/libunwind_i.h
+++ b/include/tdep-arm/libunwind_i.h
@@ -97,37 +97,49 @@ struct cursor
static inline int
dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_readable ((unw_word_t) (uintptr_t) addr))
return -1;
- *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
+
+ *val = *addr;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_writable ((unw_word_t) (uintptr_t) addr))
return -1;
- *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
+
+ *addr = val;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
{
+/* ANDROID support update. */
if (!DWARF_GET_LOC (loc))
return -1;
- *val = *(unw_word_t *) DWARF_GET_LOC (loc);
- return 0;
+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
+ 0, c->as_arg);
+/* End of ANDROID update. */
}
static inline int
dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
{
+/* ANDROID support update. */
if (!DWARF_GET_LOC (loc))
return -1;
- *(unw_word_t *) DWARF_GET_LOC (loc) = val;
- return 0;
+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
+ 1, c->as_arg);
+/* End of ANDROID update. */
}
#else /* !UNW_LOCAL_ONLY */
diff --git a/include/tdep-hppa/libunwind_i.h b/include/tdep-hppa/libunwind_i.h
index 1a595ad2..e8bb4f2b 100644
--- a/include/tdep-hppa/libunwind_i.h
+++ b/include/tdep-hppa/libunwind_i.h
@@ -94,37 +94,49 @@ struct cursor
static inline int
dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_readable ((unw_word_t) (uintptr_t) addr))
return -1;
- *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
+
+ *val = *addr;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_writable ((unw_word_t) (uintptr_t) addr))
return -1;
- *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
+
+ *addr = val;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
{
+/* ANDROID support update. */
if (!DWARF_GET_LOC (loc))
return -1;
- *val = *(unw_word_t *) DWARF_GET_LOC (loc);
- return 0;
+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
+ 0, c->as_arg);
+/* End of ANDROID update. */
}
static inline int
dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
{
+/* ANDROID support update. */
if (!DWARF_GET_LOC (loc))
return -1;
- *(unw_word_t *) DWARF_GET_LOC (loc) = val;
- return 0;
+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
+ 1, c->as_arg);
+/* End of ANDROID update. */
}
#else /* !UNW_LOCAL_ONLY */
diff --git a/include/tdep-mips/libunwind_i.h b/include/tdep-mips/libunwind_i.h
index 9dae5557..0c532260 100644
--- a/include/tdep-mips/libunwind_i.h
+++ b/include/tdep-mips/libunwind_i.h
@@ -104,37 +104,53 @@ typedef long mips_reg_t;
static inline int
dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_readable ((unw_word_t) (uintptr_t) addr))
return -1;
- *val = *(unw_fpreg_t *) (intptr_t) DWARF_GET_LOC (loc);
+
+ *val = *addr;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_writable ((unw_word_t) (uintptr_t) addr))
return -1;
- *(unw_fpreg_t *) (intptr_t) DWARF_GET_LOC (loc) = val;
+
+ *addr = val;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ mips_reg_t *addr = (mips_reg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_readable ((unw_word_t) (uintptr_t) addr))
return -1;
- *val = *(mips_reg_t *) (intptr_t) DWARF_GET_LOC (loc);
+
+ *val = *addr;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ mips_reg_t *addr = (mips_reg_t *) (uintptr_t) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_writable ((unw_word_t) (uintptr_t) addr))
return -1;
- *(mips_reg_t *) (intptr_t) DWARF_GET_LOC (loc) = val;
+
+ *addr = val;
return 0;
+/* End of ANDROID update. */
}
#else /* !UNW_LOCAL_ONLY */
diff --git a/include/tdep-sh/libunwind_i.h b/include/tdep-sh/libunwind_i.h
index dd361bfd..29b162b4 100644
--- a/include/tdep-sh/libunwind_i.h
+++ b/include/tdep-sh/libunwind_i.h
@@ -95,37 +95,49 @@ struct cursor
static inline int
dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_readable ((unw_word_t) addr))
return -1;
- *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
+
+ *val = *addr;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
{
- if (!DWARF_GET_LOC (loc))
+/* ANDROID support update. */
+ unw_fpreg_t *addr = (unw_fpreg_t *) DWARF_GET_LOC (loc);
+ if (!addr || !map_local_is_writable ((unw_word_t) addr))
return -1;
- *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
+
+ *addr = val;
return 0;
+/* End of ANDROID update. */
}
static inline int
dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
{
+/* ANDROID support update. */
if (!DWARF_GET_LOC (loc))
return -1;
- *val = *(unw_word_t *) DWARF_GET_LOC (loc);
- return 0;
+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
+ 0, c->as_arg);
+/* End of ANDROID update. */
}
static inline int
dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
{
+/* ANDROID support update. */
if (!DWARF_GET_LOC (loc))
return -1;
- *(unw_word_t *) DWARF_GET_LOC (loc) = val;
- return 0;
+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
+ 1, c->as_arg);
+/* End of ANDROID update. */
}
#else /* !UNW_LOCAL_ONLY */