kernel: Fix compilation for non-gki kernels (#543)

This commit is contained in:
TwinbornPlate75
2025-11-08 01:19:11 +08:00
committed by GitHub
parent 74f24bafed
commit c24ed3b5c4
3 changed files with 46 additions and 1 deletions

View File

@@ -1176,7 +1176,11 @@ do_umount:
tw->old_cred = get_current_cred(); tw->old_cred = get_current_cred();
tw->cb.func = umount_tw_func; tw->cb.func = umount_tw_func;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
int err = task_work_add(current, &tw->cb, TWA_RESUME); int err = task_work_add(current, &tw->cb, TWA_RESUME);
#else
int err = task_work_add(current, &tw->cb, true);
#endif
if (err) { if (err) {
if (tw->old_cred) { if (tw->old_cred) {
put_cred(tw->old_cred); put_cred(tw->old_cred);
@@ -1328,7 +1332,11 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
tw->old_cred = get_current_cred(); tw->old_cred = get_current_cred();
tw->cb.func = umount_tw_func; tw->cb.func = umount_tw_func;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
int err = task_work_add(current, &tw->cb, TWA_RESUME); int err = task_work_add(current, &tw->cb, TWA_RESUME);
#else
int err = task_work_add(current, &tw->cb, true);
#endif
if (err) { if (err) {
if (tw->old_cred) { if (tw->old_cred) {
put_cred(tw->old_cred); put_cred(tw->old_cred);

View File

@@ -52,6 +52,7 @@ static ssize_t mksu_wrapper_write_iter (struct kiocb *iocb, struct iov_iter *iov
return orig->f_op->write_iter(iocb, iovi); return orig->f_op->write_iter(iocb, iovi);
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
static int mksu_wrapper_iopoll(struct kiocb *kiocb, struct io_comp_batch* icb, unsigned int v) { static int mksu_wrapper_iopoll(struct kiocb *kiocb, struct io_comp_batch* icb, unsigned int v) {
struct ksu_file_wrapper* data = kiocb->ki_filp->private_data; struct ksu_file_wrapper* data = kiocb->ki_filp->private_data;
@@ -67,6 +68,7 @@ static int mksu_wrapper_iopoll(struct kiocb *kiocb, bool spin) {
return orig->f_op->iopoll(kiocb, spin); return orig->f_op->iopoll(kiocb, spin);
} }
#endif #endif
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
static int mksu_wrapper_iterate (struct file *fp, struct dir_context *dc) { static int mksu_wrapper_iterate (struct file *fp, struct dir_context *dc) {
@@ -257,6 +259,7 @@ static ssize_t mksu_wrapper_copy_file_range(struct file *f1, loff_t off1, struct
return -EINVAL; return -EINVAL;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
static loff_t mksu_wrapper_remap_file_range(struct file *file_in, loff_t pos_in, static loff_t mksu_wrapper_remap_file_range(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out, struct file *file_out, loff_t pos_out,
loff_t len, unsigned int remap_flags) { loff_t len, unsigned int remap_flags) {
@@ -277,6 +280,29 @@ static int mksu_wrapper_fadvise(struct file *fp, loff_t off1, loff_t off2, int f
} }
return -EINVAL; return -EINVAL;
} }
#else
static int mksu_wrapper_clone_file_range(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out, u64 len) {
// TODO: determine which file to use
struct ksu_file_wrapper* data = file_in->private_data;
struct file* orig = data->orig;
if (orig->f_op->clone_file_range) {
return orig->f_op->clone_file_range(orig, pos_in, file_out, pos_out, len);
}
return -EINVAL;
}
static ssize_t mksu_wrapper_dedupe_file_range(struct file *src_file, u64 loff,
u64 len, struct file *dst_file, u64 dst_loff) {
// TODO: determine which file to use
struct ksu_file_wrapper* data = src_file->private_data;
struct file* orig = data->orig;
if (orig->f_op->dedupe_file_range) {
return orig->f_op->dedupe_file_range(orig, loff, len, dst_file, dst_loff);
}
return -EINVAL;
}
#endif
static int mksu_wrapper_release(struct inode *inode, struct file *filp) { static int mksu_wrapper_release(struct inode *inode, struct file *filp) {
mksu_delete_file_wrapper(filp->private_data); mksu_delete_file_wrapper(filp->private_data);
@@ -298,7 +324,9 @@ struct ksu_file_wrapper* mksu_create_file_wrapper(struct file* fp) {
p->ops.write = fp->f_op->write ? mksu_wrapper_write : NULL; p->ops.write = fp->f_op->write ? mksu_wrapper_write : NULL;
p->ops.read_iter = fp->f_op->read_iter ? mksu_wrapper_read_iter : NULL; p->ops.read_iter = fp->f_op->read_iter ? mksu_wrapper_read_iter : NULL;
p->ops.write_iter = fp->f_op->write_iter ? mksu_wrapper_write_iter : NULL; p->ops.write_iter = fp->f_op->write_iter ? mksu_wrapper_write_iter : NULL;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
p->ops.iopoll = fp->f_op->iopoll ? mksu_wrapper_iopoll : NULL; p->ops.iopoll = fp->f_op->iopoll ? mksu_wrapper_iopoll : NULL;
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
p->ops.iterate = fp->f_op->iterate ? mksu_wrapper_iterate : NULL; p->ops.iterate = fp->f_op->iterate ? mksu_wrapper_iterate : NULL;
#endif #endif
@@ -309,7 +337,7 @@ struct ksu_file_wrapper* mksu_create_file_wrapper(struct file* fp) {
p->ops.mmap = fp->f_op->mmap ? mksu_wrapper_mmap : NULL; p->ops.mmap = fp->f_op->mmap ? mksu_wrapper_mmap : NULL;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
p->ops.fop_flags = fp->f_op->fop_flags; p->ops.fop_flags = fp->f_op->fop_flags;
#else #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
p->ops.mmap_supported_flags = fp->f_op->mmap_supported_flags; p->ops.mmap_supported_flags = fp->f_op->mmap_supported_flags;
#endif #endif
p->ops.open = fp->f_op->open ? mksu_wrapper_open : NULL; p->ops.open = fp->f_op->open ? mksu_wrapper_open : NULL;
@@ -330,8 +358,13 @@ struct ksu_file_wrapper* mksu_create_file_wrapper(struct file* fp) {
p->ops.fallocate = fp->f_op->fallocate ? mksu_wrapper_fallocate : NULL; p->ops.fallocate = fp->f_op->fallocate ? mksu_wrapper_fallocate : NULL;
p->ops.show_fdinfo = fp->f_op->show_fdinfo ? mksu_wrapper_show_fdinfo : NULL; p->ops.show_fdinfo = fp->f_op->show_fdinfo ? mksu_wrapper_show_fdinfo : NULL;
p->ops.copy_file_range = fp->f_op->copy_file_range ? mksu_wrapper_copy_file_range : NULL; p->ops.copy_file_range = fp->f_op->copy_file_range ? mksu_wrapper_copy_file_range : NULL;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
p->ops.remap_file_range = fp->f_op->remap_file_range ? mksu_wrapper_remap_file_range : NULL; p->ops.remap_file_range = fp->f_op->remap_file_range ? mksu_wrapper_remap_file_range : NULL;
p->ops.fadvise = fp->f_op->fadvise ? mksu_wrapper_fadvise : NULL; p->ops.fadvise = fp->f_op->fadvise ? mksu_wrapper_fadvise : NULL;
#else
p->ops.clone_file_range = fp->f_op->clone_file_range ? mksu_wrapper_clone_file_range : NULL;
p->ops.dedupe_file_range = fp->f_op->dedupe_file_range ? mksu_wrapper_dedupe_file_range : NULL;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
p->ops.splice_eof = fp->f_op->splice_eof ? mksu_wrapper_splice_eof : NULL; p->ops.splice_eof = fp->f_op->splice_eof ? mksu_wrapper_splice_eof : NULL;

View File

@@ -1,6 +1,10 @@
#include <linux/file.h> #include <linux/file.h>
#include <linux/fs.h> #include <linux/fs.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
typedef unsigned int __poll_t;
#endif
struct ksu_file_wrapper { struct ksu_file_wrapper {
struct file* orig; struct file* orig;
struct file_operations ops; struct file_operations ops;