I have a rather esoteric question about the behavior of the various static allocation functions that return an object handle (e.g. xSemaphoreCreateMutexStatic, etc.). My question is: can one presume that the handle value returned by the static create functions is always the address of the static buffer that was passed in?
The code does appear to work this way, however the documentation is silent on this relationship, which leads me to believe the correct answer is no.
I ask because there is a common pattern of implementing newlib’s retargetable locking feature where the global lock variables (e.g. __lock___sfp_recursive_mutex) are declared as StaticSemaphore_t. Unfortunately, the newlib code blindly passes the address of these variables to the lock acquire/release functions, which in the common implementations, gets cast to a SemaphoreHandle_t before being passed to FreeRTOS. In the future, should the handle value not be exactly the address of the static object, this code would obviously break.
I believe it currently works, but is not guarenteed. An alternative if you want to be sure is to make a structure that stores the returned handle and the static creation block, and the lock acquire routine pull the handle out of the structure.
Currently, the handle is a pointer to the memory block. However, we have experimental code that replaces the pointers with indexes for specific ports - so whether your scheme works with future major releases of FreeRTOS may depend on the kernel port.