This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix for "get time" overflow in wallclock emulator


Attached is a fix for a calculation overflow in the
wallclock emulator.

Problem Description
===================
When an application tries to get the current system
time via any of the common methods, the wallclock's
get_hw_seconds() is called to convert the system's
tick count into a second's count.

The wallclock emulator's version of this function does
not protect against reasonable overflow conditions,
since it multiplies the system tick counter by the
clock resolution dividend before dividing it.


Real-World Example of Problem
=============================
When running in the Linux synth environment, I
observed the problem with the following "typical"
parameters:


res.dividend = 1,000,000,000    [32-bit value]
res.divisor = 100               [32-bit value]
    [These resolution parameters specify
    a typical clock resolution of 100Hz]

Cyg_Clock::real_time_clock->current_value() =
    106,417,800,000    [64-bit value]
    [Corresponds to system time of
        Sun, 21 Sep 2003 21:00:00 GMT]
    [The clock ticks correspond to
        1,064,178,000 seconds from
        epoch * 100 Hz]

current_value() * res.dividend = ~1.06e20

Maximum value for 64-bit integer is
    ~1.84e19 [Hence the overflow]


Description of Fix
==================
I rearranged the calculation to divide the clock ticks
by the (calculated) system HZ value.  Since the HZ
value generally results in an integral number, no
precision should be lost.


Affect of Bug
=============
For a reasonable system clock resolution of 100Hz, the
"get time" functions will return the incorrect date
starting with dates around 1975.  This only affects
systems using the wallclock *emulator*.

--
Dan Jakubiec
Systech Corporation

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

Attachment: wallclock.pat
Description: wallclock.pat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]