Get fork() working on Windows

This is done without using Microsoft's internal APIs. MAP_PRIVATE
mappings are copied to the subprocess via a pipe, since Microsoft
doesn't want us to have proper COW pages. MAP_SHARED mappings are
remapped without needing to do any copying. Global variables need
copying along with the stack and the whole heap of anonymous mem.
This actually improves the reliability of the redbean http server
although one shouldn't expect 10k+ connections on a home computer
that isn't running software built to serve like Linux or FreeBSD.
This commit is contained in:
Justine Tunney 2020-11-13 01:27:49 -08:00
parent aea89fe832
commit db33973e0a
105 changed files with 1476 additions and 912 deletions

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_DefWindowProcA,DefWindowProcA,173
.text.windows
DefWindowProcA:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_DefWindowProcA(%rip),%rax
jmp __sysv2nt
.endfn DefWindowProcA,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_DefWindowProcW,DefWindowProcW,174
.text.windows
DefWindowProc:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_DefWindowProcW(%rip),%rax
jmp __sysv2nt
.endfn DefWindowProc,globl
.previous

View file

@ -1,2 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_FillRect,FillRect,1780
.text.windows
FillRect:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_FillRect(%rip),%rax
jmp __sysv2nt
.endfn FillRect,globl
.previous

View file

@ -1,2 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_LoadCursorA,LoadCursorA,2098
.text.windows
LoadCursorA:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_LoadCursorA(%rip),%rax
jmp __sysv2nt
.endfn LoadCursorA,globl
.previous

View file

@ -1,2 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_LoadCursorW,LoadCursorW,2101
.text.windows
LoadCursor:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_LoadCursorW(%rip),%rax
jmp __sysv2nt
.endfn LoadCursor,globl
.previous

View file

@ -1,2 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_LoadImageA,LoadImageA,2104
.text.windows
LoadImageA:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_LoadImageA(%rip),%rax
jmp __sysv2nt6
.endfn LoadImageA,globl
.previous

View file

@ -1,2 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_LoadImageW,LoadImageW,2105
.text.windows
LoadImage:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_LoadImageW(%rip),%rax
jmp __sysv2nt6
.endfn LoadImage,globl
.previous

View file

@ -1,2 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_RegisterClassA,RegisterClassA,2248
.text.windows
RegisterClassA:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_RegisterClassA(%rip)
leave
ret
.endfn RegisterClassA,globl
.previous

View file

@ -1,2 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_RegisterClassExA,RegisterClassExA,2249
.text.windows
RegisterClassExA:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_RegisterClassExA(%rip)
leave
ret
.endfn RegisterClassExA,globl
.previous

View file

@ -1,2 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_RegisterClassExW,RegisterClassExW,2250
.text.windows
RegisterClassEx:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_RegisterClassExW(%rip)
leave
ret
.endfn RegisterClassEx,globl
.previous

View file

@ -1,2 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_RegisterClassW,RegisterClassW,2251
.text.windows
RegisterClass:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_RegisterClassW(%rip)
leave
ret
.endfn RegisterClass,globl
.previous

View file

@ -1,2 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_ShowCaret,ShowCaret,2411
.text.windows
ShowCaret:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_ShowCaret(%rip)
leave
ret
.endfn ShowCaret,globl
.previous

View file

@ -1,2 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp user32,__imp_ShowCursor,ShowCursor,2412
.text.windows
ShowCursor:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_ShowCursor(%rip)
leave
ret
.endfn ShowCursor,globl
.previous