unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Óscar Fuentes" <ofv@wanadoo.es>
To: emacs-devel@gnu.org
Subject: Re: Warnings in mingw64 build on emacs-28 branch
Date: Sun, 07 Nov 2021 16:51:56 +0100	[thread overview]
Message-ID: <87r1bsezfn.fsf@telefonica.net> (raw)
In-Reply-To: 83fss880qc.fsf@gnu.org

Eli Zaretskii <eliz@gnu.org> writes:

>> 3) This warning is new with gcc 11.
>> 
>> C:/emacs/git/emacs/emacs-28/src/w32heap.c: In function 'getrlimit':
>> C:/emacs/git/emacs/emacs-28/src/w32heap.c:853:14: warning: 'm' may be used uninitialized [-Wmaybe-uninitialized]
>>   853 |         if (!VirtualQuery ((LPCVOID) &m, &m, sizeof m))
>>       |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/winbase.h:25,
>>                  from C:/msys64/mingw64/x86_64-w64-mingw32/include/windows.h:70,
>>                  from C:/emacs/git/emacs/emacs-28/src/w32common.h:24,
>>                  from C:/emacs/git/emacs/emacs-28/src/w32heap.c:54:
>> C:/msys64/mingw64/x86_64-w64-mingw32/include/memoryapi.h:45:28: note: by argument 1 of type 'LPCVOID' {aka 'const void *'} to 'VirtualQuery' declared here
>>    45 |   WINBASEAPI SIZE_T WINAPI VirtualQuery (LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength);
>>       |                            ^~~~~~~~~~~~
>> C:/emacs/git/emacs/emacs-28/src/w32heap.c:844:34: note: 'm' declared here
>>   844 |         MEMORY_BASIC_INFORMATION m;
>>       |                                  ^
>
> That's a compiler bug, I think.  I see nothing wrong in the call.

AFAIU that call to VirtualQuery does not do what we want. When lpAddress
is provided the function rounds down the address to a page boundary and
starts scanning pages *up*. Since we want information about the capacity
of the stack, the scan ignores all the space below the current page
boundary.

There is GetCurrentThreadStackLimits, but requires _WIN32_WINNT >=
0x0602 and it works on allocated pages.

OTOH, we could call CreateThread with dwStackSize set to a fixed value
and return that value from getrlimit(RLIMIT_STACK...). However, we need
the main thread's stack size as well...

There is a hack that uses NtCurrentTeb to obtain the lower address of
the stack and pass it to VirtualQuery. I don't know how portable it is
across Windows versions.




  reply	other threads:[~2021-11-07 15:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-07 14:46 Warnings in mingw64 build on emacs-28 branch Andy Moreton
2021-11-07 15:05 ` Eli Zaretskii
2021-11-07 15:51   ` Óscar Fuentes [this message]
2021-11-07 18:39     ` Eli Zaretskii
2021-11-07 19:25       ` Óscar Fuentes
2021-11-07 19:30         ` Eli Zaretskii
2021-11-07 19:57           ` Óscar Fuentes
2021-11-07 20:02             ` Eli Zaretskii
2021-11-07 18:07   ` Andy Moreton
2021-11-07 19:41     ` Andy Moreton
2021-11-07 19:59       ` Eli Zaretskii
2021-11-07 20:55         ` Andy Moreton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1bsezfn.fsf@telefonica.net \
    --to=ofv@wanadoo.es \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).