| 135 | |
| 136 | |
| 137 | int xh_core_register(const char *pathname_regex_str, const char *symbol, |
| 138 | void *new_func, void **old_func) |
| 139 | { |
| 140 | xh_core_hook_info_t *hi; |
| 141 | regex_t regex; |
| 142 | |
| 143 | if(NULL == pathname_regex_str || NULL == symbol || NULL == new_func) return XH_ERRNO_INVAL; |
| 144 | |
| 145 | if(xh_core_inited) |
| 146 | { |
| 147 | XH_LOG_ERROR("do not register hook after refresh(): %s, %s", pathname_regex_str, symbol); |
| 148 | return XH_ERRNO_INVAL; |
| 149 | } |
| 150 | |
| 151 | if(0 != regcomp(®ex, pathname_regex_str, REG_NOSUB)) return XH_ERRNO_INVAL; |
| 152 | |
| 153 | if(NULL == (hi = malloc(sizeof(xh_core_hook_info_t)))) return XH_ERRNO_NOMEM; |
| 154 | if(NULL == (hi->symbol = strdup(symbol))) |
| 155 | { |
| 156 | free(hi); |
| 157 | return XH_ERRNO_NOMEM; |
| 158 | } |
| 159 | #if XH_CORE_DEBUG |
| 160 | if(NULL == (hi->pathname_regex_str = strdup(pathname_regex_str))) |
| 161 | { |
| 162 | free(hi->symbol); |
| 163 | free(hi); |
| 164 | return XH_ERRNO_NOMEM; |
| 165 | } |
| 166 | #endif |
| 167 | hi->pathname_regex = regex; |
| 168 | hi->new_func = new_func; |
| 169 | hi->old_func = old_func; |
| 170 | |
| 171 | pthread_mutex_lock(&xh_core_mutex); |
| 172 | TAILQ_INSERT_TAIL(&xh_core_hook_info, hi, link); |
| 173 | pthread_mutex_unlock(&xh_core_mutex); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | int xh_core_ignore(const char *pathname_regex_str, const char *symbol) |
| 179 | { |