diff --git a/bin/aot.rs b/bin/aot.rs index 047f5429cb82e21b9b2f89bb778ffac5f46e7910..0e3a854d1449523fe217a749ca7e0e4f18d51fd0 100644 --- a/bin/aot.rs +++ b/bin/aot.rs @@ -139,8 +139,8 @@ pub fn gen_app_rto(conf: &RtoConfig) -> i32 { } let mut args: Vec = Vec::new(); - args.push(format!("--output={}.tmp.rto", conf.elf_path)); - args.push(format!("-{}", conf.mode)); + //args.push(format!("--output={}.tmp.rto", conf.elf_path)); + args.push(format!("--{}", conf.mode)); args.push(conf.elf_path.to_owned()); for lib in conf.libs.iter() { args.push(lib.split_whitespace().collect()); @@ -149,7 +149,13 @@ pub fn gen_app_rto(conf: &RtoConfig) -> i32 { if ret != 0 { return ret; } - - ret = fs_ext::move_file(&format!("{}.rto", conf.elf_path), &format!("{}.tmp.rto", conf.elf_path)); + let mut set: Vec = Vec::new(); + set.push("--set-rto".to_string()); + set.push("/usr/bin/bash.rto".to_string()); + ret = run_child(SYSBOOST_PATH, &set); + if ret != 0 { + return ret; + } + //ret = fs_ext::move_file(&format!("{}.rto", conf.elf_path), &format!("{}.tmp.rto", conf.elf_path)); return ret; } diff --git a/bin/daemon.rs b/bin/daemon.rs index 121b55d3281e1b13cd28551bd0909713bf81ab9d..8781d2abea5b3ada9579a6fd46d042dd1665a42d 100644 --- a/bin/daemon.rs +++ b/bin/daemon.rs @@ -11,6 +11,7 @@ use crate::lib::fs_ext; use crate::kmod_util::set_ko_rto_flag; +use crate::kmod_util::set_hpage_rto_flag; use crate::kmod_util::insmod_sysboost_ko; use crate::config::RtoConfig; use crate::config::read_config; @@ -108,22 +109,22 @@ fn process_config(path: PathBuf) -> Option { None => return None, }; - let elf = match parse_elf_file(&conf.elf_path) { - Some(elf) => elf, - None => return None, - }; + //let elf = match parse_elf_file(&conf.elf_path) { + // Some(elf) => elf, + // None => return None, + //}; // auto get lib path // In static-nolibc mode, ld and libc need to be deleted after detection. // In share mode, no detection is performed based on libs. if conf.mode == "static" { - let libs = find_libs(&conf, &elf); - conf.libs = libs; + //let libs = find_libs(&conf, &elf); + //conf.libs = libs; } else if conf.mode == "static-nolibc" { - let mut libs = find_libs(&conf, &elf); - libs.retain(|s| !s.contains(LDSO)); - libs.retain(|s| !s.contains(LIBCSO)); - conf.libs = libs; + //let mut libs = find_libs(&conf, &elf); + //libs.retain(|s| !s.contains(LDSO)); + //libs.retain(|s| !s.contains(LIBCSO)); + //conf.libs = libs; } // add elf file to watch list @@ -182,6 +183,7 @@ fn refresh_all_config(rto_configs: &mut Vec) { if rto_configs.len() > 0 { set_ko_rto_flag(true); + set_hpage_rto_flag(true); } } @@ -257,7 +259,8 @@ fn check_files_modify(inotify: &mut Inotify) -> bool { } fn start_service() { - set_ko_rto_flag(false); + set_ko_rto_flag(true); + set_hpage_rto_flag(true); clean_last_rto(); let mut rto_configs: Vec = Vec::new(); diff --git a/bin/kmod_util.rs b/bin/kmod_util.rs index 193142c6befdfe05282c9231ce751b6ad891996c..8cbc908f85903a7afea8ec4a95c24e0f74651ef0 100644 --- a/bin/kmod_util.rs +++ b/bin/kmod_util.rs @@ -10,22 +10,50 @@ // Create: 2023-8-26 use crate::lib::process_ext::run_child; +use std::fs; const KO_RTO_PARAM_PATH: &str = "/sys/module/sysboost_loader/parameters/use_rto"; +const HPAGE_RTO_PARAM_PATH: &str = "/sys/module/sysboost_loader/parameters/use_hpage"; const KO_PATH: &str = "/lib/modules/sysboost/sysboost_loader.ko"; // echo 1 > /sys/module/sysboost_loader/parameters/use_rto pub fn set_ko_rto_flag(is_set: bool) -> i32 { - let mut args: Vec = Vec::new(); + let mut args; if is_set { - args.push("1".to_string()); + args = "1".to_string(); } else { - args.push("0".to_string()); + args= "0".to_string(); } - args.push(">".to_string()); - args.push(KO_RTO_PARAM_PATH.to_string()); - let ret = run_child("/usr/bin/echo", &args); - return ret; + match fs::write(KO_RTO_PARAM_PATH.to_string(), args) { + Ok(_) => { + return 0; + } + Err(e) => { + log::error!("Error writing use_rto"); + return -1; + } + } + 0 +} + +// echo 1 > /sys/module/sysboost_loader/parameters/use_hpage +pub fn set_hpage_rto_flag(is_set: bool) -> i32 { + let mut args; + if is_set { + args = "1".to_string(); + } else { + args= "0".to_string(); + } + match fs::write(HPAGE_RTO_PARAM_PATH.to_string(), args) { + Ok(_) => { + return 0; + } + Err(e) => { + log::error!("Error writing use_hpage"); + return -1; + } + } + 0 } fn insmod_ko(path: &String) { diff --git a/src/elf_read_elf.c b/src/elf_read_elf.c index 29cd4a781a84ca4a3eaf9766e1d1ab66950b0663..3a1796b14a24feef128d303f4c23d6cdb2dabb7f 100644 --- a/src/elf_read_elf.c +++ b/src/elf_read_elf.c @@ -741,9 +741,9 @@ static int read_relocation_file(char *file_name, elf_file_t *ef) } // Compare the value with the build ID in the ELF file, the length of the build ID is 40 characters. + // In the future, you need to modify related packages to ensure that the build ID of the relocation file is the same as that of the elf file. if (memcmp(ef->build_id, old_build_id, BUILD_ID_LEN) != 0) { - SI_LOG_ERR("build id mismatch for %s\n", rel_file_name); - return -1; + SI_LOG_INFO("build id mismatch for %s\n", rel_file_name); } return 0; diff --git a/src/static_template/static_template.c b/src/static_template/static_template.c index 951c0ec8a0efa309ff0df27c749aa75094a4b1b8..fb7df7eba4d1132e58f0788cd29bf3d7c6246658 100644 --- a/src/static_template/static_template.c +++ b/src/static_template/static_template.c @@ -113,6 +113,7 @@ int main(void) NO_COMPILE_OPTIMIZE("sigfillset"); NO_COMPILE_OPTIMIZE("siglongjmp"); NO_COMPILE_OPTIMIZE("vfprintf"); + NO_COMPILE_OPTIMIZE("arc4random"); #ifdef __aarch64__ // The __stack_chk_guard and __stack_chk_fail symbols are normally supplied by a GCC library called libssp