[MinGW-Notify] [mingw] #38607: Improved standards support for aligned memory allocators

Back to archive index
MinGW Notification List mingw****@lists*****
Fri Oct 19 02:28:37 JST 2018


#38607: Improved standards support for aligned memory allocators

  Open Date: 2018-09-17 19:25
Last Update: 2018-10-18 18:28

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-10-18 18:28 Updated by: keith

Comment:

I've been exploring a possible replacement implementation for the entire
aligned heap allocator; in the process, I've just identified a further critical
defect in the current implementation, viz. for both _aligned_offset_malloc(),
and _aligned_offset_realloc(), Microsoft's documentation states:

_aligned_offset_malloc validates its parameters. If alignment is not a power of 2 or if offset is greater than or equal to size and nonzero, this function invokes the invalid parameter handler

The existing MinGW implementation correctly checks the power of two constraint
on alignment, but it seems to completely ignore the (obvious, in spite of
Microsoft's awkwardly obscure wording) offset constraint; with my modified
implementation, which does honour both constraints, the original test program
fails instantly, (where it presumably passed, but should not have, with the
original implementation).



---------------------------------------------------------------------
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



More information about the MinGW-Notify mailing list
Back to archive index