read/write function working in linux
-
I want to know how a read/write calls is accomplished in linux? I mean how a function say read() will read the data from a file. What all will be the steps from user mode read() function call to kernel mode? Will anybody explain the steps or let me know any site from where I can get this info?
-
I want to know how a read/write calls is accomplished in linux? I mean how a function say read() will read the data from a file. What all will be the steps from user mode read() function call to kernel mode? Will anybody explain the steps or let me know any site from where I can get this info?
- I suggest you post in the linux forum. 2) Since this is all open source stuff, I suggest you have a look at the stdio library source code.
-
- I suggest you post in the linux forum. 2) Since this is all open source stuff, I suggest you have a look at the stdio library source code.
Thanks for the information.
-
I want to know how a read/write calls is accomplished in linux? I mean how a function say read() will read the data from a file. What all will be the steps from user mode read() function call to kernel mode? Will anybody explain the steps or let me know any site from where I can get this info?
Hi, All modern operating systems in protected mode [^]work nearly the same when executing privileged instructions. They all pass through a call gate[^] and allow the kernel to do the system call[^]. The modern system call instructions are SYSENTER/SYSEXIT. In the old days it was interrupt 0x2e in Windows and 0x80 in Linux. Here is an example of a Win32 function which is written with both 0x2e and SYSENTER syntax. http://www.codeproject.com/Messages/2468550/Re-Send-Key-Input.aspx[^] To answer your question I would summarize as follows: 1.) Glibc simply pushes your arguments onto the stack and invokes the sysenter instruction. (An older version of Linux will invoke interrupt 0x80) 2.) When the CPU sees the SYSENTER instruction it will JMP to the address listed in the registered SYSCALL table. It will execute the instructions there. (Here is where permissions and actual I/O is performed) Best Wishes, -David Delaune
-
Hi, All modern operating systems in protected mode [^]work nearly the same when executing privileged instructions. They all pass through a call gate[^] and allow the kernel to do the system call[^]. The modern system call instructions are SYSENTER/SYSEXIT. In the old days it was interrupt 0x2e in Windows and 0x80 in Linux. Here is an example of a Win32 function which is written with both 0x2e and SYSENTER syntax. http://www.codeproject.com/Messages/2468550/Re-Send-Key-Input.aspx[^] To answer your question I would summarize as follows: 1.) Glibc simply pushes your arguments onto the stack and invokes the sysenter instruction. (An older version of Linux will invoke interrupt 0x80) 2.) When the CPU sees the SYSENTER instruction it will JMP to the address listed in the registered SYSCALL table. It will execute the instructions there. (Here is where permissions and actual I/O is performed) Best Wishes, -David Delaune
:thumbsup: 5 from me, thanks!
Chat in Europe :java: Now with 24% more Twitter
-
Hi, All modern operating systems in protected mode [^]work nearly the same when executing privileged instructions. They all pass through a call gate[^] and allow the kernel to do the system call[^]. The modern system call instructions are SYSENTER/SYSEXIT. In the old days it was interrupt 0x2e in Windows and 0x80 in Linux. Here is an example of a Win32 function which is written with both 0x2e and SYSENTER syntax. http://www.codeproject.com/Messages/2468550/Re-Send-Key-Input.aspx[^] To answer your question I would summarize as follows: 1.) Glibc simply pushes your arguments onto the stack and invokes the sysenter instruction. (An older version of Linux will invoke interrupt 0x80) 2.) When the CPU sees the SYSENTER instruction it will JMP to the address listed in the registered SYSCALL table. It will execute the instructions there. (Here is where permissions and actual I/O is performed) Best Wishes, -David Delaune
Great reply. That clears it all. Also find a good description of query at: http://www.ibm.com/developerworks/linux/library/l-system-calls/ This reply is very much similar to the explaination for windows of read/write() as explained in the chapter IO systems of book Microsoft Windows Internals by Mark E. Russinovich and David A. Solomon