More thoughts about ioctl and kernel ABIs in general
H. Peter Anvin
hpa@zytor.com
Fri Jul 11 08:12:07 GMT 2025
I wanted to show a *very* simple example... this is a Coccinelle script
that mangles the kernel termios files to change the structure names,
delete the ktermios structure (which should never have been included in
uapi; I'm going to submit a patch to the kernel to fix that), tack
underscores in front of some symbols, add __extension__ to anonymous
struct and union members, and put some definitions under #ifdef __USE_MISC.
The latter rule does cause a whole lot of #ifdef ... #endif #ifdef ..
#endif, but this can be handled with a simple postprocessing script like
the attached Perl script.
-hpa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unredundant.pl
Type: application/x-perl
Size: 1573 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250711/874cf10e/attachment-0001.pl>
-------------- next part --------------
@ struct_add_kernel @
identifier os =~ "^termio";
fresh identifier ns = "__kernel_" ## os;
@@
- struct os
+ struct ns
@ struct_add_kernel_def @
identifier os =~ "^termio";
fresh identifier ns = "__kernel_" ## os;
@@
- struct os
+ struct ns
{ ... }
@ struct_delete @
identifier sname =~ "^ktermios$";
@@
- struct sname { ... };
@ double_underscore @
identifier ob =~ "^(B[0-9]+|BOTHER|NCC|NCCS)$";
fresh identifier nb = "__" ## ob;
expression E;
@@
- #define ob E
+ #define nb E
@ double_underscore_use @
identifier double_underscore.ob;
fresh identifier nb = "__" ## ob;
@@
- ob
+ nb
@ use_misc @
identifier x =~ "^(EXT[AB]|ADDRB|CMSPAR|CRTSCTS|IBSHIFT)$";
expression E;
@@
+#ifdef __USE_MISC
#define x E
+#endif
@ anon_field_hasid @
identifier id;
type T;
attribute name __extension__;
@@
(
struct id {
...
- T;
+ __extension__ T;
...
}
|
union id {
...
- T;
+ __extension__ T;
...
}
)
@ anon_field_noid @
type T;
attribute name __extension__;
@@
(
struct {
...
- T;
+ __extension__ T;
...
}
|
union {
...
- T;
+ __extension__ T;
...
}
)
More information about the Libc-alpha
mailing list