Created
April 30, 2021 19:21
-
-
Save chibicitiberiu/dfd91540a84c1b78633b12f127d0f3a3 to your computer and use it in GitHub Desktop.
Patch for linux 5.11+ support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule src/external/lkm contains modified content | |
diff --git a/src/external/lkm/darling/binfmt.c b/src/external/lkm/darling/binfmt.c | |
index 55c8a63..cf93aca 100644 | |
--- a/src/external/lkm/darling/binfmt.c | |
+++ b/src/external/lkm/darling/binfmt.c | |
@@ -222,7 +222,7 @@ int setup_space(struct linux_binprm* bprm, struct load_results* lr) | |
// Explanation: | |
// Using STACK_TOP would cause the stack to be placed just above the commpage | |
// and would collide with it eventually. | |
- unsigned long stackAddr = commpage_address(!test_thread_flag(TIF_IA32)); | |
+ unsigned long stackAddr = commpage_address(any_64bit_mode(current_pt_regs())); | |
setup_new_exec(bprm); | |
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) | |
@@ -560,7 +560,7 @@ start_thread_common(struct pt_regs *regs, unsigned long new_ip, | |
void | |
start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp) | |
{ | |
- bool ia32 = test_thread_flag(TIF_IA32); | |
+ bool ia32 = !any_64bit_mode(regs); | |
start_thread_common(regs, new_ip, new_sp, | |
ia32 ? __USER32_CS : __USER_CS, | |
__USER_DS, | |
@@ -872,7 +872,7 @@ int macho_coredump(struct coredump_params* cprm) | |
#endif | |
// Write the Mach-O header and loader commands | |
- if (test_thread_flag(TIF_IA32)) | |
+ if (!any_64bit_mode(current_pt_regs())) | |
{ | |
// 32-bit executables | |
if (!macho_dump_headers32(cprm)) | |
diff --git a/src/external/lkm/darling/host_info.c b/src/external/lkm/darling/host_info.c | |
index 7fc353c..c12b700 100644 | |
--- a/src/external/lkm/darling/host_info.c | |
+++ b/src/external/lkm/darling/host_info.c | |
@@ -49,7 +49,7 @@ kern_return_t darling_host_info(host_flavor_t flavor, host_info_t host_info_out, | |
hinfo->cpu_type = CPU_TYPE_I386; | |
hinfo->cpu_subtype = CPU_SUBTYPE_I386_ALL; | |
#elif defined(__x86_64__) | |
- if (!test_thread_flag(TIF_IA32)) | |
+ if (any_64bit_mode(task_pt_regs(linux_current))) | |
{ | |
hinfo->cpu_type = CPU_TYPE_I386; | |
hinfo->cpu_subtype = CPU_SUBTYPE_X86_64_ALL; | |
diff --git a/src/external/lkm/darling/kqueue.c b/src/external/lkm/darling/kqueue.c | |
index 1fab4de..bfe7e3c 100644 | |
--- a/src/external/lkm/darling/kqueue.c | |
+++ b/src/external/lkm/darling/kqueue.c | |
@@ -4,7 +4,9 @@ | |
#include <linux/slab.h> | |
#include <linux/anon_inodes.h> | |
#include <linux/fs.h> | |
+#define current linux_current | |
#include <linux/fdtable.h> | |
+#undef current | |
#include <linux/poll.h> | |
#if 0 // TODO: EVFILT_SOCK support (we've gotta fix some header collisions) | |
#include <linux/net.h> | |
@@ -33,7 +35,7 @@ | |
#include "task_registry.h" | |
// re-define `fcheck` because we use `linux_current` | |
-#define fcheck(fd) fcheck_files(linux_current->files, fd) | |
+#define fcheck(fd) files_lookup_fd_rcu(linux_current->files, fd) | |
struct dkqueue_pte; | |
typedef SLIST_HEAD(dkqueue_pte_head, dkqueue_pte) dkqueue_pte_head_t; | |
@@ -252,7 +254,7 @@ static struct file *__fget_files(struct files_struct *files, unsigned int fd, | |
rcu_read_lock(); | |
loop: | |
- file = fcheck_files(files, fd); | |
+ file = files_lookup_fd_rcu(files, fd); | |
if (file) { | |
/* File object ref couldn't be taken. | |
* dup2() atomicity guarantee is the reason | |
@@ -1137,7 +1139,7 @@ static void dkqueue_fork_listener(int pid, void* context, darling_proc_event_t e | |
LIST_FOREACH(curr, &parent_proc->p_fd->kqueue_list, link) { | |
dkqueue_log("closing kqueue with fd %d on fork", curr->fd); | |
proc_fdunlock(parent_proc); | |
- ksys_close(curr->fd); | |
+ close_fd(curr->fd); | |
proc_fdlock(parent_proc); | |
} | |
proc_fdunlock(parent_proc); | |
@@ -1258,7 +1260,7 @@ int darling_kqueue_create(struct task* task) { | |
error_out: | |
if (fd >= 0) { | |
- ksys_close(fd); | |
+ close_fd(fd); | |
} else { | |
// we only cleanup the rest ourselves if the fd still hasn't been created. | |
// otherwise (if it *has* been created), Linux will call `dkqueue_release` on the file | |
diff --git a/src/external/lkm/darling/traps.c b/src/external/lkm/darling/traps.c | |
index 3363a6e..2c28187 100644 | |
--- a/src/external/lkm/darling/traps.c | |
+++ b/src/external/lkm/darling/traps.c | |
@@ -30,7 +30,9 @@ | |
#include <linux/kernel.h> | |
#include <linux/mm.h> | |
#include <linux/eventfd.h> | |
+#define current linux_current | |
#include <linux/fdtable.h> | |
+#undef current | |
#include <linux/syscalls.h> | |
#include <linux/fs_struct.h> | |
#include <linux/moduleparam.h> | |
@@ -445,7 +447,7 @@ int mach_dev_mmap(struct file* file, struct vm_area_struct *vma) | |
if (vma->vm_pgoff != 0) | |
return -LINUX_EINVAL; | |
- if (test_thread_flag(TIF_IA32)) | |
+ if (!any_64bit_mode(current_pt_regs())) | |
{ | |
if (length != commpage_length(false)) | |
return -LINUX_EINVAL; | |
@@ -490,7 +492,7 @@ struct file* xnu_task_setup(void) | |
int commpage_install(struct file* xnu_task) | |
{ | |
unsigned long addr; | |
- bool _64bit = !test_thread_flag(TIF_IA32); | |
+ bool _64bit = any_64bit_mode(current_pt_regs()); | |
addr = vm_mmap(xnu_task, commpage_address(_64bit), commpage_length(_64bit), PROT_READ, MAP_SHARED | MAP_FIXED, 0); | |
@@ -2138,7 +2140,7 @@ thread_get_state( | |
static int state_to_kernel(const struct thread_state* state) | |
{ | |
#ifdef __x86_64__ | |
- if (!test_thread_flag(TIF_IA32)) | |
+ if (any_64bit_mode(current_pt_regs())) | |
{ | |
x86_thread_state64_t tstate; | |
x86_float_state64_t fstate; | |
@@ -2175,7 +2177,7 @@ static int state_to_kernel(const struct thread_state* state) | |
static int state_from_kernel(struct thread_state* state) | |
{ | |
#ifdef __x86_64__ | |
- if (!test_thread_flag(TIF_IA32)) | |
+ if (any_64bit_mode(current_pt_regs())) | |
{ | |
x86_thread_state64_t tstate; | |
x86_float_state64_t fstate; | |
diff --git a/src/external/lkm/osfmk/duct/duct_kern_thread_act.c b/src/external/lkm/osfmk/duct/duct_kern_thread_act.c | |
index d4d51cc..312fdb1 100644 | |
--- a/src/external/lkm/osfmk/duct/duct_kern_thread_act.c | |
+++ b/src/external/lkm/osfmk/duct/duct_kern_thread_act.c | |
@@ -205,7 +205,7 @@ thread_get_state_internal( | |
if (*state_count < x86_THREAD_STATE_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
{ | |
s->tsh.flavor = flavor = x86_THREAD_STATE64; | |
s->tsh.count = x86_THREAD_STATE64_COUNT; | |
@@ -229,7 +229,7 @@ thread_get_state_internal( | |
if (*state_count < x86_FLOAT_STATE_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
{ | |
s->fsh.flavor = flavor = x86_FLOAT_STATE64; | |
s->fsh.count = x86_FLOAT_STATE64_COUNT; | |
@@ -252,7 +252,7 @@ thread_get_state_internal( | |
if (*state_count < x86_DEBUG_STATE_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
{ | |
s->dsh.flavor = flavor = x86_DEBUG_STATE64; | |
s->dsh.count = x86_DEBUG_STATE64_COUNT; | |
@@ -276,7 +276,7 @@ thread_get_state_internal( | |
{ | |
if (*state_count < x86_THREAD_STATE32_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
x86_thread_state32_t* s = (x86_thread_state32_t*) state; | |
@@ -291,7 +291,7 @@ thread_get_state_internal( | |
{ | |
if (*state_count < x86_FLOAT_STATE32_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
x86_float_state32_t* s = (x86_float_state32_t*) state; | |
@@ -317,7 +317,7 @@ thread_get_state_internal( | |
{ | |
if (*state_count < x86_THREAD_STATE64_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (!user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
x86_thread_state64_t* s = (x86_thread_state64_t*) state; | |
@@ -333,7 +333,7 @@ thread_get_state_internal( | |
{ | |
if (*state_count < x86_DEBUG_STATE32_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
x86_debug_state32_t* s = (x86_debug_state32_t*) state; | |
@@ -364,7 +364,7 @@ thread_get_state_internal( | |
{ | |
if (*state_count < x86_DEBUG_STATE64_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (!user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
x86_debug_state64_t* s = (x86_debug_state64_t*) state; | |
@@ -492,7 +492,7 @@ thread_set_state( | |
if (s->tsh.flavor == x86_THREAD_STATE32) | |
{ | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
state_count = s->tsh.count; | |
@@ -500,7 +500,7 @@ thread_set_state( | |
} | |
else if (s->tsh.flavor == x86_THREAD_STATE64) | |
{ | |
- if (test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (!user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
state_count = s->tsh.count; | |
@@ -521,7 +521,7 @@ thread_set_state( | |
if (s->fsh.flavor == x86_FLOAT_STATE32) | |
{ | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
state_count = s->fsh.count; | |
@@ -529,7 +529,7 @@ thread_set_state( | |
} | |
else if (s->fsh.flavor == x86_FLOAT_STATE64) | |
{ | |
- if (test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (!user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
state_count = s->fsh.count; | |
@@ -550,7 +550,7 @@ thread_set_state( | |
if (s->dsh.flavor == x86_DEBUG_STATE32) | |
{ | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
state_count = s->dsh.count; | |
@@ -558,7 +558,7 @@ thread_set_state( | |
} | |
else if (s->dsh.flavor == x86_DEBUG_STATE64) | |
{ | |
- if (test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (!user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
state_count = s->dsh.count; | |
@@ -578,7 +578,7 @@ thread_set_state( | |
{ | |
if (state_count < x86_THREAD_STATE32_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
const x86_thread_state32_t* s = (x86_thread_state32_t*) state; | |
@@ -590,7 +590,7 @@ thread_set_state( | |
{ | |
if (state_count < x86_THREAD_STATE64_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (!user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
const x86_thread_state64_t* s = (x86_thread_state64_t*) state; | |
@@ -604,7 +604,7 @@ thread_set_state( | |
{ | |
if (state_count < x86_FLOAT_STATE32_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
const x86_float_state32_t* s = (x86_float_state32_t*) state; | |
@@ -617,7 +617,7 @@ thread_set_state( | |
{ | |
if (state_count < x86_FLOAT_STATE64_COUNT) | |
return KERN_INVALID_ARGUMENT; | |
- if (!darling_is_task_64bit()) | |
+ if (user_64bit_mode(current_pt_regs())) | |
return KERN_INVALID_ARGUMENT; | |
const x86_float_state64_t* s = (x86_float_state64_t*) state; | |
@@ -627,7 +627,7 @@ thread_set_state( | |
} | |
case x86_DEBUG_STATE32: | |
{ | |
- if (!test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
const x86_debug_state32_t* s = (x86_debug_state32_t*) state; | |
x86_debug_state64_t s64; | |
@@ -646,7 +646,7 @@ thread_set_state( | |
} | |
case x86_DEBUG_STATE64: | |
{ | |
- if (test_ti_thread_flag(task_thread_info(ltask), TIF_IA32)) | |
+ if (!user_64bit_mode(task_pt_regs(ltask))) | |
return KERN_INVALID_ARGUMENT; | |
const x86_debug_state64_t* s = (x86_debug_state64_t*) state; | |
diff --git a/src/external/lkm/osfmk/duct/duct_vm_map.c b/src/external/lkm/osfmk/duct/duct_vm_map.c | |
index 8e3ba67..9027d78 100644 | |
--- a/src/external/lkm/osfmk/duct/duct_vm_map.c | |
+++ b/src/external/lkm/osfmk/duct/duct_vm_map.c | |
@@ -438,7 +438,7 @@ boolean_t vm_map_copy_validate_size(vm_map_t dst_map, vm_map_copy_t copy, vm_map | |
int darling_is_task_64bit(void) | |
{ | |
#if __x86_64__ || __arm64__ | |
- return !test_thread_flag(TIF_IA32); | |
+ return any_64bit_mode(task_pt_regs(linux_current)); | |
#else | |
return 0; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment