chicken-janitors
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-janitors] #1005: pointer data structures don't overflow rel


From: Chicken Trac
Subject: Re: [Chicken-janitors] #1005: pointer data structures don't overflow reliably, also this does not catch mmap error situations
Date: Thu, 18 Apr 2013 08:43:49 -0000

#1005: pointer data structures don't overflow reliably, also this does not catch
mmap error situations
----------------------+-----------------------------------------------------
  Reporter:  ckeen    |       Owner:                          
      Type:  defect   |      Status:  new                     
  Priority:  major    |   Milestone:  someday                 
 Component:  unknown  |     Version:  4.8.x                   
Resolution:           |    Keywords:  mmap ffi pointer suckage
----------------------+-----------------------------------------------------

Comment(by jrapdx):

 Using the mmap API, even in pure C, produced results exactly the same as
 you note. Here's what I think is going on.  Chicken sets the mmap result
 in the pointer block using the macro C_update_pointer, which simply casts
 the mmap address to an unsigned int and puts it in the data slot.  This is
 logical--there is no negative machine address.

 On error, mmap returns -1 as (unsigned long) (void*), and as unsigned int
 it's value is 2^64, not coincidentally represents -1 as a signed int.  But
 the address value is always unsigned, and is not (nor should it be) to
 "interpret" the mmap error result as a negative number.  Thus, the pointer
 object will sensibly never print an address value less than 0x00, since
 there is no address less than 0.

 So actually there is ''nothing wrong'' with the Chicken code, except for
 the handling of the mmap error result.  However, I can't explain how
 pointer->address prints the obscure, (double)(unsigned long) (void*) value
 as an exponential format.  Nonetheless, it ''is'' the right number, the
 the max, 2^64 unsigned long.

 Here's what I'd do to fix it.  MMap returns its error as -1, conventional
 except for the (void*) cast.  If not an error, there's no problem, the
 address will be positive and handled according to design.

 A very simple solution would be to check the mmap result (the addr2
 variable), Cast the addr2 value to a signed long, and if its -1, check
 errno, and raise an exception.  Wouldn't even bother to convert to an
 address since it doesn't point anywhere anyway, hence no disturbing output
 or confusion.

 Haven't yet tested it out thoroughly, but I'd wager it works.

 JRA

-- 
Ticket URL: <http://bugs.call-cc.org/ticket/1005#comment:1>
Chicken Scheme <http://www.call-with-current-continuation.org/>
Chicken Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]