实施系统调用:无法从用户接收参数值

时间:2018-12-09 14:15:06

标签: linux system-calls

我正在Linux中实现系统调用。我有一个问题:无法从用户那里接收参数值。我的内核版本4.19.5

这是用户代码:

int main(){
    char *name = (char*)malloc(sizeof(char)*32);

    int fd1;
    char buf[128];
    fd1 = open("/usr/src/linux-4.19.5/abc", O_WRONLY);
    if (fd1 == -1) {
        printf("ERROR\n");
        return EXIT_FAILURE;
    }
    printf("Enter process to find: ");
    scanf (" %[^\n]", name);
    write(fd1, name, strlen(name));
    long int status = syscall(335, name);
    printf("System call returned %ld\n", status);
    close(fd1);

    return 0;}

但是我无法在内核代码中接收到'name'的值: 这是内核代码:

asmlinkage long sys_process_name(char* process_name){

    struct task_struct *task;
    struct tty_struct *my_tty;
    my_tty = get_current_tty();
    char name[32];
    for_each_process(task){
        if(strcmp(task->comm,process_name) == 0){
            sprintf(name, "PID = %ld\n", (long)task_pid_nr(task));
            (my_tty->driver->ops->write) (my_tty, name, strlen(name)+1);
        }
    }
    return 0;}

process_name的值为空。

0 个答案:

没有答案