Thread local data in linux kernel module

橙三吉。 提交于 2020-01-02 04:24:05

问题


Is it possible to create thread local data in a linux kernel module?

I need to store some data for each process/thread calling my module. Is there an easy way of using thread local data, or do I have to resort to writing a hash map which uses the pid of the current process as a key?


回答1:


Assuming the interface to you kernel module is a character device driver, then you have a private_data field in the file struct (which is analogous to user space file descriptor) exactly for that.

Just allocate and assign a pointer to your structure of choice at the open file operation to it.

It's not exactly thread or process local, but in most cases a mapping of one file descriptor to your process is true and it might be good enough for you.



来源:https://stackoverflow.com/questions/7402330/thread-local-data-in-linux-kernel-module

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