c - sys_break 有什么作用?

标签 c linux gcc x86 system-calls

我正在阅读 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/

相关文章:

c - C中最简单的int数组排序函数

c - 为什么这个 MPI_Bcast 相关代码没有死锁?

c - 增加堆空间-Mac上C程序的应用程序空间?

ruby - 一行中的两个命令,当任一结束时都结束

linux - perl、系统函数和运行外部命令

c - FTP 实现 : close data socket every time

linux - 查找包含另一个文件中所有单词/行的所有文件

编译器错误消息定制

c++ - gcc 用于解析代码

c++ - 在 Linux 上构建带有链接时间代码生成的静态库的正确方法是什么?