SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /hwcore/cpu_context.h (Article 6.5) and /hwcore/cpu_context.h (Article 9.5)


001 /* Copyright (C) 2005  David Decotigny            001 /* Copyright (C) 2005  David Decotigny
002    Copyright (C) 2000-2004, The KOS team          002    Copyright (C) 2000-2004, The KOS team
003                                                   003 
004    This program is free software; you can redi    004    This program is free software; you can redistribute it and/or
005    modify it under the terms of the GNU Genera    005    modify it under the terms of the GNU General Public License
006    as published by the Free Software Foundatio    006    as published by the Free Software Foundation; either version 2
007    of the License, or (at your option) any lat    007    of the License, or (at your option) any later version.
008                                                   008    
009    This program is distributed in the hope tha    009    This program is distributed in the hope that it will be useful,
010    but WITHOUT ANY WARRANTY; without even the     010    but WITHOUT ANY WARRANTY; without even the implied warranty of
011    MERCHANTABILITY or FITNESS FOR A PARTICULAR    011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012    GNU General Public License for more details    012    GNU General Public License for more details.
013                                                   013    
014    You should have received a copy of the GNU     014    You should have received a copy of the GNU General Public License
015    along with this program; if not, write to t    015    along with this program; if not, write to the Free Software
016    Foundation, Inc., 59 Temple Place - Suite 3    016    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
017    USA.                                           017    USA. 
018 */                                                018 */
019 #ifndef _SOS_CPUCTXT_H_                           019 #ifndef _SOS_CPUCTXT_H_
020 #define _SOS_CPUCTXT_H_                           020 #define _SOS_CPUCTXT_H_
021                                                   021 
022                                                   022 
023 /**                                               023 /**
024  * @file cpu_context.h                            024  * @file cpu_context.h
025  *                                                025  *
026  * Low level API to manage kernel and user thr    026  * Low level API to manage kernel and user thread CPU contexts. Should
027  * be some kind of architecture-independent.      027  * be some kind of architecture-independent.
028  */                                               028  */
029                                                   029 
030 #include <sos/types.h>                            030 #include <sos/types.h>
031 #include <sos/errno.h>                            031 #include <sos/errno.h>
032                                                   032 
033                                                   033 
034 /**                                               034 /**
                                                   >> 035  * Prepare the system to deal with multiple CPU execution contexts
                                                   >> 036  */
                                                   >> 037 sos_ret_t sos_cpu_context_subsystem_setup(void);
                                                   >> 038 
                                                   >> 039 
                                                   >> 040 /**
035  * Opaque structure storing the CPU context of    041  * Opaque structure storing the CPU context of an inactive kernel or
036  * user thread, as saved by the low level prim    042  * user thread, as saved by the low level primitives below or by the
037  * interrupt/exception handlers.                  043  * interrupt/exception handlers.
038  *                                                044  *
039  * @note This is an (architecture-independent)    045  * @note This is an (architecture-independent) forward declaration:
040  * see cpu_context.c and the *.S files for its    046  * see cpu_context.c and the *.S files for its
041  * (architecture-dependent) definition.           047  * (architecture-dependent) definition.
042  */                                               048  */
043 struct sos_cpu_state;                             049 struct sos_cpu_state;
044                                                   050 
045                                                   051 
046 /**                                               052 /**
047  * The type of the functions passed as argumen    053  * The type of the functions passed as arguments to the Kernel thread
048  * related functions.                             054  * related functions.
049  */                                               055  */
050 typedef void (sos_cpu_kstate_function_arg1_t(s    056 typedef void (sos_cpu_kstate_function_arg1_t(sos_ui32_t arg1));
051                                                   057 
052                                                   058 
053 /**                                               059 /**
054  * Function to create an initial context for a    060  * Function to create an initial context for a kernel thread starting
055  * its execution at function start_func with t    061  * its execution at function start_func with the argument initial_arg,
056  * and having the stack defined by stack_botto    062  * and having the stack defined by stack_bottom/stack_size. When the
057  * start_func function returns, the function e    063  * start_func function returns, the function exit_func is called with
058  * argument exit_arg.                             064  * argument exit_arg.
059  *                                                065  *
060  * @param kctxt The kernel thread CPU context     066  * @param kctxt The kernel thread CPU context to initialize. The
061  * address of the newly-initialized struct sos    067  * address of the newly-initialized struct sos_cpu_state will be
062  * stored in this variable. The contents of th    068  * stored in this variable. The contents of this struct sos_cpu_state
063  * are actually located /inside/ the stack.       069  * are actually located /inside/ the stack.
064  *                                                070  *
065  * @param start_func The address of the first     071  * @param start_func The address of the first instruction that will be
066  * executed when this context will be first tr    072  * executed when this context will be first transferred on
067  * CPU. Practically speaking, this is the addr    073  * CPU. Practically speaking, this is the address of a function that
068  * is assumed to take 1 argument.                 074  * is assumed to take 1 argument.
069  *                                                075  *
070  * @param start_arg The value that will be pas    076  * @param start_arg The value that will be passed as the argument to
071  * start_func when the thread starts. The stac    077  * start_func when the thread starts. The stack will be setup
072  * accordingly to simulate a real call to the     078  * accordingly to simulate a real call to the function and really
073  * passing this arguement.                        079  * passing this arguement.
074  *                                                080  *
075  * @param stack_bottom The lowest address of t    081  * @param stack_bottom The lowest address of the stack.
076  *                                                082  *
077  * @param stack_size The size of the stack.       083  * @param stack_size The size of the stack.
078  *                                                084  *
079  * @param exit_func The address of the instruc    085  * @param exit_func The address of the instruction executed after the
080  * function start_func has returned. This func    086  * function start_func has returned. This function takes 1 parameter
081  * as argument: exit_arg.                         087  * as argument: exit_arg.
082  *                                                088  *
083  * @param exit_arg The argument passed to the     089  * @param exit_arg The argument passed to the function exit_func.
084  *                                                090  *
085  * @note the newly created context is INTERRUP    091  * @note the newly created context is INTERRUPTIBLE by default !
086  */                                               092  */
087 sos_ret_t sos_cpu_kstate_init(struct sos_cpu_s    093 sos_ret_t sos_cpu_kstate_init(struct sos_cpu_state **kctxt,
088                               sos_cpu_kstate_f    094                               sos_cpu_kstate_function_arg1_t *start_func,
089                               sos_ui32_t  star    095                               sos_ui32_t  start_arg,
090                               sos_vaddr_t stac    096                               sos_vaddr_t stack_bottom,
091                               sos_size_t  stac    097                               sos_size_t  stack_size,
092                               sos_cpu_kstate_f    098                               sos_cpu_kstate_function_arg1_t *exit_func,
093                               sos_ui32_t  exit    099                               sos_ui32_t  exit_arg);
094                                                   100 
095                                                   101 
096 /**                                               102 /**
                                                   >> 103  * Function to create an initial context for a user thread starting
                                                   >> 104  * its execution at function user_start_PC with the user_start_arg
                                                   >> 105  * argument. The address of the user stack before any modification by
                                                   >> 106  * the ustate_init() function is given by user_start_SP. The user
                                                   >> 107  * thread starts in user space first and needs a kernel stack for
                                                   >> 108  * the syscalls and for handling interrupts: the address of this
                                                   >> 109  * kernel stack is given by the kernel_stack_* parameters.
                                                   >> 110  *
                                                   >> 111  * @param uctxt The user thread CPU context to initialize. The
                                                   >> 112  * address of the newly-initialized struct sos_cpu_state will be
                                                   >> 113  * stored in this variable. The contents of this struct sos_cpu_state
                                                   >> 114  * are actually located /inside/ the kernel stack of the thread.
                                                   >> 115  *
                                                   >> 116  * @param user_start_PC The address of the first instruction that will
                                                   >> 117  * be executed in user mode when this context will be first
                                                   >> 118  * transferred on CPU. Practically speaking, this is the address of a
                                                   >> 119  * function that is assumed to take 1 argument.
                                                   >> 120  *
                                                   >> 121  * @param user_start_SP The initial user stack address.
                                                   >> 122  *
                                                   >> 123  * @param user_start_argX The 2 parameters passed to the initial user
                                                   >> 124  * thread function (in registers).
                                                   >> 125  *
                                                   >> 126  * @param kernel_stack_bottom The lowest address of the kernel stack
                                                   >> 127  * used to switch to user mode and to handle interrupts/exceptions.
                                                   >> 128  *
                                                   >> 129  * @param kernel_stack_size The size of the kernel stack (@see
                                                   >> 130  * kernel_stack_bottom).
                                                   >> 131  *
                                                   >> 132  * @note the newly thread context is INTERRUPTIBLE !
                                                   >> 133  */
                                                   >> 134 sos_ret_t sos_cpu_ustate_init(struct sos_cpu_state **uctxt,
                                                   >> 135                               sos_uaddr_t  user_start_PC,
                                                   >> 136                               sos_ui32_t   user_start_arg1,
                                                   >> 137                               sos_ui32_t   user_start_arg2,
                                                   >> 138                               sos_uaddr_t  user_initial_SP,
                                                   >> 139                               sos_vaddr_t  kernel_stack_bottom,
                                                   >> 140                               sos_size_t   kernel_stack_size);
                                                   >> 141 
                                                   >> 142 
                                                   >> 143 /**
                                                   >> 144  * Function to create an initial context for a user thread, copy of an
                                                   >> 145  * existing user thread context. The user thread needs a kernel stack
                                                   >> 146  * for the syscalls and for handling interrupts: the address of this
                                                   >> 147  * kernel stack is given by the kernel_stack_* parameters.
                                                   >> 148  *
                                                   >> 149  * @param uctxt The user thread CPU context to initialize. The
                                                   >> 150  * address of the newly-initialized struct sos_cpu_state will be
                                                   >> 151  * stored in this variable. The contents of this struct sos_cpu_state
                                                   >> 152  * are actually located /inside/ the kernel stack of the thread.
                                                   >> 153  *
                                                   >> 154  * @param model_uctxt The user thread context that will be copied to
                                                   >> 155  * the new user thread context
                                                   >> 156  *
                                                   >> 157  * @param user_retval The parameter passed to the initial user
                                                   >> 158  * thread function.
                                                   >> 159  *
                                                   >> 160  * @param kernel_stack_bottom The lowest address of the kernel stack
                                                   >> 161  * used to switch to user mode and to handle interrupts/exceptions.
                                                   >> 162  *
                                                   >> 163  * @param kernel_stack_size The size of the kernel stack (@see
                                                   >> 164  * kernel_stack_bottom).
                                                   >> 165  *
                                                   >> 166  * @note the newly thread context is INTERRUPTIBLE !
                                                   >> 167  */
                                                   >> 168 sos_ret_t sos_cpu_ustate_duplicate(struct sos_cpu_state **uctxt,
                                                   >> 169                                    const struct sos_cpu_state *model_uctxt,
                                                   >> 170                                    sos_ui32_t   user_retval,
                                                   >> 171                                    sos_vaddr_t  kernel_stack_bottom,
                                                   >> 172                                    sos_size_t   kernel_stack_size);
                                                   >> 173 
                                                   >> 174 
                                                   >> 175 /**
097  * Function that performs an immediate context    176  * Function that performs an immediate context-switch from one
098  * kernel/user thread to another one. It store    177  * kernel/user thread to another one. It stores the current executing
099  * context in from_ctxt, and restores to_conte    178  * context in from_ctxt, and restores to_context on CPU.
100  *                                                179  *
101  * @param from_ctxt The address of the struct     180  * @param from_ctxt The address of the struct sos_cpu_state will be
102  * stored in this variable. Must NOT be NULL.     181  * stored in this variable. Must NOT be NULL.
103  *                                                182  *
104  * @param to_ctxt The CPU will resume its exec    183  * @param to_ctxt The CPU will resume its execution with the struct
105  * sos_cpu_state located at this address. Must    184  * sos_cpu_state located at this address. Must NOT be NULL.
106  */                                               185  */
107 void sos_cpu_context_switch(struct sos_cpu_sta    186 void sos_cpu_context_switch(struct sos_cpu_state **from_ctxt,
108                             struct sos_cpu_sta    187                             struct sos_cpu_state *to_ctxt);
109                                                   188 
110                                                   189 
111 /*                                                190 /*
112  * Switch to the new given context (of a kerne    191  * Switch to the new given context (of a kernel/user thread) without
113  * saving the old context (of another kernel/u    192  * saving the old context (of another kernel/user thread), and call
114  * the function reclaiming_func passing it the    193  * the function reclaiming_func passing it the recalining_arg
115  * argument. The reclaining function is called    194  * argument. The reclaining function is called from within the stack
116  * of the new context, so that it can (among o    195  * of the new context, so that it can (among other things) safely
117  * destroy the stack of the former context.       196  * destroy the stack of the former context.
118  *                                                197  *
119  * @param switch_to_ctxt The context that will    198  * @param switch_to_ctxt The context that will be restored on the CPU
120  *                                                199  *
121  * @param reclaiming_func The address of the f    200  * @param reclaiming_func The address of the function that will be
122  * called after having changed the stack, but     201  * called after having changed the stack, but before restoring the CPU
123  * context to switch_to_ctxt.                     202  * context to switch_to_ctxt.
124  */                                               203  */
125 void                                              204 void
126 sos_cpu_context_exit_to(struct sos_cpu_state *    205 sos_cpu_context_exit_to(struct sos_cpu_state *switch_to_ctxt,
127                         sos_cpu_kstate_functio    206                         sos_cpu_kstate_function_arg1_t *reclaiming_func,
128                         sos_ui32_t reclaiming_    207                         sos_ui32_t reclaiming_arg) __attribute__((noreturn));
129                                                   208 
130 /* ===========================================    209 /* =======================================================================
131  * Public Accessor functions                      210  * Public Accessor functions
132  */                                               211  */
133                                                   212 
134                                                   213 
135 /**                                               214 /**
                                                   >> 215  * Return whether the saved context was in kernel or user context
                                                   >> 216  *
                                                   >> 217  * @return TRUE when context was interrupted when in user mode, FALSE
                                                   >> 218  * when in kernel mode, < 0 on error.
                                                   >> 219  */
                                                   >> 220 sos_ret_t
                                                   >> 221 sos_cpu_context_is_in_user_mode(const struct sos_cpu_state *ctxt);
                                                   >> 222 
                                                   >> 223 
                                                   >> 224 /**
136  * Return Program Counter stored in the saved     225  * Return Program Counter stored in the saved kernel/user context
137  */                                               226  */
138 sos_vaddr_t sos_cpu_context_get_PC(const struc    227 sos_vaddr_t sos_cpu_context_get_PC(const struct sos_cpu_state *ctxt);
139                                                   228 
140                                                   229 
141 /**                                               230 /**
142  * Return Stack Pointer stored in the saved ke    231  * Return Stack Pointer stored in the saved kernel/user context
143  */                                               232  */
144 sos_vaddr_t sos_cpu_context_get_SP(const struc    233 sos_vaddr_t sos_cpu_context_get_SP(const struct sos_cpu_state *ctxt);
145                                                   234 
146                                                   235 
147 /**                                               236 /**
148  * Dump the contents of the CPU context (bochs    237  * Dump the contents of the CPU context (bochs + x86_videomem)
149  */                                               238  */
150 void sos_cpu_context_dump(const struct sos_cpu    239 void sos_cpu_context_dump(const struct sos_cpu_state *ctxt);
151                                                   240 
152                                                   241 
153 /* ===========================================    242 /* =======================================================================
154  * Public Accessor functions TO BE USED ONLY B    243  * Public Accessor functions TO BE USED ONLY BY Exception handlers
155  */                                               244  */
156                                                   245 
157                                                   246 
158 /**                                               247 /**
159  * Return the argument passed by the CPU upon     248  * Return the argument passed by the CPU upon exception, as stored in the
160  * saved context                                  249  * saved context
161  */                                               250  */
162 sos_ui32_t sos_cpu_context_get_EX_info(const s    251 sos_ui32_t sos_cpu_context_get_EX_info(const struct sos_cpu_state *ctxt);
163                                                   252 
164                                                   253 
165 /**                                               254 /**
166  * Return the faulting address of the exceptio    255  * Return the faulting address of the exception
167  */                                               256  */
168 sos_vaddr_t                                       257 sos_vaddr_t
169 sos_cpu_context_get_EX_faulting_vaddr(const st    258 sos_cpu_context_get_EX_faulting_vaddr(const struct sos_cpu_state *ctxt);
                                                   >> 259 
                                                   >> 260 
                                                   >> 261 /**
                                                   >> 262  * Change the return address of the given context
                                                   >> 263  */
                                                   >> 264 sos_ret_t
                                                   >> 265 sos_cpu_context_set_EX_return_address(struct sos_cpu_state *ctxt,
                                                   >> 266                                       sos_vaddr_t ret_vaddr);
                                                   >> 267 
                                                   >> 268 
                                                   >> 269 /* =======================================================================
                                                   >> 270  * Public Accessor functions TO BE USED ONLY BY the SYSCALL handler
                                                   >> 271  */
                                                   >> 272 
                                                   >> 273 /**
                                                   >> 274  * Low-level functions used by the syscall handler. They are
                                                   >> 275  * responsible for retrieving the arguments passed to the syscall when
                                                   >> 276  * a user thread makes a syscall. Some of these arguments are
                                                   >> 277  * available as registers' values in the user context, some of them
                                                   >> 278  * are user-space addresses given by these registers.
                                                   >> 279  *
                                                   >> 280  * @return SOS_OK on success, <0 otherwise
                                                   >> 281  */
                                                   >> 282 sos_ret_t sos_syscall_get1arg(const struct sos_cpu_state *user_ctxt,
                                                   >> 283                               /* out */unsigned int *arg1);
                                                   >> 284 
                                                   >> 285 sos_ret_t sos_syscall_get2args(const struct sos_cpu_state *user_ctxt,
                                                   >> 286                                /* out */unsigned int *arg1,
                                                   >> 287                                /* out */unsigned int *arg2);
                                                   >> 288 
                                                   >> 289 sos_ret_t sos_syscall_get3args(const struct sos_cpu_state *user_ctxt,
                                                   >> 290                                /* out */unsigned int *arg1,
                                                   >> 291                                /* out */unsigned int *arg2,
                                                   >> 292                                /* out */unsigned int *arg3);
                                                   >> 293 
                                                   >> 294 sos_ret_t sos_syscall_get4args(const struct sos_cpu_state *user_ctxt,
                                                   >> 295                                /* out */unsigned int *arg1,
                                                   >> 296                                /* out */unsigned int *arg2,
                                                   >> 297                                /* out */unsigned int *arg3,
                                                   >> 298                                /* out */unsigned int *arg4);
                                                   >> 299 
                                                   >> 300 sos_ret_t sos_syscall_get5args(const struct sos_cpu_state *user_ctxt,
                                                   >> 301                                /* out */unsigned int *arg1,
                                                   >> 302                                /* out */unsigned int *arg2,
                                                   >> 303                                /* out */unsigned int *arg3,
                                                   >> 304                                /* out */unsigned int *arg4,
                                                   >> 305                                /* out */unsigned int *arg5);
                                                   >> 306 
                                                   >> 307 sos_ret_t sos_syscall_get6args(const struct sos_cpu_state *user_ctxt,
                                                   >> 308                                /* out */unsigned int *arg1,
                                                   >> 309                                /* out */unsigned int *arg2,
                                                   >> 310                                /* out */unsigned int *arg3,
                                                   >> 311                                /* out */unsigned int *arg4,
                                                   >> 312                                /* out */unsigned int *arg5,
                                                   >> 313                                /* out */unsigned int *arg6);
                                                   >> 314 
                                                   >> 315 sos_ret_t sos_syscall_get7args(const struct sos_cpu_state *user_ctxt,
                                                   >> 316                                /* out */unsigned int *arg1,
                                                   >> 317                                /* out */unsigned int *arg2,
                                                   >> 318                                /* out */unsigned int *arg3,
                                                   >> 319                                /* out */unsigned int *arg4,
                                                   >> 320                                /* out */unsigned int *arg5,
                                                   >> 321                                /* out */unsigned int *arg6,
                                                   >> 322                                /* out */unsigned int *arg7);
                                                   >> 323 
                                                   >> 324 sos_ret_t sos_syscall_get8args(const struct sos_cpu_state *user_ctxt,
                                                   >> 325                                /* out */unsigned int *arg1,
                                                   >> 326                                /* out */unsigned int *arg2,
                                                   >> 327                                /* out */unsigned int *arg3,
                                                   >> 328                                /* out */unsigned int *arg4,
                                                   >> 329                                /* out */unsigned int *arg5,
                                                   >> 330                                /* out */unsigned int *arg6,
                                                   >> 331                                /* out */unsigned int *arg7,
                                                   >> 332                                /* out */unsigned int *arg8);
170                                                   333 
171                                                   334 
172 /* ===========================================    335 /* =======================================================================
173  * Macros controlling stack poisoning.            336  * Macros controlling stack poisoning.
174  * Stack poisoning can be used to detect:         337  * Stack poisoning can be used to detect:
175  *  - unitialized local variables                 338  *  - unitialized local variables
176  *  - when the thread might have gone too deep    339  *  - when the thread might have gone too deep in the stack
177  */                                               340  */
178 /** The signature of the poison */                341 /** The signature of the poison */
179 #define SOS_CPU_STATE_STACK_POISON 0xa5           342 #define SOS_CPU_STATE_STACK_POISON 0xa5
180                                                   343 
181 /**                                               344 /**
182  * When set, mean that the whole stack is pois    345  * When set, mean that the whole stack is poisoned to detect use of
183  * unititialized variables                        346  * unititialized variables
184  */                                               347  */
185 #define SOS_CPU_STATE_DETECT_UNINIT_KERNEL_VAR    348 #define SOS_CPU_STATE_DETECT_UNINIT_KERNEL_VARS
186 /* #undef SOS_CPU_STATE_DETECT_UNINIT_KERNEL_V    349 /* #undef SOS_CPU_STATE_DETECT_UNINIT_KERNEL_VARS */
187                                                   350 
188 /**                                               351 /**
189  * When set, mean that the bottom of the stack    352  * When set, mean that the bottom of the stack is poisoned to detect
190  * probable stack overflow. Its value indicate    353  * probable stack overflow. Its value indicates the number of bytes
191  * used for this detection.                       354  * used for this detection.
192  */                                               355  */
193 #define SOS_CPU_STATE_DETECT_KERNEL_STACK_OVER    356 #define SOS_CPU_STATE_DETECT_KERNEL_STACK_OVERFLOW  64
194 /* #undef SOS_CPU_STATE_DETECT_KERNEL_STACK_OV    357 /* #undef SOS_CPU_STATE_DETECT_KERNEL_STACK_OVERFLOW */
195                                                   358 
196 #if defined(SOS_CPU_STATE_DETECT_KERNEL_STACK_    359 #if defined(SOS_CPU_STATE_DETECT_KERNEL_STACK_OVERFLOW)
197 void                                              360 void
198 sos_cpu_state_prepare_detect_kernel_stack_over    361 sos_cpu_state_prepare_detect_kernel_stack_overflow(const struct sos_cpu_state *ctxt,
199                                                   362                                                    sos_vaddr_t kernel_stack_bottom,
200                                                   363                                                    sos_size_t kernel_stack_size);
201 void sos_cpu_state_detect_kernel_stack_overflo    364 void sos_cpu_state_detect_kernel_stack_overflow(const struct sos_cpu_state *ctxt,
202                                                   365                                                 sos_vaddr_t kernel_stack_bottom,
203                                                   366                                                 sos_size_t kernel_stack_size);
204 #else                                             367 #else
205 # define sos_cpu_state_prepare_detect_kernel_s    368 # define sos_cpu_state_prepare_detect_kernel_stack_overflow(ctxt,stkbottom,stksize) \
206   ({ /* nop */ })                                 369   ({ /* nop */ })
207 # define sos_cpu_state_detect_kernel_stack_ove    370 # define sos_cpu_state_detect_kernel_stack_overflow(ctxt,stkbottom,stksize) \
208   ({ /* nop */ })                                 371   ({ /* nop */ })
209 #endif                                            372 #endif
210                                                   373 
211                                                   374 
212 /* ===========================================    375 /* =======================================================================
213  * Backtrace facility. To be used for DEBUGgin    376  * Backtrace facility. To be used for DEBUGging purpose ONLY.
214  */                                               377  */
215                                                   378 
216                                                   379 
217 /**                                               380 /**
218  * The function called at each step of the bac    381  * The function called at each step of the backtrace iterations
219  *                                                382  *
220  * @param PC The address of the next instructi    383  * @param PC The address of the next instruction of the function that
221  * will be executed                               384  * will be executed
222  *                                                385  *
223  * @param params The address of the array of t    386  * @param params The address of the array of the parameteres that have
224  * been passed to the function considered         387  * been passed to the function considered
225  *                                                388  *
226  * @param depth The index of the iteration (ie    389  * @param depth The index of the iteration (ie the depth of the
227  * current frame into the stack)                  390  * current frame into the stack)
228  *                                                391  *
229  * @param custom_arg Whatever you want: this i    392  * @param custom_arg Whatever you want: this is the argument passed as
230  * custom_arg to sos_backtrace()                  393  * custom_arg to sos_backtrace()
231  */                                               394  */
232 typedef void (sos_backtrace_callback_t)(sos_va    395 typedef void (sos_backtrace_callback_t)(sos_vaddr_t PC,
233                                         sos_va    396                                         sos_vaddr_t params,
234                                         sos_ui    397                                         sos_ui32_t depth,
235                                         void *    398                                         void *custom_arg);
236                                                   399 
237                                                   400 
238 /**                                               401 /**
239  * Call the backtracer callback on each frame     402  * Call the backtracer callback on each frame stored in the cpu_state
240  *                                                403  *
241  * @param cpu_state The CPU context we want to    404  * @param cpu_state The CPU context we want to explore. MUST be the
242  * context of a thread in Kernel mode, or NULL    405  * context of a thread in Kernel mode, or NULL. When NULL: backtrace
243  * the current CPU context.                       406  * the current CPU context.
244  *                                                407  *
245  * @param max_depth The maximum number of fram    408  * @param max_depth The maximum number of frames to explore
246  *                                                409  *
247  * @param stack_bottom The lower boundary of t    410  * @param stack_bottom The lower boundary of the stack. This is used
248  * to make sure that the frame addresses fit i    411  * to make sure that the frame addresses fit inside the stack
249  * boudaries (ie are potentially correct).        412  * boudaries (ie are potentially correct).
250  *                                                413  *
251  * @param stack_size The size of the stack. Sa    414  * @param stack_size The size of the stack. Same comment.
252  *                                                415  *
253  * @param backtracer The function to call to h    416  * @param backtracer The function to call to handle the frame for each
254  * iteration                                      417  * iteration
255  *                                                418  *
256  * @param custom_arg The arg passed as custom_    419  * @param custom_arg The arg passed as custom_arg to the backtracer
257  *                                                420  *
258  * @return The number of frames explored.         421  * @return The number of frames explored.
259  *                                                422  *
260  * @note Might be inaccurate when gcc's -fomit    423  * @note Might be inaccurate when gcc's -fomit-frame-pointer has been
261  * used.                                          424  * used.
262  */                                               425  */
263 sos_ui32_t sos_backtrace(const struct sos_cpu_    426 sos_ui32_t sos_backtrace(const struct sos_cpu_state *cpu_state,
264                          sos_ui32_t max_depth,    427                          sos_ui32_t max_depth,
265                          sos_vaddr_t stack_bot    428                          sos_vaddr_t stack_bottom,
266                          sos_size_t stack_size    429                          sos_size_t stack_size,
267                          sos_backtrace_callbac    430                          sos_backtrace_callback_t * backtracer,
268                          void *custom_arg);       431                          void *custom_arg);
269                                                   432 
270 #endif /* _SOS_CPUCTXT_H_ */                      433 #endif /* _SOS_CPUCTXT_H_ */
                                                      

source navigation ] diff markup ] identifier search ] general search ]