]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - kernel/extable.c
ring-buffer: Check if ring buffer iterator has stale data
[linux-2.6.git] / kernel / extable.c
index 7fe2628553172eadc0d49a3cbaf9d779b80b5a7c..7f8f263f85249a15ca8492fa5056c868262aa0f1 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
+#include <linux/ftrace.h>
+#include <linux/memory.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/init.h>
-#include <asm/uaccess.h>
+
 #include <asm/sections.h>
+#include <asm/uaccess.h>
+
+/*
+ * mutex protecting text section modification (dynamic code patching).
+ * some users need to sleep (allocating memory...) while they hold this lock.
+ *
+ * NOT exported to modules - patching kernel text is a really delicate matter.
+ */
+DEFINE_MUTEX(text_mutex);
 
 extern struct exception_table_entry __start___ex_table[];
 extern struct exception_table_entry __stop___ex_table[];
@@ -40,14 +52,22 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)
        return e;
 }
 
+static inline int init_kernel_text(unsigned long addr)
+{
+       if (addr >= (unsigned long)_sinittext &&
+           addr <= (unsigned long)_einittext)
+               return 1;
+       return 0;
+}
+
 int core_kernel_text(unsigned long addr)
 {
        if (addr >= (unsigned long)_stext &&
            addr <= (unsigned long)_etext)
                return 1;
 
-       if (addr >= (unsigned long)_sinittext &&
-           addr <= (unsigned long)_einittext)
+       if (system_state == SYSTEM_BOOTING &&
+           init_kernel_text(addr))
                return 1;
        return 0;
 }
@@ -56,12 +76,40 @@ int __kernel_text_address(unsigned long addr)
 {
        if (core_kernel_text(addr))
                return 1;
-       return __module_text_address(addr) != NULL;
+       if (is_module_text_address(addr))
+               return 1;
+       /*
+        * There might be init symbols in saved stacktraces.
+        * Give those symbols a chance to be printed in
+        * backtraces (such as lockdep traces).
+        *
+        * Since we are after the module-symbols check, there's
+        * no danger of address overlap:
+        */
+       if (init_kernel_text(addr))
+               return 1;
+       return 0;
 }
 
 int kernel_text_address(unsigned long addr)
 {
        if (core_kernel_text(addr))
                return 1;
-       return module_text_address(addr) != NULL;
+       return is_module_text_address(addr);
+}
+
+/*
+ * On some architectures (PPC64, IA64) function pointers
+ * are actually only tokens to some data that then holds the
+ * real function address. As a result, to find if a function
+ * pointer is part of the kernel text, we need to do some
+ * special dereferencing first.
+ */
+int func_ptr_is_kernel_text(void *ptr)
+{
+       unsigned long addr;
+       addr = (unsigned long) dereference_function_descriptor(ptr);
+       if (core_kernel_text(addr))
+               return 1;
+       return is_module_text_address(addr);
 }