4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-21 16:26:12 +08:00

Corinna Vinschen <corinna@vinschen.de>

* fhandler.cc: Add #include for asm/socket.h for dealing with FIONREAD.
(fhandler_base::ioctl): Special-case errno for FIONREAD.
* fhandler_dsp.cc (fhandler_dev_dsp::ioctl): Rename parameter for consistency.
Call fhandler_base::ioctl to decode default condition.
* fhandler_serial.cc (fhandler_serial::ioctl): Ditto.
* fhandler_tty.cc (fhandler_pty_slave::ioctl): Call fhandler_base::ioctl to
decode default condition.
* fhandler_windows.cc (fhandler_windows::ioctl): Ditto.
This commit is contained in:
Christopher Faylor 2011-07-21 20:21:46 +00:00
parent 37aeec7f72
commit e9b5cc32f7
6 changed files with 77 additions and 60 deletions

View File

@ -1,3 +1,15 @@
2011-07-21 Christopher Faylor <me.cygwin2011@cgf.cx>
Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc: Add #include for asm/socket.h for dealing with FIONREAD.
(fhandler_base::ioctl): Special-case errno for FIONREAD.
* fhandler_dsp.cc (fhandler_dev_dsp::ioctl): Rename parameter for
consistency. Call fhandler_base::ioctl to decode default condition.
* fhandler_serial.cc (fhandler_serial::ioctl): Ditto.
* fhandler_tty.cc (fhandler_pty_slave::ioctl): Call
fhandler_base::ioctl to decode default condition.
* fhandler_windows.cc (fhandler_windows::ioctl): Ditto.
2011-07-21 Corinna Vinschen <corinna@vinschen.de> 2011-07-21 Corinna Vinschen <corinna@vinschen.de>
* heap.cc (eval_start_address): Simplify test for large address * heap.cc (eval_start_address): Simplify test for large address

View File

@ -28,6 +28,7 @@ details. */
#include "ntdll.h" #include "ntdll.h"
#include "cygtls.h" #include "cygtls.h"
#include "sigproc.h" #include "sigproc.h"
#include <asm/socket.h>
#define MAX_OVERLAPPED_WRITE_LEN (64 * 1024 * 1024) #define MAX_OVERLAPPED_WRITE_LEN (64 * 1024 * 1024)
#define MIN_OVERLAPPED_WRITE_LEN (1 * 1024 * 1024) #define MIN_OVERLAPPED_WRITE_LEN (1 * 1024 * 1024)
@ -1151,6 +1152,10 @@ fhandler_base::ioctl (unsigned int cmd, void *buf)
set_nonblocking (*(int *) buf); set_nonblocking (*(int *) buf);
res = 0; res = 0;
break; break;
case FIONREAD:
set_errno (ENOTTY);
res = -1;
break;
default: default:
set_errno (EINVAL); set_errno (EINVAL);
res = -1; res = -1;

View File

@ -1170,11 +1170,11 @@ fhandler_dev_dsp::close ()
} }
int int
fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr) fhandler_dev_dsp::ioctl (unsigned int cmd, void *buf)
{ {
debug_printf ("audio_in=%08x audio_out=%08x", debug_printf ("audio_in=%08x audio_out=%08x",
(int)audio_in_, (int)audio_out_); (int)audio_in_, (int)audio_out_);
int *intptr = (int *) ptr; int *intbuf = (int *) buf;
switch (cmd) switch (cmd)
{ {
#define CASE(a) case a : debug_printf ("/dev/dsp: ioctl %s", #a); #define CASE(a) case a : debug_printf ("/dev/dsp: ioctl %s", #a);
@ -1189,13 +1189,13 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
/* This is valid even if audio_X is NULL */ /* This is valid even if audio_X is NULL */
if (IS_WRITE ()) if (IS_WRITE ())
{ {
*intptr = audio_out_->blockSize (audiofreq_, *intbuf = audio_out_->blockSize (audiofreq_,
audiobits_, audiobits_,
audiochannels_); audiochannels_);
} }
else else
{ // I am very sure that IS_READ is valid { // I am very sure that IS_READ is valid
*intptr = audio_in_->blockSize (audiofreq_, *intbuf = audio_in_->blockSize (audiofreq_,
audiobits_, audiobits_,
audiochannels_); audiochannels_);
} }
@ -1204,10 +1204,10 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
CASE (SNDCTL_DSP_SETFMT) CASE (SNDCTL_DSP_SETFMT)
{ {
int nBits; int nBits;
switch (*intptr) switch (*intbuf)
{ {
case AFMT_QUERY: case AFMT_QUERY:
*intptr = audioformat_; *intbuf = audioformat_;
return 0; return 0;
break; break;
case AFMT_U16_BE: case AFMT_U16_BE:
@ -1229,11 +1229,11 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
if (audio_out_->query (audiofreq_, nBits, audiochannels_)) if (audio_out_->query (audiofreq_, nBits, audiochannels_))
{ {
audiobits_ = nBits; audiobits_ = nBits;
audioformat_ = *intptr; audioformat_ = *intbuf;
} }
else else
{ {
*intptr = audiobits_; *intbuf = audiobits_;
return -1; return -1;
} }
} }
@ -1243,11 +1243,11 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
if (audio_in_->query (audiofreq_, nBits, audiochannels_)) if (audio_in_->query (audiofreq_, nBits, audiochannels_))
{ {
audiobits_ = nBits; audiobits_ = nBits;
audioformat_ = *intptr; audioformat_ = *intbuf;
} }
else else
{ {
*intptr = audiobits_; *intbuf = audiobits_;
return -1; return -1;
} }
} }
@ -1258,22 +1258,22 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
if (IS_WRITE ()) if (IS_WRITE ())
{ {
close_audio_out (); close_audio_out ();
if (audio_out_->query (*intptr, audiobits_, audiochannels_)) if (audio_out_->query (*intbuf, audiobits_, audiochannels_))
audiofreq_ = *intptr; audiofreq_ = *intbuf;
else else
{ {
*intptr = audiofreq_; *intbuf = audiofreq_;
return -1; return -1;
} }
} }
if (IS_READ ()) if (IS_READ ())
{ {
close_audio_in (); close_audio_in ();
if (audio_in_->query (*intptr, audiobits_, audiochannels_)) if (audio_in_->query (*intbuf, audiobits_, audiochannels_))
audiofreq_ = *intptr; audiofreq_ = *intbuf;
else else
{ {
*intptr = audiofreq_; *intbuf = audiofreq_;
return -1; return -1;
} }
} }
@ -1281,15 +1281,15 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
CASE (SNDCTL_DSP_STEREO) CASE (SNDCTL_DSP_STEREO)
{ {
int nChannels = *intptr + 1; int nChannels = *intbuf + 1;
int res = ioctl (SNDCTL_DSP_CHANNELS, &nChannels); int res = ioctl (SNDCTL_DSP_CHANNELS, &nChannels);
*intptr = nChannels - 1; *intbuf = nChannels - 1;
return res; return res;
} }
CASE (SNDCTL_DSP_CHANNELS) CASE (SNDCTL_DSP_CHANNELS)
{ {
int nChannels = *intptr; int nChannels = *intbuf;
if (IS_WRITE ()) if (IS_WRITE ())
{ {
@ -1298,7 +1298,7 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
audiochannels_ = nChannels; audiochannels_ = nChannels;
else else
{ {
*intptr = audiochannels_; *intbuf = audiochannels_;
return -1; return -1;
} }
} }
@ -1309,7 +1309,7 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
audiochannels_ = nChannels; audiochannels_ = nChannels;
else else
{ {
*intptr = audiochannels_; *intbuf = audiochannels_;
return -1; return -1;
} }
} }
@ -1323,10 +1323,10 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
set_errno(EBADF); set_errno(EBADF);
return -1; return -1;
} }
audio_buf_info *p = (audio_buf_info *) ptr; audio_buf_info *p = (audio_buf_info *) buf;
audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_); audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
debug_printf ("ptr=%p frags=%d fragsize=%d bytes=%d", debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
ptr, p->fragments, p->fragsize, p->bytes); buf, p->fragments, p->fragsize, p->bytes);
return 0; return 0;
} }
@ -1337,10 +1337,10 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
set_errno(EBADF); set_errno(EBADF);
return -1; return -1;
} }
audio_buf_info *p = (audio_buf_info *) ptr; audio_buf_info *p = (audio_buf_info *) buf;
audio_in_->buf_info (p, audiofreq_, audiobits_, audiochannels_); audio_in_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
debug_printf ("ptr=%p frags=%d fragsize=%d bytes=%d", debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
ptr, p->fragments, p->fragsize, p->bytes); buf, p->fragments, p->fragsize, p->bytes);
return 0; return 0;
} }
@ -1350,11 +1350,11 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
return 0; return 0;
CASE (SNDCTL_DSP_GETFMTS) CASE (SNDCTL_DSP_GETFMTS)
*intptr = AFMT_S16_LE | AFMT_U8; // only native formats returned here *intbuf = AFMT_S16_LE | AFMT_U8; // only native formats returned here
return 0; return 0;
CASE (SNDCTL_DSP_GETCAPS) CASE (SNDCTL_DSP_GETCAPS)
*intptr = DSP_CAP_BATCH | DSP_CAP_DUPLEX; *intbuf = DSP_CAP_BATCH | DSP_CAP_DUPLEX;
return 0; return 0;
CASE (SNDCTL_DSP_POST) CASE (SNDCTL_DSP_POST)
@ -1366,13 +1366,11 @@ fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
return 0; return 0;
default: default:
debug_printf ("/dev/dsp: ioctl 0x%08x not handled yet! FIXME:", cmd); return fhandler_base::ioctl (cmd, buf);
break; break;
#undef CASE #undef CASE
}; }
set_errno (EINVAL);
return -1;
} }
void void

View File

@ -17,6 +17,7 @@ details. */
#include "fhandler.h" #include "fhandler.h"
#include "sigproc.h" #include "sigproc.h"
#include "pinfo.h" #include "pinfo.h"
#include <asm/socket.h>
#include <ddk/ntddser.h> #include <ddk/ntddser.h>
/**********************************************************************/ /**********************************************************************/
@ -454,12 +455,12 @@ fhandler_serial::switch_modem_lines (int set, int clr)
/* ioctl: */ /* ioctl: */
int int
fhandler_serial::ioctl (unsigned int cmd, void *buffer) fhandler_serial::ioctl (unsigned int cmd, void *buf)
{ {
int res = 0; int res = 0;
# define ibuffer ((int) buffer) # define ibuf ((int) buf)
# define ipbuffer (*(int *) buffer) # define ipbuf (*(int *) buf)
DWORD ev; DWORD ev;
COMSTAT st; COMSTAT st;
@ -472,7 +473,7 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
switch (cmd) switch (cmd)
{ {
case TCFLSH: case TCFLSH:
res = tcflush (ibuffer); res = tcflush (ibuf);
break; break;
case TIOCMGET: case TIOCMGET:
DWORD modem_lines; DWORD modem_lines;
@ -483,40 +484,40 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
} }
else else
{ {
ipbuffer = 0; ipbuf = 0;
if (modem_lines & MS_CTS_ON) if (modem_lines & MS_CTS_ON)
ipbuffer |= TIOCM_CTS; ipbuf |= TIOCM_CTS;
if (modem_lines & MS_DSR_ON) if (modem_lines & MS_DSR_ON)
ipbuffer |= TIOCM_DSR; ipbuf |= TIOCM_DSR;
if (modem_lines & MS_RING_ON) if (modem_lines & MS_RING_ON)
ipbuffer |= TIOCM_RI; ipbuf |= TIOCM_RI;
if (modem_lines & MS_RLSD_ON) if (modem_lines & MS_RLSD_ON)
ipbuffer |= TIOCM_CD; ipbuf |= TIOCM_CD;
DWORD cb; DWORD cb;
DWORD mcr; DWORD mcr;
if (!DeviceIoControl (get_handle (), IOCTL_SERIAL_GET_DTRRTS, if (!DeviceIoControl (get_handle (), IOCTL_SERIAL_GET_DTRRTS,
NULL, 0, &mcr, 4, &cb, 0) || cb != 4) NULL, 0, &mcr, 4, &cb, 0) || cb != 4)
ipbuffer |= rts | dtr; ipbuf |= rts | dtr;
else else
{ {
if (mcr & 2) if (mcr & 2)
ipbuffer |= TIOCM_RTS; ipbuf |= TIOCM_RTS;
if (mcr & 1) if (mcr & 1)
ipbuffer |= TIOCM_DTR; ipbuf |= TIOCM_DTR;
} }
} }
break; break;
case TIOCMSET: case TIOCMSET:
if (switch_modem_lines (ipbuffer, ~ipbuffer)) if (switch_modem_lines (ipbuf, ~ipbuf))
res = -1; res = -1;
break; break;
case TIOCMBIS: case TIOCMBIS:
if (switch_modem_lines (ipbuffer, 0)) if (switch_modem_lines (ipbuf, 0))
res = -1; res = -1;
break; break;
case TIOCMBIC: case TIOCMBIC:
if (switch_modem_lines (0, ipbuffer)) if (switch_modem_lines (0, ipbuf))
res = -1; res = -1;
break; break;
case TIOCCBRK: case TIOCCBRK:
@ -541,21 +542,24 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
res = -1; res = -1;
} }
else else
ipbuffer = st.cbInQue; ipbuf = st.cbInQue;
break; break;
case TIOCGWINSZ: case TIOCGWINSZ:
((struct winsize *) buffer)->ws_row = 0; ((struct winsize *) buf)->ws_row = 0;
((struct winsize *) buffer)->ws_col = 0; ((struct winsize *) buf)->ws_col = 0;
break;
case FIONREAD:
set_errno (ENOTSUP);
res = -1;
break; break;
default: default:
set_errno (ENOSYS); res = fhandler_base::ioctl (cmd, buf);
res = -1;
break; break;
} }
termios_printf ("%d = ioctl (%p, %p)", res, cmd, buffer); termios_printf ("%d = ioctl (%p, %p)", res, cmd, buf);
# undef ibuffer # undef ibuf
# undef ipbuffer # undef ipbuf
return res; return res;
} }

View File

@ -980,8 +980,7 @@ fhandler_pty_slave::ioctl (unsigned int cmd, void *arg)
retval = this->tcsetpgrp ((pid_t) arg); retval = this->tcsetpgrp ((pid_t) arg);
goto out; goto out;
default: default:
set_errno (EINVAL); return fhandler_base::ioctl (cmd, arg);
return -1;
} }
acquire_output_mutex (INFINITE); acquire_output_mutex (INFINITE);

View File

@ -155,8 +155,7 @@ fhandler_windows::ioctl (unsigned int cmd, void *val)
hWnd_ = * ((HWND *) val); hWnd_ = * ((HWND *) val);
break; break;
default: default:
set_errno (EINVAL); return fhandler_base::ioctl (cmd, val);
return -1;
} }
return 0; return 0;
} }