-
Notifications
You must be signed in to change notification settings - Fork 2
Fix build #54: FINAL umount -> sys_umount fix for kernel 4.9 #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Binary file not shown.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| KernelSU-Next kernel 4.9 compatibility fix script v39 | ||
| FINAL FIX: Aggressive umount() -> sys_umount() replacement for kernel 4.9 | ||
|
|
||
| Issue: The pre-patched core_hook.c.patched file contains umount() calls | ||
| which don't exist in kernel 4.9. This fix runs AFTER the pre-patched file | ||
| is applied to ensure all umount calls are replaced. | ||
|
|
||
| This fix is designed to be the FINAL and MOST AGGRESSIVE fix. | ||
| """ | ||
|
|
||
| import sys | ||
| import os | ||
| import re | ||
|
|
||
| def aggressive_umount_fix(file_path): | ||
| """Aggressively replace all umount() calls with sys_umount()""" | ||
|
|
||
| if not os.path.exists(file_path): | ||
| return False, "File not found" | ||
|
|
||
| with open(file_path, 'r') as f: | ||
| content = f.read() | ||
|
|
||
| original_content = content | ||
| changes = [] | ||
|
|
||
| # Pattern 1: Direct umount(something) -> sys_umount(something, 0) | ||
| # This is the most common pattern causing the undefined reference | ||
| pattern1 = r'(?<!sys_)(?<!try_)\bumount\s*\(\s*([^,)]+)\s*\)' | ||
| matches1 = list(re.finditer(pattern1, content)) | ||
| if matches1: | ||
| content = re.sub(pattern1, r'sys_umount(\1, 0)', content) | ||
| changes.append(f"Replaced {len(matches1)} umount(X) calls with sys_umount(X, 0)") | ||
|
|
||
| # Pattern 2: Handle any remaining umount with two args (shouldn't exist but be safe) | ||
| pattern2 = r'(?<!sys_)(?<!try_)\bumount\s*\(' | ||
| matches2 = list(re.finditer(pattern2, content)) | ||
| if matches2: | ||
| changes.append(f"WARNING: Found {len(matches2)} remaining umount calls that need manual fix") | ||
| for i, match in enumerate(matches2): | ||
| # Get surrounding context | ||
| start = max(0, match.start() - 20) | ||
| end = min(len(content), match.end() + 40) | ||
| context = content[start:end] | ||
| changes.append(f" Match {i+1}: ...{context}...") | ||
|
|
||
| # Check if any changes were made | ||
| if content != original_content: | ||
| with open(file_path, 'w') as f: | ||
| f.write(content) | ||
| return True, changes | ||
| else: | ||
| return False, "No umount() calls found to fix" | ||
|
|
||
|
|
||
| def ensure_sys_umount_declaration(file_path): | ||
| """Ensure sys_umount is declared for kernel 4.9""" | ||
|
|
||
| with open(file_path, 'r') as f: | ||
| content = f.read() | ||
|
|
||
| # Check if already declared | ||
| if 'asmlinkage long sys_umount' in content or 'extern long sys_umount' in content: | ||
| return False, "sys_umount already declared" | ||
|
|
||
| # Add declaration after includes | ||
| declaration = '''/* Kernel 4.9 compatibility */ | ||
| asmlinkage long sys_umount(const char __user *name, int flags); | ||
| ''' | ||
|
|
||
| # Find last #include line | ||
| lines = content.split('\n') | ||
| insert_idx = 0 | ||
| for i, line in enumerate(lines): | ||
| if line.startswith('#include'): | ||
| insert_idx = i + 1 | ||
|
|
||
| lines.insert(insert_idx, declaration) | ||
| content = '\n'.join(lines) | ||
|
|
||
| with open(file_path, 'w') as f: | ||
| f.write(content) | ||
|
|
||
| return True, "Added sys_umount declaration" | ||
|
|
||
|
|
||
| def process_core_hook_files(kernel_dir): | ||
| """Process all possible core_hook.c locations with deduplication""" | ||
|
|
||
| possible_paths = [ | ||
| os.path.join(kernel_dir, 'drivers/kernelsu/core_hook.c'), | ||
| os.path.join(kernel_dir, 'drivers/kernelsu/KernelSU/kernel/core_hook.c'), | ||
| os.path.join(kernel_dir, 'KernelSU/kernel/core_hook.c'), | ||
| os.path.join(kernel_dir, 'KernelSU-Next/kernel/core_hook.c'), | ||
| ] | ||
|
|
||
| results = [] | ||
| seen_paths = set() # Track processed real paths to avoid duplicates | ||
|
|
||
| for path in possible_paths: | ||
| if not os.path.exists(path): | ||
| continue | ||
|
|
||
| real_path = os.path.realpath(path) | ||
|
|
||
| # Skip if we've already processed this real file | ||
| if real_path in seen_paths: | ||
| continue | ||
| seen_paths.add(real_path) | ||
|
|
||
| print(f"\nProcessing: {real_path}") | ||
|
|
||
| # Apply aggressive umount fix | ||
| fixed, msg = aggressive_umount_fix(real_path) | ||
| if fixed: | ||
| print(f" [FIXED] {msg}") | ||
| else: | ||
| print(f" [INFO] {msg}") | ||
|
|
||
| # Ensure declaration exists | ||
| declared, msg = ensure_sys_umount_declaration(real_path) | ||
| if declared: | ||
| print(f" [DECLARED] {msg}") | ||
|
|
||
| results.append((real_path, fixed, declared)) | ||
|
|
||
| return results | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def main(): | ||
| kernel_dir = os.environ.get('KERNEL_DIR', '') | ||
|
|
||
| if len(sys.argv) > 1: | ||
| kernel_dir = sys.argv[1] | ||
|
|
||
| if not kernel_dir: | ||
| print("Usage: KERNEL_DIR=/path/to/kernel python3 fix_kernelsu_49_v39.py [kernel_dir]") | ||
| sys.exit(1) | ||
|
|
||
| print("=" * 60) | ||
| print("KernelSU-Next 4.9 Compatibility Fix v39 (FINAL)") | ||
| print("=" * 60) | ||
| print(f"Kernel directory: {kernel_dir}") | ||
| print("") | ||
| print("This fix aggressively replaces ALL umount() calls with sys_umount()") | ||
| print("It runs AFTER the pre-patched file is applied.") | ||
| print("") | ||
|
|
||
| results = process_core_hook_files(kernel_dir) | ||
|
|
||
| print("\n" + "=" * 60) | ||
| print("SUMMARY") | ||
| print("=" * 60) | ||
|
|
||
| if results: | ||
| for path, fixed, _declared in results: | ||
| status = "FIXED" if fixed else "OK" | ||
| print(f" [{status}] {path}") | ||
| print("\nv39 fix applied. Build should now succeed.") | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return 0 | ||
|
|
||
| print(" WARNING: No core_hook.c files found!") | ||
| print(f" Searched in: {kernel_dir}") | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.