LWN: Comments on "Emulating Windows system calls in Linux" https://lwn.net/Articles/824380/ This is a special feed containing comments posted to the individual LWN article titled "Emulating Windows system calls in Linux". en-us Fri, 29 Aug 2025 13:02:01 +0000 Fri, 29 Aug 2025 13:02:01 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Emulating Windows system calls in Linux https://lwn.net/Articles/825921/ https://lwn.net/Articles/825921/ Hi-Angel <div class="FormattedComment"> <font class="QuotedText">&gt; No, you would:</font><br> &gt;<br> <font class="QuotedText">&gt; * patch WINE libraries (the only ones that should issue Linux system calls) to</font><br> <font class="QuotedText">&gt; go through a trampoline page</font><br> <p> You can&#x27;t achieve anything here by patching WINE libs because as the prev. author<br> said, there&#x27;s no problem with apps that go through them. The problem being<br> discussed is that some apps make system calls without going through WinAPI/WINE<br> libs. Let me quote the original mail:<br> <p> <font class="QuotedText">&gt; Modern Windows applications are executing system call instructions directly</font><br> <font class="QuotedText">&gt; from the application&#x27;s code without going through the WinAPI. This breaks Wine</font><br> <font class="QuotedText">&gt; emulation, because it doesn&#x27;t have a chance to intercept and emulate these</font><br> <font class="QuotedText">&gt; syscalls before they are submitted to Linux.</font><br> <p> </div> Sat, 11 Jul 2020 13:30:48 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/825188/ https://lwn.net/Articles/825188/ raoni <div class="FormattedComment"> IIRC from when I read the thread, they are OK with overhead on syscalls from windows code, they are not the concern for performance, they are concerned that applying some sort of overhead for all syscalls is a bigger performance hit because the linux libraries and the winAPI emulation code.<br> </div> Fri, 03 Jul 2020 13:28:37 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/825046/ https://lwn.net/Articles/825046/ khim <div class="FormattedComment"> Windows 7 uses SYSENTER and doesn&#x27;t work on CPUs without it.<br> <p> When applications dropped WINXP support then got the chance to use it, too.<br> </div> Thu, 02 Jul 2020 10:13:55 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/825041/ https://lwn.net/Articles/825041/ rwmj <div class="FormattedComment"> Don&#x27;t Windows and Linux system calls use entirely different mechanisms? Does Windows still use an IDT to enter the kernel?<br> </div> Thu, 02 Jul 2020 09:31:10 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824779/ https://lwn.net/Articles/824779/ mirabilos <div class="FormattedComment"> Except that the code needed to handle it almost certainly isn’t signal handler-safe or can be made to…<br> </div> Tue, 30 Jun 2020 12:31:17 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824657/ https://lwn.net/Articles/824657/ NYKevin <div class="FormattedComment"> <font class="QuotedText">&gt; as long as you can tolerate those syscalls being slow.</font><br> <p> I imagine this will depend on the game. If it&#x27;s isolated into a bunch of small levels with loading screens between them, well, the loading screens will suck, but the rest of the game should basically work most of the time, assuming the game engine isn&#x27;t trying to do something weird (like constantly telling the OS which pages to evict first).<br> <p> But if it&#x27;s an open world game that dynamically loads stuff in and out of memory all the time, then you&#x27;re in trouble.<br> </div> Sun, 28 Jun 2020 19:04:16 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824619/ https://lwn.net/Articles/824619/ roc <div class="FormattedComment"> Probably better to ask &quot;when will it be safe to assume syscalls are fast again?&quot;<br> </div> Fri, 26 Jun 2020 21:09:14 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824618/ https://lwn.net/Articles/824618/ roc <div class="FormattedComment"> When will it be safe to start assuming no-PTI when designing APIs?<br> </div> Fri, 26 Jun 2020 21:08:35 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824617/ https://lwn.net/Articles/824617/ roc <div class="FormattedComment"> Wine uses glibc and a bunch of other system libraries which do need to be patched. Those libraries aren&#x27;t trying to stop us patching them, but they&#x27;re not providing any hooks to avoid the need for patching, either.<br> <p> Again: you don&#x27;t need to patch the tricky game code with this approach ... as long as you can tolerate those syscalls being slow.<br> </div> Fri, 26 Jun 2020 21:05:17 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824597/ https://lwn.net/Articles/824597/ pbonzini <div class="FormattedComment"> Yes, the core idea though is the same, distinguishing trapped and pass-through system calls from the address.<br> </div> Fri, 26 Jun 2020 15:03:58 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824584/ https://lwn.net/Articles/824584/ pm215 <div class="FormattedComment"> That would work, but it&#x27;s not the approach suggested at the top of this comment thread, which includes &quot;The ptracer looks at the code around the syscall and if it matches certain common patterns, we patch it with a jump to a stub&quot;... (You don&#x27;t need to runtime-patch the wine libraries -- wine controls that code so it can just be built to do whatever.)<br> </div> Fri, 26 Jun 2020 14:09:28 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824551/ https://lwn.net/Articles/824551/ pbonzini <div class="FormattedComment"> No, you would:<br> <p> * patch WINE libraries (the only ones that should issue Linux system calls) to go through a trampoline page<br> <p> * use seccomp-bpf to raise SIGSYS for almost all code except that single trampoline page<br> <p> * now if you get SIGSYS you now it&#x27;s a Windows syscall, and you handle it from the SIGSYS handler<br> </div> Fri, 26 Jun 2020 12:40:54 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824549/ https://lwn.net/Articles/824549/ pm215 <div class="FormattedComment"> The patchset says it&#x27;s addressing the way that &quot;Modern Windows applications are executing system call instructions directly from the application&#x27;s code without going through the WinAPI&quot; -- so I think your approach would imply patching game code. It sounds like they already have workable approaches for apps that are traditional &quot;call the winapi library which makes the syscall&quot; style.<br> </div> Fri, 26 Jun 2020 11:49:31 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824530/ https://lwn.net/Articles/824530/ luto <div class="FormattedComment"> Pre-Meltdown, trivial syscalls like this were very fast. A trampoline oughtn’t hurt that much.<br> </div> Fri, 26 Jun 2020 05:12:08 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824529/ https://lwn.net/Articles/824529/ roc <div class="FormattedComment"> The rr approach applied to Wine would not require patching the Windows game code, only the Wine/Linux libraries which *are* somewhat cooperative.<br> <p> Discussing it on LKML, the problem with our approach for Wine is probably the issues with multiple threads potentially racing with system-call patching.<br> </div> Fri, 26 Jun 2020 01:39:07 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824526/ https://lwn.net/Articles/824526/ smcv <div class="FormattedComment"> As mentioned in the article, patching Windows game code is unlikely to work well, because in some cases it tries to detect external modifications to itself as an anti-cheating mechanism, and it&#x27;s deliberately obfuscated to make modification and tracing harder. I&#x27;m aware rr isn&#x27;t usually tracing actively cooperating processes, but it isn&#x27;t usually tracing a process that is actively uncooperative either.<br> </div> Thu, 25 Jun 2020 23:24:13 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824525/ https://lwn.net/Articles/824525/ roc <div class="FormattedComment"> rr grapples with a similar problem. We need to intercept commonly-executed system calls and wrap them with our own processing, with minimal overhead. I think Wine could probably use our approach.<br> <p> We use a seccomp filter to trap on all syscalls except for those called from a single specific trampoline page. When a library makes a syscall, the filter triggers a ptrace trap. The ptracer looks at the code around the syscall and if it matches certain common patterns, we patch it with a jump to a stub that does the extra work we need and then issues a real syscall via the trampoline. Thus, a library syscall is slow the first time and fast the rest of the time. (Another possible variant of this approach, probably faster when applicable, would be to avoid using a ptracer and have the filter trigger a SIGSYS whose handler does the patching.)<br> <p> Maybe I should post this to the list...<br> </div> Thu, 25 Jun 2020 22:56:00 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824516/ https://lwn.net/Articles/824516/ chris_se <div class="FormattedComment"> I think the user-space trampoline is the most promising solution here: it requires extremely minimal code changes to the kernel and offers full flexibility to the user-space programs, because they can use any code they want for their trampoline, and that code can be extremely hand-optimized assembly for that specific use case.<br> <p> And if somebody much more clever than me when it comes to assembly can figure out a way to do that without requiring a context switch for the instruction that triggers the trampoline (don&#x27;t know if that&#x27;s possible) then this would have the same performance as eBPF, because whether you do the comparison in ring 3 or ring 0 shouldn&#x27;t actually change anything.<br> <p> On the other hand, if you do need two additional context switches (one for entering the kernel and one for jumping back to the trampoline) then one would have to measure the performance impact here. (Though in that case one optimization could be for the kernel to postpone the speculative execution mitigations until after it has determined the syscall comes from the trampoline and should hence be used directly, and don&#x27;t do any of the mitigations both for entering and exiting ring 0 if it wants to jump immediately back to the trampoline, that should reduce the cost of the context switches quite a bit.)<br> </div> Thu, 25 Jun 2020 21:00:03 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824496/ https://lwn.net/Articles/824496/ rvolgers <div class="FormattedComment"> To clarify the kind of design I&#x27;m thinking of, you could perhaps get something more flexible than a BPF syscall filter by making all executable pages PROT_NOSYSCALL, requiring all syscalls to go via a single non-PROT_NOSYSCALL page which performs the filtering in userspace and then performs the syscall. Assuming CET is turned on, as it&#x27;s needed to ensure the filtering is done before the syscall instruction.<br> <p> Obviously there are still a lot of potential problems when you have security code running in the same address space as the code it&#x27;s defending against, so there might be something I&#x27;m missing. Certainly the trusted code that does the filtering would have to be very carefully written to defend against the program altering the filter code, and there are lots of potential race conditions if you&#x27;d want to check anything stored in memory.<br> <p> Still, it seems like a pretty flexible approach, especially considering syscall filtering via bpf is also pretty limited, and worth thinking about?<br> <p> <p> </div> Thu, 25 Jun 2020 17:57:31 +0000 Emulating Windows system calls in Linux https://lwn.net/Articles/824494/ https://lwn.net/Articles/824494/ rvolgers <div class="FormattedComment"> I was all set to dislike this proposal, but I actually think the original idea is great, and is kind of underselling itself.<br> <p> The PROT_NOSYSCALL could be turned into a remarkably elegant and effective security barrier when combined with Intel&#x27;s Indirect Branch Tracking (part of CET) to remove the possibility of jumping directly to a SYSCALL instruction.<br> <p> </div> Thu, 25 Jun 2020 17:36:37 +0000