Updated ntdll-Syscall_Emulation patchset.

This commit is contained in:
Paul Gofman 2020-11-03 19:55:50 +03:00
parent 950d7c6c43
commit 6ad4bdecd2

View File

@ -1,19 +1,19 @@
From b91699bc26a89683053a6157f343372d98da2a67 Mon Sep 17 00:00:00 2001
From 6eace1f9bc0c49f8e38ff5ead9aa3aa0b83e0d87 Mon Sep 17 00:00:00 2001
From: Paul Gofman <pgofman@codeweavers.com>
Date: Tue, 14 Jul 2020 15:00:34 +0300
Subject: [PATCH] ntdll: Support x86_64 syscall emulation.
---
configure.ac | 1 +
dlls/ntdll/unix/signal_x86_64.c | 119 ++++++++++++++++++++++++++++++++
dlls/ntdll/unix/signal_x86_64.c | 117 ++++++++++++++++++++++++++++++++
tools/winebuild/import.c | 3 +-
3 files changed, 122 insertions(+), 1 deletion(-)
3 files changed, 120 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index f147d3e845d..74a9119d691 100644
index fe8549784e2a..2168f9089f5c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -473,6 +473,7 @@ AC_CHECK_HEADERS(\
@@ -467,6 +467,7 @@ AC_CHECK_HEADERS(\
linux/joystick.h \
linux/major.h \
linux/param.h \
@ -22,7 +22,7 @@ index f147d3e845d..74a9119d691 100644
linux/types.h \
linux/ucdrom.h \
diff --git a/dlls/ntdll/unix/signal_x86_64.c b/dlls/ntdll/unix/signal_x86_64.c
index a0d3594e6b8..f693fbe6b9f 100644
index cd386096cd41..c8071e7f4e20 100644
--- a/dlls/ntdll/unix/signal_x86_64.c
+++ b/dlls/ntdll/unix/signal_x86_64.c
@@ -28,6 +28,7 @@
@ -47,7 +47,7 @@ index a0d3594e6b8..f693fbe6b9f 100644
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "ntstatus.h"
@@ -2157,6 +2165,116 @@ static inline DWORD is_privileged_instr( CONTEXT *context )
@@ -2224,6 +2232,114 @@ static inline DWORD is_privileged_instr( CONTEXT *context )
return 0;
}
@ -124,39 +124,37 @@ index a0d3594e6b8..f693fbe6b9f 100644
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
+ };
+ struct sock_fprog prog;
+ int ret;
+ NTSTATUS status;
+
+ sig_act->sa_sigaction = sigsys_handler;
+ sigaction(SIGSYS, sig_act, NULL);
+
+ if ((status = syscall(0xffff)) == STATUS_INVALID_PARAMETER)
+ {
+ TRACE("Seccomp filters already installed.\n");
+ return;
+ }
+ if (status != -ENOSYS && (status != -1 || errno != ENOSYS))
+ {
+ ERR("Unexpected status %#x, errno %d.\n", status, errno);
+ return;
+ }
+
+ memset(&prog, 0, sizeof(prog));
+ prog.len = ARRAY_SIZE(filter);
+ prog.filter = filter;
+
+ if (!(ret = prctl(PR_GET_SECCOMP, 0, NULL, 0, 0)))
+ if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
+ {
+ if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
+ {
+ perror("prctl(PR_SET_NO_NEW_PRIVS, ...)");
+ exit(1);
+ }
+
+ if (sc_seccomp(SECCOMP_SET_MODE_FILTER, flags, &prog))
+
+ {
+ perror("prctl(PR_SET_SECCOMP, ...)");
+ exit(1);
+ }
+
+ check_bpf_jit_enable();
+ perror("prctl(PR_SET_NO_NEW_PRIVS, ...)");
+ exit(1);
+ }
+ else
+ if (sc_seccomp(SECCOMP_SET_MODE_FILTER, flags, &prog))
+ {
+ if (ret == 2)
+ TRACE("Seccomp filters already installed.\n");
+ else
+ ERR("Seccomp filters cannot be installed, ret %d, error %s.\n", ret, strerror(errno));
+ perror("prctl(PR_SET_SECCOMP, ...)");
+ exit(1);
+ }
+
+ sig_act->sa_sigaction = sigsys_handler;
+ sigaction(SIGSYS, sig_act, NULL);
+ check_bpf_jit_enable();
+#else
+ WARN("Built without seccomp.\n");
+#endif
@ -164,7 +162,7 @@ index a0d3594e6b8..f693fbe6b9f 100644
/***********************************************************************
* handle_interrupt
@@ -2644,6 +2762,7 @@ void signal_init_process(void)
@@ -2711,6 +2827,7 @@ void signal_init_process(void)
if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error;
if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error;
if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error;
@ -173,10 +171,10 @@ index a0d3594e6b8..f693fbe6b9f 100644
error:
diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c
index b90d93ca5db..e750ae0ad3f 100644
index 673141321585..86721d61f6bc 100644
--- a/tools/winebuild/import.c
+++ b/tools/winebuild/import.c
@@ -1524,6 +1524,7 @@ void output_syscalls( DLLSPEC *spec )
@@ -1525,6 +1525,7 @@ void output_syscalls( DLLSPEC *spec )
/* Legends of Runeterra hooks the first system call return instruction, and
* depends on us returning to it. Adjust the return address accordingly. */
output( "\tsubq $0xb,0x8(%%rbp)\n" );
@ -184,7 +182,7 @@ index b90d93ca5db..e750ae0ad3f 100644
output( "\tmovq %%rsp,0x328(%%rcx)\n" ); /* amd64_thread_data()->syscall_frame */
output( "\tcmpq $%u,%%rax\n", count );
output( "\tjae 4f\n" );
@@ -1703,7 +1704,7 @@ void output_syscalls( DLLSPEC *spec )
@@ -1718,7 +1719,7 @@ void output_syscalls( DLLSPEC *spec )
* validate that instruction, we can just put a jmp there instead. */
output( "\t.byte 0x4c,0x8b,0xd1\n" ); /* movq %rcx,%r10 */
output( "\t.byte 0xb8\n" ); /* movl $i,%eax */