BOOLEAN FASTCALL KiSignalTimer(IN PKTIMER Timer) { BOOLEAN RequestInterrupt = FALSE; PKDPC Dpc = Timer->Dpc; ULONG Period = Timer->Period; LARGE_INTEGER Interval, SystemTime; DPRINT("KiSignalTimer(): Timer %p\n", Timer); /* Set default values */ Timer->Header.Inserted = FALSE; Timer->Header.SignalState = TRUE; /* Check if the timer has waiters */ if (!IsListEmpty(&Timer->Header.WaitListHead)) { /* Check the type of event */ if (Timer->Header.Type == TimerNotificationObject) { /* Unwait the thread */ KxUnwaitThread(&Timer->Header, IO_NO_INCREMENT); } else { /* Otherwise unwait the thread and signal the timer */ KxUnwaitThreadForEvent((PKEVENT)Timer, IO_NO_INCREMENT); } } /* Check if we have a period */ if (Period) { /* Calculate the interval and insert the timer */ Interval.QuadPart = Int32x32To64(Period, -10000); while (!KiInsertTreeTimer(Timer, Interval)); } /* Check if we have a DPC */ if (Dpc) { /* Insert it in the queue */ KeQuerySystemTime(&SystemTime); KeInsertQueueDpc(Dpc, ULongToPtr(SystemTime.LowPart), ULongToPtr(SystemTime.HighPart)); RequestInterrupt = TRUE; } /* Return whether we need to request a DPC interrupt or not */ return RequestInterrupt; }
VALUE rb_WriteConsoleOutput(VALUE self, VALUE h, VALUE buffer, VALUE srcwid, VALUE srcht, VALUE startx, VALUE starty, VALUE l, VALUE t, VALUE r, VALUE b) { COORD coords; COORD size; SMALL_RECT to; HANDLE handle = ULongToPtr( NUM2ULONG( h ) ); Check_Type( buffer, T_STRING ); size.X=NUM2UINT( srcwid ); size.Y=NUM2UINT( srcht ); coords.X=NUM2INT( startx ); coords.Y=NUM2INT( starty ); to.Left = NUM2INT( l ); to.Top = NUM2INT( t ); to.Right = NUM2INT( r ); to.Bottom = NUM2INT( b ); if (WriteConsoleOutput(handle,(CHAR_INFO *)RSTRING_PTR(buffer), size,coords,&to)) { VALUE ret = rb_ary_new(); rb_ary_push( ret, INT2FIX( to.Left ) ); rb_ary_push( ret, INT2FIX( to.Top ) ); rb_ary_push( ret, INT2FIX( to.Right ) ); rb_ary_push( ret, INT2FIX( to.Bottom ) ); return ret; } return rb_getWin32Error(); }
VALUE rb_WriteConsoleOutputAttribute(VALUE self, VALUE h, VALUE s, VALUE x, VALUE y) { unsigned short buffer[80*999*sizeof(unsigned short)]; HANDLE handle = ULongToPtr( NUM2ULONG( h ) ); DWORD written; DWORD towrite; unsigned i = 0; COORD coords; Check_Type( s, T_STRING ); towrite = RSTRING_LEN(s); for(i=0; i<towrite; i++) { buffer[i] = (unsigned short)(RSTRING_PTR(s)[i]); } coords.X=NUM2INT( x ); coords.Y=NUM2INT( y ); if (WriteConsoleOutputAttribute(handle,(const unsigned short *)&buffer, towrite,coords,&written)) { return UINT2NUM( written ); } return rb_getWin32Error(); }
static VALUE rb_GetConsoleScreenBufferInfo( VALUE self, VALUE hConsoleOutput ) { VALUE ret = rb_ary_new(); HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); CONSOLE_SCREEN_BUFFER_INFO out; if ( !GetConsoleScreenBufferInfo( handle, &out ) ) return rb_getWin32Error(); rb_ary_push( ret, UINT2NUM( out.dwSize.X ) ); rb_ary_push( ret, UINT2NUM( out.dwSize.Y ) ); rb_ary_push( ret, UINT2NUM( out.dwCursorPosition.X ) ); rb_ary_push( ret, UINT2NUM( out.dwCursorPosition.Y ) ); rb_ary_push( ret, UINT2NUM( out.wAttributes ) ); rb_ary_push( ret, INT2FIX( out.srWindow.Left ) ); rb_ary_push( ret, INT2FIX( out.srWindow.Top ) ); rb_ary_push( ret, INT2FIX( out.srWindow.Right ) ); rb_ary_push( ret, INT2FIX( out.srWindow.Bottom ) ); rb_ary_push( ret, UINT2NUM( out.dwMaximumWindowSize.X ) ); rb_ary_push( ret, UINT2NUM( out.dwMaximumWindowSize.Y ) ); return ret; }
BOOL MCIAVI_CreateWindow(WINE_MCIAVI* wma, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSW lpOpenParms) { static const WCHAR captionW[] = {'W','i','n','e',' ','M','C','I','-','A','V','I',' ','p','l','a','y','e','r',0}; HWND hParent = 0; DWORD dwStyle = WS_OVERLAPPEDWINDOW; RECT rc; /* what should be done ? */ if (wma->hWnd) return TRUE; if (dwFlags & MCI_DGV_OPEN_PARENT) hParent = lpOpenParms->hWndParent; if (dwFlags & MCI_DGV_OPEN_WS) dwStyle = lpOpenParms->dwStyle; rc.left = rc.top = 0; rc.right = (wma->hic ? wma->outbih : wma->inbih)->biWidth; rc.bottom = (wma->hic ? wma->outbih : wma->inbih)->biHeight; AdjustWindowRect(&rc, dwStyle, FALSE); if (!(dwStyle & (WS_CHILD|WS_POPUP))) /* overlapped window ? */ { rc.right -= rc.left; rc.bottom -= rc.top; rc.left = rc.top = CW_USEDEFAULT; } wma->hWnd = CreateWindowW(mciaviW, captionW, dwStyle, rc.left, rc.top, rc.right, rc.bottom, hParent, 0, MCIAVI_hInstance, ULongToPtr(wma->wDevID)); wma->hWndPaint = wma->hWnd; return wma->hWnd != 0; }
static VALUE rb_ReadConsoleOutput( VALUE self, VALUE hConsoleOutput, VALUE buffer, VALUE srcwid, VALUE srcht, VALUE startx, VALUE starty, VALUE l, VALUE t, VALUE r, VALUE b ) { VALUE ret = rb_ary_new(); COORD coords; COORD size; SMALL_RECT from; HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); size.X= NUM2UINT( srcwid ); size.Y= NUM2UINT( srcht ); coords.X= NUM2INT( startx ); coords.Y= NUM2INT( starty ); from.Left = NUM2INT( l ); from.Top = NUM2INT( t ); from.Right = NUM2INT( r ); from.Bottom = NUM2INT( b ); Check_Type( buffer, T_STRING ); if ( (unsigned long)RSTRING_LEN(buffer) < (sizeof(CHAR_INFO)*size.X*size.Y) ) rb_raise(rb_eArgError, "string buffer is too small for reading that many characters."); if (!ReadConsoleOutput(handle,(CHAR_INFO *)RSTRING_PTR(buffer),size,coords,&from)) return rb_getWin32Error(); rb_ary_push( ret, INT2FIX(from.Left) ); rb_ary_push( ret, INT2FIX(from.Top) ); rb_ary_push( ret, INT2FIX(from.Right) ); rb_ary_push( ret, INT2FIX(from.Bottom) ); return ret; }
VALUE rb_ScrollConsoleScreenBuffer( VALUE self, VALUE hConsoleOutput, VALUE left1, VALUE top1, VALUE right1, VALUE bottom1, VALUE col, VALUE row, VALUE cChar, VALUE attr, VALUE left2, VALUE top2, VALUE right2, VALUE bottom2) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); CHAR_INFO fill; COORD origin; SMALL_RECT scroll, clip; scroll.Left = NUM2INT( left1 ); scroll.Right = NUM2INT( right1 ); scroll.Top = NUM2INT( top1 ); scroll.Bottom = NUM2INT( bottom1 ); clip.Left = NUM2INT( left2 ); clip.Right = NUM2INT( right2 ); clip.Top = NUM2INT( top2 ); clip.Bottom = NUM2INT( bottom2 ); #ifdef UNICODE fill.Char.UnicodeChar = NUM2CHR( cChar ); #else fill.Char.AsciiChar = NUM2CHR( cChar ); #endif fill.Attributes = NUM2INT(attr); origin.X = NUM2UINT( col ); origin.Y = NUM2UINT( row ); if ( ScrollConsoleScreenBuffer( handle, &scroll, &clip, origin, &fill ) ) return INT2FIX(1); return rb_getWin32Error(); }
VALUE rb_SetStdHandle( VALUE self, VALUE fd, VALUE hConsoleOutput ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); if (SetStdHandle(NUM2UINT(fd), handle)) return NUM2UINT(1); return rb_getWin32Error(); }
static VALUE rb_SetConsoleMode( VALUE self, VALUE hConsoleOutput, VALUE Mode ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); if ( SetConsoleMode( handle, NUM2UINT( Mode ) ) ) return INT2FIX(1); return rb_getWin32Error(); }
static VALUE rb_GetConsoleMode(VALUE self, VALUE hConsoleOutput) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); DWORD mode; if (GetConsoleMode(handle,&mode)) return UINT2NUM(mode); return rb_getWin32Error(); }
static VALUE rb_GetNumberOfConsoleInputEvents( VALUE self, VALUE hConsoleOutput ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); DWORD events; if (GetNumberOfConsoleInputEvents(handle, &events)) return INT2FIX(events); return rb_getWin32Error(); }
VALUE rb_SetConsoleActiveScreenBuffer( VALUE self, VALUE hConsoleOutput ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); if ( !SetConsoleActiveScreenBuffer( handle ) ) return rb_getWin32Error(); return INT2FIX(1); }
VALUE rb_SetConsoleTextAttribute( VALUE self, VALUE hConsoleOutput, VALUE wAttributes ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); if ( !SetConsoleTextAttribute( handle, NUM2UINT(wAttributes) ) ) return Qnil; // no getWin32Error to allow piping/redirecting return INT2FIX(1); }
static VALUE rb_GetLargestConsoleWindowSize( VALUE self, VALUE hConsoleOutput ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); COORD size = GetLargestConsoleWindowSize( handle); VALUE ret = rb_ary_new(); rb_ary_push( ret, UINT2NUM( size.X ) ); rb_ary_push( ret, UINT2NUM( size.Y ) ); return ret; }
VALUE rb_SetConsoleCursorInfo( VALUE self, VALUE hConsoleOutput, VALUE size, VALUE visib ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); CONSOLE_CURSOR_INFO c; c.dwSize = NUM2UINT(size); c.bVisible = NUM2UINT(visib); if ( !SetConsoleCursorInfo( handle, &c ) ) return rb_getWin32Error(); return INT2FIX(1); }
VALUE rb_SetConsoleScreenBufferSize( VALUE self, VALUE hConsoleOutput, VALUE x, VALUE y ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); COORD size; size.X=NUM2UINT(x); size.Y=NUM2UINT(y); if (SetConsoleScreenBufferSize(handle, size)) return NUM2UINT(1); return rb_getWin32Error(); }
static VALUE rb_ReadConsoleInput( VALUE self, VALUE hConsoleOutput ) { VALUE ret = rb_ary_new(); HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); DWORD nofread; INPUT_RECORD event; if (!ReadConsoleInput(handle,&event,1,&nofread)) return rb_getWin32Error(); rb_ParseEvent( ret, &event ); return ret; }
static VALUE rb_WriteFile( VALUE self, VALUE hConsoleOutput, VALUE lpBuffer ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); DWORD nNumberOfBytesToWrite = RSTRING_LEN(lpBuffer); DWORD lpNumberOfBytesWritten; WriteFile( handle, RSTRING_PTR(lpBuffer), nNumberOfBytesToWrite, &lpNumberOfBytesWritten, NULL ); return UINT2NUM( lpNumberOfBytesWritten ); }
static VALUE rb_GetConsoleCursorInfo( VALUE self, VALUE hConsoleOutput ) { VALUE ret = rb_ary_new(); HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); CONSOLE_CURSOR_INFO out; if ( !GetConsoleCursorInfo( handle, &out ) ) return rb_getWin32Error(); rb_ary_push( ret, UINT2NUM( out.dwSize ) ); rb_ary_push( ret, UINT2NUM( out.bVisible ) ); return ret; }
void CDeviceGeneralPage::_UpdateUnitDeviceData( ndas::UnitDevicePtr pUnitDevice) { pUnitDevice->UpdateStatus(); pUnitDevice->UpdateInfo(); m_hCursor = AtlLoadSysCursor(IDC_APPSTARTING); SetCursor(m_hCursor); int index = pUnitDevice->GetUnitNo(); ATLASSERT(index < RTL_NUMBER_OF(m_hWorkerThread)); m_hWorkerThread[index] = CreateWorkerThreadParam(ULongToPtr(index)); }
static VALUE rb_ReadConsole( VALUE self, VALUE hConsoleOutput, VALUE buffer, VALUE numread ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); DWORD nofread; int to_read = NUM2INT(numread); Check_Type( buffer, T_STRING ); if ( RSTRING_LEN(buffer) > to_read ) rb_raise(rb_eArgError, "String is too small to read that many characters."); if (ReadConsole(handle,(void *)RSTRING_PTR(buffer), to_read, &nofread,NULL)) return UINT2NUM(nofread); return rb_getWin32Error(); }
NTSTATUS NTAPI SerialSetBaudRate( IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN ULONG NewBaudRate) { ULONG BaudRate; USHORT divisor; PUCHAR ComPortBase = ULongToPtr(DeviceExtension->BaseAddress); NTSTATUS Status = STATUS_SUCCESS; if (NewBaudRate == 0) return STATUS_INVALID_PARAMETER; divisor = (USHORT)(BAUD_CLOCK / (CLOCKS_PER_BIT * NewBaudRate)); BaudRate = BAUD_CLOCK / (CLOCKS_PER_BIT * divisor); Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, ULongToPtr(DeviceExtension->ComPort)); if (NT_SUCCESS(Status)) { UCHAR Lcr; TRACE_(SERIAL, "SerialSetBaudRate(COM%lu, %lu Bauds)\n", DeviceExtension->ComPort, BaudRate); /* Set Bit 7 of LCR to expose baud registers */ Lcr = READ_PORT_UCHAR(SER_LCR(ComPortBase)); WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr | SR_LCR_DLAB); /* Write the baud rate */ WRITE_PORT_UCHAR(SER_DLL(ComPortBase), divisor & 0xff); WRITE_PORT_UCHAR(SER_DLM(ComPortBase), divisor >> 8); /* Switch back to normal registers */ WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr); IoReleaseRemoveLock(&DeviceExtension->RemoveLock, ULongToPtr(DeviceExtension->ComPort)); } if (NT_SUCCESS(Status)) DeviceExtension->BaudRate = BaudRate; return Status; }
VALUE rb_SetConsoleCursorPosition( VALUE self, VALUE hConsoleOutput, VALUE col, VALUE row ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); COORD dwWriteCoord; dwWriteCoord.X = NUM2UINT(col); dwWriteCoord.Y = NUM2UINT(row); // Cannot call rb_getWin32Error as this function fails when // setting cursor to last column/row. if ( !SetConsoleCursorPosition( handle, dwWriteCoord ) ) return Qnil; return INT2FIX(1); }
VALUE rb_SetConsoleWindowInfo( VALUE self, VALUE hConsoleOutput, VALUE bAbsolute, VALUE left, VALUE top, VALUE right, VALUE bottom ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); SMALL_RECT rect; rect.Left = NUM2INT( left ); rect.Top = NUM2INT( top ); rect.Right = NUM2INT( right ); rect.Bottom = NUM2INT( bottom ); if (SetConsoleWindowInfo( handle, NUM2INT( bAbsolute ), &rect )) return UINT2NUM(1); return rb_getWin32Error(); }
void init_stdio(void) { int i; __gOpenFiles[0].handle = GetStdHandle(STD_INPUT_HANDLE); __gOpenFiles[1].handle = GetStdHandle(STD_OUTPUT_HANDLE); __gOpenFiles[2].handle = GetStdHandle(STD_ERROR_HANDLE); __gOpenFiles[0].flags = (GetFileType(ULongToPtr(STD_INPUT_HANDLE))== FILE_TYPE_CHAR)? FCONSOLE:0; __gOpenFiles[1].flags = (GetFileType(ULongToPtr(STD_OUTPUT_HANDLE))== FILE_TYPE_CHAR)? FCONSOLE:0; __gOpenFiles[2].flags = (GetFileType(ULongToPtr(STD_ERROR_HANDLE))== FILE_TYPE_CHAR)? FCONSOLE:0; for(i=3; i<__MAX_OPEN_FILES; i++) { __gOpenFiles[i].handle = INVHL; __gOpenFilesCopy[i].handle = INVHL; __gOpenFiles[i].flags = 0; } my_stdin = &__gOpenFiles[0]; my_stdout = &__gOpenFiles[1]; my_stderr = &__gOpenFiles[2]; }
int __cdecl main() { PVOID address = ULongToPtr(1); SIZE_T length = 512; NTSTATUS status = ZwAllocateVirtualMemory(GetCurrentProcess(), &address, 0, &length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (NT_SUCCESS(status)) { *static_cast<volatile int*>(ULongToPtr(0)) = 0; puts_red(strcpy(static_cast<char*>(ULongToPtr(1)), "null page allocated")); } else switch (status) { case STATUS_INVALID_PARAMETER_2: puts_green("null page alloc failed (may Windows 8 or MS13-031)"); break; case STATUS_CONFLICTING_ADDRESSES: puts_green("null page alloc failed (may EMET)"); break; default: printf_red("!ZwAllocateVirtualMemory"); printf("->0x%lx\n", status); } return EXIT_SUCCESS; }
VOID FORCEINLINE CompleteDPC( IN PVOID DeviceExtension, IN pblk_req vbr, IN ULONG MessageID ) { PSCSI_REQUEST_BLOCK Srb = (PSCSI_REQUEST_BLOCK)vbr->req; PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; #ifndef USE_STORPORT PRHEL_SRB_EXTENSION srbExt = (PRHEL_SRB_EXTENSION)Srb->SrbExtension; UNREFERENCED_PARAMETER( MessageID ); #endif RemoveEntryList(&vbr->list_entry); #ifdef USE_STORPORT if(!adaptExt->dump_mode && adaptExt->dpc_ok) { InsertTailList(&adaptExt->complete_list, &vbr->list_entry); StorPortIssueDpc(DeviceExtension, &adaptExt->completion_dpc, ULongToPtr(MessageID), NULL); return; } CompleteSRB(DeviceExtension, Srb); #else if (Srb->DataTransferLength > srbExt->Xfer) { Srb->DataTransferLength = srbExt->Xfer; Srb->SrbStatus = SRB_STATUS_DATA_OVERRUN; } ScsiPortNotification(RequestComplete, DeviceExtension, Srb); if(srbExt->call_next) { ScsiPortNotification(NextLuRequest, DeviceExtension, Srb->PathId, Srb->TargetId, Srb->Lun); } if (adaptExt->flush_state == FlushRequested) { adaptExt->flush_state = FlushInflight; RhelDoFlush(DeviceExtension); } #endif }
VALUE rb_WriteConsoleOutputCharacter(VALUE self, VALUE h, VALUE s, VALUE x, VALUE y) { HANDLE handle = ULongToPtr( NUM2ULONG( h ) ); DWORD written; COORD coords; Check_Type( s, T_STRING ); coords.X=NUM2INT( x ); coords.Y=NUM2INT( y ); if (WriteConsoleOutputCharacter(handle,(LPCTSTR)RSTRING_PTR(s), RSTRING_LEN(s),coords,&written)) { return UINT2NUM( written ); } return rb_getWin32Error(); }
static VALUE rb_ReadConsoleOutputCharacter( VALUE self, VALUE hConsoleOutput, VALUE charbuf, VALUE len, VALUE x, VALUE y ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); COORD coords; DWORD nofread; int l = NUM2INT(len); coords.X= NUM2UINT( x ); coords.Y= NUM2UINT( y ); if ( (unsigned long)RSTRING_LEN(charbuf) < l*sizeof(TCHAR) ) rb_raise(rb_eArgError, "String is too small to read that many characters."); if (ReadConsoleOutputCharacter(handle,RSTRING_PTR(charbuf),l, coords,&nofread)) return UINT2NUM( nofread ); return rb_getWin32Error(); }
VALUE rb_FillConsoleOutputCharacter( VALUE self, VALUE hConsoleOutput, VALUE cCharacter, VALUE nLength, VALUE col, VALUE row ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); DWORD numChars; COORD dwWriteCoord; dwWriteCoord.X = NUM2UINT(col); dwWriteCoord.Y = NUM2UINT(row); if (FillConsoleOutputCharacter( handle, NUM2CHR(cCharacter), NUM2ULONG(nLength), dwWriteCoord, &numChars )) return ULONG2NUM(numChars); return rb_getWin32Error(); }