我正在尝试将 sys exit 调用设置为一个变量
extern void *sys_call_table[];
real_sys_exit = sys_call_table[__NR_exit]
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试制作时,控制台给了我错误
error: ‘__NR_exit’ undeclared (first use in this function)
Run Code Online (Sandbox Code Playgroud)
任何提示将不胜感激:) 谢谢
我/dev按照这里的教程(chardev.c)创建了一个节点,我尝试/dev/chardev使用以下代码访问我创建的设备:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h> //perror(), errno
#include <string.h>
#define RSIZE 50
int main()
{
int fd,err_save;
char receive_buff[RSIZE];
//open device and check for error msg
fd = open("/dev/chardev", "rw");
err_save = errno;
if (fd < 0)
{
perror("open perror");
printf("error opening device, fd = %d, err_save = %d \n", fd,err_save);
}
else
{printf("Device opened\n");}
//read device and check for error msg
//memset(receive_buff, 0, sizeof(receive_buff)); //<--- strange
read(fd, …Run Code Online (Sandbox Code Playgroud) 我需要帮助来理解文件描述符
所以这是我的代码:
int main()
{
char ch;
close(1);
//now opening a file so that it gets the lowest possible fd i.e. 1
int fd=open("txt",O_RDWR);
//check..
printf("first printtf is executed\n");
scanf("%c",&ch);
printf("ur value is %c\n",ch);
printf("second printf is executed\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在上面的程序中,我尝试将 的输出重定向printf到txt文件而不是标准输出,即终端。但是如何恢复标准输出文件描述符,以便printf在第二种情况下再次正常工作,即第二个printtf应该只向终端提供输出..
这是一个非常简单的exec()系统调用示例.在这里,我试图打execlp()两次电话.但是,我没有得到例外输出.它仅显示当前目录的第一次调用的输出.
#include <stdio.h>
#include <unistd.h>
int main() {
int ret1,ret2;
ret1 = execlp( "pwd", "pwd", (char *) 0);
ret2 = execlp( "date", "date", (char *) 0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
/home/aniket
Run Code Online (Sandbox Code Playgroud)
在这里,我看不到日期的输出.任何人都可以解释为什么会发生这种情况?
有没有办法检索在 syscall() 中进行的系统调用的名称?我看到我们可以访问该号码;我可以以某种方式使用它吗?
我想以汇编语言访问errno.h中的errno,以便处理写函数调用的错误.为了这个目的,我发现在某个地方用汇编语言调用_error,但它会抛出错误:
ExitNewShell.asm:71: error: symbol `_error' undefined
ExitNewShell.asm:85: error: symbol `_error' undefined
ExitNewShell.asm:98: error: symbol `_error' undefined
ExitNewShell.asm:111: error: symbol `_error' undefined
ExitNewShell.asm:124: error: symbol `_error' undefined
ExitNewShell.asm:137: error: symbol `_error' undefined
ExitNewShell.asm:150: error: symbol `_error' undefined
ExitNewShell.asm:163: error: symbol `_error' undefined
ExitNewShell.asm:176: error: symbol `_error' undefined
Run Code Online (Sandbox Code Playgroud)
我的汇编代码:ExitNewShell.asm
[SECTION .text]
global _start
_start:
jmp ender
starter:
xor eax, eax ;clean up the registers
xor ebx, ebx
xor edx, edx
xor ecx, ecx
mov al, 4 ;syscall write
mov bl, 1 ;stdout …Run Code Online (Sandbox Code Playgroud) 计划1:
#include<stdio.h>
void main()
{
printf("Hello\n");
}
Run Code Online (Sandbox Code Playgroud)
输出:
$strace ./a.out
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
fstat64(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
.
.
.
.
write(1, "Hello\n", 6Hello
) = 6
exit_group(6) = ?
$
Run Code Online (Sandbox Code Playgroud)
计划2:
#include<stdio.h>
void main()
{
char buf[2];
setbuf(stdout,buf);
printf("Hello\n");
}
Run Code Online (Sandbox Code Playgroud)
输出:
$ strace ./a.out
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
fstat64(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
.
.
.
. …Run Code Online (Sandbox Code Playgroud) 我正在用 C 编写我自己的小外壳,或者至少我今天要开始。我想实现三个功能。
remove file1为此我需要哪些系统调用?只需打开文件并删除其内容,或者除了使用之外是否还有删除文件的系统调用rm?
mycopy source destination为此,我正在考虑让一个缓冲区并打开 file1 读入缓冲区并写出到 file2 但我不知道如何将它实际放入代码中,如果有人可以将一个小例子放在一起,这对很多人有帮助。
move source destination这只是实现复制和删除吗?
我的主要问题是使用 argv[] 参数我从来没有这样做过,所以它对我来说是新的。
我正在组装中构建一个32位操作系统.
我已经设置了IDT,我正在通过int指令处理程序interruptus .
如何启用syscall和sysenter说明以及如何处理/返回?
诚然,syscall指令在32位基于英特尔处理器的支持,所以我不能用它?sysret教学不安全是真的吗?在某处存在一个教程吗?
编辑:我的主要问题是如何启用syscall和sysenter说明!(没有重复)
assembly system-calls protected-mode osdev interrupt-handling
我是 asm 的新手,我正在尝试对 /bin/bash 执行系统调用。但是我目前遇到以下问题:
我的代码适用于第一个参数长度小于 8 个字节的任何 execve 调用,即 "/bin/sh" 或 "/bin/ls" :
.section .data
name: .string "/bin/sh"
.section .text
.globl _start
_start:
#third argument of execve, set to NULL
xor %rdx, %rdx
#push nullbyte to the stack
pushq %rdx
#push /bin/sh to the stack
pushq name
#copy stack to rdi, 1st arg of execve
mov %rsp, %rdi
#copy 59 to rax, defining syscall number for execve
movq $59, %rax
#3rd arg of execve set to NULL
movq $0, …Run Code Online (Sandbox Code Playgroud)