Hey list, I'm in the midst of doing something potentially a bit taboo in these parts: porting some Linux code to the NT kernel used by Windows. Specifically, I'm porting wireguard-linux to wireguard-nt. In evaluating whether to do a clean implementation or a 1:1 port, the latter was chosen, as implementation fidelity and past security analysis remains priority, and a simple port seemed like the most straightforward and efficient way of getting there.
Things have mostly been going along swimmingly. Packets flow now, and the whole thing basically works. One big part of this effort has been a humongous "compat.h" file that maps Linuxisms to NTisms -- things like locks and atomic ops and lists and such. Another big part of the effort has been rewriting code or reimplementing core functions where there's not an already available NT facility that has the same semantics as Linux. For example, I wrote a tiny RCU implementation recently. And finally some parts are being rearchitected. For example, while we did reimplement the queue_work_on API initially, we're now changing how we manage threads in NT anyway, so that's changing. Anyway, the point is that our porting efforts are working well so far. But... we still have this compat.h file, and we still have a lot of code that "looks like" Linux code. At some point (soon, hopefully), we're going to begin inlining the compat.h transformations, with an aim of getting rid of compat.h entirely. "Well, duh, just run the preprocessor on it," I hear some of you say. That works to a degree, but we're also using things like typedefs, and other tricks, where that isn't quite clean enough. There will also be some interesting semantic mapping -- like changing one list API into another list API. At some point, we'll also approach cosmetic things, changing variables, struct members, and function names from lovely_linux_identifiers_like_this into GrossWindowsIdentifiersLikeThis, and changing `struct reasonable_name { ... }` into `typedef struct _TERRIBLE_NAME { ... } TERRIBLE_NAME`, and things like that, because that's just how things go with NT programming. So the plan was to do this carefully by hand and maybe some grotesque sed oneliners and then hope clang-format cleans it up. But obviously coccinelle is a better tool for this, and one that would help us avoid silly errors. I was wondering if anybody on this list is a bit bored this summer and wanted to spend a week or two on this. It's perhaps not the most glamorous work, but it is very interesting -- at least in my experience so far -- to wrap my mind around NT differences to Linux, and this has stimulated me to think about some new ideas for Linux. It also might wind up being a way into some more complex coccinelle use cases, as I believe that many of the rules will be far from trivial transformations (otherwise I would have just tackled this project myself). So, if anyone here is interested, or knows somebody who's interested, please do reach out. Thanks, Jason _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci