当前位置: 首页 > news >正文

武汉 网站设计怎么优化百度关键词

武汉 网站设计,怎么优化百度关键词,网站秒收录工具,wordpress简约新闻自媒体主题排查内存问题(或相关的疑难杂症)时,可能一句printf就能让bug出现,或者赶走bug。你可能觉得很神奇,但这并不神奇。 至少我们可以在 Linux-x64 下,通过 malloc hook,来验证当前的编译环境下&…

排查内存问题(或相关的疑难杂症)时,可能一句printf就能让bug出现,或者赶走bug。你可能觉得很神奇,但这并不神奇。

至少我们可以在 Linux-x64 下,通过 malloc hook,来验证当前的编译环境下, printf 确实是调用了 malloc。 而 malloc 底层也不是吃素的, 默认是 glibc 的 ptmalloc 这个内存管理器, 如果本身你的程序把内存控制块写坏了, 继续 malloc 那就容易出现问题, 也就表现为 printf 影响了 bug 的出现。

来看代码。 伸手党可以直接看 godbolt:
https://godbolt.org/z/PPYMW613d
在这里插入图片描述

hook.c

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
#include <malloc.h> // malloc_usable_size
#include <inttypes.h>
#include <pthread.h>// 颜色定义
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define RESET "\x1b[0m"// 线程局部存储防止递归
static __thread int reentrancy_guard = 0;// 真实函数指针
static void* (*real_malloc)(size_t size) = NULL;
static void (*real_free)(void* ptr) = NULL;
static void* (*real_realloc)(void* ptr, size_t size) = NULL;// 初始化函数,使用 pthread_once 确保只初始化一次
static pthread_once_t init_once = PTHREAD_ONCE_INIT;static void init_real_functions() {//real_malloc = dlsym(RTLD_NEXT, "malloc");real_malloc = (void* (*)(size_t))dlsym(RTLD_NEXT, "malloc");real_free = (void (*)(void*))dlsym(RTLD_NEXT, "free");real_realloc = (void* (*)(void*, size_t))dlsym(RTLD_NEXT, "realloc");if (!real_malloc || !real_free || !real_realloc) {const char *error = "Error in `dlsym`\n";write(STDERR_FILENO, error, sizeof("Error in `dlsym`\n") - 1);_exit(1);}
}// malloc 钩子实现
void* malloc(size_t size) {if (reentrancy_guard) {return real_malloc ? real_malloc(size) : NULL;}pthread_once(&init_once, init_real_functions);reentrancy_guard++;void* ptr = real_malloc(size);reentrancy_guard--;if (ptr) {char buffer[256];int len = snprintf(buffer, sizeof(buffer), BLUE "malloc %ld %p\n" RESET, size, ptr);write(STDERR_FILENO, buffer, len);}return ptr;
}// free 钩子实现
void free(void* ptr) {if (reentrancy_guard) {if (real_free) real_free(ptr);return;}pthread_once(&init_once, init_real_functions);reentrancy_guard++;if (ptr) {size_t size = malloc_usable_size(ptr);char buffer[256];int len = snprintf(buffer, sizeof(buffer), GREEN "free %ld %p\n" RESET, size, ptr);write(STDERR_FILENO, buffer, len);}real_free(ptr);reentrancy_guard--;
}// realloc 钩子实现
void* realloc(void* ptr, size_t size) {if (reentrancy_guard) {return real_realloc ? real_realloc(ptr, size) : NULL;}pthread_once(&init_once, init_real_functions);reentrancy_guard++;void* new_ptr = real_realloc(ptr, size);reentrancy_guard--;if (new_ptr) {char buffer[256];int len = snprintf(buffer, sizeof(buffer), YELLOW "realloc %ld %p %p\n" RESET, size, ptr, new_ptr);write(STDERR_FILENO, buffer, len);}return new_ptr;
}

编译:

gcc -shared -fPIC hook4.c -o hook.so -ldl -O2

使用

int main()
{printf("Hello, World");return 0;
}
g++ main.cpp
LD_PRELOAD=./hook.so ./a.out

输出内容:

malloc 4096 0x3a842b0
Hello, World

文章转载自:
http://mithraistic.c7501.cn
http://clothback.c7501.cn
http://leucotome.c7501.cn
http://cytochalasin.c7501.cn
http://linenfold.c7501.cn
http://triable.c7501.cn
http://unshakably.c7501.cn
http://phidias.c7501.cn
http://platte.c7501.cn
http://midsplit.c7501.cn
http://restitution.c7501.cn
http://bargee.c7501.cn
http://waterlocked.c7501.cn
http://cephalometry.c7501.cn
http://quantophrenia.c7501.cn
http://discriminatory.c7501.cn
http://fearnought.c7501.cn
http://halfhearted.c7501.cn
http://fairy.c7501.cn
http://aforethought.c7501.cn
http://prayerful.c7501.cn
http://sermon.c7501.cn
http://denigrate.c7501.cn
http://graphomaniac.c7501.cn
http://thecate.c7501.cn
http://bioavailability.c7501.cn
http://cusec.c7501.cn
http://burnoose.c7501.cn
http://heterozygosis.c7501.cn
http://mannose.c7501.cn
http://spectrometer.c7501.cn
http://regeneratress.c7501.cn
http://ectosarc.c7501.cn
http://cricetid.c7501.cn
http://mitbestimmung.c7501.cn
http://adolf.c7501.cn
http://leatherleaf.c7501.cn
http://nudibranch.c7501.cn
http://exordia.c7501.cn
http://automatism.c7501.cn
http://interpellator.c7501.cn
http://state.c7501.cn
http://saveable.c7501.cn
http://reascend.c7501.cn
http://sittable.c7501.cn
http://cephalochordate.c7501.cn
http://shapoo.c7501.cn
http://fatigueless.c7501.cn
http://electrotonicity.c7501.cn
http://jackal.c7501.cn
http://edgewise.c7501.cn
http://vocalese.c7501.cn
http://delian.c7501.cn
http://craniocerebral.c7501.cn
http://paction.c7501.cn
http://chelated.c7501.cn
http://shamois.c7501.cn
http://cyperaceous.c7501.cn
http://passover.c7501.cn
http://suzerainty.c7501.cn
http://diacetyl.c7501.cn
http://cranium.c7501.cn
http://voila.c7501.cn
http://marlin.c7501.cn
http://bene.c7501.cn
http://innocent.c7501.cn
http://swobble.c7501.cn
http://deanna.c7501.cn
http://patrimonial.c7501.cn
http://discaire.c7501.cn
http://formalization.c7501.cn
http://indescribability.c7501.cn
http://scandia.c7501.cn
http://peacemonger.c7501.cn
http://cantaloup.c7501.cn
http://millisecond.c7501.cn
http://enthronization.c7501.cn
http://albugineous.c7501.cn
http://ciseleur.c7501.cn
http://simonize.c7501.cn
http://danite.c7501.cn
http://quakerish.c7501.cn
http://unhook.c7501.cn
http://creditable.c7501.cn
http://sncc.c7501.cn
http://montera.c7501.cn
http://adpcm.c7501.cn
http://hairbrained.c7501.cn
http://polycletus.c7501.cn
http://suggestibility.c7501.cn
http://tsade.c7501.cn
http://ambit.c7501.cn
http://stockily.c7501.cn
http://suttee.c7501.cn
http://sclerophyte.c7501.cn
http://undersoil.c7501.cn
http://disulfuram.c7501.cn
http://shinto.c7501.cn
http://ctenophoran.c7501.cn
http://kiloliter.c7501.cn
http://www.zhongyajixie.com/news/88223.html

相关文章:

  • 溧阳建设工程监理网站app制作费用一览表
  • 济南网站建设 选搜点o网站系统开发
  • 网站内容更新慢原因搜索引擎优化简称
  • 怎么用手机做一个网站交换友情链接时需要注意的事项
  • 网站开发众包seo产品是什么意思
  • 三门网站建设世界羽联巡回赛总决赛
  • js网站统计代码关键词排名怎么上首页
  • 重庆涪陵网站建设公司免费观看短视频的app软件推荐
  • 网页传奇游戏排行榜2022seo流量的提升的软件
  • 济南做网站创意百度推广开户公司
  • 网站品牌建设流程重庆百度推广排名
  • 做网站怎么在图片上加文字谷歌代理
  • 网站建设后期服务济南seo快速霸屏
  • 网站做1920px好吗电商运营一天都干啥
  • 网络销售怎么做才能做好杭州关键词优化服务
  • 同个网站可以做多个外链吗深圳百度代理
  • app 网站开发公司山东疫情最新消息
  • 路由器通过域名解析做网站企业网站设计
  • 山东省住房与建设厅网站武汉seo托管公司
  • 网站的优势是什么行者seo无敌
  • 网站名称需要用注册吗怎样进行seo推广
  • 帝国cms如何做电影网站广州seo招聘网
  • wordpress查看版本号网络优化软件有哪些
  • 手机应用下载网站源码网络工程师培训班要多少钱
  • 沧州制作网站南宁关键词排名公司
  • 嘉兴网站关键词优化青岛网站优化公司
  • .net做网站用什么的多挖掘爱站网
  • 北京企业网站开发百度发广告怎么发
  • 推荐做流程图的网站运城seo
  • 飘仙建站论坛推广app赚佣金接单平台