Cygwin: pty: Use autoload feature for pseudo console system calls.
- The autoload feature is used rather than GetModuleHandle(), GetProcAddress() for CreatePseudoConsole(), ResizePseudoConsole() and ClosePseudoConsole().
This commit is contained in:
parent
fac5a01aec
commit
70cd49e204
@ -759,4 +759,7 @@ LoadDLLfunc (PdhAddEnglishCounterW, 16, pdh)
|
|||||||
LoadDLLfunc (PdhCollectQueryData, 4, pdh)
|
LoadDLLfunc (PdhCollectQueryData, 4, pdh)
|
||||||
LoadDLLfunc (PdhGetFormattedCounterValue, 16, pdh)
|
LoadDLLfunc (PdhGetFormattedCounterValue, 16, pdh)
|
||||||
LoadDLLfunc (PdhOpenQueryW, 12, pdh)
|
LoadDLLfunc (PdhOpenQueryW, 12, pdh)
|
||||||
|
LoadDLLfuncEx (CreatePseudoConsole, 20, kernel32, 1)
|
||||||
|
LoadDLLfuncEx (ResizePseudoConsole, 8, kernel32, 1)
|
||||||
|
LoadDLLfuncEx (ClosePseudoConsole, 4, kernel32, 1)
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,12 @@ details. */
|
|||||||
extern "C" int sscanf (const char *, const char *, ...);
|
extern "C" int sscanf (const char *, const char *, ...);
|
||||||
extern "C" int ttyname_r (int, char*, size_t);
|
extern "C" int ttyname_r (int, char*, size_t);
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
HRESULT WINAPI CreatePseudoConsole (COORD, HANDLE, HANDLE, DWORD, HPCON *);
|
||||||
|
HRESULT WINAPI ResizePseudoConsole (HPCON, COORD);
|
||||||
|
VOID WINAPI ClosePseudoConsole (HPCON);
|
||||||
|
}
|
||||||
|
|
||||||
#define close_maybe(h) \
|
#define close_maybe(h) \
|
||||||
do { \
|
do { \
|
||||||
if (h && h != INVALID_HANDLE_VALUE) \
|
if (h && h != INVALID_HANDLE_VALUE) \
|
||||||
@ -2157,14 +2163,8 @@ fhandler_pty_master::close ()
|
|||||||
/* FIXME: Pseudo console can be accessed via its handle
|
/* FIXME: Pseudo console can be accessed via its handle
|
||||||
only in the process which created it. What else can we do? */
|
only in the process which created it. What else can we do? */
|
||||||
if (master_pid_tmp == myself->pid)
|
if (master_pid_tmp == myself->pid)
|
||||||
{
|
|
||||||
/* Release pseudo console */
|
/* Release pseudo console */
|
||||||
HMODULE hModule = GetModuleHandle ("kernel32.dll");
|
|
||||||
FARPROC func = GetProcAddress (hModule, "ClosePseudoConsole");
|
|
||||||
VOID (WINAPI *ClosePseudoConsole) (HPCON) = NULL;
|
|
||||||
ClosePseudoConsole = (VOID (WINAPI *) (HPCON)) func;
|
|
||||||
ClosePseudoConsole (getPseudoConsole ());
|
ClosePseudoConsole (getPseudoConsole ());
|
||||||
}
|
|
||||||
get_ttyp ()->switch_to_pcon_in = false;
|
get_ttyp ()->switch_to_pcon_in = false;
|
||||||
get_ttyp ()->switch_to_pcon_out = false;
|
get_ttyp ()->switch_to_pcon_out = false;
|
||||||
}
|
}
|
||||||
@ -2348,10 +2348,6 @@ fhandler_pty_master::ioctl (unsigned int cmd, void *arg)
|
|||||||
only in the process which created it. What else can we do? */
|
only in the process which created it. What else can we do? */
|
||||||
if (getPseudoConsole () && get_ttyp ()->master_pid == myself->pid)
|
if (getPseudoConsole () && get_ttyp ()->master_pid == myself->pid)
|
||||||
{
|
{
|
||||||
HMODULE hModule = GetModuleHandle ("kernel32.dll");
|
|
||||||
FARPROC func = GetProcAddress (hModule, "ResizePseudoConsole");
|
|
||||||
HRESULT (WINAPI *ResizePseudoConsole) (HPCON, COORD) = NULL;
|
|
||||||
ResizePseudoConsole = (HRESULT (WINAPI *) (HPCON, COORD)) func;
|
|
||||||
COORD size;
|
COORD size;
|
||||||
size.X = ((struct winsize *) arg)->ws_col;
|
size.X = ((struct winsize *) arg)->ws_col;
|
||||||
size.Y = ((struct winsize *) arg)->ws_row;
|
size.Y = ((struct winsize *) arg)->ws_row;
|
||||||
@ -3103,20 +3099,14 @@ fhandler_pty_master::setup_pseudoconsole ()
|
|||||||
process in a pseudo console and get them from the helper.
|
process in a pseudo console and get them from the helper.
|
||||||
Slave process will attach to the pseudo console in the
|
Slave process will attach to the pseudo console in the
|
||||||
helper process using AttachConsole(). */
|
helper process using AttachConsole(). */
|
||||||
HMODULE hModule = GetModuleHandle ("kernel32.dll");
|
|
||||||
FARPROC func = GetProcAddress (hModule, "CreatePseudoConsole");
|
|
||||||
HRESULT (WINAPI *CreatePseudoConsole)
|
|
||||||
(COORD, HANDLE, HANDLE, DWORD, HPCON *) = NULL;
|
|
||||||
if (!func)
|
|
||||||
return false;
|
|
||||||
CreatePseudoConsole =
|
|
||||||
(HRESULT (WINAPI *) (COORD, HANDLE, HANDLE, DWORD, HPCON *)) func;
|
|
||||||
COORD size = {80, 25};
|
COORD size = {80, 25};
|
||||||
CreatePipe (&from_master, &to_slave, &sec_none, 0);
|
CreatePipe (&from_master, &to_slave, &sec_none, 0);
|
||||||
|
SetLastError (ERROR_SUCCESS);
|
||||||
HRESULT res = CreatePseudoConsole (size, from_master, to_master,
|
HRESULT res = CreatePseudoConsole (size, from_master, to_master,
|
||||||
0, &get_ttyp ()->hPseudoConsole);
|
0, &get_ttyp ()->hPseudoConsole);
|
||||||
if (res != S_OK)
|
if (res != S_OK || GetLastError () == ERROR_PROC_NOT_FOUND)
|
||||||
{
|
{
|
||||||
|
if (res != S_OK)
|
||||||
system_printf ("CreatePseudoConsole() failed. %08x\n",
|
system_printf ("CreatePseudoConsole() failed. %08x\n",
|
||||||
GetLastError ());
|
GetLastError ());
|
||||||
CloseHandle (from_master);
|
CloseHandle (from_master);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user