gpt4 book ai didi

c - 标记为只读的程序可执行文件

转载 作者:太空宇宙 更新时间:2023-11-04 00:40:31 25 4
gpt4 key购买 nike

我正在阅读有关段错误的维基百科,并通过以下代码和语句得出结论。

int main(void)
{
char *s = "hello world";
*s = 'H';
}

When the program containing this code is compiled, the string "hello world" is placed in the section of the program executable file marked as read-only; when loaded, the operating system places it with other strings and constant data in a read-only segment of memory. When executed, a variable, s, is set to point to the string's location, and an attempt is made to write an H character through the variable into the memory, causing a segmentation fault. Compiling such a program with a compiler that does not check for the assignment of read-only locations at compile time.

我的问题是关于文件权限,即可执行文件何时标记为只读以及何时读写 等等?

我想了解有关文件权限的所有信息。我们可以显式更改文件权限吗?

最佳答案

“hello world”存储在内存 的只读部分。写入可执行文件内存给定部分的能力与写入磁盘上可执行文件的能力无关。

关于c - 标记为只读的程序可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10326734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com