Re: do_brk() error return

From: David Schwartz (davids_at_webmaster.com)
Date: 07/30/04


Date: Thu, 29 Jul 2004 23:18:59 -0700


"sean larsson" <infamous42md@ERASEMEhotpop.com> wrote in message
news:20040729225306.2af2214c.infamous42md@ERASEMEhotpop.com...
> the do_brk() function returns an unsigned long. usually this value is
> the new address of the top of the heap. however, when it encounters an
> error, it will return a negative error code, ie -EAGAIN or w/e. so, i'm
> wondering: what if the top of the heap address has the high order bit
> set? i know that the heap usually starts at a low address on my x86
> computers, but i haven't run linux on other platforms so i'm not sure if
> that holds true. and also, why would the developers return a negative
> value in a function that returns an unsigned long? you'd need to cast
> the return to signed type, or test high order bit to check for an error,
> which seems like a dumb thing to do imho. comments?

    None of these error values could ever be page aligned addresses. It's
ugly, but it's safe.

    They don't return a negative value in a function that returns an
unsigned long. They return a value that will compare equivalent to a
particular negative number. Many functions work this way. For example,
'time' returns a 'time_t', which may or may not be signed, however it
returns something that will compare equivalent to '(time_t) -1' on error.

    DS



Relevant Pages

  • Re: do_brk() error return
    ... "David Schwartz" wrote: ... >> is the new address of the top of the heap. ... >> encounters an error, it will return a negative error code, ie ... >> address has the high order bit set? ...
    (comp.os.linux.development.system)
  • Re: do_brk() error return
    ... sean larsson wrote: ... > the new address of the top of the heap. ... > the return to signed type, or test high order bit to check for an error, ... Error codes are from the interval -1 to -124. ...
    (comp.os.linux.development.system)
  • do_brk() error return
    ... the new address of the top of the heap. ... error, it will return a negative error code, ie -EAGAIN or w/e. ... the return to signed type, or test high order bit to check for an error, ...
    (comp.os.linux.development.system)