Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

c - How to change tast_struct current into specific task_struct in x86?

In high level, I tried to de-couple system call into two parts and my question occurs in kernel part. I tried to invoke function stored in system call table. Before invoking it, I need to switch current task information to user's (The reason I need to do this is that if I request getpid(), I need to know task_struct of one who requests getpid in user space).

For example:

// memorize who actually request system call
task_struct *target = current;
.
.
context switch
.
.
// change task status to user space who request system call (target)
... how to do it?
// call specific system call
(sys_call_ptr_t *)syscall_table)[num](reg)
// restore task status back to original one
...

I know current can't be l-value, I'm looking for the answer about how to pretend current task is user's (target) and then call system call. After that, restore current task back to original one.

Edit: The thing I want to achieve is to separate calling system call into 2 parts, which can avoid interrupt occur to handle system call. The way I make it is using shared memory between kernel and user space. In this shared memory, it records information about request from user space. In kernel part, I can know some information about requests of user gave and do corresponding task by looking up system call table and then calling it. Unfortunately, the information I have in shared memory is not enough. For example, I didn't have task_struct current of request asker in user space. As a result, calling getpid will not get the real ID of request asker in user space (This is also why I try to change current status and then call getpid, then result will be desired). I think get the current of asker in user space is the general solution for all system call.

question from:https://stackoverflow.com/questions/65881680/how-to-change-tast-struct-current-into-specific-task-struct-in-x86

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...