博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux下面mmap和setsignal函数用法
阅读量:6934 次
发布时间:2019-06-27

本文共 969 字,大约阅读时间需要 3 分钟。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
char* buf;struct stat statbuf;void handler(int signo){ printf("permission denied\n"); if (mprotect(buf, statbuf.st_size, PROT_READ|PROT_WRITE) == -1) { perror("failed to alter permission"); exit(1); } printf("permission modified\n");}int main(){ int fd; if (signal(SIGSEGV, handler) == SIG_ERR) { printf("can not set handler for SIGSEGV.\n"); exit(0); } if (stat("test.txt", &statbuf) == -1) { perror("failed to get stat"); exit(1); } fd = open("test.txt", O_RDWR); if (fd == -1) { perror("failed to open file\n"); exit(1); } buf = (char*)mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); // readonly memory map printf("try to write to a readonly memccpy map\n"); memcpy(buf, "china\n", 6); if (munmap(buf, statbuf.st_size) == -1) { perror("failed to unmap\n"); exit(1); } close(fd); return 0;}

 

转载地址:http://lhgjl.baihongyu.com/

你可能感兴趣的文章
IBM发布全球首台商用量子计算机
查看>>
在一个成熟的分布式系统中 如何下手做高可用?
查看>>
CoreOS 和 Kubernetes 1.5 自主运行 Kubernetes、Container Linux
查看>>
The only supported ciphers are AES-128-CBC and AES-256-CBC
查看>>
sphinx 全文搜索引擎
查看>>
Kotlin成为正式的Android编程语言
查看>>
物联网技术周报第 141 期: 使用 Alexa Voice 和 Raspberry Pi 构建图片识别应用
查看>>
微软必应从.NET Core 2.1获得了性能提升
查看>>
四说大数据时代“神话”:从大数据到深数据\n
查看>>
vue.js仿饿了么app---webpack配置项
查看>>
架构周报:微信后台系统的演进之路
查看>>
Oracle宣布提供新的Java支持价格体系
查看>>
phpstrom配置svn/git提交
查看>>
关于Redux的一些总结(一):Action & 中间件 & 异步
查看>>
专访1药网技术副总裁黄哲铿:揭秘技术跨界管理之道
查看>>
Markdown通用的常用语法说明
查看>>
gulp关于scss的基础配置
查看>>
PHP:echo、print、print_r() 和 var_dump()
查看>>
Gerrit代码Review入门实战
查看>>
Swift中一个类中的枚举(enum)类型的数据该如何实现序列化(NSCoder)
查看>>