From 67172ec4bd5618319b45e77e9b7721b59b706a75 Mon Sep 17 00:00:00 2001 From: Max Khon Date: Thu, 6 Sep 2018 07:30:17 -0400 Subject: [PATCH] Fix build on vzkernel 3.10 --- ashmem/Makefile | 4 ++++ ashmem/ashmem.c | 2 +- binder/binder.c | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ashmem/Makefile b/ashmem/Makefile index 9f1a920..017e5b7 100644 --- a/ashmem/Makefile +++ b/ashmem/Makefile @@ -3,6 +3,10 @@ obj-m := ashmem_linux.o ashmem_linux-y := deps.o ashmem.o KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build +VZ= $(shell uname -r | grep vz) +ifneq ($(VZ),) +ccflags-y += -DVZKERNEL +endif all: $(MAKE) -C $(KERNEL_SRC) V=0 M=$$PWD diff --git a/ashmem/ashmem.c b/ashmem/ashmem.c index cb354dc..6b1be9e 100644 --- a/ashmem/ashmem.c +++ b/ashmem/ashmem.c @@ -380,7 +380,7 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma) } /* requested protection bits must match our allowed protection mask */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) || defined(VZKERNEL) if (unlikely((vma->vm_flags & ~calc_vm_prot_bits(asma->prot_mask, 0)) & calc_vm_prot_bits(PROT_MASK, 0))) { #else diff --git a/binder/binder.c b/binder/binder.c index 9ccadf1..a9d04b2 100644 --- a/binder/binder.c +++ b/binder/binder.c @@ -61,6 +61,10 @@ #include "binder.h" #include "binder_trace.h" +#ifndef MAX_NICE +#define MAX_NICE 19 +#endif + static DEFINE_MUTEX(binder_main_lock); static DEFINE_MUTEX(binder_deferred_lock); static DEFINE_MUTEX(binder_mmap_lock); @@ -484,6 +488,16 @@ static inline void binder_unlock(const char *tag) mutex_unlock(&binder_main_lock); } +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) +/* + * Convert rlimit style value [1,40] to nice value [-20, 19]. + */ +static inline long rlimit_to_nice(long prio) +{ + return (MAX_NICE - prio + 1); +} +#endif + static void binder_set_nice(long nice) { long min_nice; @@ -1608,8 +1622,10 @@ static int binder_translate_binder(struct flat_binder_object *fp, (u64)node->cookie); return -EINVAL; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) return -EPERM; +#endif ref = binder_get_ref_for_node(target_proc, node); if (!ref) @@ -1648,8 +1664,10 @@ static int binder_translate_handle(struct flat_binder_object *fp, proc->pid, thread->pid, fp->handle); return -EINVAL; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) return -EPERM; +#endif if (ref->node->proc == target_proc) { if (fp->hdr.type == BINDER_TYPE_HANDLE) @@ -1718,11 +1736,13 @@ static int binder_translate_fd(int fd, ret = -EBADF; goto err_fget; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) ret = security_binder_transfer_file(proc->tsk, target_proc->tsk, file); if (ret < 0) { ret = -EPERM; goto err_security; } +#endif target_fd = task_get_unused_fd_flags(target_proc, O_CLOEXEC); if (target_fd < 0) { @@ -1943,11 +1963,13 @@ static void binder_transaction(struct binder_proc *proc, return_error = BR_DEAD_REPLY; goto err_dead_binder; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) if (security_binder_transaction(proc->tsk, target_proc->tsk) < 0) { return_error = BR_FAILED_REPLY; goto err_invalid_target_handle; } +#endif if (!(tr->flags & TF_ONE_WAY) && thread->transaction_stack) { struct binder_transaction *tmp; @@ -3236,9 +3258,11 @@ static int binder_ioctl_set_ctx_mgr(struct file *filp) ret = -EBUSY; goto out; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) ret = security_binder_set_context_mgr(proc->tsk); if (ret < 0) goto out; +#endif if (uid_valid(context->binder_context_mgr_uid)) { if (!uid_eq(context->binder_context_mgr_uid, curr_euid)) { pr_err("BINDER_SET_CONTEXT_MGR bad uid %d != %d\n",