#ifndef __KSU_H_KERNEL_COMPAT #define __KSU_H_KERNEL_COMPAT #include #include #include #include "ss/policydb.h" #include "linux/key.h" // for kernel without get_cred_rcu #ifndef KSU_COMPAT_HAS_GET_CRED_RCU static inline const struct cred *get_cred_rcu(const struct cred *cred) { struct cred *nonconst_cred = (struct cred *) cred; if (!cred) return NULL; #ifdef KSU_COMPAT_ATOMIC_LONG if (!atomic_long_inc_not_zero(&nonconst_cred->usage)) #else if (!atomic_inc_not_zero(&nonconst_cred->usage)) #endif return NULL; validate_creds(cred); #ifdef KSU_COMPAT_HAS_NONCONST_CRED nonconst_cred->non_rcu = 0; #endif return cred; } #endif /* * Adapt to Huawei HISI kernel without affecting other kernels , * Huawei Hisi Kernel EBITMAP Enable or Disable Flag , * From ss/ebitmap.h */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)) && \ (LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)) || \ (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)) && \ (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)) #ifdef HISI_SELINUX_EBITMAP_RO #define CONFIG_IS_HW_HISI #endif #endif // Checks for UH, KDP and RKP #ifdef SAMSUNG_UH_DRIVER_EXIST #if defined(CONFIG_UH) || defined(CONFIG_KDP) || defined(CONFIG_RKP) #error "CONFIG_UH, CONFIG_KDP and CONFIG_RKP is enabled! Please disable or remove it before compile a kernel with KernelSU!" #endif #endif extern long ksu_strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, long count); #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || \ defined(CONFIG_IS_HW_HISI) || \ defined(CONFIG_KSU_ALLOWLIST_WORKAROUND) extern struct key *init_session_keyring; #endif extern void ksu_android_ns_fs_check(); extern struct file *ksu_filp_open_compat(const char *filename, int flags, umode_t mode); extern ssize_t ksu_kernel_read_compat(struct file *p, void *buf, size_t count, loff_t *pos); extern ssize_t ksu_kernel_write_compat(struct file *p, const void *buf, size_t count, loff_t *pos); #endif