]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/misc/tegra-profiler/backtrace.h
5ee544cdd49671a21c5f45f7252c4bca9f5be791
[sojka/nv-tegra/linux-3.10.git] / drivers / misc / tegra-profiler / backtrace.h
1 /*
2  * drivers/misc/tegra-profiler/backtrace.h
3  *
4  * Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  */
16
17 #ifndef __QUADD_BACKTRACE_H
18 #define __QUADD_BACKTRACE_H
19
20 #include <linux/mm.h>
21 #include <linux/bitops.h>
22
23 #define QUADD_MAX_STACK_DEPTH           64
24
25 #define QUADD_UNW_TYPES_SIZE \
26         DIV_ROUND_UP(QUADD_MAX_STACK_DEPTH * 4, sizeof(u32) * BITS_PER_BYTE)
27
28 struct quadd_hrt_ctx;
29
30 struct quadd_callchain {
31         int nr;
32
33         union {
34                 u32 ip_32[QUADD_MAX_STACK_DEPTH];
35                 u64 ip_64[QUADD_MAX_STACK_DEPTH];
36         };
37
38         u32 types[QUADD_UNW_TYPES_SIZE];
39
40         int cs_64;
41
42         unsigned int unw_method;
43         unsigned int unw_rc;
44
45         unsigned long curr_sp;
46         unsigned long curr_fp;
47         unsigned long curr_fp_thumb;
48         unsigned long curr_pc;
49
50         struct quadd_hrt_ctx *hrt;
51 };
52
53 struct quadd_ctx;
54 struct pt_regs;
55
56 unsigned int
57 quadd_get_user_callchain(struct pt_regs *regs,
58                          struct quadd_callchain *cc_data,
59                          struct quadd_ctx *ctx,
60                          struct task_struct *task);
61
62 int
63 quadd_callchain_store(struct quadd_callchain *cc,
64                       unsigned long ip, unsigned int type);
65
66 unsigned long
67 quadd_user_stack_pointer(struct pt_regs *regs);
68
69 unsigned long
70 quadd_get_user_frame_pointer(struct pt_regs *regs);
71
72 unsigned long
73 quadd_user_link_register(struct pt_regs *regs);
74
75 static inline int
76 is_vma_addr(unsigned long addr, struct vm_area_struct *vma,
77             unsigned long nbytes)
78 {
79         return  vma &&
80                 addr >= vma->vm_start &&
81                 addr < vma->vm_end - nbytes;
82 }
83
84 static inline int
85 validate_pc_addr(unsigned long addr, unsigned long nbytes)
86 {
87         return addr && addr < TASK_SIZE - nbytes;
88 }
89
90 static inline int
91 validate_stack_addr(unsigned long addr,
92                     struct vm_area_struct *vma,
93                     unsigned long nbytes)
94 {
95         if (addr & 0x03)
96                 return 0;
97
98         return is_vma_addr(addr, vma, nbytes);
99 }
100
101 #endif  /* __QUADD_BACKTRACE_H */