From: "Steven Smith" <sos22@cam.ac.uk>
To: Vineet Joglekar <vintya@excite.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Implementation of read( )
Date: Mon, 26 Jan 2004 21:28:31 +0000 [thread overview]
Message-ID: <20040126212831.GA57901@archibold.chu.cam.ac.uk> (raw)
In-Reply-To: <20040126201655.DBEB51E447@xprdmailfe25.nwk.excite.com>
[-- Attachment #1: Type: text/plain, Size: 1193 bytes --]
> I have read that read() makes the kernel invoke sys_read()
Yup.
> and I want to do the same thing with some additional
> functionalities. Where can i get the implementation of the read()
> function so that on the parallel lines I will be able to write my
> own my_read() function which in turn will call the sys_read() too?
Nowadays, most programs will use glibc's implementation of read, which
is in the glibc source (sysdeps/unix/sysv/linux/i386/syscall.S,
mostly). There is, however, a macro in asm/unistd.h in the kernel
source pool which will do the basics for you. The code goes like
this:
#include <asm/unistd.h>
#define __NR_private_read __NR_read
_syscall3(int, private_read, int, fd, char *, buf, size_t, size);
Calling private_read will then make the read system call directly
without going through libc. Strictly speaking, it is valid to just
redefine read in the obvious way, but that gets horribly confusing.
The alternative approach is to call your function read, taking
advantage of the fact that a normal symbol will override one of the
weak symbols in libc, and then just call __libc_read when you need to
use the libc implementation.
Steven Smith,
sos22@cam.ac.uk
[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]
next prev parent reply other threads:[~2004-01-26 21:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-26 20:16 Implementation of read( ) Vineet Joglekar
2004-01-26 21:28 ` Steven Smith [this message]
2004-01-26 22:51 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040126212831.GA57901@archibold.chu.cam.ac.uk \
--to=sos22@cam.ac.uk \
--cc=linux-c-programming@vger.kernel.org \
--cc=vintya@excite.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).