mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
* libio/fileops.c (_IO_file_sync_mmap): New function.
(_IO_file_jumps_mmap): Use it. (_IO_file_underflow_mmap): Rewritten. If after EOF or fflush, repeat the stat check and resize the mapped buffer as necessary. 2002-07-31 Roland McGrath <roland@frob.com> * libio/fileops.c (decide_maybe_mmap): New static function. Code taken from libio/iofopen.c:__fopen_maybe_mmap to try to mmap the file contents. Then switch the jump tables to the mmap tables if it worked, or the vanilla file tables if not. (_IO_file_underflow_maybe_mmap): New function. (_IO_file_seekoff_maybe_mmap): New function. (_IO_file_xsgetn_maybe_mmap): New function. (_IO_file_jumps_maybe_mmap): New variable, jump table using those. * libio/libioP.h: Declare those. * libio/wfileops.c (_IO_wfile_underflow_maybe_mmap): New function. (_IO_wfile_jumps_maybe_mmap): New variable, jump table using that. * libio/iofopen.c (__fopen_maybe_mmap): Don't try to mmap here. If the stream is read-only, set its jump tables to those new ones. * libio/iofdopen.c (_IO_new_fdopen) [_G_HAVE_MMAP]: Set the initial jump tables to the maybe_mmap ones, and don't call __fopen_maybe_mmap. We need the tables set before _IO_file_attach. * libio/tst-mmap-eofsync.c: New file. * libio/tst-mmap-fflushsync.c: New file. * libio/bug-mmap-fflush.c: New file. * libio/tst-mmap2-eofsync.c: New file. * libio/Makefile (tests): Add them. * libio/wfileops.c (_IO_wfile_underflow_mmap): Don't set EOF bit when _IO_file_underflow_mmap fails, it already set the appropriate bit.
This commit is contained in:
@ -314,11 +314,9 @@ _IO_wfile_underflow_mmap (_IO_FILE *fp)
|
||||
if (fp->_IO_read_ptr >= fp->_IO_read_end
|
||||
/* No. But maybe the read buffer is not fully set up. */
|
||||
&& _IO_file_underflow_mmap (fp) == EOF)
|
||||
{
|
||||
/* Nothing available. */
|
||||
fp->_flags |= _IO_EOF_SEEN;
|
||||
return WEOF;
|
||||
}
|
||||
/* Nothing available. _IO_file_underflow_mmap has set the EOF or error
|
||||
flags as appropriate. */
|
||||
return WEOF;
|
||||
|
||||
/* There is more in the external. Convert it. */
|
||||
read_stop = (const char *) fp->_IO_read_ptr;
|
||||
@ -356,6 +354,18 @@ _IO_wfile_underflow_mmap (_IO_FILE *fp)
|
||||
return WEOF;
|
||||
}
|
||||
|
||||
static wint_t
|
||||
_IO_wfile_underflow_maybe_mmap (_IO_FILE *fp)
|
||||
{
|
||||
/* This is the first read attempt. Doing the underflow will choose mmap
|
||||
or vanilla operations and then punt to the chosen underflow routine.
|
||||
Then we can punt to ours. */
|
||||
if (_IO_file_underflow_maybe_mmap (fp) == EOF)
|
||||
return WEOF;
|
||||
|
||||
return _IO_WUNDERFLOW (fp);
|
||||
}
|
||||
|
||||
|
||||
wint_t
|
||||
_IO_wfile_overflow (f, wch)
|
||||
@ -896,3 +906,27 @@ struct _IO_jump_t _IO_wfile_jumps_mmap =
|
||||
JUMP_INIT(showmanyc, _IO_default_showmanyc),
|
||||
JUMP_INIT(imbue, _IO_default_imbue)
|
||||
};
|
||||
|
||||
struct _IO_jump_t _IO_wfile_jumps_maybe_mmap =
|
||||
{
|
||||
JUMP_INIT_DUMMY,
|
||||
JUMP_INIT(finish, _IO_new_file_finish),
|
||||
JUMP_INIT(overflow, (_IO_overflow_t) INTUSE(_IO_wfile_overflow)),
|
||||
JUMP_INIT(underflow, (_IO_underflow_t) _IO_wfile_underflow_maybe_mmap),
|
||||
JUMP_INIT(uflow, (_IO_underflow_t) INTUSE(_IO_wdefault_uflow)),
|
||||
JUMP_INIT(pbackfail, (_IO_pbackfail_t) INTUSE(_IO_wdefault_pbackfail)),
|
||||
JUMP_INIT(xsputn, INTUSE(_IO_wfile_xsputn)),
|
||||
JUMP_INIT(xsgetn, INTUSE(_IO_file_xsgetn)),
|
||||
JUMP_INIT(seekoff, INTUSE(_IO_wfile_seekoff)),
|
||||
JUMP_INIT(seekpos, _IO_default_seekpos),
|
||||
JUMP_INIT(setbuf, _IO_file_setbuf_mmap),
|
||||
JUMP_INIT(sync, (_IO_sync_t) INTUSE(_IO_wfile_sync)),
|
||||
JUMP_INIT(doallocate, _IO_wfile_doallocate),
|
||||
JUMP_INIT(read, INTUSE(_IO_file_read)),
|
||||
JUMP_INIT(write, _IO_new_file_write),
|
||||
JUMP_INIT(seek, INTUSE(_IO_file_seek)),
|
||||
JUMP_INIT(close, _IO_file_close),
|
||||
JUMP_INIT(stat, INTUSE(_IO_file_stat)),
|
||||
JUMP_INIT(showmanyc, _IO_default_showmanyc),
|
||||
JUMP_INIT(imbue, _IO_default_imbue)
|
||||
};
|
||||
|
Reference in New Issue
Block a user