BlueHat IL 2023: Microsoft rewriting core Windows libraries in Rust

  • Rust discussion starts at: https://youtu.be/8T6ClX-y2AE?t=2610

    Highlights:

        * 2 projects: dwrite and Win32k
        * 2 devs, 6 months to rewrite 152KLOC C++ to 90KLOC Rust re dwrite
        * Performance increases of 5-15% re dwrite
        * Only about 10% of Win32k code is unsafe
        * No perf regressions re Win32k
        * Syscall in the Windows kernel now written in Rust

  • Overlooked is that it's one of two incredible successes that have come out of Mozilla:

    * The open web, David defeating Goliath Microsoft (arguably like a small open source retailer defeating Amazon today).

    * Rust: Not entirely Mozilla, but they played an essential, major role nurturing it, and were among the first to deploy it.

    Any others that I'm overlooking?

  • Those memory bugs are costly after all. I think the best part of this presentation is they managed to improve performance while adding memory safety. Two people rebuilding a 90kloc c++ into rust in 6 months is also pretty impressive.

  • One the subject of porting code from one language to another (ignoring that the headline says "rewrite", which implies more than a dumb port).

    Are there any tools to help map out the work that needs to be done? I found myself doing this by hand recently, doing graph search on a piece of paper. I needed to port one function, so I identified all the functions that function called, wrote them down, and then looked into the next layer of functions etc. I manually searched the potential call graphs by reading the code and wrote down all possible functions involved. I then crossed of functions that seemed obvious, such as a function to retrieve the value of a dictionary with a default value, such simple functions are trivial and need no special effort. In the end I had a list of functions that needed to be ported one-by-one and I began working from the bottom up.

    I was wondering if there are any tools that could automate this process? It seems to be the beginning of a source-to-source compiler, but such a compiler could be kept simple by embracing that most of the work can be presented to a human to perform manually. The "compilers" only job is to structure the work and break it down into small chunks.

  • Writing kernel-mode code in Windows with rust is very cool, but I am curious if there are code samples out there for this kind of thing.

    Windows kernel drivers are usually fully asynchronous so I'm curious how rust handles IRPs and completion callbacks and such in the kernel.

  • Would it be a good idea to rewrite glibc in Rust?

  • [flagged]

  • MS and Amazon own and run Rust, this isn’t surprising.