unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#73444: 30.0.50; mingw-w64: Emacs uses CRT's `read` when _FORTIFY_SOURCE > 0
@ 2024-09-23 22:15 Óscar Fuentes
       [not found] ` <handler.73444.B.17271297536353.ack@debbugs.gnu.org>
  2024-09-24 11:48 ` Eli Zaretskii
  0 siblings, 2 replies; 13+ messages in thread
From: Óscar Fuentes @ 2024-09-23 22:15 UTC (permalink / raw)
  To: 73444


On Onssee
When the macro _FORTIFY_SOURCE > 0, mingw-64 provides an inline
definition of `read` on io.h:

__mingw_bos_extern_ovr
int read(int __fh, void * __dst, unsigned int __n)
{
  return _read(__fh, __dst, __n);
}

*Before* #including io.h, ms-w32.h does

#define read    sys_read

so the inline definition of read above ends like this:

int sys_read(int __fh, void * __dst, unsigned int __n)
{
  return _read(__fh, __dst, __n);
}

As the result of this, the above definition is used instead of Emacs'
definition of sys_read. The resulting Emacs is unusable due to problems
handling subprocesses.

A hack that avoids this consists on doing something like:

#define read dummy_read
// etc
#include <io.h>
// etc
#undef read
#define read sys_read
int sys_read (int, char *, unsigned int);

or simpler but untested:

#define _read sys_read
// etc
#include <io.h>
// etc

Either way it is necessary to condition the hack on the value of
_FORTIFY_SOURCE.

More generally, the way Emacs/NT overrides the CRT functions is
susceptible to break anytime upstream does something like, this case,
adding an inline definition, or some other unanticipated change. AFAIK
the C standard says that precisely what Emacs is doing incurs on
undefined behavior.

Any ideas about how to future-proof the solution for this problem?

BTW, the initial bug report for this was in March 2023 and only today
was succesfully analyzed (1) This gives an idea of how problematic this
practice of redefining standard functions can be.

1. https://github.com/msys2/MINGW-packages/issues/17343#issuecomment-2368903501





^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-09-30 16:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <PAWPR10MB776986E318800B89028B74F7F0682@PAWPR10MB7769.EURPRD10.PROD.OUTLOOK.COM>
2024-09-25 10:13 ` bug#73444: 30.0.50; mingw-w64: Emacs uses CRT's `read` when _FORTIFY_SOURCE > 0 Óscar Fuentes
2024-09-25 11:46 ` Eli Zaretskii
2024-09-23 22:15 Óscar Fuentes
     [not found] ` <handler.73444.B.17271297536353.ack@debbugs.gnu.org>
2024-09-23 22:29   ` Óscar Fuentes
2024-09-24 11:51     ` Eli Zaretskii
2024-09-24 12:34       ` Óscar Fuentes
2024-09-24 13:12         ` Eli Zaretskii
2024-09-24 14:06           ` Óscar Fuentes
2024-09-24 15:36             ` Eli Zaretskii
2024-09-24 11:48 ` Eli Zaretskii
2024-09-24 12:55   ` Óscar Fuentes
2024-09-24 13:27     ` Eli Zaretskii
2024-09-30 16:10       ` Óscar Fuentes

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