Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How does fdentry.users work?

1 view
Skip to first unread message

kd

unread,
Dec 12, 2008, 2:44:57 AM12/12/08
to
I'm from Gaisler Research. We are trying to port Lynxos to the Leon-
sparc
platform. We have come quite far now, I can boot up, /init starts and
forks off /bin/dlsh. Here
comes the problem: the libc function getwd() goes into
a swait() when sys/kernel/read,c:close_fd() is called. Here is the
callpath:

src/lib/libc/getwd.c:getwd()
-> src/lib/libc/getwd.c:opendirstat()
-> ...
sys/kernel/read.c:open()
-> sys/kernel/read.c:get_fd()

[ here fdentry index 5 is allocated. fdentry.users = 0 ]

sys/kernel/read.c:lseek()
-> sys/kernel/read_text.c:getf(5)

[ getf sets fdentry.users = 1 ]

-> sys/kernel/read.c:close(5)
-> sys/kernel/read.c:close_fd(5)
=> while (fdp->users != 0) { ...
if (swait(&currpptr->fdcsem, 1)) {

[ Here I enter swait ]

So here the question:

lseek() gets a fdentry and increments fdentry.users. It _doesnt
decrement_
fdentry.users on return and fdentry.users stays 1. Therefore the
following close() waits
on fdentry.users that is 1.

How is this supposed to work?

I cannot see a call to freef_fd() somewhere in the code. I suppost
that lseek should
call freef_fd() on return. What am I making wrong here ... ?

I'd apreciate your help.

-- Konrad

Steve Watt

unread,
Dec 12, 2008, 3:15:13 PM12/12/08
to
In article <e4088c4b-af48-46f3...@c36g2000prc.googlegroups.com>,
kd <eise...@web.de> wrote:
[ ... ]

>So here the question:
>
>lseek() gets a fdentry and increments fdentry.users. It _doesnt
>decrement_
>fdentry.users on return and fdentry.users stays 1. Therefore the
>following close() waits
>on fdentry.users that is 1.
>
>How is this supposed to work?
>
>I cannot see a call to freef_fd() somewhere in the code. I suppost
>that lseek should
>call freef_fd() on return. What am I making wrong here ... ?

Caution: Extremely old neurons (I haven't been in the LynxOS sources for
almost 9 years)...

I seem to recall that there's some magic about currtptr->fd (maybe it's
currfd?) where at system call return, if it's not 0 / -1 / something
invalid, a freef_fd() happens automatically.

So check in the syscal return trampoline code; it might be in there.
--
Steve Watt KD6GGD PP-ASEL-IA ICBM: 121W 56' 57.5" / 37N 20' 15.3"
Internet: steve @ Watt.COM Whois: SW32-ARIN
Free time? There's no such thing. It just comes in varying prices...

Cyril Novikov

unread,
Dec 12, 2008, 4:33:09 PM12/12/08
to
Steve Watt wrote:
> In article <e4088c4b-af48-46f3...@c36g2000prc.googlegroups.com>,
> kd <eise...@web.de> wrote:
> [ ... ]
>> So here the question:
>>
>> lseek() gets a fdentry and increments fdentry.users. It _doesnt
>> decrement_
>> fdentry.users on return and fdentry.users stays 1. Therefore the
>> following close() waits
>> on fdentry.users that is 1.
>>
>> How is this supposed to work?
>>
>> I cannot see a call to freef_fd() somewhere in the code. I suppost
>> that lseek should
>> call freef_fd() on return. What am I making wrong here ... ?
>
> Caution: Extremely old neurons (I haven't been in the LynxOS sources for
> almost 9 years)...
>
> I seem to recall that there's some magic about currtptr->fd (maybe it's
> currfd?) where at system call return, if it's not 0 / -1 / something
> invalid, a freef_fd() happens automatically.
>
> So check in the syscal return trampoline code; it might be in there.

Yeah, if there's an fd in use, the syscall handler automatically releases it
before returning. That's why most syscalls that getf() don't have a matching
release.

kd

unread,
Dec 13, 2008, 9:56:20 AM12/13/08
to
Hi,
Thanks, this makess sense. I'll investigate this path.
-- Konrad

On Dec 12, 9:15 pm, Steve Watt <steve.removet...@Watt.COM> wrote:

0 new messages