LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-18-2008, 12:56 AM   #1
vineeth.thampi
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
Unhappy errno implementation


Hello All,

Can I please know the implementation details of errno global variable.

I am specifically looking for the following details like:
[1] Where is the variable stored? (In some places it was mentioned that errno was a macro)
[2] If it's stored as a variable, how does a system call (In kernel mode) access a variable stored in user mode?
[3] How is errno made thread-safe?

Thanks for your time,

Vineeth
 
Old 09-18-2008, 01:01 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
First post, welcome. (But is this homework, me wonders?)

errno is part of libc, which all applications link with. Each thread gets its own thread-private copy of errno. A macro can be used to define a thread-private variable, so that existing source code that uses errno does not need to change.
 
Old 09-18-2008, 11:19 PM   #3
vineeth.thampi
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Hi,

Thanks for the prompt response and please be assured that it not a homework

Regarding "errno is part of libc, which all applications link with", (say it is a single threaded application), when the process gets loaded in memory errno will become part of the process. At that time:
[1] In which segment will the variable gets stored?
[2] How does a system call change a variable stored in user space?

Thanks again for your time,

Vineeth
 
Old 09-18-2008, 11:45 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
1) segments are specific to certain architectures (eg. x86), so this question is not relevant to errno in general, but is rather an implementation detail about where process global or thread-private globals are stored.

2) A result code is passed back during the kernel-to-user space transition, and libc takes care of setting errno. The libc library implements syscall, so it can set errno just before passing control back to the calling program. The libc syscall implementation mechanics are architecture specific, but they are generally very simple.

Last edited by Mr. C.; 09-18-2008 at 11:47 PM.
 
Old 09-24-2008, 09:37 PM   #5
vineeth.thampi
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks again for the quick response.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
errno implementation vineeth_thampi Linux - Newbie 2 12-06-2006 05:39 AM
errno saurabhtopno Linux - General 3 05-04-2006 01:47 AM
MySQL, errno 13 Ephracis Linux - Software 1 01-02-2005 07:11 PM
errno cynthia Linux - Networking 3 09-24-2004 01:58 PM
How to use errno sibtay Programming 4 09-24-2004 09:38 AM


All times are GMT -5. The time now is 07:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration