sys_get_temp_dir();

本文介绍了解决 PHP 中使用 cURL 出现的错误:无法创建临时文件。通过打印系统临时文件夹位置并调整文件夹的安全权限来解决问题。

php出错:curl_setopt_array(): Unable to create temporary file


打印出系统临时文件夹位置(sys_get_temp_dir();),然后在文件夹属性,安全赋予权限

########################## TCL Event Handlers ############################ fanuc_system_A.tcl - lathe## This is a 2-Axis Horizontal Lathe Machine.## Created by Postino @ Fri Mar 9 12:19:40 2018 -0800# with Post Builder version 12.0.2.##########################################################################=============================================================proc PB_CMD___log_revisions { } {#=============================================================# Dummy command to log changes in this post --## 15-Jul-2014 gsl - Initial version# 28-Oct-2015 shuai - Add PB_CMD_uplevel_MOM_generic_cycle to check non-cutting motions.# Output contour data or tracking data based on if UDE (Cutter Compensation)# has been set. Make the return motion output after lathe rough cycle G71/G71.# 05-Nov-2015 shuai - Output finish operation G70 using previous rough contour data# if the subroutine name is same between them.# 25-Dec-2015 shuai - Add command PB_CMD_check_additional_profiling, PB_CMD_check_first_buffer_for_return_motion,# PB_CMD_finish_turn_cycle_contour_start, PB_CMD_finish_turn_cycle_contour_end,# PB_CMD_output_turning_cycle_command, PB_CMD_override_rough_contour_data_with_finish,# PB_CMD_set_contour_motion, PB_CMD_calculate_contour_line_number,# PB_CMD_set_turning_cycle_type and PB_CMD_calculate_parameters_for_turning_cycle_block.# 17-May-2016 Jintao - Add mom_kin_lathe_cycle_workplane_transform to fix PR6763943# 25-Nov-2016 shuai - Improve the functionality of Lathe Rough Cycle (G70/ G71/G72). The following issues have been enhanced.# - 1. In MOM_generic_cycle event:# - 1.1 Remove the checking condition for G70\G71\G72 that whether a from point has been set or not.# - 1.2 If a finish operation uses the previous corresponding contour of a rough turning operation, it will also need to skip to the next generic event.# - 2. Lathe rough cycle has been initialized in MOM_generic_cycle, so remove the command "PB_CMD_init_rough_turn_cycle_output" from proc "PB_approach_move".# - 3. In PB_CMD_init_rough_turn_cycle_output, additional profiling should be checked to fulfill some conditions when initializing contour data.# - 4. Add a new proc "PB_CMD_check_settings_for_additional_profiling" to check the settings for additional profile.# - 5. Add a new proc "PB_CMD_check_variables_for_turning_rough_cycle" to check some variables for turning rough cycle.# - 6. Adjust the line number according to turning operation type in PB_CMD_calculate_contour_line_number so as to get the correct values for parameters P and Q.# - 7. Exclude the own name of rough turning operation from the operation name list in command PB_CMD_turn_cycle_contour_end# when contour data of rough operation is overridden by finish operation.# 13-Dec-2016 shuai - Bug fix PR7290132. Output the correct line number for P and Q no matter the output status of sequence number is ON or OFF.# Delete the original command "PB_CMD_output_spindle". Rename the command "PB_CMD_output_spindle_speed" to "PB_CMD_output_spindle".# Update the command "PB_CMD_calculate_contour_line_number".# 21-Dec-2016 shuai - Bug fix PR7290203.# Refactor the output logic for lathe rough cycle function# to make the events content between the second MOM_generic_cycle (EXCLUDE) and MOM_contour_end (INCLUDE)# output at the end position of MOM_contour_end event.# 1. Update the handlers.# "MOM_linear_move", "MOM_circular_move", "MOM_contour_start" and "MOM_generic_cycle".# 2. Update the commands.# "PB_CMD_calculate_parameters_for_turning_cycle_block", "PB_CMD_finish_turn_cycle_contour_start", "PB_CMD_finish_turn_cycle_contour_end",# "PB_CMD_init_rough_turn_cycle_output", "PB_CMD_output_turning_cycle_command", "PB_CMD_override_rough_contour_data_with_finish",# "PB_CMD_turn_cycle_contour_start", "PB_CMD_turn_cycle_contour_end" and "PB_CMD_uplevel_MOM_generic_cycle".# 3. Delete the commands.# "PB_CMD__check_block_linear_for_rough_turn_cycle", "PB_CMD__check_block_circular_move_for_rough_turn_cycle", "PB_CMD__check_block_skip_for_rough_turn_cycle",# "PB_CMD__check_block_rapid_move_for_return_motion", "PB_CMD_check_first_buffer_for_return_motion" and "PB_CMD_calculate_contour_line_number".# 5. Delete the blocks.# "circular_move_rough_turn_cycle" and "linear_move_rough_turn_cycle".# 6. Enhance the MOM_abort command with "catch" to make it not output error message.# 7. Enhance the temp file name with clock time to make it unique in current output folder.# 25-April-2017 lili - Update implementation of lathe rough cycle function. All related commands please see PB_CMD_init_turn_cycle_setting, PB_CMD_uplevel_MOM_generic_cycle,# PB_CMD_turn_cycle_contour_start and PB_CMD_turn_cycle_contour_end.# Add PB_CMD_init_turn_cycle_setting at "start of program".} set cam_post_dir [MOM_ask_env_var UGII_CAM_POST_DIR] set mom_sys_this_post_dir "[file dirname [info script]]" set mom_sys_this_post_name "[file rootname [file tail [info script]]]" if { ![info exists mom_sys_post_initialized] } { if { ![info exists mom_sys_ugpost_base_initialized] } { source ${cam_post_dir}ugpost_base.tcl set mom_sys_ugpost_base_initialized 1 } set mom_sys_debug_mode OFF if { ![info exists env(PB_SUPPRESS_UGPOST_DEBUG)] } { set env(PB_SUPPRESS_UGPOST_DEBUG) 0 } if { $env(PB_SUPPRESS_UGPOST_DEBUG) } { set mom_sys_debug_mode OFF } if { ![string compare $mom_sys_debug_mode "OFF"] } { proc MOM_before_each_add_var {} {} proc MOM_before_each_event {} {} proc MOM_before_load_address {} {} proc MOM_end_debug {} {} } else { set cam_debug_dir [MOM_ask_env_var UGII_CAM_DEBUG_DIR] source ${cam_debug_dir}mom_review.tcl } #### Listing File variables set mom_sys_list_output "OFF" set mom_sys_header_output "OFF" set mom_sys_list_file_rows "40" set mom_sys_list_file_columns "30" set mom_sys_warning_output "OFF" set mom_sys_warning_output_option "FILE" set mom_sys_group_output "OFF" set mom_sys_list_file_suffix "lpt" set mom_sys_output_file_suffix "ptp" set mom_sys_commentary_output "ON" set mom_sys_commentary_list "x z feed speed" set mom_sys_pb_link_var_mode "OFF" if { [string match "OFF" $mom_sys_warning_output] } { catch { rename MOM__util_print ugpost_MOM__util_print } proc MOM__util_print { args } {} } MOM_set_debug_mode $mom_sys_debug_mode if { [string match "OFF" $mom_sys_warning_output] } { catch { rename MOM__util_print "" } catch { rename ugpost_MOM__util_print MOM__util_print } } #============================================================= proc MOM_before_output { } { #============================================================= # This command is executed just before every NC block is # to be output to a file. # # - Never overload this command! # - Any customization should be done in PB_CMD_before_output! # if { [llength [info commands PB_CMD_kin_before_output]] &&\ [llength [info commands PB_CMD_before_output]] } { PB_CMD_kin_before_output } # Write output buffer to the listing file with warnings global mom_sys_list_output if { [string match "ON" $mom_sys_list_output] } { LIST_FILE } else { global tape_bytes mom_o_buffer if { ![info exists tape_bytes] } { set tape_bytes [string length $mom_o_buffer] } else { incr tape_bytes [string length $mom_o_buffer] } } } if { [string match "OFF" [MOM_ask_env_var UGII_CAM_POST_LINK_VAR_MODE]] } { set mom_sys_link_var_mode "OFF" } else { set mom_sys_link_var_mode "$mom_sys_pb_link_var_mode" } set mom_sys_control_out "(" set mom_sys_control_in ")" set mom_sys_post_initialized 1 } set mom_sys_use_default_unit_fragment "ON" set mom_sys_alt_unit_post_name "fanuc_system_A__MM.pui"########## SYSTEM VARIABLE DECLARATIONS ############## set mom_sys_rapid_code "0" set mom_sys_linear_code "1" set mom_sys_circle_code(CLW) "2" set mom_sys_circle_code(CCLW) "3" set mom_sys_lathe_thread_advance_type(1) "33" set mom_sys_lathe_thread_advance_type(2) "34" set mom_sys_lathe_thread_advance_type(3) "35" set mom_sys_delay_code(SECONDS) "4" set mom_sys_delay_code(REVOLUTIONS) "4" set mom_sys_cutcom_code(OFF) "40" set mom_sys_cutcom_code(LEFT) "41" set mom_sys_cutcom_code(RIGHT) "42" set mom_sys_adjust_code "43" set mom_sys_adjust_code_minus "44" set mom_sys_adjust_cancel_code "49" set mom_sys_unit_code(IN) "20" set mom_sys_unit_code(MM) "21" set mom_sys_cycle_drill_break_chip_code "73" set mom_sys_cycle_off "80" set mom_sys_cycle_drill_code "81" set mom_sys_cycle_drill_deep_code "83" set mom_sys_cycle_drill_dwell_code "82" set mom_sys_cycle_tap_code "84" set mom_sys_cycle_bore_code "85" set mom_sys_output_code(ABSOLUTE) "90" set mom_sys_output_code(INCREMENTAL) "91" set mom_sys_reset_code "50" set mom_sys_feed_rate_mode_code(IPM) "98" set mom_sys_feed_rate_mode_code(IPR) "99" set mom_sys_feed_rate_mode_code(FRN) "93" set mom_sys_spindle_mode_code(SFM) "96" set mom_sys_spindle_mode_code(RPM) "97" set mom_sys_return_code "28" set mom_sys_cycle_ret_code(AUTO) "98" set mom_sys_cycle_ret_code(MANUAL) "99" set mom_sys_program_stop_code "0" set mom_sys_optional_stop_code "1" set mom_sys_end_of_program_code "2" set mom_sys_spindle_direction_code(CLW) "3" set mom_sys_spindle_direction_code(CCLW) "4" set mom_sys_spindle_direction_code(OFF) "5" set mom_sys_tool_change_code "6" set mom_sys_coolant_code(MIST) "7" set mom_sys_coolant_code(ON) "8" set mom_sys_coolant_code(FLOOD) "8" set mom_sys_coolant_code(OFF) "9" set mom_sys_head_code(INDEPENDENT) "21" set mom_sys_head_code(DEPENDENT) "22" set mom_sys_rewind_code "30" set mom_sys_sim_cycle_drill "0" set mom_sys_sim_cycle_drill_dwell "0" set mom_sys_sim_cycle_drill_deep "0" set mom_sys_sim_cycle_drill_break_chip "0" set mom_sys_sim_cycle_tap "0" set mom_sys_sim_cycle_bore "0" set mom_sys_cir_vector "Vector - Arc Start to Center" set mom_sys_spindle_max_rpm_code "50" set mom_sys_spindle_cancel_sfm_code "93" set mom_sys_spindle_ranges "0" set mom_sys_rewind_stop_code "\#" set mom_sys_home_pos(0) "0" set mom_sys_home_pos(1) "0" set mom_sys_home_pos(2) "0" set mom_sys_zero "0" set mom_sys_opskip_block_leader "/" set mom_sys_seqnum_start "10" set mom_sys_seqnum_incr "10" set mom_sys_seqnum_freq "1" set mom_sys_seqnum_max "9999" set mom_sys_lathe_x_double "1" set mom_sys_lathe_i_double "1" set mom_sys_lathe_x_factor "1" set mom_sys_lathe_z_factor "1" set mom_sys_lathe_i_factor "1" set mom_sys_lathe_k_factor "1" set mom_sys_leader(N) "N" set mom_sys_leader(X) "X" set mom_sys_leader(Y) "Y" set mom_sys_leader(Z) "Z" set mom_sys_turret_index(INDEPENDENT) "1" set mom_sys_turret_index(DEPENDENT) "2" set mom_sys_delay_param(SECONDS,format) "Dwell_SECONDS" set mom_sys_delay_param(REVOLUTIONS,format) "Dwell_REVOLUTIONS" set mom_sys_contour_feed_mode(LINEAR) "IPM" set mom_sys_rapid_feed_mode(LINEAR) "IPM" set mom_sys_cycle_feed_mode "IPM" set mom_sys_feed_param(IPM,format) "Feed_IPM" set mom_sys_feed_param(IPR,format) "Feed_IPR" set mom_sys_feed_param(FRN,format) "Feed_INV" set mom_sys_vnc_rapid_dogleg "1" set mom_sys_prev_mach_head "" set mom_sys_curr_mach_head "" set mom_sys_output_cycle95 "1" set mom_sys_lathe_y_factor "1" set mom_sys_head_code(INDEPENDENT) "21" set mom_sys_head_code(DEPENDENT) "22" set mom_sys_advanced_turbo_output "0" set mom_sys_linearization_method "angle" set mom_sys_tool_number_max "32" set mom_sys_tool_number_min "1" set mom_sys_post_description "This is a 2-Axis Horizontal Lathe Machine." set mom_sys_word_separator " " set mom_sys_end_of_block "" set mom_sys_ugpadvkins_used "0" set mom_sys_post_builder_version "12.0.2"####### KINEMATIC VARIABLE DECLARATIONS ############## set mom_kin_4th_axis_center_offset(0) "0.0" set mom_kin_4th_axis_center_offset(1) "0.0" set mom_kin_4th_axis_center_offset(2) "0.0" set mom_kin_4th_axis_max_limit "0.0" set mom_kin_4th_axis_min_incr "0.0" set mom_kin_4th_axis_min_limit "0.0" set mom_kin_4th_axis_point(0) "0.0" set mom_kin_4th_axis_point(1) "0.0" set mom_kin_4th_axis_point(2) "0.0" set mom_kin_4th_axis_zero "0.0" set mom_kin_5th_axis_center_offset(0) "0.0" set mom_kin_5th_axis_center_offset(1) "0.0" set mom_kin_5th_axis_center_offset(2) "0.0" set mom_kin_5th_axis_max_limit "0.0" set mom_kin_5th_axis_min_incr "0.0" set mom_kin_5th_axis_min_limit "0.0" set mom_kin_5th_axis_point(0) "0.0" set mom_kin_5th_axis_point(1) "0.0" set mom_kin_5th_axis_point(2) "0.0" set mom_kin_5th_axis_zero "0.0" set mom_kin_arc_output_mode "FULL_CIRCLE" set mom_kin_arc_valid_plane "XY" set mom_kin_clamp_time "2.0" set mom_kin_dependent_head "NONE" set mom_kin_flush_time "2.0" set mom_kin_ind_to_dependent_head_x "0" set mom_kin_ind_to_dependent_head_z "0" set mom_kin_independent_head "NONE" set mom_kin_linearization_flag "1" set mom_kin_linearization_tol "0.001" set mom_kin_machine_resolution ".0001" set mom_kin_machine_type "lathe" set mom_kin_machine_zero_offset(0) "0.0" set mom_kin_machine_zero_offset(1) "0.0" set mom_kin_machine_zero_offset(2) "0.0" set mom_kin_max_arc_radius "9999.9999" set mom_kin_max_dpm "0.0" set mom_kin_max_fpm "400" set mom_kin_max_fpr "1000" set mom_kin_max_frn "99999.999" set mom_kin_min_arc_length "0.01" set mom_kin_min_arc_radius "0.0001" set mom_kin_min_dpm "0.0" set mom_kin_min_fpm "0.1" set mom_kin_min_fpr "0.001" set mom_kin_min_frn "0.001" set mom_kin_output_unit "IN" set mom_kin_pivot_gauge_offset "0.0" set mom_kin_post_data_unit "IN" set mom_kin_rapid_feed_rate "600" set mom_kin_tool_change_time "0.0" set mom_kin_x_axis_limit "40" set mom_kin_y_axis_limit "40" set mom_kin_z_axis_limit "35"if [llength [info commands MOM_SYS_do_template] ] { if [llength [info commands MOM_do_template] ] { rename MOM_do_template "" } rename MOM_SYS_do_template MOM_do_template}#=============================================================proc MOM_start_of_program { } {#============================================================= global mom_logname mom_date is_from global mom_coolant_status mom_cutcom_status global mom_clamp_status mom_cycle_status global mom_spindle_status mom_cutcom_plane pb_start_of_program_flag global mom_cutcom_adjust_register mom_tool_adjust_register global mom_tool_length_adjust_register mom_length_comp_register global mom_flush_register mom_wire_cutcom_adjust_register global mom_wire_cutcom_status set pb_start_of_program_flag 0 set mom_coolant_status UNDEFINED set mom_cutcom_status UNDEFINED set mom_clamp_status UNDEFINED set mom_cycle_status UNDEFINED set mom_spindle_status UNDEFINED set mom_cutcom_plane UNDEFINED set mom_wire_cutcom_status UNDEFINED catch {unset mom_cutcom_adjust_register} catch {unset mom_tool_adjust_register} catch {unset mom_tool_length_adjust_register} catch {unset mom_length_comp_register} catch {unset mom_flush_register} catch {unset mom_wire_cutcom_adjust_register} set is_from "" catch { OPEN_files } ;# Open warning and listing files LIST_FILE_HEADER ;# List header in commentary listing global mom_sys_post_initialized if { $mom_sys_post_initialized > 1 } { return } set ::mom_sys_start_program_clock_seconds [clock seconds] # Load parameters for alternate output units PB_load_alternate_unit_settings rename PB_load_alternate_unit_settings ""#************uplevel #0 {#=============================================================proc MOM_sync { } {#============================================================= if [llength [info commands PB_CMD_kin_handle_sync_event] ] { PB_CMD_kin_handle_sync_event }}#=============================================================proc MOM_set_csys { } {#============================================================= if [llength [info commands PB_CMD_kin_set_csys] ] { PB_CMD_kin_set_csys }}#=============================================================proc MOM_msys { } {#=============================================================}#=============================================================proc MOM_end_of_program { } {#===================
09-07
#include "sc_hook.h" #include <linux/kthread.h> MODULE_AUTHOR("xfliu"); MODULE_DESCRIPTION("Syscall hook"); MODULE_VERSION("0.01"); static sys_call_ptr_t* sys_call_table; sys_call_ptr_t old_sys_table[MAX_SC_IDX]; int hook_sys_table[sc_end_type]; char hook_sys_name[sc_end_type][16]; atomic_t sc_ref_table[sc_end_type]; char* cur_module = NULL; #define SC_FUNC_PART #ifdef SC_FUNC_PART int num=0; static struct task_struct *kthread = NULL; //此逻辑与架构无关 static int sc_hook_process(int sc_map_idx, int sc_table_idx, const char* file_name) { int name_len = 0; int ret = 0; if (!task_ctx) { return 0; } if (file_name) { SC_DEBUG(sc_debug, KERN_INFO "open file :%s\n", file_name); if (IsFileIgnore(file_name)) { return 0; } name_len = strlen(task_ctx->sc_task[sc_table_idx].filename); // no file_name : hook action if (0 == name_len) ret = 0; // have file_name name but current name not equals file_name : pass else if (0 != strcmp(file_name, task_ctx->sc_task[sc_table_idx].filename)) ret = 1; // have file_name name and current name not equals file_name : hook // actions else ret = 0; } if (1 == ret) return 0; // check fault rate and decide whether hook action or not if (task_ctx->sc_task[sc_table_idx].sc_para[sc_map_idx].drop_rate > 0) { ret = process_drop(&task_ctx->sc_task[sc_table_idx].sc_para[sc_map_idx]); if (NF_ACCEPT == ret) { SC_DEBUG(sc_debug, KERN_INFO "systemcall miss this time:%d\n", sc_table_idx); return 0; } } else { SC_DEBUG(sc_debug, KERN_INFO "systemcall null:%d\n", sc_table_idx); return 0; } SC_DEBUG( sc_debug, KERN_INFO "systemcall match this time:%d\n", sc_table_idx); if (task_ctx->sc_task[sc_table_idx].sc_para[sc_map_idx].err_code) { SC_DEBUG(sc_debug, KERN_INFO "systemcall err_code[%d]:%d\n", task_ctx->sc_task[sc_table_idx].sc_para[sc_map_idx].err_code, sc_table_idx); return -task_ctx->sc_task[sc_table_idx].sc_para[sc_map_idx].err_code; } if (task_ctx->sc_task[sc_table_idx].sc_para[sc_map_idx].delay_time) { SC_DEBUG(sc_debug, KERN_INFO "systemcall sleep[%d]:%d\n", task_ctx->sc_task[sc_table_idx].sc_para[sc_map_idx].delay_time, sc_table_idx); msleep(task_ctx->sc_task[sc_table_idx].sc_para[sc_map_idx].delay_time); } SC_DEBUG(sc_debug, KERN_INFO "systemcall do nothing:%d\n", sc_table_idx); return 0; } # ifdef PTREGS_SYSCALL_STUBS static long ref_sys_process(const struct pt_regs* regs, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = (old_sys_table[sc_idx])(regs); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_open(const struct pt_regs* regs) { char filetemp[256] = {0}; if (copy_from_user(filetemp, (char*)regs->regs[1], sizeof(filetemp))) { return ref_sys_process(regs, __NR_openat, sc_open_type); } int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_openat, sc_open_type); //__NR_open ret = check_if_hook(sc_open_type); if (ret < 0) return ref_sys_process(regs, __NR_openat, sc_open_type); return sc_hook_process(sc_open_type, ret, filetemp); } static asmlinkage long hook_write(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_write, sc_write_type); ret = check_if_hook(sc_write_type); if (ret < 0) return ref_sys_process(regs, __NR_write, sc_write_type); return sc_hook_process(sc_write_type, ret, NULL); } static asmlinkage long hook_read(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_read, sc_read_type); ret = check_if_hook(sc_read_type); if (ret < 0) return ref_sys_process(regs, __NR_read, sc_read_type); return sc_hook_process(sc_read_type, ret, NULL); } static asmlinkage long hook_accept(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_accept, sc_accept_type); ret = check_if_hook(sc_accept_type); if (ret < 0) return ref_sys_process(regs, __NR_accept, sc_accept_type); return sc_hook_process(sc_accept_type, ret, NULL); } static asmlinkage long hook_connect(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_connect, sc_connect_type); ret = check_if_hook(sc_connect_type); if (ret < 0) return ref_sys_process(regs, __NR_connect, sc_connect_type); return sc_hook_process(sc_connect_type, ret, NULL); } static asmlinkage long hook_sendto(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_sendto, sc_send_type); ret = check_if_hook(sc_send_type); if (ret < 0) return ref_sys_process(regs, __NR_sendto, sc_send_type); return sc_hook_process(sc_send_type, ret, NULL); } static asmlinkage long hook_recvfrom(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_recvfrom, sc_recv_type); ret = check_if_hook(sc_recv_type); if (ret < 0) return ref_sys_process(regs, __NR_recvfrom, sc_recv_type); return sc_hook_process(sc_recv_type, ret, NULL); } static asmlinkage long hook_lseek(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_lseek, sc_lseek_type); ret = check_if_hook(sc_lseek_type); if (ret < 0) return ref_sys_process(regs, __NR_lseek, sc_lseek_type); return sc_hook_process(sc_lseek_type, ret, NULL); } static asmlinkage long hook_fsync(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_fsync, sc_fsync_type); ret = check_if_hook(sc_fsync_type); if (ret < 0) return ref_sys_process(regs, __NR_fsync, sc_fsync_type); return sc_hook_process(sc_fsync_type, ret, NULL); } static asmlinkage long hook_socket(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_socket, sc_socket_type); ret = check_if_hook(sc_socket_type); if (ret < 0) return ref_sys_process(regs, __NR_socket, sc_socket_type); return sc_hook_process(sc_socket_type, ret, NULL); } static long asmlinkage hook_bind(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_bind, sc_bind_type); ret = check_if_hook(sc_bind_type); if (ret < 0) return ref_sys_process(regs, __NR_bind, sc_bind_type); return sc_hook_process(sc_bind_type, ret, NULL); } static asmlinkage long hook_listen(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_listen, sc_listen_type); ret = check_if_hook(sc_listen_type); if (ret < 0) return ref_sys_process(regs, __NR_listen, sc_listen_type); return sc_hook_process(sc_listen_type, ret, NULL); } static asmlinkage long hook_mount(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_mount, sc_mount_type); ret = check_if_hook(sc_mount_type); if (ret < 0) return ref_sys_process(regs, __NR_mount, sc_mount_type); return sc_hook_process(sc_mount_type, ret, NULL); } static asmlinkage long hook_umount(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_umount2, sc_umount2_type); ret = check_if_hook(sc_umount2_type); if (ret < 0) return ref_sys_process(regs, __NR_umount2, sc_umount2_type); return sc_hook_process(sc_umount2_type, ret, NULL); } static asmlinkage long hook_ioctl(const struct pt_regs* regs) { int ret = 0; if (!task_ctx) return ref_sys_process(regs, __NR_ioctl, sc_ioctl_type); ret = check_if_hook(sc_ioctl_type); if (ret < 0) return ref_sys_process(regs, __NR_ioctl, sc_ioctl_type); return sc_hook_process(sc_ioctl_type, ret, NULL); } # else typedef long (*open_sys)(const char __user* filename, int flags, int mode); static long ref_open_process(const char __user* filename, int flags, int mode, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((open_sys) old_sys_table[sc_idx])(filename, flags, mode); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_open(const char __user* filename, int flags, int mode) { char filetemp[256] = {0}; int ret = 0; if (copy_from_user(filetemp, filename, sizeof(filetemp))) { return ref_open_process(filename, flags, mode, __NR_open, sc_open_type); } if (!task_ctx) return ref_open_process(filename, flags, mode, __NR_open, sc_open_type); ret = check_if_hook(sc_open_type); if (ret < 0) return ref_open_process(filename, flags, mode, __NR_open, sc_open_type); return sc_hook_process(sc_open_type, ret, filetemp); } typedef long (*fs_sys)(unsigned int fd, const char __user* buf, size_t count); static long ref_fs_process(unsigned int fd, const char __user* buf, size_t count, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((fs_sys) old_sys_table[sc_idx])(fd, buf, count); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_read(unsigned int fd, char __user* buf, size_t count) { int ret = 0; if (!task_ctx) return ref_fs_process(fd, buf, count, __NR_read, sc_read_type); ret = check_if_hook(sc_read_type); if (ret < 0) return ref_fs_process(fd, buf, count, __NR_read, sc_read_type); return sc_hook_process(sc_read_type, ret, NULL); } static asmlinkage long hook_write(unsigned int fd, const char __user* buf, size_t count) { int ret = 0; if (!task_ctx || fd <= 2) return ref_fs_process(fd, buf, count, __NR_write, sc_write_type); ret = check_if_hook(sc_write_type); if (ret < 0) return ref_fs_process(fd, buf, count, __NR_write, sc_write_type); return sc_hook_process(sc_write_type, ret, NULL); } typedef long (*socket_sys)(int family, int type, int protocol); static long ref_socket_process(int family, int type, int protocol, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((socket_sys) old_sys_table[sc_idx])(family, type, protocol); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_socket(int family, int type, int protocol) { int ret = 0; if (!task_ctx) return ref_socket_process(family, type, protocol, __NR_socket, sc_socket_type); ret = check_if_hook(sc_socket_type); if (ret < 0) return ref_socket_process(family, type, protocol, __NR_socket, sc_socket_type); return sc_hook_process(sc_socket_type, ret, NULL); } typedef long (*bind_sys)(int fd, struct sockaddr __user *umyaddr, int addrlen); static long ref_bind_process(int fd, struct sockaddr __user *umyaddr, int addrlen, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((bind_sys) old_sys_table[sc_idx])(fd, umyaddr, addrlen); atomic_dec(&sc_ref_table[sc_type]); return ret; } static long asmlinkage hook_bind(int fd, struct sockaddr __user *umyaddr, int addrlen) { int ret = 0; if (!task_ctx) return ref_bind_process(fd, umyaddr, addrlen, __NR_bind, sc_bind_type); ret = check_if_hook(sc_bind_type); if (ret < 0) return ref_bind_process(fd, umyaddr, addrlen, __NR_bind, sc_bind_type); return sc_hook_process(sc_bind_type, ret, NULL); } typedef long (*listen_sys)(int fd, int backlog); static long ref_listen_process(int fd, int backlog, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((listen_sys) old_sys_table[sc_idx])(fd, backlog); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_listen(int fd, int backlog) { int ret = 0; if (!task_ctx) return ref_listen_process(fd, backlog, __NR_listen, sc_listen_type); ret = check_if_hook(sc_listen_type); if (ret < 0) return ref_listen_process(fd, backlog, __NR_listen, sc_listen_type); return sc_hook_process(sc_listen_type, ret, NULL); } typedef long (*netp_sys)(int, struct sockaddr __user*, int __user*); static long ref_netp_process(int fd, struct sockaddr __user* user, int __user* id, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((netp_sys) old_sys_table[sc_idx])(fd, user, id); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_accept(int fd, struct sockaddr __user* user, int __user* id) { int ret = 0; if (!task_ctx) return ref_netp_process(fd, user, id, __NR_accept, sc_accept_type); ret = check_if_hook(sc_accept_type); if (ret < 0) return ref_netp_process(fd, user, id, __NR_accept, sc_accept_type); return sc_hook_process(sc_accept_type, ret, NULL); } typedef long (*neti_sys)(int, struct sockaddr __user*, int); static long ref_neti_process(int fd, struct sockaddr __user* user, int id, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((neti_sys) old_sys_table[sc_idx])(fd, user, id); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_connect(int fd, struct sockaddr __user* user, int id) { int ret = 0; if (!task_ctx) return ref_neti_process(fd, user, id, __NR_connect, sc_connect_type); ret = check_if_hook(sc_connect_type); if (ret < 0) return ref_neti_process(fd, user, id, __NR_connect, sc_connect_type); return sc_hook_process(sc_connect_type, ret, NULL); } typedef long (*netli_sys)(int, void __user*, size_t, unsigned, struct sockaddr __user*, int); static long ref_netli_process(int fd, void __user* user, size_t len, unsigned id, struct sockaddr __user* addr, int l_len, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((netli_sys) old_sys_table[sc_idx])(fd, user, len, id, addr, l_len); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_sendto(int fd, void __user* user, size_t len, unsigned id, struct sockaddr __user* addr, int l_len) { int ret = 0; if (!task_ctx) return ref_netli_process(fd, user, len, id, addr, l_len, __NR_sendto, sc_send_type); ret = check_if_hook(sc_send_type); if (ret < 0) return ref_netli_process(fd, user, len, id, addr, l_len, __NR_sendto, sc_send_type); return sc_hook_process(sc_send_type, ret, NULL); } typedef long (*netlp_sys)(int, void __user*, size_t, unsigned, struct sockaddr __user*, int __user*); static long ref_netlp_process(int fd, void __user* user, size_t len, unsigned id, struct sockaddr __user* addr, int __user* l_len, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((netlp_sys) old_sys_table[sc_idx])(fd, user, len, id, addr, l_len); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_recvfrom(int fd, void __user* user, size_t len, unsigned id, struct sockaddr __user* addr, int __user* l_len) { int ret = 0; if (!task_ctx) return ref_netlp_process(fd, user, len, id, addr, l_len, __NR_recvfrom, sc_recv_type); ret = check_if_hook(sc_recv_type); if (ret < 0) return ref_netlp_process(fd, user, len, id, addr, l_len, __NR_recvfrom, sc_recv_type); return sc_hook_process(sc_recv_type, ret, NULL); } typedef long (*mount_sys)(char __user *dev_name, char __user *dir_name, char __user *type, unsigned long flags, void __user *data); static long ref_mount_process(char __user *dev_name, char __user *dir_name, char __user *type, unsigned long flags, void __user *data, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((mount_sys) old_sys_table[sc_idx])(dev_name, dir_name, type, flags, data); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_mount(char __user *dev_name, char __user *dir_name, char __user *type, unsigned long flags, void __user *data) { int ret = 0; if (!task_ctx) return ref_mount_process(dev_name, dir_name, type, flags, data, __NR_mount, sc_mount_type); ret = check_if_hook(sc_mount_type); if (ret < 0) return ref_mount_process(dev_name, dir_name, type, flags, data, __NR_mount, sc_mount_type); return sc_hook_process(sc_mount_type, ret, NULL); } typedef long (*umount_sys)(char __user *name, int flags); static long ref_umount_process(char __user *name, int flags, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((umount_sys) old_sys_table[sc_idx])(name, flags); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_umount(char __user *name, int flags) { int ret = 0; if (!task_ctx) return ref_umount_process(name, flags, __NR_umount2, sc_umount2_type); ret = check_if_hook(sc_umount2_type); if (ret < 0) return ref_umount_process(name, flags, __NR_umount2, sc_umount2_type); return sc_hook_process(sc_umount2_type, ret, NULL); } typedef long (*ioctl_sys)(unsigned int fd, unsigned int cmd, unsigned long arg); static long ref_ioctl_process(unsigned int fd, unsigned int cmd, unsigned long arg, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((ioctl_sys) old_sys_table[sc_idx])(fd, cmd, arg); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { int ret = 0; if (!task_ctx) return ref_ioctl_process(fd, cmd, arg, __NR_ioctl, sc_ioctl_type); ret = check_if_hook(sc_ioctl_type); if (ret < 0) return ref_ioctl_process(fd, cmd, arg, __NR_ioctl, sc_ioctl_type); return sc_hook_process(sc_ioctl_type, ret, NULL); } typedef long (*lseek_sys)(unsigned int fd, off_t offset, unsigned int whence); static long ref_lseek_process(unsigned int fd, off_t offset, unsigned int whence, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((lseek_sys) old_sys_table[sc_idx])(fd, offset, whence); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_lseek(unsigned int fd, off_t offset, unsigned int whence) { int ret = 0; if (!task_ctx) return ref_lseek_process(fd, offset, whence, __NR_lseek, sc_lseek_type); ret = check_if_hook(sc_lseek_type); if (ret < 0) return ref_lseek_process(fd, offset, whence, __NR_lseek, sc_lseek_type); return sc_hook_process(sc_lseek_type, ret, NULL); } typedef long (*fsync_sys)(unsigned int fd); static long ref_fsync_process(unsigned int fd, int sc_idx, int sc_type) { int ret = 0; atomic_inc(&sc_ref_table[sc_type]); ret = ((fsync_sys) old_sys_table[sc_idx])(fd); atomic_dec(&sc_ref_table[sc_type]); return ret; } static asmlinkage long hook_fsync(unsigned int fd) { int ret = 0; if (!task_ctx) return ref_fsync_process(fd, __NR_fsync, sc_fsync_type); ret = check_if_hook(sc_fsync_type); if (ret < 0) return ref_fsync_process(fd, __NR_fsync, sc_fsync_type); return sc_hook_process(sc_fsync_type, ret, NULL); } # endif // end for PTREGS_SYSCALL_STUBS #endif // end for SC_FUNC_PART #define LOCAL_FUNC #ifdef LOCAL_FUNC #if 1 //初版 static int sysm_info_mgr(sys_call_ptr_t hook_fn, int sc_idx, int sc_type) { hook_sys_table[sc_type] = sc_idx; printk("sysm_info_mgr sc_type:%d,index:%d \n", sc_type, sc_idx); strcpy(hook_sys_name[sc_type], cur_module); old_sys_table[sc_idx] = sys_call_table[sc_idx]; printk("sysm_info_mgr sc_type,index999999999999999999\n"); printk("准备读写入内核操作\n"); disable_write_protect(); sys_call_table[sc_idx] = hook_fn; enable_write_protect(); printk("准备读写入内核操作完成9999999\n"); return 0; } #endif #if 0 //初版 static void release_sc(void) { int i = 0; int timer = 0; bool bFInd = true; long long timecount = 0; disable_write_protect(); for (; i < sc_end_type; i++) { sys_call_table[hook_sys_table[i]] = old_sys_table[hook_sys_table[i]]; printk("system-call:%dindex:%d \n", i, hook_sys_table[i]); } enable_write_protect(); /* unload system-call is tough trouble, i will explain it for you as the * followings as we all know, system-call may in a blocked state. * something horrible may happen when we do release_sc while a process * stuck in a blocked state by system-call. cus the code segment was * freed once we rmmod the ko. however, when blocked systerm-call wake * up, it returns to the disappreared code segment. and this case may * panic kernel. * * to prevent this happen, i have tryed a lot ways but not found a * perfect one till now. a sc-reference protected by lock may work, but * i give it up for the perfomance, use a atomic value instead! anyway, * this is a dangerous function. remember to FIXME when you got an * better idea */ while (1) { //如果某个系统调用被频繁使用,引用计数可能永远不会降为0,导致无限等待,会不会出现这种情况呢。 // every 1s tells users that where we stuck in if (timer / 1000 >= 1) { timer = 0; for (i = 0; i < sc_end_type; i++) { if (atomic_read(&sc_ref_table[i]) > 0) { bFInd = false; printk("system-call:%s is in use(%d) now, wait it to " "exit\n", hook_sys_name[i], atomic_read(&sc_ref_table[i])); } } if (bFInd) { printk("module-sc-%s removed.\n", hook_sys_name[i]); break; } } msleep(ms_nap); timer += ms_nap; timecount += ms_nap; if (timecount > 10 * 1000) { printk("module-sc-%s removed.\n", hook_sys_name[i]); break; } } } #endif #if 1 //rmmod卸载问题修改 static void release_sc(void) { int i = 0; int wait_count = 0; const int MAX_WAIT = 300; // 最大等待30秒 (300 * 100ms) // 1. 首先解除所有钩子 disable_write_protect(); for (i = 0; i < sc_end_type; i++) { if (hook_sys_table[i] > 0) { sys_call_table[hook_sys_table[i]] = old_sys_table[hook_sys_table[i]]; printk("unhook system-call:%d, index:%d\n", i, hook_sys_table[i]); } } enable_write_protect(); // 2. 等待引用计数归零,但有超时机制 for (wait_count = 0; wait_count < MAX_WAIT; wait_count++) { bool all_zero = true; for (i = 0; i < sc_end_type; i++) { int ref_count = atomic_read(&sc_ref_table[i]); if (ref_count > 0) { all_zero = false; if (wait_count % 10 == 0) { // 每1秒打印一次 printk("waiting for %s, refcount: %d\n", hook_sys_name[i], ref_count); } break; } } if (all_zero) { printk("all system calls released successfully\n"); break; } msleep(100); // 等待100ms } if (wait_count >= MAX_WAIT) { printk("warning: forced unload after timeout, some syscalls may still be in use\n"); } // 3. 清理状态 for (i = 0; i < sc_end_type; i++) { hook_sys_table[i] = 0; hook_sys_name[i][0] = '\0'; } } #endif #endif #if 1 //初版 //挂钩子崩溃 static int sc_reg(void) { int i = 0; int ret = 0; for (; i < sc_end_type; i++) { atomic_set(&sc_ref_table[i], 0); } // hook open cur_module = "open"; # ifdef PTREGS_SYSCALL_STUBS ret = sysm_info_mgr(hook_open, __NR_openat, sc_open_type); # else ret = sysm_info_mgr((sys_call_ptr_t) hook_open, __NR_open, sc_open_type); # endif if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_open_type]); } // hook read cur_module = "read"; ret = sysm_info_mgr((sys_call_ptr_t) hook_read, __NR_read, sc_read_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_read_type]); } // hook write cur_module = "write"; ret = sysm_info_mgr((sys_call_ptr_t) hook_write, __NR_write, sc_write_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_write_type]); } // hook lseek cur_module = "hook_lseek"; ret = sysm_info_mgr((sys_call_ptr_t) hook_lseek, __NR_lseek, sc_lseek_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_lseek_type]); } // hook fsync cur_module = "hook_fsync"; ret = sysm_info_mgr((sys_call_ptr_t) hook_fsync, __NR_fsync, sc_fsync_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_fsync_type]); } // hook socket cur_module = "socket"; ret = sysm_info_mgr((sys_call_ptr_t) hook_socket, __NR_socket, sc_socket_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_socket_type]); } //hook bind cur_module = "bind"; ret = sysm_info_mgr((sys_call_ptr_t) hook_bind, __NR_bind, sc_bind_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_bind_type]); } //hook listen cur_module = "listen"; ret = sysm_info_mgr((sys_call_ptr_t) hook_listen, __NR_listen, sc_listen_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_listen_type]); } // hook accept cur_module = "accept"; ret = sysm_info_mgr( (sys_call_ptr_t) hook_accept, __NR_accept, sc_accept_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_accept_type]); } // hook connect cur_module = "connect"; ret = sysm_info_mgr((sys_call_ptr_t) hook_connect, __NR_connect, sc_connect_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_connect_type]); } // hook send/sendto cur_module = "sendto-send"; ret = sysm_info_mgr((sys_call_ptr_t) hook_sendto, __NR_sendto, sc_send_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_send_type]); } // hook recv/recvfrom cur_module = "recvfrom-recv"; ret = sysm_info_mgr( (sys_call_ptr_t) hook_recvfrom, __NR_recvfrom, sc_recv_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_recv_type]); } // hook mount cur_module = "mount"; ret = sysm_info_mgr((sys_call_ptr_t) hook_mount, __NR_mount, sc_mount_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_mount_type]); } // hook umount cur_module = "umount"; ret = sysm_info_mgr((sys_call_ptr_t) hook_umount, __NR_umount2, sc_umount2_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_umount2_type]); } // hook ioctl cur_module = "hook_ioctl"; ret = sysm_info_mgr((sys_call_ptr_t) hook_ioctl, __NR_ioctl, sc_ioctl_type); if (0 != ret) { printk("ERROR: hook %s failed\n", cur_module); return 1; } else { printk("module-sc-%s inserted.\n", hook_sys_name[sc_ioctl_type]); } // FIXME TODO HERE return 0; } #endif static int reader_thread(void *data) { while (!kthread_should_stop()) { // printk(KERN_INFO "test content: %s\n", test); // printk(KERN_INFO "buffer content: %s\n", buffer); printk(KERN_INFO "process: %s\n", task_ctx->sc_task[1].process); printk(KERN_INFO "pid: %s\n", task_ctx->sc_task[1].pid); printk(KERN_INFO "start_time: %d\n", task_ctx->sc_task[1].start_time); msleep(1000); // Sleep for 1 second } return 0; } static int __init scm_init(void) { // get sys_call_table sys_call_table = get_sysm_name();//内核,获取系统调用表 if (!sys_call_table) { printk("%s-%s insert error, no sys_call_table\n", MODULE_NAME, __func__); return 1; } if (0 != sc_reg()) goto release_resource; printk(KERN_INFO "不挂钩子正常获取到了内核table1111111111111111"); // netfiletr mode init if (nf) { if (0 != nf_reg()) { printk("netfilter-%s insert error,失败99999999999, register failed\n", __func__); goto release_resource; } printk("%s-%s inserted with nf,成功999999999999999999999999\n", MODULE_NAME, __func__); } else { printk("%s-%s inserted without nf\n", MODULE_NAME, __func__); } // shm module init if (insert_dev) { // shm_size = sizeof(chaosRunTaskCtlTabInline); printk("shm初始化成功91111111111111111\n"); printk("dev_reg-------------------\n"); if (0 != dev_reg()) { printk("%s-%s insert error, dev register failed\n",MODULE_NAME,__func__); goto release_resource; } printk("%s-%s inserted with dev\n", MODULE_NAME, __func__); } else { printk("%s-%s inserted without dev\n", MODULE_NAME, __func__); } // kthread = kthread_run(reader_thread, NULL, "sc_hook"); printk("task_ctx is %p, shm_size is %d(%lu)-----------------\n", task_ctx, shm_size, sizeof(chaosRunTaskCtlTabInline)); if(task_ctx) { printk("task_ctx init\n"); } else { printk("task_ctx init error\n"); } return 0; release_resource: release_sc(); nf_unreg(); return 1; } #if 0 //初版 static void __exit scm_exit(void) { if (insert_dev) dev_unreg(); printk("release nf\n"); if (nf) nf_unreg(); release_sc(); printk("%s-%s removed.\n", MODULE_NAME, __func__); // wait for a while for safety printk("wait netfilter exit(%dms)\n", NF_TIMEOUT); msleep(NF_TIMEOUT); printk("release shm dev:%s\n", MODULE_NAME); } #endif //rmmod卸载问题 static void __exit scm_exit(void) { printk("starting module unload...\n"); // 2. 释放系统调用钩子 printk("releasing system call hooks...\n"); release_sc(); // 3. 释放netfilter printk("releasing netfilter...\n"); if (nf) nf_unreg(); // 4. 最后释放设备 printk("releasing device...\n"); if (insert_dev) dev_unreg(); printk("%s-%s removed successfully.\n", MODULE_NAME, __func__); } module_init(scm_init); module_exit(scm_exit);在调用钩子函数时disable_write_protect总是崩溃,我想知道在arm架构下的读写还可以怎么实现
10-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值