Send MinGW-Notify mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.osdn.me/mailman/listinfo/mingw-notify
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of MinGW-Notify digest..."


Please do not reply to this notification; the sender address is unable to 
accept incoming e-mail.  If you wish to unsubscribe you can do so at 
https://lists.osdn.me/mailman/listinfo/mingw-notify.



Today's Topics:

   1. [mingw] #38607: Improved standards support for aligned memory
      allocators (MinGW Notification List)
   2. [mingw] #38607: Improved standards support for aligned memory
      allocators (MinGW Notification List)


----------------------------------------------------------------------

Message: 1
Date: Tue, 18 Sep 2018 14:34:39 +0100
From: MinGW Notification List <[email protected]>
Subject: [MinGW-Notify] [mingw] #38607: Improved standards support for
        aligned memory allocators
To: OSDN Ticket System <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

#38607: Improved standards support for aligned memory allocators

  Open Date: 2018-09-17 19:25
Last Update: 2018-09-18 14:34

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/38607
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=38607

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2018-09-18 14:34 Updated by: keith

Comment:

To clarify, some potential issues I've noted in the current
mingw-aligned-malloc.c implementation:?

 1. The alignment must be an integer power of two, greater than or equal to
    sizeof (void *). The power of two requirement is okay, (and indeed
    imperative), but since malloc() itself aligns on address boundaries which
    are multiples of eight bytes, and (on Win32) sizeof (void *) is only four
    bytes, the minimum requirement is set too small ? realistically, it should
    be no less than the natural alignment gap, within the struct:?

     1.  struct
     2.  {  char             c;
     3.     union
     4.     { void          *p;
     5.       intptr_t       i;
     6.       long double    f;
     7.     }
     8.  } alignment;

    between the c and the p elements, i.e.:?

     1.  alignment_min = (size_t)(& alignment.p) - (size_t)(& alignment.c);

 2. The additional padding requirement, to accommodate the requested alignment,
    and storage for the malloc() base address, is over-specified; rather than:?

     1.  p0 = malloc (size + (alignment + sizeof (void *)));

    it should be:?

     1.  p0 = malloc (size + alignment - 1 + sizeof (void *));

    and more importantly, (because that correction reduces the allocation
    request by only one byte), instead of:?

     1.  p = (void *)((((uintptr_t)(p0) + (alignment + sizeof (void *)) + 
offset) & ~(alignment - 1)) - offset)

    the alignment calculation should be:?

     1.  p = (void *)((((uintptr_t)(p0) + alignment - 1 + sizeof (void *) + 
offset) & ~(alignment - 1)) - offset)

    in which case, the -1 adjustment is much more critical ? it ensures that
    the alignment boundary is correctly rounded downwards, avoiding a potential
    over-alignment by one entire alignment frame higher in memory, which would
    open the door to a buffer overrun, when the buffer is populated from an
    address which is one such frame address higher in memory than has been
    allowed for, in the allocation.

Besides the above, there are other issues, for a follow-on comment.



---------------------------------------------------------------------
Ticket Status:

      Reporter: keith
         Owner: (None)
          Type: Feature Request
        Status: Open
      Priority: 5 - Medium
     MileStone: (None)
     Component: WSL
      Severity: 5 - Medium
    Resolution: None
---------------------------------------------------------------------

Ticket details:

Microsoft introduced _aligned_malloc(), and associated functions, with
MSVCR70.DLL. Although subsequently supported in MSVCRT.DLL, from WinXP onwards,
exposure of these APIs interferes with a clean build of GCC ? not only insofar
as, having detected presence of the APIs, GCC would become dependent on WinXP
and later, thus needlessly breaking legacy support, but furthermore, the GCC
sources neglect to include the requisite <malloc.h> header file, and thus do
not build cleanly.

Legacy support for similar APIs was added to MinGW, in 2003/2004, under feature
request #260; however, it may be ill-advised to make GCC dependent on these
MinGW specific APIs, for the following reasons:???

 1. A patch, to incorporate them, would be unlikely to be accepted upstream.
 2. If the APIs are not detected, GCC will provide its own replacement
    functions.
 3. A review reveals potential flaws in the MinGW implementation.

Consequently, I suggest:?

 1. **Not** exposing the Microsoft APIs in libmsvcrt.a
 2. Reworking the MinGW implementation, to address potential flaws.
 3. Consider adding support for ISO-C11's aligned_alloc() and POSIX.1's
    posix_memalign() APIs.



-- 
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN

Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/38607
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=38607


------------------------------

Message: 2
Date: Tue, 18 Sep 2018 14:57:57 +0100
From: MinGW Notification List <[email protected]>
Subject: [MinGW-Notify] [mingw] #38607: Improved standards support for
        aligned memory allocators
To: OSDN Ticket System <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

#38607: Improved standards support for aligned memory allocators

  Open Date: 2018-09-17 19:25
Last Update: 2018-09-18 14:57

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/38607
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=38607

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2018-09-18 14:57 Updated by: keith

Comment:

Following on from my preceding comment, (which ran out of space), further
issues with the existing mingw-aligned-malloc.c implementation:?

  ? A comment, within the __mingw_aligned_offset_realloc() implementation,
    (correctly) states that "it is an error for the alignment to change";
    (specifically, it is an error if either the alignment, or the offset, (or
    both), differ from the values specified in the original
    __mingw_aligned_offset_malloc() call, which created the buffer which is to
    be resized). Unfortunately, while:?

     1.  p == (void *)((((uintptr_t)(p0) + (alignment + sizeof (void *)) + 
offset) & ~(alignment - 1)) - offset)

    (or corrected, as in the preceding comment):?

     1.  p == (void *)((((uintptr_t)(p0) + alignment - 1 + sizeof (void *) + 
offset) & ~(alignment - 1)) - offset)

    is a necessary condition of compliance with the stated constraint, it is
    not a sufficient condition. Furthermore, since the original alignment and
    offset parameters are not stored, (nor is any provision made for the
    possibility of storing them), there simply isn't sufficient information
    available to __mingw_aligned_offset_realloc(), to formulate a necessary and
    sufficient conditional test.



---------------------------------------------------------------------
Ticket Status:

      Reporter: keith
         Owner: (None)
          Type: Feature Request
        Status: Open
      Priority: 5 - Medium
     MileStone: (None)
     Component: WSL
      Severity: 5 - Medium
    Resolution: None
---------------------------------------------------------------------

Ticket details:

Microsoft introduced _aligned_malloc(), and associated functions, with
MSVCR70.DLL. Although subsequently supported in MSVCRT.DLL, from WinXP onwards,
exposure of these APIs interferes with a clean build of GCC ? not only insofar
as, having detected presence of the APIs, GCC would become dependent on WinXP
and later, thus needlessly breaking legacy support, but furthermore, the GCC
sources neglect to include the requisite <malloc.h> header file, and thus do
not build cleanly.

Legacy support for similar APIs was added to MinGW, in 2003/2004, under feature
request #260; however, it may be ill-advised to make GCC dependent on these
MinGW specific APIs, for the following reasons:???

 1. A patch, to incorporate them, would be unlikely to be accepted upstream.
 2. If the APIs are not detected, GCC will provide its own replacement
    functions.
 3. A review reveals potential flaws in the MinGW implementation.

Consequently, I suggest:?

 1. **Not** exposing the Microsoft APIs in libmsvcrt.a
 2. Reworking the MinGW implementation, to address potential flaws.
 3. Consider adding support for ISO-C11's aligned_alloc() and POSIX.1's
    posix_memalign() APIs.



-- 
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN

Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/38607
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=38607


------------------------------

_______________________________________________
MinGW-Notify mailing list
[email protected]
https://lists.osdn.me/mailman/listinfo/mingw-notify


End of MinGW-Notify Digest, Vol 12, Issue 4
*******************************************

Reply via email to