Is it safe to pass a pointer to a static struct to a function?
I have something like this:
mymodule.c:
static MYEVENT_STRUC_T event;
uint_32 _myRtos_set_event(MYEVENT_STRUCT_T* event_ptr, uint_32 mask);
uint_32 mymodule_set_event(uint_32 event_mask){
/* Kernel function */
/* Defined outside mymodule.c,*/
/* Is it safe to call it with &event? */
return _myRtos_set_event(&event, event_mask);
}
It is safe. static
doesn't mean "can't be used outside the module", but rather "can't be referenced outside the module", i.e. the symbol itself won't be exported, but the variable still exists somewhere in the memory of the process an can be used between modules as well.
The only thing I'm uncertain of is that I'm not sure it's safe to pass data from user-mode to kernel-mode via pointer, if that's what you're doing. If I recall correctly, there is some function you're supposed to call that copies memory from user-space to kernel-space. Not entirely sure, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With