Fix build on vzkernel 3.10

This commit is contained in:
Max Khon 2018-09-06 07:30:17 -04:00
parent bb8a4c9972
commit 67172ec4bd
3 changed files with 29 additions and 1 deletions

View File

@ -3,6 +3,10 @@ obj-m := ashmem_linux.o
ashmem_linux-y := deps.o ashmem.o ashmem_linux-y := deps.o ashmem.o
KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build
VZ= $(shell uname -r | grep vz)
ifneq ($(VZ),)
ccflags-y += -DVZKERNEL
endif
all: all:
$(MAKE) -C $(KERNEL_SRC) V=0 M=$$PWD $(MAKE) -C $(KERNEL_SRC) V=0 M=$$PWD

View File

@ -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 */ /* 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)) & if (unlikely((vma->vm_flags & ~calc_vm_prot_bits(asma->prot_mask, 0)) &
calc_vm_prot_bits(PROT_MASK, 0))) { calc_vm_prot_bits(PROT_MASK, 0))) {
#else #else

View File

@ -61,6 +61,10 @@
#include "binder.h" #include "binder.h"
#include "binder_trace.h" #include "binder_trace.h"
#ifndef MAX_NICE
#define MAX_NICE 19
#endif
static DEFINE_MUTEX(binder_main_lock); static DEFINE_MUTEX(binder_main_lock);
static DEFINE_MUTEX(binder_deferred_lock); static DEFINE_MUTEX(binder_deferred_lock);
static DEFINE_MUTEX(binder_mmap_lock); static DEFINE_MUTEX(binder_mmap_lock);
@ -484,6 +488,16 @@ static inline void binder_unlock(const char *tag)
mutex_unlock(&binder_main_lock); 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) static void binder_set_nice(long nice)
{ {
long min_nice; long min_nice;
@ -1608,8 +1622,10 @@ static int binder_translate_binder(struct flat_binder_object *fp,
(u64)node->cookie); (u64)node->cookie);
return -EINVAL; return -EINVAL;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) if (security_binder_transfer_binder(proc->tsk, target_proc->tsk))
return -EPERM; return -EPERM;
#endif
ref = binder_get_ref_for_node(target_proc, node); ref = binder_get_ref_for_node(target_proc, node);
if (!ref) if (!ref)
@ -1648,8 +1664,10 @@ static int binder_translate_handle(struct flat_binder_object *fp,
proc->pid, thread->pid, fp->handle); proc->pid, thread->pid, fp->handle);
return -EINVAL; return -EINVAL;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) if (security_binder_transfer_binder(proc->tsk, target_proc->tsk))
return -EPERM; return -EPERM;
#endif
if (ref->node->proc == target_proc) { if (ref->node->proc == target_proc) {
if (fp->hdr.type == BINDER_TYPE_HANDLE) if (fp->hdr.type == BINDER_TYPE_HANDLE)
@ -1718,11 +1736,13 @@ static int binder_translate_fd(int fd,
ret = -EBADF; ret = -EBADF;
goto err_fget; goto err_fget;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
ret = security_binder_transfer_file(proc->tsk, target_proc->tsk, file); ret = security_binder_transfer_file(proc->tsk, target_proc->tsk, file);
if (ret < 0) { if (ret < 0) {
ret = -EPERM; ret = -EPERM;
goto err_security; goto err_security;
} }
#endif
target_fd = task_get_unused_fd_flags(target_proc, O_CLOEXEC); target_fd = task_get_unused_fd_flags(target_proc, O_CLOEXEC);
if (target_fd < 0) { if (target_fd < 0) {
@ -1943,11 +1963,13 @@ static void binder_transaction(struct binder_proc *proc,
return_error = BR_DEAD_REPLY; return_error = BR_DEAD_REPLY;
goto err_dead_binder; goto err_dead_binder;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
if (security_binder_transaction(proc->tsk, if (security_binder_transaction(proc->tsk,
target_proc->tsk) < 0) { target_proc->tsk) < 0) {
return_error = BR_FAILED_REPLY; return_error = BR_FAILED_REPLY;
goto err_invalid_target_handle; goto err_invalid_target_handle;
} }
#endif
if (!(tr->flags & TF_ONE_WAY) && thread->transaction_stack) { if (!(tr->flags & TF_ONE_WAY) && thread->transaction_stack) {
struct binder_transaction *tmp; struct binder_transaction *tmp;
@ -3236,9 +3258,11 @@ static int binder_ioctl_set_ctx_mgr(struct file *filp)
ret = -EBUSY; ret = -EBUSY;
goto out; goto out;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
ret = security_binder_set_context_mgr(proc->tsk); ret = security_binder_set_context_mgr(proc->tsk);
if (ret < 0) if (ret < 0)
goto out; goto out;
#endif
if (uid_valid(context->binder_context_mgr_uid)) { if (uid_valid(context->binder_context_mgr_uid)) {
if (!uid_eq(context->binder_context_mgr_uid, curr_euid)) { if (!uid_eq(context->binder_context_mgr_uid, curr_euid)) {
pr_err("BINDER_SET_CONTEXT_MGR bad uid %d != %d\n", pr_err("BINDER_SET_CONTEXT_MGR bad uid %d != %d\n",