Freeing (vfree-ing) pointer to volatile data

左心房为你撑大大i 提交于 2019-12-02 07:16:55

The vfree function (and every sane deallocation function in general) does not care about your actual data (be it volatile or not). It just expects a (valid) pointer (think: passing the pointer as a long value in a CPU register).

Based on that value, the function will:

  1. call the SLAB/SLUB to free the memory
  2. remove the memory mapping

So yes, casting to a void * will not cause any harm at runtime.

My conclusion was that just casting the pointer to void * would not cause a problem and the fact that free and vfree don't directly accept pointers to volatile data is just something that was overlooked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!