How to enforce the use of the proper interfaces to core kernel structures?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all.

Please forgive my lenghty message due to my poor knowledge of the English 
language that prevents me from being more straightforward and brief.

In hacking Linux code often we have to access data structures and variables 
embedded in them. We all know that most of these objects need some special 
attention when manipulating them, like previous verifying of some particular 
condition, acquiring locks, atomically r/w and so on.

This is why developers of core structure usually provide some standardized 
controlled data access method as macros and as other function interfaces.

As an example (maybe it is not the most appropriate), "set_task_state(task, 
state)" not only sets the given task the given state, it also provide a 
memory barrier() when needed (SMP). If I am not missing something, only on UP 
it is a simpler "task->state = state".

The problem is that any client code handling the variable "task->state" could 
change its value without being forced to only use the set_task_state() macro. 
This may well be a bug.

Obviously the example can be extended to any data variable that needs 
particular care in dealing with. Someone hacking kernel code might not even 
know that a special interface has been created and should be used. Those 
interfaces are disseminated in headers so that overlooking them might be not 
so exceptional.

Sometimes it also happens to me to miss the existence of an interface and so I 
write code that directly manipulate that data which only by chance, often 
either from reading code developed by others or when debugging something that 
doesn't work, I eventually find the proper way to access.

Now I have three question:

1) Is what I discuss here a perceived problem? Am I missing something that 
makes this a no problem?

2) Is it possible to enforce, in client's code, the use of the proper 
interfaces to core kernel structures? (I mean something like the object 
oriented language as C++ do with "private" objects embedded data that can 
only be initialised, accessed and finalized by public interfaces).

3) If both C language and GCC extension couldn't help, is there any idea for 
practical solutions within Linux kernel?

Thank you for your kind attention.

fabio


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux