我正在阅读 list of Linux system calls找到sys_break
,其描述如下。
Syntax: int sys_break()
Source: kernel/sys.c
Action: return -ENOSYS
Details: call exists only for compatibility
有谁知道 sys_break
是做什么的?还是什么都不做?
最佳答案
我可能是错的,但我假设它被 brk(2)
系统调用所取代,该系统调用用于控制分配给进程数据段的内存量。最初的 break
调用已被弃用,可能是因为 break
是 C 编程语言中的关键字。我在 Unix V6 中找到了以下评论源代码(1976 年或之前编写):
/* break system call.
* -- bad planning: "break" is a dirty word in C.
*/
sbreak()
{
register a, n, d;
int i;
/* set n to new data size
* set d to new-old
* set n to new total size
*/
...
}
因此,在 C 编程语言发明之前,Unix 是用汇编程序编写的,没有将 break
定义为保留字。
sys_break
本身作为 17 号系统调用在 Unix V1 中引入(这是 PDP-11 汇编程序):
# V1/u2.s - 1971-11-03
sysbreak: / set the program break
mov u.break,r1 / move users break point to r1
cmp r1,$core / is it the same or lower than core?
blos 1f / yes, 1f
cmp r1,sp / is it the same or higher than the stack?
bhis 1f / yes, 1f
bit $1,r1 / is it an odd address
beq 2f / no, its even
clrb (r1)+ / yes, make it even
2: / clear area between the break point and the stack
cmp r1,sp / is it higher or same than the stack
bhis 1f / yes, quit
clr (r1)+ / clear word
br 2b / go back
1:
jsr r0,arg; u.break / put the "address" in u.break (set new
/ break point)
br sysret4 / br sysret
现在,如果您比较 V6 和 V1,您会发现系统调用的含义随时间发生了变化。最初它用于为进程设置断点,在 V6 中它基本上是 brk(2)
系统调用。
关于c - sys_break 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8861543/