diff --git a/base/applications/network/ping/CMakeLists.txt b/base/applications/network/ping/CMakeLists.txt index 9146b26b2bd..8cb9b9ffca2 100644 --- a/base/applications/network/ping/CMakeLists.txt +++ b/base/applications/network/ping/CMakeLists.txt @@ -1,4 +1,5 @@ +set_unicode() add_definitions(-D__USE_W32_SOCKETS) add_executable(ping ping.c ping.rc) diff --git a/base/applications/network/ping/lang/de-DE.rc b/base/applications/network/ping/lang/de-DE.rc new file mode 100644 index 00000000000..676ca86d40e --- /dev/null +++ b/base/applications/network/ping/lang/de-DE.rc @@ -0,0 +1,35 @@ +LANGUAGE LANG_GERMAN, SUBLANG_GERMAN + +STRINGTABLE DISCARDABLE +BEGIN + IDS_USAGE "\nSyntax: ping [-t] [-n Anzahl] [-l Gre] [-w Zeitlimit] Zielhost\n\n" \ + "Optionen:\n" \ + " -t Sendet fortlaufend Pings an den angegebenen Host.\n" \ + " Drcken Sie STRG-C, um den Vorgang abzubrechen.\n" \ + " -n Anzahl Anzahl der Echoanforderungen, die gesendet werden.\n" \ + " -l Gre Gre des Sendepuffers.\n" \ + " -w Zeitlimit Zeitlimit in Millisekunden fr eine Antwort.\n\n\0" + + IDS_PING_WITH_BYTES "\nPinging %1 [%2] with %3!d! bytes Data:\n\n\0" + IDS_PING_STATISTICS "\nPing Statistik fr %1:\n\0" + IDS_PACKETS_SENT_RECEIVED_LOST " Packets: Gesendet = %1!d!, Empfangen = %2!d!, Verloren = %3!d! (%4!d!%% Verlust),\n\0" + IDS_APPROXIMATE_ROUND_TRIP "Durchschnittliche Antwortzeit in Millisekunden:\n\0" + IDS_MIN_MAX_AVERAGE " Minimum = %1, Maximum = %2, Durchschnitt = %3\n\0" + IDS_NOT_ENOUGH_RESOURCES "Nicht gengend freie Resourcen verfgbar.\n\0" + IDS_UNKNOWN_HOST "Unbekannter Host %1.\n\0" + IDS_SETSOCKOPT_FAILED "setsockopt ist fehlgeschlagen (%1!d!).\n\0" + IDS_COULD_NOT_CREATE_SOCKET "Konnte keinen Socket erzeugen (#%1!d!).\n\0" + IDS_COULD_NOT_INIT_WINSOCK "Die Winsock DLL konnte nicht initialisiert werden.\n\0" + IDS_DEST_MUST_BE_SPECIFIED "Name oder IP-Address des Zielhostes muss angegeben werden.\n\0" + IDS_BAD_PARAMETER "Ungltiger Parameter %1.\n\0" + IDS_BAD_OPTION_FORMAT "Ungltiges Options-Format %1.\n\0" + IDS_BAD_OPTION "Ungltige Option %1.\n\0" + IDS_BAD_VALUE_OPTION_L "Ungltiger Wert fr Option -l, Erlaubter Bereich ist von 0 bis %1!d!.\n\0" + IDS_REPLY_FROM "Antwort von %1: bytes=%2!d! time%3%4 TTL=%5!d!\n\0" + IDS_DEST_UNREACHABLE "Zielhost nicht erreichbar.\n\0" + IDS_COULD_NOT_TRANSMIT "Es konnten keine Daten gesendet werden (%1!d!).\n\0" + IDS_COULD_NOT_RECV "Es konnten keine Daten empfangen werden (%1!d!).\n\0" + IDS_REQUEST_TIMEOUT "Zeitberschreitung der Anforderung.\n\0" + IDS_MS "ms\0" + IDS_1MS "1ms\0" +END diff --git a/base/applications/network/ping/lang/en-US.rc b/base/applications/network/ping/lang/en-US.rc new file mode 100644 index 00000000000..c9f9445b4cb --- /dev/null +++ b/base/applications/network/ping/lang/en-US.rc @@ -0,0 +1,35 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE DISCARDABLE +BEGIN + IDS_USAGE "\nUsage: ping [-t] [-n count] [-l size] [-w timeout] destination-host\n\n" \ + "Options:\n" \ + " -t Ping the specified host until stopped.\n" \ + " To stop - type Control-C.\n" \ + " -n count Number of echo requests to send.\n" \ + " -l size Send buffer size.\n" \ + " -w timeout Timeout in milliseconds to wait for each reply.\n\n\0" + + IDS_PING_WITH_BYTES "\nPinging %1 [%2] with %3!d! bytes of data:\n\n\0" + IDS_PING_STATISTICS "\nPing statistics for %1:\n\0" + IDS_PACKETS_SENT_RECEIVED_LOST " Packets: Sent = %1!d!, Received = %2!d!, Lost = %3!d! (%4!d!%% loss),\n\0" + IDS_APPROXIMATE_ROUND_TRIP "Approximate round trip times in milli-seconds:\n\0" + IDS_MIN_MAX_AVERAGE " Minimum = %1, Maximum = %2, Average = %3\n\0" + IDS_NOT_ENOUGH_RESOURCES "Not enough free resources available.\n\0" + IDS_UNKNOWN_HOST "Unknown host %1.\n\0" + IDS_SETSOCKOPT_FAILED "setsockopt failed (%1!d!).\n\0" + IDS_COULD_NOT_CREATE_SOCKET "Could not create socket (#%1!d!).\n\0" + IDS_COULD_NOT_INIT_WINSOCK "Could not initialize winsock dll.\n\0" + IDS_DEST_MUST_BE_SPECIFIED "Name or IP address of destination host must be specified.\n\0" + IDS_BAD_PARAMETER "Bad parameter %1.\n\0" + IDS_BAD_OPTION_FORMAT "Bad option format %1.\n\0" + IDS_BAD_OPTION "Bad option %1.\n\0" + IDS_BAD_VALUE_OPTION_L "Bad value for option -l, valid range is from 0 to %1!d!.\n\0" + IDS_REPLY_FROM "Reply from %1: bytes=%2!d! time%3%4 TTL=%5!d!\n\0" + IDS_DEST_UNREACHABLE "Destination host unreachable.\n\0" + IDS_COULD_NOT_TRANSMIT "Could not transmit data (%1!d!).\n\0" + IDS_COULD_NOT_RECV "Could not receive data (%1!d!).\n\0" + IDS_REQUEST_TIMEOUT "Request timed out.\n\0" + IDS_MS "ms\0" + IDS_1MS "1ms\0" +END diff --git a/base/applications/network/ping/lang/fr-FR.rc b/base/applications/network/ping/lang/fr-FR.rc new file mode 100644 index 00000000000..4794c7637c8 --- /dev/null +++ b/base/applications/network/ping/lang/fr-FR.rc @@ -0,0 +1,35 @@ +LANGUAGE LANG_FRENCH, SUBLANG_NEUTRAL + +STRINGTABLE DISCARDABLE +BEGIN + IDS_USAGE "\nUtilisation : ping [-t] [-n nombre] [-l taille] [-w délai] hôte-destination\n\n" \ + "Options :\n" \ + " -t Ping l'hôte spécifié jusqu'à l'arrêt.\n" \ + " Pour l'arrêter, tapez Ctrl+c.\n" \ + " -n nombre Nombre de requêtes echo à envoyer.\n" \ + " -l taille Taille du tampon d'envoi.\n" \ + " -w délai Délai d'attente en millisecondes pour chaque réponse.\n\n\0" + + IDS_PING_WITH_BYTES "\nPing de %1 [%2] avec %3!d! octets de données :\n\n\0" + IDS_PING_STATISTICS "\nStatistiques du ping de %1 :\n\0" + IDS_PACKETS_SENT_RECEIVED_LOST " Paquets : Envoyés = %1!d!, Reçus = %2!d!, Perdus = %3!d! (%4!d!%% de perte),\n\0" + IDS_APPROXIMATE_ROUND_TRIP "Délai approximatif de réponse en millisecondes :\n\0" + IDS_MIN_MAX_AVERAGE " Minimum = %1, Maximum = %2, Moyenne = %3\n\0" + IDS_NOT_ENOUGH_RESOURCES "Ressources libres disponibles insuffisantes.\n\0" + IDS_UNKNOWN_HOST "Hôte inconnu %1.\n\0" + IDS_SETSOCKOPT_FAILED "Échec de setsockopt (%1!d!).\n\0" + IDS_COULD_NOT_CREATE_SOCKET "Impossible de créer la socket (#%1!d!).\n\0" + IDS_COULD_NOT_INIT_WINSOCK "Impossible d'initialiser winsock dll.\n\0" + IDS_DEST_MUST_BE_SPECIFIED "Le nom ou l'adresse IP de l'hôte de destination doit être spécifié.\n\0" + IDS_BAD_PARAMETER "Paramètre incorrect %1.\n\0" + IDS_BAD_OPTION_FORMAT "Format d'option incorrect %1.\n\0" + IDS_BAD_OPTION "Option incorrecte %1.\n\0" + IDS_BAD_VALUE_OPTION_L "Valeur incorrecte pour l'option -l, elle doit être entre 0 et %1!d!.\n\0" + IDS_REPLY_FROM "Réponse de %1 : octets=%2!d! durée%3%4 TTL=%5!d!\n\0" + IDS_DEST_UNREACHABLE "Hôte de destination injoignable.\n\0" + IDS_COULD_NOT_TRANSMIT "Échec lors de la transmission (%1!d!).\n\0" + IDS_COULD_NOT_RECV "Échec lors de la récéption (%1!d!).\n\0" + IDS_REQUEST_TIMEOUT "Expiration du délai d'attente.\n\0" + IDS_MS "ms\0" + IDS_1MS "1ms\0" +END diff --git a/base/applications/network/ping/lang/it-IT.rc b/base/applications/network/ping/lang/it-IT.rc new file mode 100644 index 00000000000..18806e6e012 --- /dev/null +++ b/base/applications/network/ping/lang/it-IT.rc @@ -0,0 +1,35 @@ +LANGUAGE LANG_ITALIAN, SUBLANG_NEUTRAL + +STRINGTABLE DISCARDABLE +BEGIN + IDS_USAGE "\nUso: ping [-t] [-n conteggio] [-l dimensione] [-w timeout] host-destinazione\n\n" \ + "Opzioni:\n" \ + " -t Esegue il ping dell'host specificato finch non termina.\n" \ + " Per fermare - digitare Control-C.\n" \ + " -n conteggio Numero di richieste echo da inviare.\n" \ + " -l dimensione Dimensione del buffer di invio.\n" \ + " -w timeout Timeout in millisecondi per l'attesa di ogni risposta.\n\n\0" + + IDS_PING_WITH_BYTES "\nPing in corso %1 [%2] con %3!d! bytes di dati:\n\n\0" + IDS_PING_STATISTICS "\nStatistiche di Ping per %1:\n\0" + IDS_PACKETS_SENT_RECEIVED_LOST " Pacchetti: Inviati = %1!d!, Ricevuti = %2!d!, Persi = %3!d! (%4!d!%% perdita),\n\0" + IDS_APPROXIMATE_ROUND_TRIP "Tempo approssimato di andata e ritorno in milli-secondi:\n\0" + IDS_MIN_MAX_AVERAGE " Minimo = %1, Massimo = %2, Media = %3\n\0" + IDS_NOT_ENOUGH_RESOURCES "Risorse disponibili insufficienti.\n\0" + IDS_UNKNOWN_HOST "Host sconosciuto%1.\n\0" + IDS_SETSOCKOPT_FAILED "setsockopt fallito (%1!d!).\n\0" + IDS_COULD_NOT_CREATE_SOCKET "Impossibile creare il socket (#%1!d!).\n\0" + IDS_COULD_NOT_INIT_WINSOCK "Impossibile inizializzare winsock dll.\n\0" + IDS_DEST_MUST_BE_SPECIFIED "Il nome o l'IP dell'host deve essere specificato.\n\0" + IDS_BAD_PARAMETER "Parametro errato %1.\n\0" + IDS_BAD_OPTION_FORMAT "Formato opzione errato %1.\n\0" + IDS_BAD_OPTION "Opzione errata %1.\n\0" + IDS_BAD_VALUE_OPTION_L "Valore errato per il parametro -l, l'intervallo valido tra 0 to %1!d!.\n\0" + IDS_REPLY_FROM "Risposta da %1: bytes=%2!d! time%3%4 TTL=%5!d!\n\0" + IDS_DEST_UNREACHABLE "Host destinazione irraggiungibile.\n\0" + IDS_COULD_NOT_TRANSMIT "Impossibile trasmettere dati (%1!d!).\n\0" + IDS_COULD_NOT_RECV "Impossibile ricevere dati (%1!d!).\n\0" + IDS_REQUEST_TIMEOUT "Richiesta scaduta.\n\0" + IDS_MS "ms\0" + IDS_1MS "1ms\0" +END diff --git a/base/applications/network/ping/lang/pl-PL.rc b/base/applications/network/ping/lang/pl-PL.rc new file mode 100644 index 00000000000..9fa3f839b75 --- /dev/null +++ b/base/applications/network/ping/lang/pl-PL.rc @@ -0,0 +1,42 @@ +/* + * translated by Caemyr (Olaf Siejka) + * caemyr@gmail.com + * Jan, 2011 + */ + + +LANGUAGE LANG_POLISH, SUBLANG_DEFAULT + +STRINGTABLE DISCARDABLE +BEGIN + IDS_USAGE "\nSposb uycia: ping [-t] [-n ilo] [-l bajtw] [-w czas] host-docelowy\n\n" \ + "Opcje:\n" \ + " -t Pinguj wskazanego hosta w sposb cigy.\n" \ + " Aby przerwa - wcinij Control C.\n" \ + " -n ilo Ilo prb pingowania.\n" \ + " -l bajtw Rozmiar pakietu echo w bajtach .\n" \ + " -w czas Opnienie oczekiwanej odpowiedzi, w milisekundach.\n\n\0" + + IDS_PING_WITH_BYTES "\nPingowanie %1 [%2] przy uyciu %3!d! bajtw danych:\n\n\0" + IDS_PING_STATISTICS "\nStatystyka wynikw badania hosta %1:\n\0" + IDS_PACKETS_SENT_RECEIVED_LOST " Pakiety: Wysane = %1!d!, Odebrane = %2!d!, Utracone = %3!d! (%4!d!%% strat),\n\0" + IDS_APPROXIMATE_ROUND_TRIP "Cakowity, przybliony czas podry pakietu w millisekundach:\n\0" + IDS_MIN_MAX_AVERAGE " Minimum = %1, Maksimum = %2, Uredniony = %3\n\0" + IDS_NOT_ENOUGH_RESOURCES "Brak dostpnych zasobw.\n\0" + IDS_UNKNOWN_HOST "Nieznany host %1.\n\0" + IDS_SETSOCKOPT_FAILED "Bd w setsockopt (%1!d!).\n\0" + IDS_COULD_NOT_CREATE_SOCKET "Bd podczas tworzenia gniazda (#%1!d!).\n\0" + IDS_COULD_NOT_INIT_WINSOCK "Bd podczas inicjalizacji winsock dll.\n\0" + IDS_DEST_MUST_BE_SPECIFIED "Brak nazwy hosta bd adresu IP.\n\0" + IDS_BAD_PARAMETER "Nieprawidowy parametr %1.\n\0" + IDS_BAD_OPTION_FORMAT "Nieprawidowy format opcji %1.\n\0" + IDS_BAD_OPTION "Nieprawidowa opcja %1.\n\0" + IDS_BAD_VALUE_OPTION_L "Nieprawidowa warto dla opcji -l, wymagana liczba naturalna od 0 do %1!d!.\n\0" + IDS_REPLY_FROM "Odpowied z %1: bajtw=%2!d! czas%3%4 TTL=%5!d!\n\0" + IDS_DEST_UNREACHABLE "Host docelowy nieosigalny.\n\0" + IDS_COULD_NOT_TRANSMIT "Bd podczas transmisji danych (%1!d!).\n\0" + IDS_COULD_NOT_RECV "Bd podczas odbioru danych (%1!d!).\n\0" + IDS_REQUEST_TIMEOUT "Brak odpowiedzi.\n\0" + IDS_MS "ms\0" + IDS_1MS "1ms\0" +END diff --git a/base/applications/network/ping/ping.c b/base/applications/network/ping/ping.c index 19aa099842c..616498d926e 100644 --- a/base/applications/network/ping/ping.c +++ b/base/applications/network/ping/ping.c @@ -12,6 +12,7 @@ #include #include #include +#include "resource.h" #define NDEBUG @@ -67,10 +68,10 @@ BOOL DontFragment; ULONG TTLValue; ULONG TOSValue; ULONG Timeout; -CHAR TargetName[256]; +WCHAR TargetName[256]; SOCKET IcmpSock; SOCKADDR_IN Target; -LPSTR TargetIP; +WCHAR TargetIP[16]; FD_SET Fds; TIMEVAL Timeval; UINT CurrentSeqNum; @@ -85,6 +86,7 @@ LARGE_INTEGER TicksPerMs; /* Ticks per millisecond */ LARGE_INTEGER TicksPerUs; /* Ticks per microsecond */ LARGE_INTEGER SentTime; BOOL UsePerformanceCounter; +HANDLE hStdOutput; #ifndef NDEBUG /* Display the contents of a buffer */ @@ -107,16 +109,71 @@ static VOID DisplayBuffer( } #endif /* !NDEBUG */ +LPWSTR +MyLoadString(UINT uID) +{ + HRSRC hres; + HGLOBAL hResData; + WCHAR *pwsz; + UINT string_num, i; + + hres = FindResourceW(NULL, MAKEINTRESOURCEW((LOWORD(uID) >> 4) + 1), RT_STRING); + if (!hres) return NULL; + + hResData = LoadResource(NULL, hres); + if (!hResData) return NULL; + + pwsz = LockResource(hResData); + if (!pwsz) return NULL; + + string_num = uID & 15; + for (i = 0; i < string_num; i++) + pwsz += *pwsz + 1; + + return pwsz + 1; +} + +void FormatOutput(UINT uID, ...) +{ + va_list valist; + + WCHAR Buf[1024]; + LPWSTR pBuf = Buf; + LPWSTR Format; + DWORD written; + UINT DataLength; + + va_start(valist, uID); + + Format = MyLoadString(uID); + if (!Format) return; + + DataLength = FormatMessage(FORMAT_MESSAGE_FROM_STRING, Format, 0, 0, Buf,\ + sizeof(Buf) / sizeof(WCHAR), &valist); + + if(!DataLength) + { + if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) + return; + + DataLength = FormatMessage(FORMAT_MESSAGE_FROM_STRING |\ + FORMAT_MESSAGE_ALLOCATE_BUFFER,\ + Format, 0, 0, (LPWSTR)&pBuf, 0, &valist); + + if(!DataLength) + return; + } + + WriteConsole(hStdOutput, pBuf, DataLength, &written, NULL); + + if(pBuf != Buf) + LocalFree(pBuf); +} + /* Display usage information on screen */ static VOID Usage(VOID) { - printf("\nUsage: ping [-t] [-n count] [-l size] [-w timeout] destination-host\n\n"); - printf("Options:\n"); - printf(" -t Ping the specified host until stopped.\n"); - printf(" To stop - type Control-C.\n"); - printf(" -n count Number of echo requests to send.\n"); - printf(" -l size Send buffer size.\n"); - printf(" -w timeout Timeout in milliseconds to wait for each reply.\n\n"); + FormatOutput(IDS_USAGE); } /* Reset configuration to default values */ @@ -157,26 +214,26 @@ static VOID Reset(VOID) } /* Return ULONG in a string */ -static ULONG GetULONG(LPSTR String) +static ULONG GetULONG(LPWSTR String) { UINT i, Length; ULONG Value; - LPSTR StopString; + LPWSTR StopString; i = 0; - Length = (UINT)_tcslen(String); - while ((i < Length) && ((String[i] < '0') || (String[i] > '9'))) i++; - if ((i >= Length) || ((String[i] < '0') || (String[i] > '9'))) + Length = (UINT)wcslen(String); + while ((i < Length) && ((String[i] < L'0') || (String[i] > L'9'))) i++; + if ((i >= Length) || ((String[i] < L'0') || (String[i] > L'9'))) { InvalidOption = TRUE; return 0; } - Value = strtoul(&String[i], &StopString, 10); + Value = wcstoul(&String[i], &StopString, 10); return Value; } /* Return ULONG in a string. Try next paramter if not successful */ -static ULONG GetULONG2(LPSTR String1, LPSTR String2, PINT i) +static ULONG GetULONG2(LPWSTR String1, LPWSTR String2, PINT i) { ULONG Value; @@ -184,7 +241,7 @@ static ULONG GetULONG2(LPSTR String1, LPSTR String2, PINT i) if (InvalidOption) { InvalidOption = FALSE; - if (String2[0] != '-') + if (String2[0] != L'-') { Value = GetULONG(String2); if (!InvalidOption) @@ -196,7 +253,7 @@ static ULONG GetULONG2(LPSTR String1, LPSTR String2, PINT i) } /* Parse command line parameters */ -static BOOL ParseCmdline(int argc, char* argv[]) +static BOOL ParseCmdline(int argc, LPWSTR argv[]) { INT i; BOOL ShowUsage; @@ -210,34 +267,35 @@ static BOOL ParseCmdline(int argc, char* argv[]) for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') + if (argv[i][0] == L'-') { switch (argv[i][1]) { - case 't': NeverStop = TRUE; break; - case 'a': ResolveAddresses = TRUE; break; - case 'n': PingCount = GetULONG2(&argv[i][2], argv[i + 1], &i); break; - case 'l': + case L't': NeverStop = TRUE; break; + case L'a': ResolveAddresses = TRUE; break; + case L'n': PingCount = GetULONG2(&argv[i][2], argv[i + 1], &i); break; + case L'l': DataSize = GetULONG2(&argv[i][2], argv[i + 1], &i); if (DataSize > ICMP_MAXSIZE - sizeof(ICMP_ECHO_PACKET) - sizeof(IPv4_HEADER)) { - printf("Bad value for option -l, valid range is from 0 to %d.\n", - ICMP_MAXSIZE - (int)sizeof(ICMP_ECHO_PACKET) - (int)sizeof(IPv4_HEADER)); + FormatOutput(IDS_BAD_VALUE_OPTION_L, ICMP_MAXSIZE - \ + (int)sizeof(ICMP_ECHO_PACKET) - \ + (int)sizeof(IPv4_HEADER)); return FALSE; } break; - case 'f': DontFragment = TRUE; break; - case 'i': TTLValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break; - case 'v': TOSValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break; - case 'w': Timeout = GetULONG2(&argv[i][2], argv[i + 1], &i); break; + case L'f': DontFragment = TRUE; break; + case L'i': TTLValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break; + case L'v': TOSValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break; + case L'w': Timeout = GetULONG2(&argv[i][2], argv[i + 1], &i); break; default: - printf("Bad option %s.\n", argv[i]); + FormatOutput(IDS_BAD_OPTION, argv[i]); Usage(); return FALSE; } if (InvalidOption) { - printf("Bad option format %s.\n", argv[i]); + FormatOutput(IDS_BAD_OPTION_FORMAT, argv[i]); return FALSE; } } @@ -245,12 +303,12 @@ static BOOL ParseCmdline(int argc, char* argv[]) { if (FoundTarget) { - printf("Bad parameter %s.\n", argv[i]); + FormatOutput(IDS_BAD_PARAMETER, argv[i]); return FALSE; } else { - lstrcpy(TargetName, argv[i]); + wcscpy(TargetName, argv[i]); FoundTarget = TRUE; } } @@ -258,7 +316,7 @@ static BOOL ParseCmdline(int argc, char* argv[]) if ((!ShowUsage) && (!FoundTarget)) { - printf("Name or IP address of destination host must be specified.\n"); + FormatOutput(IDS_DEST_MUST_BE_SPECIFIED); return FALSE; } @@ -298,20 +356,21 @@ static BOOL Setup(VOID) INT Status; ULONG Addr; PHOSTENT phe; + CHAR aTargetName[256]; wVersionRequested = MAKEWORD(2, 2); Status = WSAStartup(wVersionRequested, &WsaData); if (Status != 0) { - printf("Could not initialize winsock dll.\n"); + FormatOutput(IDS_COULD_NOT_INIT_WINSOCK); return FALSE; } IcmpSock = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0, 0); if (IcmpSock == INVALID_SOCKET) { - printf("Could not create socket (#%d).\n", WSAGetLastError()); + FormatOutput(IDS_COULD_NOT_CREATE_SOCKET, WSAGetLastError()); return FALSE; } @@ -321,7 +380,7 @@ static BOOL Setup(VOID) (const char *)&DontFragment, sizeof(DontFragment)) == SOCKET_ERROR) { - printf("setsockopt failed (%d).\n", WSAGetLastError()); + FormatOutput(IDS_SETSOCKOPT_FAILED, WSAGetLastError()); return FALSE; } @@ -331,35 +390,44 @@ static BOOL Setup(VOID) (const char *)&TTLValue, sizeof(TTLValue)) == SOCKET_ERROR) { - printf("setsockopt failed (%d).\n", WSAGetLastError()); + FormatOutput(IDS_SETSOCKOPT_FAILED, WSAGetLastError()); return FALSE; } - ZeroMemory(&Target, sizeof(Target)); - phe = NULL; - Addr = inet_addr(TargetName); - if (Addr == INADDR_NONE) + if(!WideCharToMultiByte(CP_ACP, 0, TargetName, -1, aTargetName,\ + sizeof(aTargetName), NULL, NULL)) { - phe = gethostbyname(TargetName); - if (phe == NULL) - { - printf("Unknown host %s.\n", TargetName); - return FALSE; - } + FormatOutput(IDS_UNKNOWN_HOST, TargetName); + return FALSE; } - if (phe != NULL) + ZeroMemory(&Target, sizeof(Target)); + phe = NULL; + Addr = inet_addr(aTargetName); + if (Addr == INADDR_NONE) + { + phe = gethostbyname(aTargetName); + if (phe == NULL) + { + FormatOutput(IDS_UNKNOWN_HOST, TargetName); + return FALSE; + } + CopyMemory(&Target.sin_addr, phe->h_addr, phe->h_length); - else - Target.sin_addr.s_addr = Addr; - - if (phe != NULL) Target.sin_family = phe->h_addrtype; + } else + { + Target.sin_addr.s_addr = Addr; Target.sin_family = AF_INET; + } - TargetIP = inet_ntoa(Target.sin_addr); + + swprintf(TargetIP, L"%d.%d.%d.%d", Target.sin_addr.S_un.S_un_b.s_b1,\ + Target.sin_addr.S_un.S_un_b.s_b2,\ + Target.sin_addr.S_un.S_un_b.s_b3,\ + Target.sin_addr.S_un.S_un_b.s_b4); CurrentSeqNum = 1; SentCount = 0; LostCount = 0; @@ -405,16 +473,18 @@ static VOID QueryTime(PLARGE_INTEGER Time) } } -static VOID TimeToMsString(LPSTR String, LARGE_INTEGER Time) +static VOID TimeToMsString(LPWSTR String, LARGE_INTEGER Time) { - CHAR Convstr[40]; + WCHAR Convstr[40]; LARGE_INTEGER LargeTime; + LPWSTR ms; LargeTime.QuadPart = Time.QuadPart / TicksPerMs.QuadPart; - _i64toa(LargeTime.QuadPart, Convstr, 10); - strcpy(String, Convstr); - strcat(String, "ms"); + _i64tow(LargeTime.QuadPart, Convstr, 10); + wcscpy(String, Convstr); + ms = MyLoadString(IDS_MS); + wcscat(String, ms); } /* Locate the ICMP data and print it. Returns TRUE if the packet was good, @@ -424,10 +494,11 @@ static BOOL DecodeResponse(PCHAR buffer, UINT size, PSOCKADDR_IN from) PIPv4_HEADER IpHeader; PICMP_ECHO_PACKET Icmp; UINT IphLength; - CHAR Time[100]; + WCHAR Time[100]; LARGE_INTEGER RelativeTime; LARGE_INTEGER LargeTime; - CHAR Sign[2]; + WCHAR Sign[2]; + WCHAR wfromIP[16]; IpHeader = (PIPv4_HEADER)buffer; @@ -473,18 +544,27 @@ static BOOL DecodeResponse(PCHAR buffer, UINT size, PSOCKADDR_IN from) if ((RelativeTime.QuadPart / TicksPerMs.QuadPart) < 1) { - strcpy(Sign, "<"); - strcpy(Time, "1ms"); + LPWSTR ms1; + + wcscpy(Sign, L"<"); + ms1 = MyLoadString(IDS_1MS); + wcscpy(Time, ms1); } else { - strcpy(Sign, "="); + wcscpy(Sign, L"="); TimeToMsString(Time, RelativeTime); } - printf("Reply from %s: bytes=%d time%s%s TTL=%d\n", inet_ntoa(from->sin_addr), - size - IphLength - (int)sizeof(ICMP_ECHO_PACKET), Sign, Time, IpHeader->TTL); + swprintf(wfromIP, L"%d.%d.%d.%d", from->sin_addr.S_un.S_un_b.s_b1,\ + from->sin_addr.S_un.S_un_b.s_b2,\ + from->sin_addr.S_un.S_un_b.s_b3,\ + from->sin_addr.S_un.S_un_b.s_b4); + FormatOutput(IDS_REPLY_FROM, wfromIP,\ + size - IphLength - (int)sizeof(ICMP_ECHO_PACKET),\ + Sign, Time, IpHeader->TTL); + if (RelativeTime.QuadPart < MinRTT.QuadPart || !MinRTTSet) { MinRTT.QuadPart = RelativeTime.QuadPart; @@ -513,7 +593,7 @@ static BOOL Ping(VOID) Buffer = GlobalAlloc(0, Size); if (!Buffer) { - printf("Not enough free resources available.\n"); + FormatOutput(IDS_NOT_ENOUGH_RESOURCES); return FALSE; } @@ -556,9 +636,9 @@ static BOOL Ping(VOID) if (Status == SOCKET_ERROR) { if (WSAGetLastError() == WSAEHOSTUNREACH) - printf("Destination host unreachable.\n"); + FormatOutput(IDS_DEST_UNREACHABLE); else - printf("Could not transmit data (%d).\n", WSAGetLastError()); + FormatOutput(IDS_COULD_NOT_TRANSMIT, WSAGetLastError()); GlobalFree(Buffer); return FALSE; } @@ -588,7 +668,7 @@ static BOOL Ping(VOID) { if (WSAGetLastError() != WSAETIMEDOUT) { - printf("Could not receive data (%d).\n", WSAGetLastError()); + FormatOutput(IDS_COULD_NOT_RECV, WSAGetLastError()); GlobalFree(Buffer); return FALSE; } @@ -597,7 +677,7 @@ static BOOL Ping(VOID) if (Status == 0) { - printf("Request timed out.\n"); + FormatOutput(IDS_REQUEST_TIMEOUT); GlobalFree(Buffer); return TRUE; } @@ -610,20 +690,21 @@ static BOOL Ping(VOID) /* Program entry point */ -int main(int argc, char* argv[]) +int wmain(int argc, LPWSTR argv[]) { UINT Count; - CHAR MinTime[20]; - CHAR MaxTime[20]; - CHAR AvgTime[20]; + WCHAR MinTime[20]; + WCHAR MaxTime[20]; + WCHAR AvgTime[20]; + + hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); Reset(); if ((ParseCmdline(argc, argv)) && (Setup())) { - printf("\nPinging %s [%s] with %d bytes of data:\n\n", - TargetName, TargetIP, DataSize); + FormatOutput(IDS_PING_WITH_BYTES, TargetName, TargetIP, DataSize); Count = 0; while ((NeverStop) || (Count < PingCount)) @@ -653,15 +734,15 @@ int main(int argc, char* argv[]) TimeToMsString(AvgTime, AvgRTT); /* Print statistics */ - printf("\nPing statistics for %s:\n", TargetIP); - printf(" Packets: Sent = %d, Received = %d, Lost = %d (%d%% loss),\n", + FormatOutput(IDS_PING_STATISTICS, TargetIP); + FormatOutput(IDS_PACKETS_SENT_RECEIVED_LOST,\ SentCount, SentCount - LostCount, LostCount, Count); + /* Print approximate times or NO approximate times if 100% loss */ if ((SentCount - LostCount) > 0) { - printf("Approximate round trip times in milli-seconds:\n"); - printf(" Minimum = %s, Maximum = %s, Average = %s\n", - MinTime, MaxTime, AvgTime); + FormatOutput(IDS_APPROXIMATE_ROUND_TRIP); + FormatOutput(IDS_MIN_MAX_AVERAGE, MinTime, MaxTime, AvgTime); } } return 0; diff --git a/base/applications/network/ping/ping.rc b/base/applications/network/ping/ping.rc index e85608046c5..e138e7c4235 100644 --- a/base/applications/network/ping/ping.rc +++ b/base/applications/network/ping/ping.rc @@ -1,7 +1,15 @@ /* $Id$ */ +#include +#include "resource.h" #define REACTOS_STR_FILE_DESCRIPTION "ReactOS TCP/IPv4 Win32 Ping\0" #define REACTOS_STR_INTERNAL_NAME "ping\0" #define REACTOS_STR_ORIGINAL_FILENAME "ping.exe\0" #define REACTOS_STR_ORIGINAL_COPYRIGHT "Casper S. Hornstrup (chorns@users.sourceforge.net)\0" #include + +#include "lang/de-DE.rc" +#include "lang/en-US.rc" +#include "lang/fr-FR.rc" +#include "lang/pl-PL.rc" +#include "lang/it-IT.rc" diff --git a/base/applications/network/ping/resource.h b/base/applications/network/ping/resource.h new file mode 100644 index 00000000000..c5733252ba0 --- /dev/null +++ b/base/applications/network/ping/resource.h @@ -0,0 +1,24 @@ +#define IDS_USAGE 0 +#define IDS_PING_WITH_BYTES 1 +#define IDS_PING_STATISTICS 2 +#define IDS_PACKETS_SENT_RECEIVED_LOST 3 +#define IDS_APPROXIMATE_ROUND_TRIP 4 +#define IDS_MIN_MAX_AVERAGE 5 +#define IDS_NOT_ENOUGH_RESOURCES 6 +#define IDS_UNKNOWN_HOST 7 +#define IDS_SETSOCKOPT_FAILED 8 +#define IDS_COULD_NOT_CREATE_SOCKET 9 +#define IDS_COULD_NOT_INIT_WINSOCK 10 +#define IDS_DEST_MUST_BE_SPECIFIED 11 +#define IDS_BAD_PARAMETER 12 +#define IDS_BAD_OPTION_FORMAT 13 +#define IDS_BAD_OPTION 14 +#define IDS_BAD_VALUE_OPTION_L 15 +#define IDS_REPLY_FROM 16 +#define IDS_DEST_UNREACHABLE 17 +#define IDS_COULD_NOT_TRANSMIT 18 +#define IDS_COULD_NOT_RECV 19 +#define IDS_REQUEST_TIMEOUT 20 +#define IDS_MS 21 +#define IDS_1MS 22 + diff --git a/base/applications/rapps/rapps/kdewin.txt b/base/applications/rapps/rapps/kdewin.txt index 4c47525940a..ced1b4a3a9e 100644 --- a/base/applications/rapps/rapps/kdewin.txt +++ b/base/applications/rapps/rapps/kdewin.txt @@ -2,13 +2,13 @@ [Section] Name = K Desktop Environment -Version = 0.9.7-0 +Version = 0.9.8-1 Licence = GPL Description = KDE for Windows. Size = 2.0MB Category = 15 URLSite = http://www.winkde.org/ -URLDownload = http://www.winkde.org/pub/kde/ports/win32/installer/kdewin-installer-gui-0.9.7-0.exe +URLDownload = http://www.winkde.org/pub/kde/ports/win32/installer/kdewin-installer-gui-0.9.8-1.exe CDPath = none [Section.0407] diff --git a/base/applications/rapps/rapps/libreoffice.txt b/base/applications/rapps/rapps/libreoffice.txt index 2fd0d9df7c9..60c99c5f174 100644 --- a/base/applications/rapps/rapps/libreoffice.txt +++ b/base/applications/rapps/rapps/libreoffice.txt @@ -2,13 +2,13 @@ [Section] Name = LibreOffice -Version = 3.3.0 RC2 +Version = 3.3.0 RC3 Licence = LGPL Description = Former called OpenOffice. Open Source Office Suite. -Size = 206.0MB +Size = 209.0MB Category = 6 URLSite = http://www.documentfoundation.org/ -URLDownload = http://download.documentfoundation.org/libreoffice/testing/3.3.0-rc2/win/x86/LibO_3.3.0rc2_Win_x86_install_multi.exe +URLDownload = http://download.documentfoundation.org/libreoffice/testing/3.3.0-rc3/win/x86/LibO_3.3.0rc3_Win_x86_install_multi.exe CDPath = none [Section.0407] diff --git a/base/applications/rapps/rapps/mono2.txt b/base/applications/rapps/rapps/mono2.txt index 5911b62896b..309fc5d201c 100644 --- a/base/applications/rapps/rapps/mono2.txt +++ b/base/applications/rapps/rapps/mono2.txt @@ -2,13 +2,13 @@ [Section] Name = Mono .net Development Framework -Version = 2.8.1 +Version = 2.8.2 Licence = Unknown Description = Open Source .net Framework. Size = 77MB Category = 14 URLSite = http://www.mono-project.com/Main_Page -URLDownload = http://ftp.novell.com/pub/mono/archive/2.8.1/windows-installer/3/mono-2.8.1-gtksharp-2.12.10-win32-3.exe +URLDownload = http://ftp.novell.com/pub/mono/archive/2.8.2/windows-installer/1/mono-2.8.2-gtksharp-2.12.10-win32-1.exe CDPath = none [Section.0415] diff --git a/base/applications/rapps/rapps/python.txt b/base/applications/rapps/rapps/python.txt index 4c77199eb62..f18ae1ccfca 100644 --- a/base/applications/rapps/rapps/python.txt +++ b/base/applications/rapps/rapps/python.txt @@ -2,13 +2,13 @@ [Section] Name = Python -Version = 2.6.6 +Version = 2.7.1 Licence = GPL/LGPL Description = A remarkably powerful dynamic programming language. -Size = 14.5MB +Size = 15.0MB Category = 7 URLSite = http://www.python.org/ -URLDownload = http://www.python.org/ftp/python/2.6.6/python-2.6.6.msi +URLDownload = http://www.python.org/ftp/python/2.7.1/python-2.7.1.msi CDPath = none [Section.0407] diff --git a/base/applications/rapps/rapps/sbforvmware.txt b/base/applications/rapps/rapps/sbforvmware.txt new file mode 100644 index 00000000000..4b73234b775 --- /dev/null +++ b/base/applications/rapps/rapps/sbforvmware.txt @@ -0,0 +1,48 @@ +; UTF-8 + +[Section] +Name = SoundBlaster Driver for VMWare +Version = 5.12.1.5017 +Licence = Unknown +Description = Unzip in the "ReactOS" folder then restart ReactOS twice. +Size = 2.2MB +Category = 13 +URLSite = Unknown +URLDownload = http://svn.reactos.org/packages/sb_vmware.exe +CDPath = none + +[Section.0405] +Name = Ovladač SoundBlaster pro VMWare +Licence = Neznámá +Description = Rozbalte do složky "ReactOS" a pak ReactOS dvakrát restartujte. +URLSite = Neznámá + +[Section.0407] +Name = SoundBlaster Treiber für VMWare +Licence = Unbekannt +Description = Entpacken in das "ReactOS"-Verzeichnis und ReactOS zweimal neustarten. +URLSite = Unbekannt + +[Section.040a] +Name = Driver SoundBlaster para VMWare +Licence = Desconocida +Description = Descomprimir en la carpeta "Reactos" y reiniciar Reactos dos veces. +URLSite = Desconocida + +[Section.0415] +Name = Sterownik SoundBlaster dla VMWare +Licence = Nieznana +Description = Rozpakuj zawartość w folderze "ReactOS" i dwukrotnie zrestartuj system. +URLSite = Nieznana + +[Section.0419] +Name = Драйвер SoundBlaster для VMWare +Licence = Не указано +Description = Pазархивируйте содержимое в папку "ReactOS", затем дважды перезагрузите систему. +URLSite = Не указано + +[Section.0422] +Name = Драйвер SoundBlaster для VMWare +Licence = Невідома +Description = Pозархівуйте вміст в теку "ReactOS" після чого двічі перезавантажте систему. +URLSite = Не вказано diff --git a/base/applications/rapps/rapps/tuxpaint.txt b/base/applications/rapps/rapps/tuxpaint.txt index e3216ae0233..60928f66842 100644 --- a/base/applications/rapps/rapps/tuxpaint.txt +++ b/base/applications/rapps/rapps/tuxpaint.txt @@ -2,13 +2,13 @@ [Section] Name = TuxPaint -Version = 0.9.21b +Version = 0.9.21c Licence = GPL Description = An Open Source bitmap graphics editor geared towards young children. Size = 11MB Category = 3 URLSite = http://tuxpaint.org/ -URLDownload = http://ovh.dl.sourceforge.net/project/tuxpaint/tuxpaint/0.9.21b/tuxpaint-0.9.21b-win32-installer.exe +URLDownload = http://ovh.dl.sourceforge.net/project/tuxpaint/tuxpaint/0.9.21c/tuxpaint-0.9.21c-win32-installer.exe CDPath = none [Section.0405] diff --git a/base/applications/shutdown/lang/fr-FR.rc b/base/applications/shutdown/lang/fr-FR.rc index deb41dc298e..e50c5e92c7b 100644 --- a/base/applications/shutdown/lang/fr-FR.rc +++ b/base/applications/shutdown/lang/fr-FR.rc @@ -4,7 +4,7 @@ STRINGTABLE DISCARDABLE BEGIN IDS_USAGE, "Utilisation: shutdown [-?] [-l | -s | -r] [-f]\n\n\ - Aucun argument ou -?\tAffichent ce message\n\ + Aucun argument ou -?\tAffiche ce message\n\ -l\t\t\tSe dconnecter\n\ -s\t\t\tteindre l'ordinateur\n\ -r\t\t\tteindre et redmarrer l'ordinateur\n\ diff --git a/base/shell/explorer-new/CMakeLists.txt b/base/shell/explorer-new/CMakeLists.txt index 4b62255228b..2ac2ed9106d 100644 --- a/base/shell/explorer-new/CMakeLists.txt +++ b/base/shell/explorer-new/CMakeLists.txt @@ -31,6 +31,7 @@ add_importlibs(explorer_new oleaut32 shell32 shlwapi + version msvcrt kernel32 ntdll) diff --git a/base/shell/explorer-new/explorer.c b/base/shell/explorer-new/explorer.c index 8716edc021f..888e9d42ffc 100644 --- a/base/shell/explorer-new/explorer.c +++ b/base/shell/explorer-new/explorer.c @@ -26,6 +26,12 @@ HANDLE hProcessHeap; HKEY hkExplorer = NULL; DRAWCAPTEMP DrawCapTemp = NULL; +typedef struct _LANGCODEPAGE +{ + WORD wLanguage; + WORD wCodePage; +} LANGCODEPAGE, *PLANGCODEPAGE; + /* undoc GUID */ DEFINE_GUID(CLSID_RebarBandSite, 0xECD4FC4D, 0x521C, 0x11D0, 0xB7, 0x92, 0x00, 0xA0, 0xC9, 0x03, 0x12, 0xE1); @@ -270,6 +276,80 @@ SetShellReadyEvent(IN LPCTSTR lpEventName) return FALSE; } +BOOL +GetVersionInfoString(IN TCHAR *szFileName, + IN TCHAR *szVersionInfo, + OUT TCHAR *szBuffer, + IN UINT cbBufLen) +{ + LPVOID lpData = NULL; + TCHAR szSubBlock[128]; + TCHAR *lpszLocalBuf = NULL; + LANGID UserLangId; + PLANGCODEPAGE lpTranslate = NULL; + DWORD dwLen; + DWORD dwHandle; + UINT cbTranslate; + UINT cbLen; + BOOL bRet = FALSE; + unsigned int i; + + dwLen = GetFileVersionInfoSize(szFileName,&dwHandle); + + if (dwLen > 0) + { + lpData = HeapAlloc(hProcessHeap,0,dwLen); + + if (lpData != NULL) + { + if (GetFileVersionInfo(szFileName, + 0, + dwLen, + lpData) != 0) + { + UserLangId = GetUserDefaultLangID(); + + VerQueryValue(lpData, + TEXT("\\VarFileInfo\\Translation"), + (LPVOID *)&lpTranslate, + &cbTranslate); + + for (i = 0;i < (cbTranslate / sizeof(LANGCODEPAGE));i++) + { + /* If the bottom eight bits of the language id's + match, use this version information (since this + means that the version information and the users + default language are the same). */ + if ((lpTranslate[i].wLanguage & 0xFF) == + (UserLangId & 0xFF)) + { + wnsprintf(szSubBlock, + sizeof(szSubBlock) / sizeof(szSubBlock[0]), + TEXT("\\StringFileInfo\\%04X%04X\\%s"), + lpTranslate[i].wLanguage, + lpTranslate[i].wCodePage,szVersionInfo); + + if (VerQueryValue(lpData, + szSubBlock, + (LPVOID *)&lpszLocalBuf, + &cbLen) != 0) + { + wcsncpy(szBuffer,lpszLocalBuf,cbBufLen); + + bRet = TRUE; + break; + } + } + } + } + HeapFree(hProcessHeap,0,lpData); + lpData = NULL; + } + } + + return bRet; +} + INT WINAPI _tWinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, diff --git a/base/shell/explorer-new/taskswnd.c b/base/shell/explorer-new/taskswnd.c index a694267111c..6a4501191cc 100644 --- a/base/shell/explorer-new/taskswnd.c +++ b/base/shell/explorer-new/taskswnd.c @@ -1715,6 +1715,64 @@ TaskSwitchWnd_HandleButtonClick(IN OUT PTASK_SWITCH_WND This, return FALSE; } + +static VOID +TaskSwitchWnd_HandleTaskItemRightClick(IN OUT PTASK_SWITCH_WND This, + IN OUT PTASK_ITEM TaskItem) +{ + + HMENU hmenu = GetSystemMenu(TaskItem->hWnd, FALSE); + + if (hmenu) { + POINT pt; + GetCursorPos(&pt); + int cmd = TrackPopupMenu(hmenu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_RETURNCMD, pt.x, pt.y, 0, This->hWndToolbar, NULL); + if (cmd) { + SetForegroundWindow(TaskItem->hWnd); // reactivate window after the context menu has closed + PostMessage(TaskItem->hWnd, WM_SYSCOMMAND, cmd, 0); + } + } +} + +static VOID +TaskSwitchWnd_HandleTaskGroupRightClick(IN OUT PTASK_SWITCH_WND This, + IN OUT PTASK_GROUP TaskGroup) +{ + /* TODO: Show task group right click menu */ +} + +static BOOL +TaskSwitchWnd_HandleButtonRightClick(IN OUT PTASK_SWITCH_WND This, + IN WORD wIndex) +{ + PTASK_ITEM TaskItem; + PTASK_GROUP TaskGroup; + if (This->IsGroupingEnabled) + { + TaskGroup = FindTaskGroupByIndex(This, + (INT)wIndex); + if (TaskGroup != NULL && TaskGroup->IsCollapsed) + { + TaskSwitchWnd_HandleTaskGroupRightClick(This, + TaskGroup); + return TRUE; + } + } + + TaskItem = FindTaskItemByIndex(This, + (INT)wIndex); + + if (TaskItem != NULL) + { + TaskSwitchWnd_HandleTaskItemRightClick(This, + TaskItem); + return TRUE; + } + + return FALSE; +} + + static LRESULT TaskSwichWnd_HandleItemPaint(IN OUT PTASK_SWITCH_WND This, IN OUT NMTBCUSTOMDRAW *nmtbcd) @@ -2001,7 +2059,8 @@ TaskSwitchWndProc(IN HWND hwnd, (LPARAM)&pt); if (iBtn >= 0) { - /* FIXME: Display the system menu of the window */ + TaskSwitchWnd_HandleButtonRightClick(This, + iBtn); } else goto ForwardContextMenuMsg; diff --git a/base/shell/explorer/utility/utility.h b/base/shell/explorer/utility/utility.h index 835594a6d84..10a47154aa1 100644 --- a/base/shell/explorer/utility/utility.h +++ b/base/shell/explorer/utility/utility.h @@ -29,6 +29,7 @@ #define WIN32_LEAN_AND_MEAN #define WIN32_EXTRA_LEAN #include +#include // Unicode support #if defined(UNICODE) && !defined(_UNICODE) diff --git a/base/system/winlogon/wlx.c b/base/system/winlogon/wlx.c index 7dcb9bc3471..3258c19b166 100644 --- a/base/system/winlogon/wlx.c +++ b/base/system/winlogon/wlx.c @@ -961,7 +961,9 @@ CreateWindowStationAndDesktops( DWORD SidSize, AclSize; PACL pDefaultAcl = NULL; PACL pUserDesktopAcl = NULL; + SECURITY_DESCRIPTOR DefaultSecurityDescriptor; SECURITY_ATTRIBUTES DefaultSecurity; + SECURITY_DESCRIPTOR UserDesktopSecurityDescriptor; SECURITY_ATTRIBUTES UserDesktopSecurity; BOOL ret = FALSE; @@ -1008,8 +1010,24 @@ CreateWindowStationAndDesktops( ERR("WL: AddAccessAllowedAce() failed (error %lu)\n", GetLastError()); goto cleanup; } + + /* + * Create the default security descriptor + */ + if (!InitializeSecurityDescriptor(&DefaultSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION)) + { + ERR("WL: InitializeSecurityDescriptor() failed (error %lu)\n", GetLastError()); + goto cleanup; + } + + if (!SetSecurityDescriptorDacl(&DefaultSecurityDescriptor, TRUE, pDefaultAcl, FALSE)) + { + ERR("WL: SetSecurityDescriptorDacl() failed (error %lu)\n", GetLastError()); + goto cleanup; + } + DefaultSecurity.nLength = sizeof(SECURITY_ATTRIBUTES); - DefaultSecurity.lpSecurityDescriptor = pDefaultAcl; + DefaultSecurity.lpSecurityDescriptor = &DefaultSecurityDescriptor; DefaultSecurity.bInheritHandle = TRUE; /* @@ -1021,8 +1039,24 @@ CreateWindowStationAndDesktops( ERR("WL: AddAccessAllowedAce() failed (error %lu)\n", GetLastError()); goto cleanup; } + + /* + * Create the user desktop security descriptor + */ + if (!InitializeSecurityDescriptor(&UserDesktopSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION)) + { + ERR("WL: InitializeSecurityDescriptor() failed (error %lu)\n", GetLastError()); + goto cleanup; + } + + if (!SetSecurityDescriptorDacl(&UserDesktopSecurityDescriptor, TRUE, pUserDesktopAcl, FALSE)) + { + ERR("WL: SetSecurityDescriptorDacl() failed (error %lu)\n", GetLastError()); + goto cleanup; + } + UserDesktopSecurity.nLength = sizeof(SECURITY_ATTRIBUTES); - UserDesktopSecurity.lpSecurityDescriptor = pUserDesktopAcl; + UserDesktopSecurity.lpSecurityDescriptor = &UserDesktopSecurityDescriptor; UserDesktopSecurity.bInheritHandle = TRUE; /* diff --git a/boot/freeldr/freeldr/arch/i386/machpc.c b/boot/freeldr/freeldr/arch/i386/machpc.c index 1b985f28c4d..879e2029d6e 100644 --- a/boot/freeldr/freeldr/arch/i386/machpc.c +++ b/boot/freeldr/freeldr/arch/i386/machpc.c @@ -23,7 +23,7 @@ VOID PcMachInit(const char *CmdLine) { EnableA20(); - + /* Setup vtbl */ MachVtbl.ConsPutChar = PcConsPutChar; MachVtbl.ConsKbHit = PcConsKbHit; @@ -33,7 +33,6 @@ PcMachInit(const char *CmdLine) MachVtbl.VideoGetDisplaySize = PcVideoGetDisplaySize; MachVtbl.VideoGetBufferSize = PcVideoGetBufferSize; MachVtbl.VideoSetTextCursorPosition = PcVideoSetTextCursorPosition; - MachVtbl.VideoSetTextCursorPosition = PcVideoSetTextCursorPosition; MachVtbl.VideoHideShowTextCursor = PcVideoHideShowTextCursor; MachVtbl.VideoPutChar = PcVideoPutChar; MachVtbl.VideoCopyOffScreenBufferToVRAM = PcVideoCopyOffScreenBufferToVRAM; diff --git a/boot/freeldr/freeldr/windows/winldr.c b/boot/freeldr/freeldr/windows/winldr.c index d4e6f11b271..a8c91fea1e9 100644 --- a/boot/freeldr/freeldr/windows/winldr.c +++ b/boot/freeldr/freeldr/windows/winldr.c @@ -208,7 +208,7 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, Extension->AcpiTable = (PVOID)1; } -#ifndef _M_ARM +#ifdef _M_IX86 /* Set headless block pointer */ if (WinLdrTerminalConnected) { @@ -538,7 +538,7 @@ LoadAndBootWindows(PCSTR OperatingSystemName, /* Allocate and minimalistic-initialize LPB */ AllocateAndInitLPB(&LoaderBlock); -#ifndef _M_ARM +#ifdef _M_IX86 /* Setup redirection support */ WinLdrSetupEms(BootOptions); #endif diff --git a/dll/win32/cryptui/main.c b/dll/win32/cryptui/main.c index a95a7a487d3..43daba7287c 100644 --- a/dll/win32/cryptui/main.c +++ b/dll/win32/cryptui/main.c @@ -27,6 +27,7 @@ #include "winbase.h" #include "winnls.h" #include "winuser.h" +#include "undocuser.h" #include "softpub.h" #include "wingdi.h" #include "richedit.h" diff --git a/dll/win32/gdi32/CMakeLists.txt b/dll/win32/gdi32/CMakeLists.txt index 9baa9f9e94d..d5409c672ab 100644 --- a/dll/win32/gdi32/CMakeLists.txt +++ b/dll/win32/gdi32/CMakeLists.txt @@ -9,6 +9,11 @@ include_directories(include) spec2def(gdi32.dll gdi32.spec) +if(ARCH MATCHES i386) +list(APPEND SOURCE + objects/efloat.c) +endif() + list(APPEND SOURCE main/dllmain.c misc/heap.c diff --git a/dll/win32/gdi32/gdi32.spec b/dll/win32/gdi32/gdi32.spec index cfe82e337c9..b3b0fdd34c9 100644 --- a/dll/win32/gdi32/gdi32.spec +++ b/dll/win32/gdi32/gdi32.spec @@ -32,7 +32,7 @@ @ stdcall ColorCorrectPalette(ptr ptr long long) @ stdcall ColorMatchToTarget(ptr ptr long) @ stdcall CombineRgn(long long long long) -@ stdcall CombineTransform(ptr ptr ptr) NtGdiCombineTransform +@ stdcall CombineTransform(ptr ptr ptr) @ stdcall CopyEnhMetaFileA(long str) @ stdcall CopyEnhMetaFileW(long wstr) @ stdcall CopyMetaFileA(long str) @@ -285,7 +285,7 @@ @ stdcall GdiEntry9(ptr ptr ptr ptr ptr ptr) @ stdcall GdiFixUpHandle(ptr) @ stdcall GdiFlush() -@ stdcall GdiFullscreenControl(ptr ptr long ptr ptr) NtGdiFullscreenControl +@ stdcall GdiFullscreenControl(ptr ptr long ptr ptr) NtGdiFullscreenControl @ stdcall GdiGetBatchLimit() @ stdcall GdiGetBitmapBitsSize(ptr) @ stdcall GdiGetCharDimensions(long ptr ptr) @@ -299,7 +299,7 @@ @ stdcall GdiGetPageHandle(ptr long ptr) @ stdcall GdiGetSpoolFileHandle(wstr ptr wstr) @ stdcall GdiGetSpoolMessage(ptr long ptr long) NtGdiGetSpoolMessage -@ stdcall GdiGradientFill(long ptr long ptr long long) +@ stdcall GdiGradientFill(long ptr long ptr long long) @ stdcall GdiInitSpool() NtGdiInitSpool @ stdcall GdiInitializeLanguagePack(long) @ stdcall GdiIsMetaFileDC(long) diff --git a/dll/win32/gdi32/include/gdi32p.h b/dll/win32/gdi32/include/gdi32p.h index d76f21a534d..49673de0ce2 100644 --- a/dll/win32/gdi32/include/gdi32p.h +++ b/dll/win32/gdi32/include/gdi32p.h @@ -292,7 +292,6 @@ int FASTCALL DocumentEventEx(PVOID,HANDLE,HDC,int,ULONG,PVOID,ULONG,PVOID); BOOL FASTCALL EndPagePrinterEx(PVOID,HANDLE); BOOL FASTCALL LoadTheSpoolerDrv(VOID); - FORCEINLINE PVOID GdiAllocBatchCommand( @@ -379,4 +378,43 @@ GdiAllocBatchCommand( return pHdr; } +FORCEINLINE +PDC_ATTR +GdiGetDcAttr(HDC hdc) +{ + PDC_ATTR pdcattr; + + if (!GdiGetHandleUserData((HGDIOBJ)hdc, GDI_OBJECT_TYPE_DC, (PVOID*)&pdcattr)) return NULL; + return pdcattr; +} + +#ifdef _M_IX86 +FLOATL FASTCALL EFtoF(EFLOAT_S * efp); +#define FOtoF(pfo) EFtoF((EFLOAT_S*)pfo) +#else +#define FOtoF(pfo) (*(pfo)) +#endif + +/* This is an inlined version of lrintf. */ +FORCEINLINE +int +_lrintf(float f) +{ +#if defined(_M_IX86) && defined(__GNUC__) + int ret; + __asm__ __volatile__ ("fistpl %0" : "=m" (ret) : "t" (f) : "st"); + return ret; +#elif defined(_M_IX86) && defined(_MSC_VER) + int ret; + __asm + { + fld f; + fistp ret; + } +#else + /* slow, but portable */ + return (int)(f >= 0 ? f+0.5 : f-0.5); +#endif +} + /* EOF */ diff --git a/dll/win32/gdi32/objects/coord.c b/dll/win32/gdi32/objects/coord.c index 9f89ae1c89a..c736ab7ddae 100644 --- a/dll/win32/gdi32/objects/coord.c +++ b/dll/win32/gdi32/objects/coord.c @@ -1,145 +1,155 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS System Libraries + * FILE: dll/gdi32/objects/coord.c + * PURPOSE: Functions for coordinate transformation + * PROGRAMMER: + */ #include "precomp.h" -/* the following deal with IEEE single-precision numbers */ -#define EXCESS 126L -#define SIGNBIT 0x80000000L -#define SIGN(fp) ((fp) & SIGNBIT) -#define EXP(fp) (((fp) >> 23L) & 0xFF) -#define MANT(fp) ((fp) & 0x7FFFFFL) -#define PACK(s,e,m) ((s) | ((e) << 23L) | (m)) - -// Sames as lrintf. -#ifdef __GNUC__ -#define FLOAT_TO_INT(in,out) \ - __asm__ __volatile__ ("fistpl %0" : "=m" (out) : "t" (in) : "st"); -#else -#define FLOAT_TO_INT(in,out) \ - __asm fld in; \ - __asm fistp out; -#endif - -LONG -FASTCALL -EFtoF( EFLOAT_S * efp) +/* Currently we use a MATRIX inside the DC_ATTR containing the + coordinate transformations, while we deal with XFORM structures + internally. If we move all coordinate transformation to gdi32, + we might as well have an XFORM structure in the DC_ATTR. */ +void +MatrixToXForm(XFORM *pxform, const MATRIX *pmx) { - long Mant, Exp, Sign = 0; - - if (!efp->lMant) return 0; - - Mant = efp->lMant; - Exp = efp->lExp; - Sign = SIGN(Mant); - -//// M$ storage emulation - if( Sign ) Mant = -Mant; - Mant = ((Mant & 0x3fffffff) >> 7); - Exp += (EXCESS-1); -//// - Mant = MANT(Mant); - return PACK(Sign, Exp, Mant); + XFORML *pxforml = (XFORML*)pxform; + pxforml->eM11 = FOtoF(&pmx->efM11); + pxforml->eM12 = FOtoF(&pmx->efM12); + pxforml->eM21 = FOtoF(&pmx->efM21); + pxforml->eM22 = FOtoF(&pmx->efM22); + pxforml->eDx = FOtoF(&pmx->efDx); + pxforml->eDy = FOtoF(&pmx->efDy); } -VOID -FASTCALL -FtoEF( EFLOAT_S * efp, FLOATL f) -{ - long Mant, Exp, Sign = 0; - gxf_long worker; - -#ifdef _X86_ - worker.l = f; // It's a float stored in a long. -#else - worker.f = f; -#endif - - Exp = EXP(worker.l); - Mant = MANT(worker.l); - if (SIGN(worker.l)) Sign = -1; -//// M$ storage emulation - Mant = ((Mant << 7) | 0x40000000); - Mant ^= Sign; - Mant -= Sign; - Exp -= (EXCESS-1); -//// - efp->lMant = Mant; - efp->lExp = Exp; -} - - -VOID FASTCALL -CoordCnvP(MATRIX_S * mx, LPPOINT Point) +void +GdiTransformPoints2( + XFORM *pxform, + PPOINT pptOut, + PPOINT pptIn, + ULONG nCount) { + ULONG i; FLOAT x, y; - gxf_long a, b, c; - x = (FLOAT)Point->x; - y = (FLOAT)Point->y; - - a.l = EFtoF( &mx->efM11 ); - b.l = EFtoF( &mx->efM21 ); - c.l = EFtoF( &mx->efDx ); - x = x * a.f + y * b.f + c.f; - - a.l = EFtoF( &mx->efM12 ); - b.l = EFtoF( &mx->efM22 ); - c.l = EFtoF( &mx->efDy ); - y = x * a.f + y * b.f + c.f; - - FLOAT_TO_INT(x, Point->x ); - FLOAT_TO_INT(y, Point->y ); + for (i = 0; i < nCount; i++) + { + x = pptIn[i].x * pxform->eM11 + pptIn[i].y * pxform->eM12 + pxform->eDx; + pptOut[i].x = _lrintf(x); + y = pptIn[i].x * pxform->eM21 + pptIn[i].y * pxform->eM22 + pxform->eDy; + pptOut[i].y = _lrintf(y); + } } +FORCEINLINE +void +GdiTransformPoints( + MATRIX *pmx, + PPOINT pptOut, + PPOINT pptIn, + ULONG nCount) +{ + XFORM xform; + + MatrixToXForm(&xform, pmx); + GdiTransformPoints2(&xform, pptOut, pptIn, nCount); +} + +#define MAX_OFFSET 4294967040.0 BOOL WINAPI -DPtoLP ( HDC hDC, LPPOINT Points, INT Count ) +CombineTransform( + LPXFORM pxfResult, + const XFORM *pxf1, + const XFORM *pxf2) { -#if 0 - INT i; - PDC_ATTR Dc_Attr; + XFORM xformTmp; - if (!GdiGetHandleUserData((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE; + /* Check paramters */ + if (!pxfResult || !pxf1 || !pxf2) return FALSE; - if (Dc_Attr->flXform & ( DEVICE_TO_WORLD_INVALID | // Force a full recalibration! - PAGE_XLATE_CHANGED | // Changes or Updates have been made, - PAGE_EXTENTS_CHANGED | // do processing in kernel space. - WORLD_XFORM_CHANGED )) -#endif - return NtGdiTransformPoints( hDC, Points, Points, Count, GdiDpToLp); // DPtoLP mode. + /* Do matrix multiplication */ + xformTmp.eM11 = pxf1->eM11 * pxf2->eM11 + pxf1->eM12 * pxf2->eM21; + xformTmp.eM12 = pxf1->eM11 * pxf2->eM12 + pxf1->eM12 * pxf2->eM22; + xformTmp.eM21 = pxf1->eM21 * pxf2->eM11 + pxf1->eM22 * pxf2->eM21; + xformTmp.eM22 = pxf1->eM21 * pxf2->eM12 + pxf1->eM22 * pxf2->eM22; + xformTmp.eDx = pxf1->eDx * pxf2->eM11 + pxf1->eDy * pxf2->eM21 + pxf2->eDx; + xformTmp.eDy = pxf1->eDx * pxf2->eM12 + pxf1->eDy * pxf2->eM22 + pxf2->eDy; + + *pxfResult = xformTmp; #if 0 - else + /* windows compatibility fixups (needs more work) */ + if (_isnan(xformTmp.eM12)) { - for ( i = 0; i < Count; i++ ) - CoordCnvP ( &Dc_Attr->mxDeviceToWorld, &Points[i] ); + if (pxf1->eM11 == 0 || pxf2->eM12 == 0) pxfResult->eM12 = 0.; } - return TRUE; #endif -} + /* Check for invalid offset ranges */ + if (xformTmp.eDx > MAX_OFFSET || xformTmp.eDx < -MAX_OFFSET || + xformTmp.eDy > MAX_OFFSET || xformTmp.eDy < -MAX_OFFSET) + { + return FALSE; + } + return TRUE; +} BOOL WINAPI -LPtoDP ( HDC hDC, LPPOINT Points, INT Count ) +DPtoLP(HDC hdc, LPPOINT lpPoints, INT nCount) { #if 0 INT i; - PDC_ATTR Dc_Attr; + PDC_ATTR pdcattr; - if (!GdiGetHandleUserData((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE; - - if (Dc_Attr->flXform & ( PAGE_XLATE_CHANGED | // Check for Changes and Updates - PAGE_EXTENTS_CHANGED | - WORLD_XFORM_CHANGED )) -#endif - return NtGdiTransformPoints( hDC, Points, Points, Count, GdiLpToDp); // LPtoDP mode -#if 0 - else + pdcattr = GdiGetDcAttr(hdc); + if (!pdcattr) { - for ( i = 0; i < Count; i++ ) - CoordCnvP ( &Dc_Attr->mxWorldToDevice, &Points[i] ); + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; } + + if (pdcattr->flXform & ANY_XFORM_CHANGES) + { + GdiFixupTransforms(pdcattr); + } + + // FIXME: can this fail on Windows? + GdiTransformPoints(&pdcattr->mxDeviceToWorld, lpPoints, lpPoints, nCount); + return TRUE; #endif + return NtGdiTransformPoints(hdc, lpPoints, lpPoints, nCount, GdiDpToLp); +} + +BOOL +WINAPI +LPtoDP(HDC hdc, LPPOINT lpPoints, INT nCount) +{ +#if 0 + INT i; + PDC_ATTR pdcattr; + + pdcattr = GdiGetDcAttr(hdc); + if (!pdcattr) + { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + + if (pdcattr->flXform & ANY_XFORM_CHANGES) + { + GdiFixupTransforms(pdcattr); + } + + // FIXME: can this fail on Windows? + GdiTransformPoints(&pdcattr->mxWorldToDevice, lpPoints, lpPoints, nCount); + + return TRUE; +#endif + return NtGdiTransformPoints(hdc, lpPoints, lpPoints, nCount, GdiLpToDp); } /* @@ -185,9 +195,26 @@ GetCurrentPositionEx(HDC hdc, */ BOOL WINAPI -GetWorldTransform( HDC hDC, LPXFORM lpXform ) +GetWorldTransform(HDC hDC, LPXFORM lpXform) { - return NtGdiGetTransform( hDC, GdiWorldSpaceToPageSpace, lpXform); +#if 0 + PDC_ATTR pdcattr; + + pdcattr = GdiGetDcAttr(hdc); + if (!pdcattr) + { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + + if (pdcattr->flXform & ANY_XFORM_INVALID) + { + GdiFixupTransforms(pdcattr); + } + + MatrixToXForm(lpXform, &pdcattr->mxWorldToDevice); +#endif + return NtGdiGetTransform(hDC, GdiWorldSpaceToPageSpace, lpXform); } diff --git a/dll/win32/gdi32/objects/efloat.c b/dll/win32/gdi32/objects/efloat.c new file mode 100644 index 00000000000..001472e76f6 --- /dev/null +++ b/dll/win32/gdi32/objects/efloat.c @@ -0,0 +1,62 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS System Libraries + * FILE: dll/gdi32/objects/coord.c + * PURPOSE: Functions to convert between FLOAT and EFLOAT + * PROGRAMMER: James Tabor + */ +#include "precomp.h" + +/* the following deal with IEEE single-precision numbers */ +#define EXCESS 126L +#define SIGNBIT 0x80000000L +#define SIGN(fp) ((fp) & SIGNBIT) +#define EXP(fp) (((fp) >> 23L) & 0xFF) +#define MANT(fp) ((fp) & 0x7FFFFFL) +#define PACK(s,e,m) ((s) | ((e) << 23L) | (m)) + +FLOATL +FASTCALL +EFtoF(EFLOAT_S * efp) +{ + ULONG Mant, Exp, Sign; + + if (!efp->lMant) return 0; + + Mant = efp->lMant; + Exp = efp->lExp; + Sign = SIGN(Mant); + + if (Sign) Mant = -Mant; + Mant >>= 7; + Exp += (EXCESS-1); + + Mant = MANT(Mant); + return PACK(Sign, Exp, Mant); +} + +VOID +FASTCALL +FtoEF( EFLOAT_S * efp, FLOATL f) +{ + ULONG Mant, Exp, Sign = 0; + gxf_long worker; + +#ifdef _X86_ + worker.l = f; // It's a float stored in a long. +#else + worker.f = f; +#endif + + Exp = EXP(worker.l); + Mant = MANT(worker.l); + if (SIGN(worker.l)) Sign = -1; + + Mant = ((Mant << 7) | 0x40000000); + Mant ^= Sign; + Mant -= Sign; + Exp -= (EXCESS-1); + + efp->lMant = Mant; + efp->lExp = Exp; +} diff --git a/dll/win32/iphlpapi/iphlpapi_private.h b/dll/win32/iphlpapi/iphlpapi_private.h index de7f05e654e..767b97c9ed8 100644 --- a/dll/win32/iphlpapi/iphlpapi_private.h +++ b/dll/win32/iphlpapi/iphlpapi_private.h @@ -160,9 +160,4 @@ BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT,LPSTR,LPDWORD); #endif -#ifdef FORCE_DEBUG -#undef DPRINT -#define DPRINT(fmt,x...) DbgPrint("%s:%d:%s: " fmt, __FILE__, __LINE__, __FUNCTION__, ## x) -#endif - #endif/*IPPRIVATE_H*/ diff --git a/dll/win32/iphlpapi/resinfo_reactos.c b/dll/win32/iphlpapi/resinfo_reactos.c index 5ee58c1ddb7..6ee496a4b75 100644 --- a/dll/win32/iphlpapi/resinfo_reactos.c +++ b/dll/win32/iphlpapi/resinfo_reactos.c @@ -47,6 +47,8 @@ #include "iphlpapi.h" #include "wine/debug.h" +WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi); + typedef struct _NAME_SERVER_LIST_PRIVATE { UINT NumServers; IP_ADDR_STRING * pCurrent; @@ -74,7 +76,7 @@ QueryNameServer( if (Status != ERROR_SUCCESS) { /* failed to retrieve size */ - DbgPrint("Status %x\n", Status); + TRACE("Status %x\n", Status); return Status; } diff --git a/dll/win32/kernel32/file/cnotify.c b/dll/win32/kernel32/file/cnotify.c index c7aff9c3589..3f6420bf7ec 100644 --- a/dll/win32/kernel32/file/cnotify.c +++ b/dll/win32/kernel32/file/cnotify.c @@ -219,7 +219,7 @@ ReadDirectoryChangesW( EventHandle, IoApcRoutine, CompletionRoutine, /* ApcContext */ - lpOverlapped ? (PIO_STATUS_BLOCK)lpOverlapped->Internal : &IoStatus, + lpOverlapped ? (PIO_STATUS_BLOCK) lpOverlapped : &IoStatus, lpBuffer, nBufferLength, dwNotifyFilter, diff --git a/dll/win32/setupapi/cfgmgr.c b/dll/win32/setupapi/cfgmgr.c index e995e8fbf3e..78feede365a 100644 --- a/dll/win32/setupapi/cfgmgr.c +++ b/dll/win32/setupapi/cfgmgr.c @@ -179,6 +179,34 @@ CONFIGRET WINAPI CMP_Report_LogOn( } +/*********************************************************************** + * CMP_WaitServicesAvailable [SETUPAPI.@] + */ +CONFIGRET +WINAPI +CMP_WaitServicesAvailable(HMACHINE hMachine) +{ + RPC_BINDING_HANDLE BindingHandle = NULL; + CONFIGRET ret = CR_SUCCESS; + WORD Version; + + if (!PnpGetLocalHandles(&BindingHandle, NULL)) + return CR_FAILURE; + + RpcTryExcept + { + ret = PNP_GetVersion(BindingHandle, &Version); + } + RpcExcept(EXCEPTION_EXECUTE_HANDLER) + { + ret = RpcStatusToCmStatus(RpcExceptionCode()); + } + RpcEndExcept; + + return ret; +} + + /*********************************************************************** * CM_Add_Empty_Log_Conf [SETUPAPI.@] */ @@ -1825,7 +1853,7 @@ CONFIGRET WINAPI CM_Get_Device_ID_ExA( WCHAR szBufferW[MAX_DEVICE_ID_LEN]; CONFIGRET ret = CR_SUCCESS; - FIXME("%lx %p %ld %ld %lx\n", + TRACE("%lx %p %ld %ld %lx\n", dnDevInst, Buffer, BufferLen, ulFlags, hMachine); if (Buffer == NULL) @@ -1931,7 +1959,7 @@ CONFIGRET WINAPI CM_Get_Device_ID_List_ExA( LPWSTR pszFilterW = NULL; CONFIGRET ret = CR_SUCCESS; - FIXME("%p %p %ld %ld %lx\n", + TRACE("%p %p %ld %ld %lx\n", pszFilter, Buffer, BufferLen, ulFlags, hMachine); BufferW = MyMalloc(BufferLen * sizeof(WCHAR)); @@ -2016,7 +2044,7 @@ CONFIGRET WINAPI CM_Get_Device_ID_List_ExW( RpcTryExcept { ret = PNP_GetDeviceList(BindingHandle, - pszFilter, + (LPWSTR)pszFilter, Buffer, &BufferLen, ulFlags); @@ -2264,6 +2292,8 @@ CONFIGRET WINAPI CM_Get_First_Log_Conf_Ex( if (ret != CR_SUCCESS) return ret; + if (plcLogConf) + { pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO)); if (pLogConfInfo == NULL) return CR_OUT_OF_MEMORY; @@ -2274,6 +2304,7 @@ CONFIGRET WINAPI CM_Get_First_Log_Conf_Ex( pLogConfInfo->ulTag = ulTag; *plcLogConf = (LOG_CONF)pLogConfInfo; + } return CR_SUCCESS; } diff --git a/dll/win32/setupapi/devinst.c b/dll/win32/setupapi/devinst.c index a05fecb29ef..81b21eb0e52 100644 --- a/dll/win32/setupapi/devinst.c +++ b/dll/win32/setupapi/devinst.c @@ -1158,29 +1158,8 @@ BOOL WINAPI SetupDiClassNameFromGuidExW( if (hKey == INVALID_HANDLE_VALUE) return FALSE; - /* Retrieve the class name data */ - dwLength = ClassNameSize * sizeof(WCHAR); - - do - { - /* Allocate a buffer to retrieve the class name data */ - Buffer = HeapAlloc(GetProcessHeap(), 0, dwLength); - - if (Buffer == NULL) - { - rc = GetLastError(); - break; - } - - /* Query for the class name data */ - rc = RegQueryValueExW(hKey, Class, NULL, &dwRegType, (LPBYTE) Buffer, &dwLength); - - /* Clean up the buffer if needed */ - if (rc != ERROR_SUCCESS) - HeapFree(GetProcessHeap(), 0, Buffer); - } while (rc == ERROR_MORE_DATA); - - /* Close the key */ + /* Retrieve the class name data and close the key */ + rc = QueryRegistryValue(hKey, Class, (LPBYTE *) &Buffer, &dwRegType, &dwLength); RegCloseKey(hKey); /* Make sure we got the data */ @@ -1193,7 +1172,7 @@ BOOL WINAPI SetupDiClassNameFromGuidExW( /* Make sure the data is a string */ if (dwRegType != REG_SZ) { - HeapFree(GetProcessHeap(), 0, Buffer); + MyFree(Buffer); SetLastError(ERROR_GEN_FAILURE); return FALSE; } @@ -1217,7 +1196,7 @@ BOOL WINAPI SetupDiClassNameFromGuidExW( *RequiredSize = dwLength; /* Clean up the buffer */ - HeapFree(GetProcessHeap(), 0, Buffer); + MyFree(Buffer); /* Make sure the buffer was large enough */ if ((ClassName == NULL) || (dwLength > ClassNameSize)) @@ -1757,7 +1736,7 @@ BOOL WINAPI SetupDiCreateDeviceInfoW( */ SetLastError(ERROR_DEVINST_ALREADY_EXISTS); } - else if (GetLastError() == ERROR_FILE_NOT_FOUND) + else if (GetLastError() == ERROR_NO_SUCH_DEVINST) { struct DeviceInfo *deviceInfo; @@ -2198,69 +2177,82 @@ BOOL WINAPI SetupDiGetClassDescriptionExW( DWORD dwLength; DWORD dwRegType; LONG rc; + PWSTR Buffer; TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid), ClassDescription, ClassDescriptionSize, RequiredSize, debugstr_w(MachineName), Reserved); + /* Make sure there's a GUID */ if (!ClassGuid) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } - else if (!ClassDescription && ClassDescriptionSize > 0) + + /* Make sure there's a real buffer when there's a size */ + if (!ClassDescription && ClassDescriptionSize > 0) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } + /* Open the key for the GUID */ hKey = SetupDiOpenClassRegKeyExW(ClassGuid, KEY_QUERY_VALUE, DIOCR_INSTALLER, MachineName, Reserved); if (hKey == INVALID_HANDLE_VALUE) - { - WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError()); return FALSE; - } - if (ClassDescriptionSize < sizeof(UNICODE_NULL) || !ClassDescription) - dwLength = 0; - else - dwLength = ClassDescriptionSize * sizeof(WCHAR) - sizeof(UNICODE_NULL); - - rc = RegQueryValueExW(hKey, - NULL, - NULL, - &dwRegType, - (LPBYTE)ClassDescription, - &dwLength); + /* Retrieve the class description data and close the key */ + rc = QueryRegistryValue(hKey, NULL, (LPBYTE *) &Buffer, &dwRegType, &dwLength); RegCloseKey(hKey); - if (rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS) + + /* Make sure we got the data */ + if (rc != ERROR_SUCCESS) { SetLastError(rc); return FALSE; } - else if (dwRegType != REG_SZ) + + /* Make sure the data is a string */ + if (dwRegType != REG_SZ) { + MyFree(Buffer); SetLastError(ERROR_GEN_FAILURE); return FALSE; } - if (RequiredSize) - *RequiredSize = dwLength / sizeof(WCHAR) + 1; + /* Determine the length of the class description */ + dwLength /= sizeof(WCHAR); - if (ClassDescriptionSize * sizeof(WCHAR) >= dwLength + sizeof(UNICODE_NULL)) + /* Count the null-terminator if none is present */ + if ((dwLength == 0) || (Buffer[dwLength - 1] != UNICODE_NULL)) + dwLength++; + + /* Inform the caller about the class description */ + if ((ClassDescription != NULL) && (dwLength <= ClassDescriptionSize)) { - if (ClassDescriptionSize > sizeof(UNICODE_NULL)) - ClassDescription[ClassDescriptionSize / sizeof(WCHAR)] = UNICODE_NULL; - return TRUE; + memcpy(ClassDescription, Buffer, (dwLength - 1) * sizeof(WCHAR)); + ClassDescription[dwLength - 1] = UNICODE_NULL; } - else + + /* Inform the caller about the required size */ + if (RequiredSize != NULL) + *RequiredSize = dwLength; + + /* Clean up the buffer */ + MyFree(Buffer); + + /* Make sure the buffer was large enough */ + if ((ClassDescription == NULL) || (dwLength > ClassDescriptionSize)) { SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } + + return TRUE; } /*********************************************************************** @@ -2357,7 +2349,7 @@ HDEVINFO WINAPI SetupDiGetClassDevsExW( if (!(flags & DIGCF_ALLCLASSES) && !class) { SetLastError(ERROR_INVALID_PARAMETER); - return NULL; + return INVALID_HANDLE_VALUE; } /* Create the deviceset if not set */ diff --git a/dll/win32/setupapi/setupapi.spec b/dll/win32/setupapi/setupapi.spec index 43514139704..344d7f337b1 100644 --- a/dll/win32/setupapi/setupapi.spec +++ b/dll/win32/setupapi/setupapi.spec @@ -6,7 +6,7 @@ @ stdcall CMP_Report_LogOn(long long) @ stdcall CMP_UnregisterNotification(ptr) @ stdcall CMP_WaitNoPendingInstallEvents(long) -@ stub CMP_WaitServicesAvailable +@ stdcall CMP_WaitServicesAvailable(ptr) @ stdcall CM_Add_Empty_Log_Conf(ptr ptr long long) @ stdcall CM_Add_Empty_Log_Conf_Ex(ptr ptr long long ptr) @ stdcall CM_Add_IDA(ptr str long) diff --git a/dll/win32/user32/CMakeLists.txt b/dll/win32/user32/CMakeLists.txt index 1b015fd2ba2..27b724e80e0 100644 --- a/dll/win32/user32/CMakeLists.txt +++ b/dll/win32/user32/CMakeLists.txt @@ -39,7 +39,6 @@ list(APPEND SOURCE misc/usrapihk.c misc/winhelp.c misc/winsta.c - misc/wsprintf.c windows/accel.c windows/caret.c windows/class.c @@ -74,6 +73,7 @@ add_library(user32 SHARED set_module_type(user32 win32dll) target_link_libraries(user32 + user32_wsprintf wine win32ksys ${PSEH_LIB}) diff --git a/dll/win32/user32/controls/icontitle.c b/dll/win32/user32/controls/icontitle.c index 465a1a40ca4..0b30a21cdff 100644 --- a/dll/win32/user32/controls/icontitle.c +++ b/dll/win32/user32/controls/icontitle.c @@ -22,11 +22,6 @@ #include -#ifdef __REACTOS__ -#define MAKEINTATOMW(atom) ((LPCWSTR)((ULONG_PTR)((WORD)(atom)))) -#define ICONTITLE_CLASS_ATOM MAKEINTATOMW(32772) -#endif - static BOOL bMultiLineTitle; static HFONT hIconTitleFont; @@ -35,7 +30,7 @@ static HFONT hIconTitleFont; */ const struct builtin_class_descr ICONTITLE_builtin_class = { - (LPCWSTR)ICONTITLE_CLASS_ATOM, /* name */ + WC_ICONTITLE, /* name */ 0, /* style */ NULL, /* procA (winproc is Unicode only) */ IconTitleWndProc, /* procW */ diff --git a/dll/win32/user32/controls/listbox.c b/dll/win32/user32/controls/listbox.c index e290860b49b..44a5bb5b5b7 100644 --- a/dll/win32/user32/controls/listbox.c +++ b/dll/win32/user32/controls/listbox.c @@ -38,17 +38,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(listbox); -/* Start of hack section -------------------------------- */ - -#define WM_LBTRACKPOINT 0x0131 -#define WS_EX_DRAGDETECT 0x00000002L -#define WM_BEGINDRAG 0x022C - -UINT_PTR WINAPI SetSystemTimer(HWND,UINT_PTR,UINT,TIMERPROC); -BOOL WINAPI KillSystemTimer(HWND,UINT_PTR); - -/* End of hack section -------------------------------- */ - /* Items array granularity */ #define LB_ARRAY_GRANULARITY 16 diff --git a/dll/win32/user32/controls/static.c b/dll/win32/user32/controls/static.c index 6d40bbc8d5f..bc0b92b361c 100644 --- a/dll/win32/user32/controls/static.c +++ b/dll/win32/user32/controls/static.c @@ -845,31 +845,28 @@ static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style ) DeleteObject( hBrush ); } -/* Modified for ReactOS */ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style ) { RECT rc, iconRect; HBRUSH hbrush; HICON hIcon; - ICONINFO info; + SIZE size; GetClientRect( hwnd, &rc ); hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc); hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ); - if (!hIcon || (!GetIconInfo(hIcon, &info))) + if (!hIcon || !get_icon_size( hIcon, &size )) { FillRect(hdc, &rc, hbrush); } else { - BITMAP bm; - if (!GetObjectW(info.hbmColor, sizeof(BITMAP), &bm)) return; if (style & SS_CENTERIMAGE) { - iconRect.left = (rc.right - rc.left) / 2 - bm.bmWidth / 2; - iconRect.top = (rc.bottom - rc.top) / 2 - bm.bmHeight / 2; - iconRect.right = iconRect.left + bm.bmWidth; - iconRect.bottom = iconRect.top + bm.bmHeight; + iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2; + iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2; + iconRect.right = iconRect.left + size.cx; + iconRect.bottom = iconRect.top + size.cy; } else iconRect = rc; @@ -966,3 +963,4 @@ static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style ) break; } } + diff --git a/dll/win32/user32/include/controls.h b/dll/win32/user32/include/controls.h index 456763de8ac..99a935c7897 100644 --- a/dll/win32/user32/include/controls.h +++ b/dll/win32/user32/include/controls.h @@ -1,14 +1,5 @@ #pragma once -/* Missing from Winuser.h */ -#define ES_COMBO 0x00000200 /* Undocumented. Parent is a combobox */ -#ifndef MAKEINTATOMA -#define MAKEINTATOMA(atom) ((LPCSTR)((ULONG_PTR)((WORD)(atom)))) -#endif -#ifndef WM_ISACTIVEICON -#define WM_ISACTIVEICON 0x0035 -#endif - #ifndef HBMMENU_CALLBACK #define HBMMENU_CALLBACK ((HBITMAP) -1) #endif @@ -46,11 +37,6 @@ /* winuser.h */ -// I dont know where this goes - -#define LB_CARETON 0x01a3 -#define LB_CARETOFF 0x01a4 - /* combo box */ #define ID_CB_LISTBOX 1000 @@ -106,7 +92,6 @@ extern BOOL COMBO_FlipListbox( LPHEADCOMBO, BOOL, BOOL ); #define LB_ADDSTRING_UPPER 0x1AC #define LB_ADDSTRING_LOWER 0x1AD -#define DESKTOP_CLASS_ATOM MAKEINTATOMA(32769) /* Desktop */ LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ); LRESULT WINAPI User32DefWindowProc(HWND,UINT,WPARAM,LPARAM,BOOL); BOOL WINAPI RegisterClientPFN(VOID); diff --git a/dll/win32/user32/include/cursor.h b/dll/win32/user32/include/cursor.h index a8e966eae4e..ad7723aec69 100644 --- a/dll/win32/user32/include/cursor.h +++ b/dll/win32/user32/include/cursor.h @@ -10,3 +10,6 @@ HICON CreateCursorIconFromData(PVOID ImageData, int yHotspot, BOOL fIcon); + +BOOL get_icon_size(HICON hIcon, SIZE *size); + diff --git a/dll/win32/user32/include/message.h b/dll/win32/user32/include/message.h index b631d8f662a..71ff89d02c2 100644 --- a/dll/win32/user32/include/message.h +++ b/dll/win32/user32/include/message.h @@ -11,9 +11,6 @@ BOOL FASTCALL MessageInit(VOID); VOID FASTCALL MessageCleanup(VOID); -#define WM_ALTTABACTIVE 0x0029 -#define WM_SETVISIBLE 0x0009 - static __inline BOOL IsCallProcHandle(IN WNDPROC lpWndProc) { diff --git a/dll/win32/user32/include/regcontrol.h b/dll/win32/user32/include/regcontrol.h index 1eb3d875be5..0527532c449 100644 --- a/dll/win32/user32/include/regcontrol.h +++ b/dll/win32/user32/include/regcontrol.h @@ -10,9 +10,6 @@ */ #pragma once -#define IS_ATOM(x) \ - (((ULONG_PTR)(x) > 0x0) && ((ULONG_PTR)(x) < 0x10000)) - /* Built-in class descriptor */ struct builtin_class_descr { diff --git a/dll/win32/user32/include/user32.h b/dll/win32/user32/include/user32.h index a0472b3ae62..f93eee60a27 100644 --- a/dll/win32/user32/include/user32.h +++ b/dll/win32/user32/include/user32.h @@ -33,6 +33,9 @@ #include #include +/* Undocumented user definitions*/ +#include + /* WINE Headers */ #include @@ -47,60 +50,9 @@ (GetWin32ClientInfo()->pDeskInfo && GetWin32ClientInfo()->pDeskInfo->fsHooks & HOOKID_TO_FLAG(HookId))) /* Temporarily in here for now. */ -typedef struct _USERAPIHOOKINFO -{ - DWORD m_size; - LPCWSTR m_dllname1; - LPCWSTR m_funname1; - LPCWSTR m_dllname2; - LPCWSTR m_funname2; -} USERAPIHOOKINFO,*PUSERAPIHOOKINFO; - -typedef LRESULT(CALLBACK *WNDPROC_OWP)(HWND,UINT,WPARAM,LPARAM,ULONG_PTR,PDWORD); - -typedef struct _UAHOWP -{ - BYTE* MsgBitArray; - DWORD Size; -} UAHOWP, *PUAHOWP; - -typedef struct tagUSERAPIHOOK -{ - DWORD size; - WNDPROC DefWindowProcA; - WNDPROC DefWindowProcW; - UAHOWP DefWndProcArray; - FARPROC GetScrollInfo; - FARPROC SetScrollInfo; - FARPROC EnableScrollBar; - FARPROC AdjustWindowRectEx; - FARPROC SetWindowRgn; - WNDPROC_OWP PreWndProc; - WNDPROC_OWP PostWndProc; - UAHOWP WndProcArray; - WNDPROC_OWP PreDefDlgProc; - WNDPROC_OWP PostDefDlgProc; - UAHOWP DlgProcArray; - FARPROC GetSystemMetrics; - FARPROC SystemParametersInfoA; - FARPROC SystemParametersInfoW; - FARPROC ForceResetUserApiHook; - FARPROC DrawFrameControl; - FARPROC DrawCaption; - FARPROC MDIRedrawFrame; - FARPROC GetRealWindowOwner; -} USERAPIHOOK, *PUSERAPIHOOK; - -typedef enum _UAPIHK -{ - uahLoadInit, - uahStop, - uahShutdown -} UAPIHK, *PUAPIHK; extern RTL_CRITICAL_SECTION gcsUserApiHook; extern USERAPIHOOK guah; -typedef DWORD (CALLBACK * USERAPIHOOKPROC)(UAPIHK State, ULONG_PTR Info); BOOL FASTCALL BeginIfHookedUserApiHook(VOID); BOOL FASTCALL EndUserApiHook(VOID); BOOL FASTCALL IsInsideUserApiHook(VOID); diff --git a/dll/win32/user32/include/user32p.h b/dll/win32/user32/include/user32p.h index c748874c485..9a27bbc19ac 100644 --- a/dll/win32/user32/include/user32p.h +++ b/dll/win32/user32/include/user32p.h @@ -26,6 +26,9 @@ #include "winsta.h" #include "ntwrapper.h" +#define IS_ATOM(x) \ + (((ULONG_PTR)(x) > 0x0) && ((ULONG_PTR)(x) < 0x10000)) + /* One/Two Param Functions */ #define NtUserMsqSetWakeMask(dwWaitMask) \ (HANDLE)NtUserCallOneParam(dwWaitMask, ONEPARAM_ROUTINE_GETINPUTEVENT) diff --git a/dll/win32/user32/include/window.h b/dll/win32/user32/include/window.h index 3b604e25f6a..1cf65da7cfa 100644 --- a/dll/win32/user32/include/window.h +++ b/dll/win32/user32/include/window.h @@ -12,8 +12,6 @@ extern HBRUSH SysBrushes[]; #define NUM_SYSCOLORS 31 -#define IS_ATOM(x) \ - (((ULONG_PTR)(x) > 0x0) && ((ULONG_PTR)(x) < 0x10000)) #define UserHasAnyFrameStyle(Style, ExStyle) \ (((Style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \ diff --git a/dll/win32/user32/misc/desktop.c b/dll/win32/user32/misc/desktop.c index f6b1657c581..e6ee527d274 100644 --- a/dll/win32/user32/misc/desktop.c +++ b/dll/win32/user32/misc/desktop.c @@ -20,7 +20,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(user32); #if 0 // Kept for referencing. const struct builtin_class_descr DESKTOP_builtin_class = { - (LPCWSTR) DESKTOP_CLASS_ATOM, /* name */ + WC_DESKTOP, /* name */ CS_DBLCLKS, /* style */ NULL, /* procA (winproc is Unicode only) */ (WNDPROC) DesktopWndProc, /* procW */ diff --git a/dll/win32/user32/misc/wsprintf.c b/dll/win32/user32/misc/wsprintf.c deleted file mode 100644 index 6b70d8b8ef6..00000000000 --- a/dll/win32/user32/misc/wsprintf.c +++ /dev/null @@ -1,536 +0,0 @@ -/* - * wsprintf functions - * - * Copyright 1996 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - * - * NOTE: - * This code is duplicated in shlwapi. If you change something here make sure - * to change it in shlwapi too. - */ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS User32 - * PURPOSE: [w]sprintf functions - * FILE: lib/user32/wsprintf.c - * PROGRAMER: Steven Edwards - * REVISION HISTORY: 2003/07/13 Merged from wine user/wsprintf.c - * NOTES: Adapted from Wine - */ - -#include - -#define WINE_NO_TRACE_MSGS -#include - -WINE_DEFAULT_DEBUG_CHANNEL(string); - - -#define WPRINTF_LEFTALIGN 0x0001 /* Align output on the left ('-' prefix) */ -#define WPRINTF_PREFIX_HEX 0x0002 /* Prefix hex with 0x ('#' prefix) */ -#define WPRINTF_ZEROPAD 0x0004 /* Pad with zeros ('0' prefix) */ -#define WPRINTF_LONG 0x0008 /* Long arg ('l' prefix) */ -#define WPRINTF_SHORT 0x0010 /* Short arg ('h' prefix) */ -#define WPRINTF_UPPER_HEX 0x0020 /* Upper-case hex ('X' specifier) */ -#define WPRINTF_WIDE 0x0040 /* Wide arg ('w' prefix) */ - -typedef enum -{ - WPR_UNKNOWN, - WPR_CHAR, - WPR_WCHAR, - WPR_STRING, - WPR_WSTRING, - WPR_SIGNED, - WPR_UNSIGNED, - WPR_HEXA -} WPRINTF_TYPE; - -typedef struct -{ - UINT flags; - UINT width; - UINT precision; - WPRINTF_TYPE type; -} WPRINTF_FORMAT; - -typedef union { - WCHAR wchar_view; - CHAR char_view; - LPCSTR lpcstr_view; - LPCWSTR lpcwstr_view; - INT int_view; -} WPRINTF_DATA; - -static const CHAR null_stringA[] = "(null)"; -static const WCHAR null_stringW[] = { '(', 'n', 'u', 'l', 'l', ')', 0 }; - -/*********************************************************************** - * WPRINTF_ParseFormatA - * - * Parse a format specification. A format specification has the form: - * - * [-][#][0][width][.precision]type - * - * Return value is the length of the format specification in characters. - */ -static INT WPRINTF_ParseFormatA( LPCSTR format, WPRINTF_FORMAT *res ) -{ - LPCSTR p = format; - - res->flags = 0; - res->width = 0; - res->precision = 0; - if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; } - if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; } - if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; } - while ((*p >= '0') && (*p <= '9')) /* width field */ - { - res->width = res->width * 10 + *p - '0'; - p++; - } - if (*p == '.') /* precision field */ - { - p++; - while ((*p >= '0') && (*p <= '9')) - { - res->precision = res->precision * 10 + *p - '0'; - p++; - } - } - if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; } - else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; } - else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; } - switch(*p) - { - case 'c': - res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR; - break; - case 'C': - res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR; - break; - case 'd': - case 'i': - res->type = WPR_SIGNED; - break; - case 's': - res->type = (res->flags & (WPRINTF_LONG |WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING; - break; - case 'S': - res->type = (res->flags & (WPRINTF_SHORT|WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING; - break; - case 'u': - res->type = WPR_UNSIGNED; - break; - case 'p': - res->width = 8; - res->flags |= WPRINTF_ZEROPAD; - /* fall through */ - case 'X': - res->flags |= WPRINTF_UPPER_HEX; - /* fall through */ - case 'x': - res->type = WPR_HEXA; - break; - default: /* unknown format char */ - res->type = WPR_UNKNOWN; - p--; /* print format as normal char */ - break; - } - return (INT)(p - format) + 1; -} - - -/*********************************************************************** - * WPRINTF_ParseFormatW - * - * Parse a format specification. A format specification has the form: - * - * [-][#][0][width][.precision]type - * - * Return value is the length of the format specification in characters. - */ -static INT WPRINTF_ParseFormatW( LPCWSTR format, WPRINTF_FORMAT *res ) -{ - LPCWSTR p = format; - - res->flags = 0; - res->width = 0; - res->precision = 0; - if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; } - if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; } - if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; } - while ((*p >= '0') && (*p <= '9')) /* width field */ - { - res->width = res->width * 10 + *p - '0'; - p++; - } - if (*p == '.') /* precision field */ - { - p++; - while ((*p >= '0') && (*p <= '9')) - { - res->precision = res->precision * 10 + *p - '0'; - p++; - } - } - if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; } - else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; } - else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; } - switch((CHAR)*p) - { - case 'c': - res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR; - break; - case 'C': - res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR; - break; - case 'd': - case 'i': - res->type = WPR_SIGNED; - break; - case 's': - res->type = ((res->flags & WPRINTF_SHORT) && !(res->flags & WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING; - break; - case 'S': - res->type = (res->flags & (WPRINTF_LONG|WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING; - break; - case 'u': - res->type = WPR_UNSIGNED; - break; - case 'p': - res->width = 8; - res->flags |= WPRINTF_ZEROPAD; - /* fall through */ - case 'X': - res->flags |= WPRINTF_UPPER_HEX; - /* fall through */ - case 'x': - res->type = WPR_HEXA; - break; - default: - res->type = WPR_UNKNOWN; - p--; /* print format as normal char */ - break; - } - return (INT)(p - format) + 1; -} - - -/*********************************************************************** - * WPRINTF_GetLen - */ -static UINT WPRINTF_GetLen( WPRINTF_FORMAT *format, WPRINTF_DATA *arg, - LPSTR number, UINT maxlen ) -{ - UINT len; - - if (format->flags & WPRINTF_LEFTALIGN) format->flags &= ~WPRINTF_ZEROPAD; - if (format->width > maxlen) format->width = maxlen; - switch(format->type) - { - case WPR_CHAR: - case WPR_WCHAR: - return (format->precision = 1); - case WPR_STRING: - if (!arg->lpcstr_view) arg->lpcstr_view = null_stringA; - for (len = 0; !format->precision || (len < format->precision); len++) - if (!*(arg->lpcstr_view + len)) break; - if (len > maxlen) len = maxlen; - return (format->precision = len); - case WPR_WSTRING: - if (!arg->lpcwstr_view) arg->lpcwstr_view = null_stringW; - for (len = 0; !format->precision || (len < format->precision); len++) - if (!*(arg->lpcwstr_view + len)) break; - if (len > maxlen) len = maxlen; - return (format->precision = len); - case WPR_SIGNED: - len = sprintf( number, "%d", arg->int_view ); - break; - case WPR_UNSIGNED: - len = sprintf( number, "%u", (UINT)arg->int_view ); - break; - case WPR_HEXA: - len = sprintf( number, - (format->flags & WPRINTF_UPPER_HEX) ? "%X" : "%x", - (UINT)arg->int_view); - break; - default: - return 0; - } - if (len > maxlen) len = maxlen; - if (format->precision < len) format->precision = len; - if (format->precision > maxlen) format->precision = maxlen; - if ((format->flags & WPRINTF_ZEROPAD) && (format->width > format->precision)) - format->precision = format->width; - if (format->flags & WPRINTF_PREFIX_HEX) len += 2; - return len; -} - - -/*********************************************************************** - * wvsnprintfA (internal) - */ -static INT wvsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, __ms_va_list args ) -{ - WPRINTF_FORMAT format; - LPSTR p = buffer; - UINT i, len, sign; - CHAR number[20]; - WPRINTF_DATA argData; - - TRACE("%p %u %s\n", buffer, maxlen, debugstr_a(spec)); - - while (*spec && (maxlen > 1)) - { - if (*spec != '%') { *p++ = *spec++; maxlen--; continue; } - spec++; - if (*spec == '%') { *p++ = *spec++; maxlen--; continue; } - spec += WPRINTF_ParseFormatA( spec, &format ); - - switch(format.type) - { - case WPR_WCHAR: - argData.wchar_view = (WCHAR)va_arg( args, int ); - break; - case WPR_CHAR: - argData.char_view = (CHAR)va_arg( args, int ); - break; - case WPR_STRING: - argData.lpcstr_view = va_arg( args, LPCSTR ); - break; - case WPR_WSTRING: - argData.lpcwstr_view = va_arg( args, LPCWSTR ); - break; - case WPR_HEXA: - case WPR_SIGNED: - case WPR_UNSIGNED: - argData.int_view = va_arg( args, INT ); - break; - default: - argData.wchar_view = 0; - break; - } - - len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 ); - sign = 0; - if (!(format.flags & WPRINTF_LEFTALIGN)) - for (i = format.precision; i < format.width; i++, maxlen--) - *p++ = ' '; - switch(format.type) - { - case WPR_WCHAR: - *p++ = argData.wchar_view; - break; - case WPR_CHAR: - *p++ = argData.char_view; - break; - case WPR_STRING: - memcpy( p, argData.lpcstr_view, len ); - p += len; - break; - case WPR_WSTRING: - { - LPCWSTR ptr = argData.lpcwstr_view; - for (i = 0; i < len; i++) *p++ = (CHAR)*ptr++; - } - break; - case WPR_HEXA: - if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3)) - { - *p++ = '0'; - *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x'; - maxlen -= 2; - len -= 2; - } - /* fall through */ - case WPR_SIGNED: - /* Transfer the sign now, just in case it will be zero-padded*/ - if (number[0] == '-') - { - *p++ = '-'; - sign = 1; - } - /* fall through */ - case WPR_UNSIGNED: - for (i = len; i < format.precision; i++, maxlen--) *p++ = '0'; - memcpy( p, number + sign, len - sign ); - p += len - sign; - break; - case WPR_UNKNOWN: - continue; - } - if (format.flags & WPRINTF_LEFTALIGN) - for (i = format.precision; i < format.width; i++, maxlen--) - *p++ = ' '; - maxlen -= len; - } - *p = 0; - TRACE("%s\n",debugstr_a(buffer)); - return (maxlen > 1) ? (INT)(p - buffer) : -1; -} - - -/*********************************************************************** - * wvsnprintfW (internal) - */ -static INT wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, __ms_va_list args ) -{ - WPRINTF_FORMAT format; - LPWSTR p = buffer; - UINT i, len, sign; - CHAR number[20]; - WPRINTF_DATA argData; - - TRACE("%p %u %s\n", buffer, maxlen, debugstr_w(spec)); - - while (*spec && (maxlen > 1)) - { - if (*spec != '%') { *p++ = *spec++; maxlen--; continue; } - spec++; - if (*spec == '%') { *p++ = *spec++; maxlen--; continue; } - spec += WPRINTF_ParseFormatW( spec, &format ); - - switch(format.type) - { - case WPR_WCHAR: - argData.wchar_view = (WCHAR)va_arg( args, int ); - break; - case WPR_CHAR: - argData.char_view = (CHAR)va_arg( args, int ); - break; - case WPR_STRING: - argData.lpcstr_view = va_arg( args, LPCSTR ); - break; - case WPR_WSTRING: - argData.lpcwstr_view = va_arg( args, LPCWSTR ); - break; - case WPR_HEXA: - case WPR_SIGNED: - case WPR_UNSIGNED: - argData.int_view = va_arg( args, INT ); - break; - default: - argData.wchar_view = 0; - break; - } - - len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 ); - sign = 0; - if (!(format.flags & WPRINTF_LEFTALIGN)) - for (i = format.precision; i < format.width; i++, maxlen--) - *p++ = ' '; - switch(format.type) - { - case WPR_WCHAR: - *p++ = argData.wchar_view; - break; - case WPR_CHAR: - *p++ = argData.char_view; - break; - case WPR_STRING: - { - LPCSTR ptr = argData.lpcstr_view; - for (i = 0; i < len; i++) *p++ = (WCHAR)*ptr++; - } - break; - case WPR_WSTRING: - if (len) memcpy( p, argData.lpcwstr_view, len * sizeof(WCHAR) ); - p += len; - break; - case WPR_HEXA: - if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3)) - { - *p++ = '0'; - *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x'; - maxlen -= 2; - len -= 2; - } - /* fall through */ - case WPR_SIGNED: - /* Transfer the sign now, just in case it will be zero-padded*/ - if (number[0] == '-') - { - *p++ = '-'; - sign = 1; - } - /* fall through */ - case WPR_UNSIGNED: - for (i = len; i < format.precision; i++, maxlen--) *p++ = '0'; - for (i = sign; i < len; i++) *p++ = (WCHAR)number[i]; - break; - case WPR_UNKNOWN: - continue; - } - if (format.flags & WPRINTF_LEFTALIGN) - for (i = format.precision; i < format.width; i++, maxlen--) - *p++ = ' '; - maxlen -= len; - } - *p = 0; - TRACE("%s\n",debugstr_w(buffer)); - return (maxlen > 1) ? (INT)(p - buffer) : -1; -} - - -/*********************************************************************** - * wvsprintfA (USER32.@) - */ -INT WINAPI wvsprintfA( LPSTR buffer, LPCSTR spec, __ms_va_list args ) -{ - INT res = wvsnprintfA( buffer, 1024, spec, args ); - return ( res == -1 ) ? 1024 : res; -} - - -/*********************************************************************** - * wvsprintfW (USER32.@) - */ -INT WINAPI wvsprintfW( LPWSTR buffer, LPCWSTR spec, __ms_va_list args ) -{ - INT res = wvsnprintfW( buffer, 1024, spec, args ); - return ( res == -1 ) ? 1024 : res; -} - - -/*********************************************************************** - * wsprintfA (USER32.@) - */ -INT WINAPIV wsprintfA( LPSTR buffer, LPCSTR spec, ... ) -{ - __ms_va_list valist; - INT res; - - __ms_va_start( valist, spec ); - res = wvsnprintfA( buffer, 1024, spec, valist ); - __ms_va_end( valist ); - return ( res == -1 ) ? 1024 : res; -} - - -/*********************************************************************** - * wsprintfW (USER32.@) - */ -INT WINAPIV wsprintfW( LPWSTR buffer, LPCWSTR spec, ... ) -{ - __ms_va_list valist; - INT res; - - __ms_va_start( valist, spec ); - res = wvsnprintfW( buffer, 1024, spec, valist ); - __ms_va_end( valist ); - return ( res == -1 ) ? 1024 : res; -} diff --git a/dll/win32/user32/windows/class.c b/dll/win32/user32/windows/class.c index 70171c6d0eb..c598d00708b 100644 --- a/dll/win32/user32/windows/class.c +++ b/dll/win32/user32/windows/class.c @@ -339,27 +339,11 @@ IntGetWndProc(PWND pWnd, BOOL Ansi) return (gcpd ? gcpd : Ret); } -/* - * @implemented - */ -DWORD WINAPI -GetClassLongA(HWND hWnd, int nIndex) +static ULONG_PTR FASTCALL +IntGetClassLongA(PWND Wnd, PCLS Class, int nIndex) { - PWND Wnd; - PCLS Class; ULONG_PTR Ret = 0; - TRACE("%p %d\n", hWnd, nIndex); - - Wnd = ValidateHwnd(hWnd); - if (!Wnd) - return 0; - - _SEH2_TRY - { - Class = DesktopPtrToUser(Wnd->pcls); - if (Class != NULL) - { if (nIndex >= 0) { if (nIndex + sizeof(ULONG_PTR) < nIndex || @@ -429,42 +413,15 @@ GetClassLongA(HWND hWnd, int nIndex) break; } } - } - else - { - WARN("Invalid class for hwnd 0x%p!\n", hWnd); - } - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - Ret = 0; - } - _SEH2_END; return Ret; } -/* - * @implemented - */ -DWORD WINAPI -GetClassLongW ( HWND hWnd, int nIndex ) +static ULONG_PTR FASTCALL +IntGetClassLongW (PWND Wnd, PCLS Class, int nIndex) { - PWND Wnd; - PCLS Class; ULONG_PTR Ret = 0; - TRACE("%p %d\n", hWnd, nIndex); - - Wnd = ValidateHwnd(hWnd); - if (!Wnd) - return 0; - - _SEH2_TRY - { - Class = DesktopPtrToUser(Wnd->pcls); - if (Class != NULL) - { if (nIndex >= 0) { if (nIndex + sizeof(ULONG_PTR) < nIndex || @@ -487,7 +444,7 @@ GetClassLongW ( HWND hWnd, int nIndex ) Ret = (ULONG_PTR)Class->cbclsExtra; break; - case GCL_HBRBACKGROUND: + case GCLP_HBRBACKGROUND: Ret = (ULONG_PTR)Class->hbrBackground; if (Ret != 0 && Ret < 0x4000) Ret = (ULONG_PTR)GetSysColorBrush((ULONG)Ret - 1); @@ -497,7 +454,7 @@ GetClassLongW ( HWND hWnd, int nIndex ) Ret = (ULONG_PTR)Class->hModule; break; - case GCL_MENUNAME: + case GCLP_MENUNAME: Ret = (ULONG_PTR)Class->lpszClientUnicodeMenuName; break; @@ -533,6 +490,51 @@ GetClassLongW ( HWND hWnd, int nIndex ) break; } } + + return Ret; +} + +/* + * @implemented + */ +DWORD WINAPI +GetClassLongA(HWND hWnd, int nIndex) +{ + PWND Wnd; + PCLS Class; + ULONG_PTR Ret = 0; + + TRACE("%p %d\n", hWnd, nIndex); + + Wnd = ValidateHwnd(hWnd); + if (!Wnd) + return 0; + + _SEH2_TRY + { + Class = DesktopPtrToUser(Wnd->pcls); + if (Class != NULL) + { +#ifdef _WIN64 + switch (nIndex) + { + case GCLP_HBRBACKGROUND: + case GCLP_HCURSOR: + case GCLP_HICON: + case GCLP_HICONSM: + case GCLP_HMODULE: + case GCLP_MENUNAME: + case GCLP_WNDPROC: + SetLastError(ERROR_INVALID_INDEX); + break; + + default: + Ret = IntGetClassLongA(Wnd, Class, nIndex); + break; + } +#else + Ret = IntGetClassLongA(Wnd, Class, nIndex); +#endif } else { @@ -541,35 +543,146 @@ GetClassLongW ( HWND hWnd, int nIndex ) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { + Ret = 0; } _SEH2_END; - return Ret; + return (DWORD)Ret; +} + +/* + * @implemented + */ +DWORD WINAPI +GetClassLongW ( HWND hWnd, int nIndex ) +{ + PWND Wnd; + PCLS Class; + ULONG_PTR Ret = 0; + + TRACE("%p %d\n", hWnd, nIndex); + + Wnd = ValidateHwnd(hWnd); + if (!Wnd) + return 0; + + _SEH2_TRY + { + Class = DesktopPtrToUser(Wnd->pcls); + if (Class != NULL) + { +#ifdef _WIN64 + switch (nIndex) + { + case GCLP_HBRBACKGROUND: + case GCLP_HCURSOR: + case GCLP_HICON: + case GCLP_HICONSM: + case GCLP_HMODULE: + case GCLP_MENUNAME: + case GCLP_WNDPROC: + SetLastError(ERROR_INVALID_INDEX); + break; + + default: + Ret = IntGetClassLongW(Wnd, Class, nIndex); + break; + } +#else + Ret = IntGetClassLongW(Wnd, Class, nIndex); +#endif + } + else + { + WARN("Invalid class for hwnd 0x%p!\n", hWnd); + } + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Ret = 0; + } + _SEH2_END; + + return (DWORD)Ret; } #ifdef _WIN64 /* - * @unimplemented + * @implemented */ ULONG_PTR WINAPI GetClassLongPtrA(HWND hWnd, INT nIndex) { - UNIMPLEMENTED; + PWND Wnd; + PCLS Class; + ULONG_PTR Ret = 0; + + TRACE("%p %d\n", hWnd, nIndex); + + Wnd = ValidateHwnd(hWnd); + if (!Wnd) return 0; + + _SEH2_TRY + { + Class = DesktopPtrToUser(Wnd->pcls); + if (Class != NULL) + { + Ret = IntGetClassLongA(Wnd, Class, nIndex); + } + else + { + WARN("Invalid class for hwnd 0x%p!\n", hWnd); + } + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Ret = 0; + } + _SEH2_END; + + return Ret; } /* - * @unimplemented + * @implemented */ ULONG_PTR WINAPI GetClassLongPtrW(HWND hWnd, INT nIndex) { - UNIMPLEMENTED; + PWND Wnd; + PCLS Class; + ULONG_PTR Ret = 0; + + TRACE("%p %d\n", hWnd, nIndex); + + Wnd = ValidateHwnd(hWnd); + if (!Wnd) return 0; + + _SEH2_TRY + { + Class = DesktopPtrToUser(Wnd->pcls); + if (Class != NULL) + { + Ret = IntGetClassLongW(Wnd, Class, nIndex); + } + else + { + WARN("Invalid class for hwnd 0x%p!\n", hWnd); + } + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Ret = 0; + } + _SEH2_END; + + return Ret; } #endif diff --git a/dll/win32/user32/windows/cursoricon.c b/dll/win32/user32/windows/cursoricon.c index 165e52df3fa..009a8475fac 100644 --- a/dll/win32/user32/windows/cursoricon.c +++ b/dll/win32/user32/windows/cursoricon.c @@ -1173,13 +1173,21 @@ HICON WINAPI CreateIcon( iinfo.fIcon = TRUE; iinfo.xHotspot = nWidth / 2; iinfo.yHotspot = nHeight / 2; + if (bPlanes * bBitsPixel > 1) + { + iinfo.hbmColor = CreateBitmap( nWidth, nHeight, bPlanes, bBitsPixel, lpXORbits ); iinfo.hbmMask = CreateBitmap( nWidth, nHeight, 1, 1, lpANDbits ); - iinfo.hbmColor = CreateBitmap( nWidth, nHeight, bPlanes, bBitsPixel, lpXORbits ); + } + else + { + iinfo.hbmMask = CreateBitmap( nWidth, nHeight * 2, 1, 1, lpANDbits ); + iinfo.hbmColor = NULL; + } hIcon = CreateIconIndirect( &iinfo ); DeleteObject( iinfo.hbmMask ); - DeleteObject( iinfo.hbmColor ); + if (iinfo.hbmColor) DeleteObject( iinfo.hbmColor ); return hIcon; } @@ -1477,8 +1485,9 @@ HICON WINAPI CreateIconIndirect(PICONINFO iconinfo) bmpXor.bmWidth, bmpXor.bmHeight, bmpXor.bmWidthBytes, bmpXor.bmPlanes, bmpXor.bmBitsPixel); - width = bmpXor.bmWidth; - height = bmpXor.bmHeight; + // the size of the mask bitmap always determines the icon size! + width = bmpAnd.bmWidth; + height = bmpAnd.bmHeight; if (bmpXor.bmPlanes * bmpXor.bmBitsPixel != 1) { color = CreateBitmap( width, height, bmpXor.bmPlanes, bmpXor.bmBitsPixel, NULL ); @@ -2181,3 +2190,23 @@ User32SetupDefaultCursors(PVOID Arguments, return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS)); } + +BOOL get_icon_size(HICON hIcon, SIZE *size) +{ + ICONINFO info; + BITMAP bitmap; + + if (!GetIconInfo(hIcon, &info)) return FALSE; + if (!GetObject(info.hbmMask, sizeof(bitmap), &bitmap)) return FALSE; + + size->cx = bitmap.bmWidth; + size->cy = bitmap.bmHeight; + + /* Black and white icons store both the XOR and AND bitmap in hbmMask */ + if (!info.hbmColor) + { + size->cy /= 2; + } + + return TRUE; +} diff --git a/dll/win32/user32/windows/defwnd.c b/dll/win32/user32/windows/defwnd.c index 76b34be0e9f..774b74552ca 100644 --- a/dll/win32/user32/windows/defwnd.c +++ b/dll/win32/user32/windows/defwnd.c @@ -16,13 +16,6 @@ #include WINE_DEFAULT_DEBUG_CHANNEL(user32); -#ifndef WM_SETVISIBLE -#define WM_SETVISIBLE 9 -#endif -#ifndef WM_QUERYDROPOBJECT -#define WM_QUERYDROPOBJECT 0x022B -#endif - LRESULT DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active); LRESULT DefWndNCCalcSize(HWND hWnd, BOOL CalcSizeStruct, RECT *Rect); LRESULT DefWndNCActivate(HWND hWnd, WPARAM wParam); diff --git a/dll/win32/user32/windows/dialog.c b/dll/win32/user32/windows/dialog.c index c1a219efcd9..ac36d7366cd 100644 --- a/dll/win32/user32/windows/dialog.c +++ b/dll/win32/user32/windows/dialog.c @@ -39,17 +39,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(user32); #define DF_END 0x0001 #define DF_OWNERENABLED 0x0002 -#define CW_USEDEFAULT16 ((short)0x8000) #define DWLP_ROS_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR)) #define GETDLGINFO(hwnd) DIALOG_get_info(hwnd, FALSE) #define SETDLGINFO(hwnd, info) SetWindowLongPtrW((hwnd), DWLP_ROS_DIALOGINFO, (LONG_PTR)(info)) #define GET_WORD(ptr) (*(WORD *)(ptr)) #define GET_DWORD(ptr) (*(DWORD *)(ptr)) -#define MAKEINTATOMA(atom) ((LPCSTR)((ULONG_PTR)((WORD)(atom)))) -#define MAKEINTATOMW(atom) ((LPCWSTR)((ULONG_PTR)((WORD)(atom)))) -#define DIALOG_CLASS_ATOMA MAKEINTATOMA(32770) /* Dialog */ -#define DIALOG_CLASS_ATOMW MAKEINTATOMW(32770) /* Dialog */ - void WINAPI WinPosActivateOtherWindow(HWND hwnd); /* INTERNAL STRUCTS **********************************************************/ @@ -118,7 +112,7 @@ typedef struct */ const struct builtin_class_descr DIALOG_builtin_class = { - DIALOG_CLASS_ATOMW, /* name */ + WC_DIALOG, /* name */ CS_SAVEBITS | CS_DBLCLKS, /* style */ (WNDPROC) DefDlgProcA, /* procA */ (WNDPROC) DefDlgProcW, /* procW */ @@ -632,7 +626,7 @@ static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result ) switch(GET_WORD(p)) { case 0x0000: - result->className = DIALOG_CLASS_ATOMW; + result->className = WC_DIALOG; p++; break; case 0xffff: @@ -995,6 +989,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, if (template.style & WS_VISIBLE && !(GetWindowLongPtrW( hwnd, GWL_STYLE ) & WS_VISIBLE)) { ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */ + IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART, hwnd, OBJID_WINDOW, CHILDID_SELF, 0); } return hwnd; } diff --git a/dll/win32/user32/windows/menu.c b/dll/win32/user32/windows/menu.c index 32b00314769..4bdfce8e2af 100644 --- a/dll/win32/user32/windows/menu.c +++ b/dll/win32/user32/windows/menu.c @@ -66,11 +66,6 @@ static BOOL fEndMenu = FALSE; #define SEPARATOR_HEIGHT (5) #define MENU_TAB_SPACE (8) -#define MAKEINTATOMA(atom) ((LPCSTR)((ULONG_PTR)((WORD)(atom)))) -#define MAKEINTATOMW(atom) ((LPCWSTR)((ULONG_PTR)((WORD)(atom)))) -#define POPUPMENU_CLASS_ATOMA MAKEINTATOMA(32768) /* PopupMenu */ -#define POPUPMENU_CLASS_ATOMW MAKEINTATOMW(32768) /* PopupMenu */ - typedef struct { UINT TrackFlags; @@ -86,7 +81,7 @@ typedef struct */ const struct builtin_class_descr POPUPMENU_builtin_class = { - POPUPMENU_CLASS_ATOMW, /* name */ + WC_MENU, /* name */ CS_SAVEBITS | CS_DBLCLKS, /* style */ (WNDPROC) NULL, /* FIXME - procA */ (WNDPROC) PopupMenuWndProcW, /* FIXME - procW */ @@ -1626,7 +1621,7 @@ static BOOL FASTCALL MenuShowPopup(HWND hwndOwner, HMENU hmenu, UINT id, UINT fl if( y < info.rcMonitor.top ) y = info.rcMonitor.top; /* NOTE: In Windows, top menu popup is not owned. */ - MenuInfo.Wnd = CreateWindowExW( 0, POPUPMENU_CLASS_ATOMW, NULL, + MenuInfo.Wnd = CreateWindowExW( 0, WC_MENU, NULL, WS_POPUP, x, y, width, height, hwndOwner, 0, (HINSTANCE) GetWindowLongPtrW(hwndOwner, GWLP_HINSTANCE), (LPVOID) MenuInfo.Self); diff --git a/dll/win32/user32/windows/window.c b/dll/win32/user32/windows/window.c index be687a64b6f..d2a7bb9ee97 100644 --- a/dll/win32/user32/windows/window.c +++ b/dll/win32/user32/windows/window.c @@ -18,8 +18,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(user32); LRESULT DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active); void MDI_CalcDefaultChildPos( HWND hwndClient, INT total, LPPOINT lpPos, INT delta, UINT *id ); -#define CW_USEDEFAULT16 0x00008000 - /* FUNCTIONS *****************************************************************/ diff --git a/drivers/filesystems/npfs/dirctl.c b/drivers/filesystems/npfs/dirctl.c index ff7f0ecb0f1..2fbfbd4fa4d 100644 --- a/drivers/filesystems/npfs/dirctl.c +++ b/drivers/filesystems/npfs/dirctl.c @@ -37,6 +37,8 @@ NpfsQueryDirectory(PNPFS_CCB Ccb, PFILE_DIRECTORY_INFORMATION DirectoryBuffer; PFILE_FULL_DIR_INFORMATION FullDirBuffer; PFILE_BOTH_DIR_INFORMATION BothDirBuffer; + ULONG InfoSize = 0; + ULONG NameLength; Stack = IoGetCurrentIrpStackLocation(Irp); @@ -109,11 +111,36 @@ NpfsQueryDirectory(PNPFS_CCB Ccb, DPRINT("Buffer = %p tofind = %wZ\n", Buffer, &Ccb->u.Directory.SearchPattern); + switch (FileInformationClass) + { + case FileDirectoryInformation: + InfoSize = sizeof(FILE_DIRECTORY_INFORMATION) - sizeof(WCHAR); + break; + + case FileFullDirectoryInformation: + InfoSize = sizeof(FILE_FULL_DIR_INFORMATION) - sizeof(WCHAR); + break; + + case FileBothDirectoryInformation: + InfoSize = sizeof(FILE_BOTH_DIR_INFORMATION) - sizeof(WCHAR); + break; + + case FileNamesInformation: + InfoSize = sizeof(FILE_NAMES_INFORMATION) - sizeof(WCHAR); + break; + + default: + DPRINT1("Invalid information class: %lu\n", FileInformationClass); + return STATUS_INVALID_INFO_CLASS; + } + PipeIndex = 0; Vcb = Ccb->Fcb->Vcb; CurrentEntry = Vcb->PipeListHead.Flink; - while (CurrentEntry != &Vcb->PipeListHead && Found == FALSE) + while (CurrentEntry != &Vcb->PipeListHead && + Found == FALSE && + Status == STATUS_SUCCESS) { /* Get the FCB of the next pipe */ PipeFcb = CONTAINING_RECORD(CurrentEntry, @@ -134,7 +161,20 @@ NpfsQueryDirectory(PNPFS_CCB Ccb, if (PipeIndex >= FileIndex) { - RtlZeroMemory(Buffer, BufferLength); + /* Determine whether or not the full pipe name fits into the buffer */ + if (InfoSize + PipeFcb->PipeName.Length > BufferLength) + { + NameLength = BufferLength - InfoSize; + Status = STATUS_BUFFER_OVERFLOW; + } + else + { + NameLength = PipeFcb->PipeName.Length; + Status = STATUS_SUCCESS; + } + + /* Initialize the information struct */ + RtlZeroMemory(Buffer, InfoSize); switch (FileInformationClass) { @@ -145,12 +185,10 @@ NpfsQueryDirectory(PNPFS_CCB Ccb, DirectoryBuffer->FileAttributes = FILE_ATTRIBUTE_NORMAL; DirectoryBuffer->EndOfFile.QuadPart = PipeFcb->CurrentInstances; DirectoryBuffer->AllocationSize.LowPart = PipeFcb->MaximumInstances; - DirectoryBuffer->FileNameLength = PipeFcb->PipeName.Length; + DirectoryBuffer->FileNameLength = NameLength; RtlCopyMemory(DirectoryBuffer->FileName, PipeFcb->PipeName.Buffer, - PipeFcb->PipeName.Length); - *Size = sizeof(FILE_DIRECTORY_INFORMATION) + PipeFcb->PipeName.Length - sizeof(WCHAR); - Status = STATUS_SUCCESS; + NameLength); break; case FileFullDirectoryInformation: @@ -160,12 +198,10 @@ NpfsQueryDirectory(PNPFS_CCB Ccb, FullDirBuffer->FileAttributes = FILE_ATTRIBUTE_NORMAL; FullDirBuffer->EndOfFile.QuadPart = PipeFcb->CurrentInstances; FullDirBuffer->AllocationSize.LowPart = PipeFcb->MaximumInstances; - FullDirBuffer->FileNameLength = PipeFcb->PipeName.Length; + FullDirBuffer->FileNameLength = NameLength; RtlCopyMemory(FullDirBuffer->FileName, PipeFcb->PipeName.Buffer, - PipeFcb->PipeName.Length); - *Size = sizeof(FILE_FULL_DIR_INFORMATION) + PipeFcb->PipeName.Length - sizeof(WCHAR); - Status = STATUS_SUCCESS; + NameLength); break; case FileBothDirectoryInformation: @@ -175,32 +211,30 @@ NpfsQueryDirectory(PNPFS_CCB Ccb, BothDirBuffer->FileAttributes = FILE_ATTRIBUTE_NORMAL; BothDirBuffer->EndOfFile.QuadPart = PipeFcb->CurrentInstances; BothDirBuffer->AllocationSize.LowPart = PipeFcb->MaximumInstances; - BothDirBuffer->FileNameLength = PipeFcb->PipeName.Length; + BothDirBuffer->FileNameLength = NameLength; RtlCopyMemory(BothDirBuffer->FileName, PipeFcb->PipeName.Buffer, - PipeFcb->PipeName.Length); - *Size = sizeof(FILE_BOTH_DIR_INFORMATION) + PipeFcb->PipeName.Length - sizeof(WCHAR); - Status = STATUS_SUCCESS; + NameLength); break; case FileNamesInformation: NamesBuffer = (PFILE_NAMES_INFORMATION)Buffer; NamesBuffer->NextEntryOffset = 0; NamesBuffer->FileIndex = PipeIndex; - NamesBuffer->FileNameLength = PipeFcb->PipeName.Length; + NamesBuffer->FileNameLength = NameLength; RtlCopyMemory(NamesBuffer->FileName, PipeFcb->PipeName.Buffer, - PipeFcb->PipeName.Length); - *Size = sizeof(FILE_NAMES_INFORMATION) + PipeFcb->PipeName.Length - sizeof(WCHAR); - Status = STATUS_SUCCESS; + NameLength); break; default: - DPRINT1("Invalid information class: %lu\n", FileInformationClass); - Status = STATUS_INVALID_INFO_CLASS; + /* Should never happen! */ + ASSERT(FALSE); break; } + *Size = InfoSize + NameLength; + Ccb->u.Directory.FileIndex = PipeIndex; Found = TRUE; diff --git a/drivers/usb/usbehci/fdo.c b/drivers/usb/usbehci/fdo.c index 1886f4ae119..02dd3e7ab5e 100644 --- a/drivers/usb/usbehci/fdo.c +++ b/drivers/usb/usbehci/fdo.c @@ -46,7 +46,7 @@ EhciDefferedRoutine(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVO DPRINT("Asyn Complete!\n"); ULONG CurrentAddr, OffSet; PQUEUE_HEAD CompletedQH, NextQH; - PQUEUE_TRANSFER_DESCRIPTOR CompletedTD; + PQUEUE_TRANSFER_DESCRIPTOR CompletedTD, NextTD; /* AsyncListAddr Register will have the next QueueHead to execute */ CurrentAddr = GetAsyncListQueueRegister(hcd); @@ -64,14 +64,13 @@ EhciDefferedRoutine(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVO /* Free memory for the Descriptors */ CompletedTD = CompletedQH->TransferDescriptor; - //DumpTransferDescriptor(CompletedTD); - FreeDescriptor(CompletedTD); - CompletedTD = CompletedTD->NextDescriptor; - //DumpTransferDescriptor(CompletedTD); - FreeDescriptor(CompletedTD); - CompletedTD = CompletedTD->NextDescriptor; - //DumpTransferDescriptor(CompletedTD); + NextTD = CompletedTD; + while (NextTD) + { + CompletedTD = NextTD; + NextTD = NextTD->NextDescriptor; FreeDescriptor(CompletedTD); + } /* If the Event is set then release waiter */ if (CompletedQH->Event) @@ -79,27 +78,25 @@ EhciDefferedRoutine(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVO KeSetEvent(CompletedQH->Event, IO_NO_INCREMENT, FALSE); } - /* Free the Mdl */ - ASSERT(CompletedQH->MdlToFree); + /* Free the Mdl if there was one */ + if(CompletedQH->MdlToFree) IoFreeMdl(CompletedQH->MdlToFree); /* Is there an IRP that needs to be completed */ if (CompletedQH->IrpToComplete) { PIRP Irp; - + PIO_STACK_LOCATION Stack; + PURB Urb; + Irp = CompletedQH->IrpToComplete; + Stack = IoGetCurrentIrpStackLocation(Irp); + ASSERT(Stack); + Urb = (PURB) Stack->Parameters.Others.Argument1; /* Check for error */ if (CStatus & EHCI_ERROR_INT) { - PIO_STACK_LOCATION Stack; - PURB Urb; - - Stack = IoGetCurrentIrpStackLocation(Irp); - ASSERT(Stack); - Urb = (PURB) Stack->Parameters.Others.Argument1; - ASSERT(FALSE); /* Haled bit should be set */ if (CompletedQH->Token.Bits.Halted) { diff --git a/drivers/usb/usbehci/irp.c b/drivers/usb/usbehci/irp.c index ead34f69e07..4f43c5ea37b 100644 --- a/drivers/usb/usbehci/irp.c +++ b/drivers/usb/usbehci/irp.c @@ -139,20 +139,21 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) } } else - DPRINT("Interrupt Transfer not for hub\n"); + DPRINT1("Interrupt Transfer not for hub\n"); break; } case URB_FUNCTION_GET_STATUS_FROM_DEVICE: { DPRINT1("URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"); - if (Urb->UrbControlGetStatusRequest.Index == 0) + /* If for the hub device */ + if ((Urb->UrbControlGetStatusRequest.Index == 0) && (UsbDevice == PdoDeviceExtension->UsbDevices[0])) { ASSERT(Urb->UrbBulkOrInterruptTransfer.TransferBuffer != NULL); - *(PUSHORT)Urb->UrbControlGetStatusRequest.TransferBuffer = USB_PORT_STATUS_CONNECT | USB_PORT_STATUS_ENABLE; + *(PUSHORT)Urb->UrbControlGetStatusRequest.TransferBuffer = USB_PORT_STATUS_CONNECT /*| USB_PORT_STATUS_ENABLE*/; } else { - DPRINT1("Uknown identifier\n"); + DPRINT1("UsbDeviceHandle %x, Index %x not implemented yet\n", UsbDevice, Urb->UrbControlGetStatusRequest.Index); Urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION; Status = STATUS_UNSUCCESSFUL; } @@ -189,15 +190,14 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) ASSERT(Urb->UrbControlDescriptorRequest.TransferBuffer != NULL); - DPRINT("Calling BuildSetUpPacketFromUrb\n"); BuildSetupPacketFromURB(&FdoDeviceExtension->hcd, Urb, &CtrlSetup); - DPRINT("SubmitControlTransfer\n"); + IoMarkIrpPending(Irp); + Status = STATUS_PENDING; SubmitControlTransfer(&FdoDeviceExtension->hcd, &CtrlSetup, Urb->UrbControlDescriptorRequest.TransferBuffer, Urb->UrbControlDescriptorRequest.TransferBufferLength, Irp); - break; } case USB_CONFIGURATION_DESCRIPTOR_TYPE: @@ -267,24 +267,15 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) if (Urb->UrbControlDescriptorRequest.Index == 0) DPRINT1("Requesting LANGID's\n"); - CtrlSetup.bmRequestType._BM.Recipient = BMREQUEST_TO_DEVICE; - CtrlSetup.bmRequestType._BM.Type = BMREQUEST_STANDARD; - CtrlSetup.bmRequestType._BM.Reserved = 0; - CtrlSetup.bmRequestType._BM.Dir = BMREQUEST_DEVICE_TO_HOST; - CtrlSetup.bRequest = USB_REQUEST_GET_DESCRIPTOR; - CtrlSetup.wValue.LowByte = Urb->UrbControlDescriptorRequest.Index; - CtrlSetup.wValue.HiByte = Urb->UrbControlDescriptorRequest.DescriptorType; - CtrlSetup.wIndex.W = Urb->UrbControlDescriptorRequest.LanguageId; - CtrlSetup.wLength = Urb->UrbControlDescriptorRequest.TransferBufferLength; + BuildSetupPacketFromURB(&FdoDeviceExtension->hcd, Urb, &CtrlSetup); + IoMarkIrpPending(Irp); + Status = STATUS_PENDING; SubmitControlTransfer(&FdoDeviceExtension->hcd, &CtrlSetup, Urb->UrbControlDescriptorRequest.TransferBuffer, Urb->UrbControlDescriptorRequest.TransferBufferLength, Irp); - - IoMarkIrpPending(Irp); - Status = STATUS_PENDING; break; } default: @@ -301,11 +292,11 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) DPRINT1("Selecting Configuration\n"); DPRINT1("ConfigurationHandle %x\n",Urb->UrbSelectConfiguration.ConfigurationHandle); - if (Urb->UrbSelectConfiguration.ConfigurationDescriptor) { - Urb->UrbSelectConfiguration.ConfigurationHandle = (PVOID)&PdoDeviceExtension->UsbDevices[0]->ActiveConfig->ConfigurationDescriptor; - DPRINT("ConfigHandle %x\n", Urb->UrbSelectConfiguration.ConfigurationHandle); + Urb->UrbSelectConfiguration.ConfigurationHandle = &UsbDevice->ActiveConfig->ConfigurationDescriptor; + DPRINT1("ConfigHandle %x\n", Urb->UrbSelectConfiguration.ConfigurationHandle); + ASSERT(FALSE); InterfaceInfo = &Urb->UrbSelectConfiguration.Interface; DPRINT1("Length %x\n", InterfaceInfo->Length); @@ -324,7 +315,7 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) InterfaceInfo->Pipes[pCount].MaximumPacketSize = UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor.wMaxPacketSize; InterfaceInfo->Pipes[pCount].EndpointAddress = UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor.bEndpointAddress; InterfaceInfo->Pipes[pCount].Interval = UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor.bInterval; - InterfaceInfo->Pipes[pCount].PipeType = UsbdPipeTypeInterrupt; + InterfaceInfo->Pipes[pCount].PipeType = UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor.bmAttributes; InterfaceInfo->Pipes[pCount].PipeHandle = (PVOID)&UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor; if (InterfaceInfo->Pipes[pCount].MaximumTransferSize == 0) InterfaceInfo->Pipes[pCount].MaximumTransferSize = 4096; @@ -337,9 +328,39 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) else { /* FIXME: Set device to unconfigured state */ + DPRINT1("Setting device to unconfigured state not implemented!\n"); } break; } + case URB_FUNCTION_SELECT_INTERFACE: + { + USB_DEFAULT_PIPE_SETUP_PACKET CtrlSetup; + PUSBD_INTERFACE_INFORMATION InterfaceInfo; + int i; + + DPRINT1("Select Interface!\n"); + DPRINT1("Config Handle %x\n", Urb->UrbSelectInterface.ConfigurationHandle); + + InterfaceInfo = &Urb->UrbSelectInterface.Interface; + DPRINT1("InterfaceNumber %x\n", InterfaceInfo->InterfaceNumber); + DPRINT1("AlternateSetting %x\n", InterfaceInfo->AlternateSetting); + DPRINT1("NumPipes %x\n", InterfaceInfo->NumberOfPipes); + for (i=0;iNumberOfPipes;i++) + { + InterfaceInfo->Pipes[i].PipeHandle = (PVOID)&UsbDevice->ActiveInterface->EndPoints[i]->EndPointDescriptor; + } + + BuildSetupPacketFromURB(&FdoDeviceExtension->hcd, Urb, &CtrlSetup); + IoMarkIrpPending(Irp); + Status = STATUS_PENDING; + + SubmitControlTransfer(&FdoDeviceExtension->hcd, + &CtrlSetup, + NULL, + 0, + Irp); + break; + } case URB_FUNCTION_CLASS_DEVICE: { DPRINT1("URB_FUNCTION_CLASS_DEVICE\n"); @@ -456,7 +477,7 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) { case USB_REQUEST_GET_STATUS: { - DPRINT1("USB_REQUEST_GET_STATUS Port %d\n", Urb->UrbControlVendorClassRequest.Index); + DPRINT("USB_REQUEST_GET_STATUS Port %d\n", Urb->UrbControlVendorClassRequest.Index); ASSERT(Urb->UrbControlVendorClassRequest.TransferBuffer != 0); DPRINT("PortStatus %x\n", PdoDeviceExtension->Ports[Urb->UrbControlVendorClassRequest.Index-1].PortStatus); @@ -467,23 +488,21 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) } case USB_REQUEST_CLEAR_FEATURE: { - DPRINT1("USB_REQUEST_CLEAR_FEATURE Port %d, value %x\n", Urb->UrbControlVendorClassRequest.Index, - Urb->UrbControlVendorClassRequest.Value); switch (Urb->UrbControlVendorClassRequest.Value) { case C_PORT_CONNECTION: - DPRINT1("C_PORT_CONNECTION\n"); + DPRINT("C_PORT_CONNECTION\n"); PdoDeviceExtension->Ports[Urb->UrbControlVendorClassRequest.Index-1].PortChange &= ~USB_PORT_STATUS_CONNECT; break; case C_PORT_RESET: - DPRINT1("C_PORT_RESET\n"); + DPRINT("C_PORT_RESET\n"); PdoDeviceExtension->Ports[Urb->UrbControlVendorClassRequest.Index-1].PortChange &= ~USB_PORT_STATUS_RESET; + PdoDeviceExtension->Ports[Urb->UrbControlVendorClassRequest.Index-1].PortStatus |= USB_PORT_STATUS_ENABLE; break; default: - DPRINT1("Unknown Value for Clear Feature %x \n", Urb->UrbControlVendorClassRequest.Value); + DPRINT("Unknown Value for Clear Feature %x \n", Urb->UrbControlVendorClassRequest.Value); break; } - CompletePendingURBRequest(PdoDeviceExtension); break; } case USB_REQUEST_SET_FEATURE: @@ -495,18 +514,10 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) { case PORT_RESET: { - //PWORKITEMDATA WorkItemData; - - PdoDeviceExtension->Ports[Urb->UrbControlVendorClassRequest.Index-1].PortStatus |= USB_PORT_STATUS_ENABLE; + DPRINT("Port Reset %d\n", Urb->UrbControlVendorClassRequest.Index-1); PdoDeviceExtension->Ports[Urb->UrbControlVendorClassRequest.Index-1].PortChange |= USB_PORT_STATUS_RESET; - + PdoDeviceExtension->Ports[Urb->UrbControlVendorClassRequest.Index-1].PortStatus &= ~USB_PORT_STATUS_ENABLE; ResetPort(&FdoDeviceExtension->hcd, Urb->UrbControlVendorClassRequest.Index-1); - //WorkItemData = ExAllocatePool(NonPagedPool, sizeof(WORKITEMDATA)); - //WorkItemData->Context = PdoDeviceExtension; - //ExInitializeWorkItem(&WorkItemData->WorkItem, (PWORKER_THREAD_ROUTINE)WorkerThread, (PVOID) WorkItemData) - //ExQueueWorkItem(&WorkItemData->WorkItem, DelayedWorkQueue); - //IoMarkIrpPending(Irp); - //Status = STATUS_PENDING; break; } case PORT_ENABLE: @@ -525,7 +536,10 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) break; } } + + if (!(PdoDeviceExtension->Ports[Urb->UrbControlVendorClassRequest.Index-1].PortStatus & 0x8000)) CompletePendingURBRequest(PdoDeviceExtension); + break; } case USB_REQUEST_SET_ADDRESS: @@ -577,6 +591,23 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) } break; } + case URB_FUNCTION_CONTROL_TRANSFER: + { + DPRINT1("URB_FUNCTION_CONTROL_TRANSFER\n"); + DPRINT1("PipeHandle %x\n", Urb->UrbControlTransfer.PipeHandle); + DPRINT1("TransferFlags %x\n", Urb->UrbControlTransfer.TransferFlags); + DPRINT1("TransferLength %x\n", Urb->UrbControlTransfer.TransferBufferLength); + DPRINT1("TransferBuffer %x\n", Urb->UrbControlTransfer.TransferBuffer); + DPRINT1("TransferMDL %x\n", Urb->UrbControlTransfer.TransferBufferMDL); + DPRINT1("SetupPacket %x\n", Urb->UrbControlTransfer.SetupPacket); + ASSERT(FALSE); + break; + } + case URB_FUNCTION_CLASS_INTERFACE: + { + DPRINT1("URB_FUNCTION_CLASS_INTERFACE\n"); + break; + } default: { DPRINT1("Unhandled URB %x\n", Urb->UrbHeader.Function); @@ -586,14 +617,6 @@ NTSTATUS HandleUrbRequest(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PIRP Irp) Irp->IoStatus.Status = Status; Irp->IoStatus.Information = Information; - - if (Urb->UrbHeader.Status == USBD_STATUS_SUCCESS) - { - /* Fake a successful Control Transfer */ - Urb->UrbHeader.Function = 0x08; - Urb->UrbHeader.UsbdFlags = 0; - } - return Status; } @@ -606,23 +629,25 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension) KeAcquireSpinLock(&DeviceExtension->IrpQueueLock, &oldIrql); - while (!IsListEmpty(&DeviceExtension->IrpQueue)) + if (IsListEmpty(&DeviceExtension->IrpQueue)) { + DPRINT1("There should have been one SCE request pending\n"); + KeReleaseSpinLock(&DeviceExtension->IrpQueueLock, oldIrql); + return; + } NextIrp = RemoveHeadList(&DeviceExtension->IrpQueue); Irp = CONTAINING_RECORD(NextIrp, IRP, Tail.Overlay.ListEntry); if (!Irp) { - DPRINT1("No IRP\n"); - break; + DPRINT1("No Irp\n"); + return; } + IoSetCancelRoutine(Irp, NULL); KeReleaseSpinLock(&DeviceExtension->IrpQueueLock, oldIrql); + HandleUrbRequest(DeviceExtension, Irp); IoCompleteRequest(Irp, IO_NO_INCREMENT); - KeAcquireSpinLock(&DeviceExtension->IrpQueueLock, &oldIrql); - } - - KeReleaseSpinLock(&DeviceExtension->IrpQueueLock, oldIrql); } diff --git a/drivers/usb/usbehci/physmem.c b/drivers/usb/usbehci/physmem.c index ac6b4ede83c..eb696da9f09 100644 --- a/drivers/usb/usbehci/physmem.c +++ b/drivers/usb/usbehci/physmem.c @@ -31,7 +31,6 @@ AllocateMemory(PEHCI_HOST_CONTROLLER hcd, ULONG Size, ULONG *PhysicalAddress) Size = ((Size + SMALL_ALLOCATION_SIZE - 1) / SMALL_ALLOCATION_SIZE) * SMALL_ALLOCATION_SIZE; BlocksNeeded = Size / SMALL_ALLOCATION_SIZE; - do { if (MemoryPage->IsFull) @@ -52,6 +51,11 @@ AllocateMemory(PEHCI_HOST_CONTROLLER hcd, ULONG Size, ULONG *PhysicalAddress) freeCount = 0; } + if ((i-freeCount+1 + BlocksNeeded) > sizeof(MemoryPage->Entry)) + { + freeCount = 0; + continue; + } if (freeCount == BlocksNeeded) { for (j = 0; j < freeCount; j++) @@ -80,13 +84,13 @@ VOID ReleaseMemory(ULONG Address) { PMEM_HEADER MemoryPage; - ULONG Index, i; + ULONG Index, i, BlockSize; MemoryPage = (PMEM_HEADER)(Address & ~(PAGE_SIZE - 1)); Index = (Address - ((ULONG)MemoryPage + sizeof(MEM_HEADER))) / SMALL_ALLOCATION_SIZE; - - for (i = 0; i < MemoryPage->Entry[Index].Blocks; i++) + BlockSize = MemoryPage->Entry[Index].Blocks; + for (i = 0; i < BlockSize; i++) { MemoryPage->Entry[Index + i].InUse = 0; MemoryPage->Entry[Index + i].Blocks = 0; diff --git a/drivers/usb/usbehci/physmem.h b/drivers/usb/usbehci/physmem.h index 9b9de0b2970..ef1355da9df 100644 --- a/drivers/usb/usbehci/physmem.h +++ b/drivers/usb/usbehci/physmem.h @@ -11,7 +11,8 @@ typedef struct _MEM_ENTRY typedef struct _MEM_HEADER { UCHAR IsFull; - MEM_ENTRY Entry[127]; + MEM_ENTRY Entry[124]; + UCHAR Reserved[3]; } MEM_HEADER, *PMEM_HEADER; VOID diff --git a/drivers/usb/usbehci/transfer.c b/drivers/usb/usbehci/transfer.c index 436bd17ecdb..4d33726ce9d 100644 --- a/drivers/usb/usbehci/transfer.c +++ b/drivers/usb/usbehci/transfer.c @@ -77,6 +77,9 @@ BuildSetupPacketFromURB(PEHCI_HOST_CONTROLLER hcd, PURB Urb, PUSB_DEFAULT_PIPE_S /* SET CONFIG */ case URB_FUNCTION_SELECT_CONFIGURATION: CtrlSetup->bRequest = USB_REQUEST_SET_CONFIGURATION; + CtrlSetup->wValue.W = Urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue; + CtrlSetup->wIndex.W = 0; + CtrlSetup->wLength = 0; CtrlSetup->bmRequestType.B = 0x00; break; @@ -111,7 +114,11 @@ BuildSetupPacketFromURB(PEHCI_HOST_CONTROLLER hcd, PURB Urb, PUSB_DEFAULT_PIPE_S /* SET INTERFACE*/ case URB_FUNCTION_SELECT_INTERFACE: - DPRINT1("Not implemented\n"); + CtrlSetup->bRequest = USB_REQUEST_SET_INTERFACE; + CtrlSetup->wValue.W = Urb->UrbSelectInterface.Interface.AlternateSetting; + CtrlSetup->wIndex.W = Urb->UrbSelectInterface.Interface.InterfaceNumber; + CtrlSetup->wLength = 0; + CtrlSetup->bmRequestType.B = 0x01; break; /* SYNC FRAME */ @@ -150,6 +157,8 @@ SubmitControlTransfer(PEHCI_HOST_CONTROLLER hcd, KeInitializeEvent(Event, NotificationEvent, FALSE); } + if (TransferBuffer) + { /* Allocate Mdl for Buffer */ pMdl = IoAllocateMdl(TransferBuffer, TransferBufferLength, @@ -162,6 +171,7 @@ SubmitControlTransfer(PEHCI_HOST_CONTROLLER hcd, //MmProbeAndLockPages(pMdl, KernelMode, IoReadAccess); MdlPhysicalAddr = MmGetPhysicalAddress((PVOID)TransferBuffer).LowPart; + } QueueHead = CreateQueueHead(hcd); @@ -175,9 +185,12 @@ SubmitControlTransfer(PEHCI_HOST_CONTROLLER hcd, /* Save the first descriptor */ QueueHead->TransferDescriptor = Descriptor[0]; + if (TransferBuffer) + { Descriptor[1] = CreateDescriptor(hcd, PID_CODE_IN_TOKEN, - TransferBufferLength); + TransferBufferLength); + } Descriptor[2] = CreateDescriptor(hcd, PID_CODE_OUT_TOKEN, @@ -186,17 +199,34 @@ SubmitControlTransfer(PEHCI_HOST_CONTROLLER hcd, Descriptor[1]->Token.Bits.InterruptOnComplete = FALSE; /* Link the descriptors */ + + if (TransferBuffer) + { Descriptor[0]->NextDescriptor = Descriptor[1]; Descriptor[1]->NextDescriptor = Descriptor[2]; Descriptor[1]->PreviousDescriptor = Descriptor[0]; Descriptor[2]->PreviousDescriptor = Descriptor[1]; - + } + else + { + Descriptor[0]->NextDescriptor = Descriptor[2]; + Descriptor[2]->PreviousDescriptor = Descriptor[0]; + } + /* Assign the descritors buffers */ Descriptor[0]->BufferPointer[0] = (ULONG)CtrlPhysicalPA; - Descriptor[1]->BufferPointer[0] = MdlPhysicalAddr; + if (TransferBuffer) + { + Descriptor[1]->BufferPointer[0] = MdlPhysicalAddr; Descriptor[0]->NextPointer = Descriptor[1]->PhysicalAddr; - Descriptor[1]->NextPointer = Descriptor[2]->PhysicalAddr; + Descriptor[1]->NextPointer = Descriptor[2]->PhysicalAddr; + } + else + { + Descriptor[0]->NextPointer = Descriptor[2]->PhysicalAddr; + } + QueueHead->NextPointer = Descriptor[0]->PhysicalAddr; QueueHead->IrpToComplete = IrpToComplete; diff --git a/drivers/usb/usbehci/usbehci.h b/drivers/usb/usbehci/usbehci.h index 111496ce18d..b5353874a30 100644 --- a/drivers/usb/usbehci/usbehci.h +++ b/drivers/usb/usbehci/usbehci.h @@ -17,6 +17,7 @@ #define DEVICEBUSY 0x04 #define DEVICESTOPPED 0x08 #define DEVICESTALLED 0x10 +#define DEVICEREMOVED 0x20 #define MAX_USB_DEVICES 127 @@ -71,6 +72,8 @@ typedef struct _USB_DEVICE BOOLEAN IsHub; USB_DEVICE_SPEED DeviceSpeed; USB_DEVICE_TYPE DeviceType; + ULONG DeviceState; + PDEVICE_OBJECT UsbDevicePdo; USB_DEVICE_DESCRIPTOR DeviceDescriptor; UNICODE_STRING LanguageIDs; UNICODE_STRING iManufacturer; diff --git a/drivers/usb/usbehci/usbiffn.c b/drivers/usb/usbehci/usbiffn.c index 9d2efddd31f..43bdd6605fa 100644 --- a/drivers/usb/usbehci/usbiffn.c +++ b/drivers/usb/usbehci/usbiffn.c @@ -132,21 +132,21 @@ InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle) CtrlSetup.wIndex.W = 0; CtrlSetup.wLength = sizeof(USB_DEVICE_DESCRIPTOR); CtrlSetup.bmRequestType.B = 0x80; - + SubmitControlTransfer(&FdoDeviceExtension->hcd, &CtrlSetup, &UsbDevice->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR), NULL); - + //DumpDeviceDescriptor(&UsbDevice->DeviceDescriptor); - + if (UsbDevice->DeviceDescriptor.bLength != 0x12) { DPRINT1("Failed to get Device Descriptor from device connected on port %d\n", UsbDevice->Port); return STATUS_DEVICE_DATA_ERROR; } - + if (UsbDevice->DeviceDescriptor.bNumConfigurations == 0) { DPRINT1("Device on port %d has no configurations!\n", UsbDevice->Port); @@ -171,7 +171,7 @@ InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle) } Ptr = Buffer; - + for (i = 0; i < UsbDevice->DeviceDescriptor.bNumConfigurations; i++) { /* Get the Device Configuration Descriptor */ @@ -184,7 +184,7 @@ InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle) CtrlSetup.wValue.HiByte = USB_CONFIGURATION_DESCRIPTOR_TYPE; CtrlSetup.wIndex.W = 0; CtrlSetup.wLength = PAGE_SIZE; - + SubmitControlTransfer(&FdoDeviceExtension->hcd, &CtrlSetup, Buffer, @@ -223,14 +223,13 @@ InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle) UsbDevice->Configs[i]->Interfaces[j]->EndPoints[k] = ExAllocatePoolWithTag(NonPagedPool, sizeof(USB_ENDPOINT), USB_POOL_TAG); RtlCopyMemory(&UsbDevice->Configs[i]->Interfaces[j]->EndPoints[k]->EndPointDescriptor, EndpointDesc, sizeof(USB_ENDPOINT_DESCRIPTOR)); + Ptr += sizeof(USB_ENDPOINT_DESCRIPTOR); } - } } UsbDevice->ActiveConfig = UsbDevice->Configs[0]; UsbDevice->ActiveInterface = UsbDevice->Configs[0]->Interfaces[0]; - return STATUS_SUCCESS; /* Set the device address */ @@ -244,13 +243,14 @@ InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle) CtrlSetup.wLength = 0; DPRINT1("Setting Address to %x\n", UsbDevice->Address); - + SubmitControlTransfer(&FdoDeviceExtension->hcd, &CtrlSetup, NULL, 0, NULL); + PdoDeviceExtension->UsbDevices[i]->DeviceState = DEVICEINTIALIZED; return STATUS_SUCCESS; } @@ -334,15 +334,12 @@ RemoveUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle, ULONG Flags) } ExFreePool(UsbDevice); - - /* DeConfig Device */ break; - case USBD_KEEP_DEVICE_DATA: - DPRINT1("USBD_KEEP_DEVICE_DATA Not implemented!\n"); - break; - case USBD_MARK_DEVICE_BUSY: - DPRINT1("USBD_MARK_DEVICE_BUSY Not implemented!\n"); + UsbDevice->DeviceState |= DEVICEBUSY; + /* Fall through */ + case USBD_KEEP_DEVICE_DATA: + UsbDevice->DeviceState |= DEVICEREMOVED; break; default: DPRINT1("Unknown Remove Flags %x\n", Flags); @@ -354,8 +351,60 @@ NTSTATUS USB_BUSIFFN RestoreUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE OldDeviceHandle, PUSB_DEVICE_HANDLE NewDeviceHandle) { - DPRINT1("Ehci: RestoreUsbDevice not implemented! %x, %x, %x\n", BusContext, OldDeviceHandle, NewDeviceHandle); - return STATUS_NOT_SUPPORTED; + PUSB_DEVICE OldUsbDevice; + PUSB_DEVICE NewUsbDevice; + + DPRINT1("Ehci: RestoreUsbDevice %x, %x, %x\n", BusContext, OldDeviceHandle, NewDeviceHandle); + + OldUsbDevice = DeviceHandleToUsbDevice(BusContext, OldDeviceHandle); + NewUsbDevice = DeviceHandleToUsbDevice(BusContext, NewDeviceHandle); + + if (!OldUsbDevice) + { + DPRINT1("OldDeviceHandle is invalid\n"); + return STATUS_DEVICE_NOT_CONNECTED; + } + + if (!(OldUsbDevice->DeviceState & DEVICEREMOVED)) + { + DPRINT1("UsbDevice is not marked as Removed!\n"); + return STATUS_UNSUCCESSFUL; + } + + if (!NewUsbDevice) + { + DPRINT1("NewDeviceHandle is invalid\n"); + return STATUS_DEVICE_NOT_CONNECTED; + } + + if ((OldUsbDevice->DeviceDescriptor.idVendor == NewUsbDevice->DeviceDescriptor.idVendor) && + (OldUsbDevice->DeviceDescriptor.idProduct == NewUsbDevice->DeviceDescriptor.idProduct)) + { + PUSB_CONFIGURATION ConfigToDelete; + int i; + + NewUsbDevice->DeviceState &= ~DEVICEBUSY; + NewUsbDevice->DeviceState &= ~DEVICEREMOVED; + + NewUsbDevice->ActiveConfig = OldUsbDevice->ActiveConfig; + NewUsbDevice->ActiveInterface = OldUsbDevice->ActiveInterface; + + for (i = 0; i < NewUsbDevice->DeviceDescriptor.bNumConfigurations; i++) + { + ConfigToDelete = NewUsbDevice->Configs[i]; + ASSERT(OldUsbDevice->Configs[i]); + NewUsbDevice->Configs[i] = OldUsbDevice->Configs[i]; + OldUsbDevice->Configs[i] = ConfigToDelete; + } + + RemoveUsbDevice(BusContext, OldDeviceHandle, 0); + return STATUS_SUCCESS; + } + else + { + DPRINT1("VendorId or ProductId did not match!\n"); + return STATUS_DEVICE_NOT_CONNECTED; + } } NTSTATUS @@ -407,13 +456,24 @@ QueryDeviceInformation(PVOID BusContext, return STATUS_INVALID_PARAMETER; } - DeviceInfo->PortNumber = UsbDevice->Port; - DeviceInfo->HubAddress = 1; + DeviceInfo->HubAddress = 0; DeviceInfo->DeviceAddress = UsbDevice->Address; DeviceInfo->DeviceSpeed = UsbDevice->DeviceSpeed; DeviceInfo->DeviceType = UsbDevice->DeviceType; + + if (!UsbDevice->DeviceState) + { + DeviceInfo->CurrentConfigurationValue = 0; + DeviceInfo->NumberOfOpenPipes = 0; + DeviceInfo->PortNumber = 0; + } + else + { DeviceInfo->CurrentConfigurationValue = UsbDevice->ActiveConfig->ConfigurationDescriptor.bConfigurationValue; + /* FIXME: Use correct number of open pipes instead of all available */ DeviceInfo->NumberOfOpenPipes = UsbDevice->ActiveInterface->InterfaceDescriptor.bNumEndpoints; + DeviceInfo->PortNumber = UsbDevice->Port; + } RtlCopyMemory(&DeviceInfo->DeviceDescriptor, &UsbDevice->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR)); @@ -495,15 +555,15 @@ GetExtendedHubInformation(PVOID BusContext, DPRINT1("InformationLevel should really be set to 0. Ignoring\n"); } - UsbExtHubInfo->NumberOfPorts = 8; + UsbExtHubInfo->NumberOfPorts = FdoDeviceExntension->hcd.ECHICaps.HCSParams.PortCount; for (i=0; i < UsbExtHubInfo->NumberOfPorts; i++) { UsbExtHubInfo->Port[i].PhysicalPortNumber = i + 1; - UsbExtHubInfo->Port[i].PortLabelNumber = FdoDeviceExntension->hcd.ECHICaps.HCSParams.PortCount; + UsbExtHubInfo->Port[i].PortLabelNumber = i + 1; UsbExtHubInfo->Port[i].VidOverride = 0; UsbExtHubInfo->Port[i].PidOverride = 0; - UsbExtHubInfo->Port[i].PortAttributes = USB_PORTATTR_SHARED_USB2; + UsbExtHubInfo->Port[i].PortAttributes = USB_PORTATTR_SHARED_USB2;// | USB_PORTATTR_OWNED_BY_CC; } *LengthReturned = FIELD_OFFSET(USB_EXTHUB_INFORMATION_0, Port[8]); @@ -600,7 +660,17 @@ VOID USB_BUSIFFN SetDeviceHandleData(PVOID BusContext, PVOID DeviceHandle, PDEVICE_OBJECT UsbDevicePdo) { - DPRINT1("Ehci: SetDeviceHandleData not implemented %x, %x, %x\n", BusContext, DeviceHandle, UsbDevicePdo); + PUSB_DEVICE UsbDevice; + + DPRINT1("Ehci: SetDeviceHandleData %x, %x, %x\n", BusContext, DeviceHandle, UsbDevicePdo); + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return; + } + + UsbDevice->UsbDevicePdo = UsbDevicePdo; } @@ -654,6 +724,6 @@ NTSTATUS USB_BUSIFFN EnumLogEntry(PVOID BusContext, ULONG DriverTag, ULONG EnumTag, ULONG P1, ULONG P2) { - DPRINT1("Ehci: EnumLogEntry called\n"); + DPRINT1("Ehci: EnumLogEntry called %x, %x, %x, %x\n", DriverTag, EnumTag, P1, P2); return STATUS_SUCCESS; } diff --git a/include/crt/mingw32/intrin_x86.h b/include/crt/mingw32/intrin_x86.h index 61250438145..a92f2b307ef 100644 --- a/include/crt/mingw32/intrin_x86.h +++ b/include/crt/mingw32/intrin_x86.h @@ -79,22 +79,37 @@ extern "C" { #define _alloca(s) __builtin_alloca(s) #endif -/*** Atomic operations ***/ +/*** Memory barriers ***/ -#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 -#define _ReadWriteBarrier() __sync_synchronize() -#else -__INTRIN_INLINE void _MemoryBarrier(void) +#ifdef _x86_64 +__INTRIN_INLINE void __faststorefence(void) +{ + long local; + __asm__ __volatile__("lock; orl $0, %0;" : : "m"(local)); +} +#endif + +__INTRIN_INLINE void _mm_lfence(void) +{ + __asm__ __volatile__("lfence"); +} + +__INTRIN_INLINE void _mm_sfence(void) +{ + __asm__ __volatile__("sfence"); +} + +__INTRIN_INLINE void _ReadWriteBarrier(void) { __asm__ __volatile__("" : : : "memory"); } -#define _ReadWriteBarrier() _MemoryBarrier() -#endif -/* BUGBUG: GCC only supports full barriers */ +/* GCC only supports full barriers */ #define _ReadBarrier _ReadWriteBarrier #define _WriteBarrier _ReadWriteBarrier +/*** Atomic operations ***/ + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 __INTRIN_INLINE char _InterlockedCompareExchange8(volatile char * const Destination, const char Exchange, const char Comperand) diff --git a/include/ndk/ketypes.h b/include/ndk/ketypes.h index f5ec606d05f..9792c100aba 100644 --- a/include/ndk/ketypes.h +++ b/include/ndk/ketypes.h @@ -118,7 +118,6 @@ Author: #define DISPATCH_LENGTH 106 #endif -#define SharedUserdata ((KUSER_SHARED_DATA *CONST)(USER_SHARED_DATA|KSEG0_BASE)) #else // diff --git a/include/psdk/cfgmgr32.h b/include/psdk/cfgmgr32.h index 4623a65c11f..41c401f5196 100644 --- a/include/psdk/cfgmgr32.h +++ b/include/psdk/cfgmgr32.h @@ -943,6 +943,10 @@ CONFIGRET WINAPI CMP_UnregisterNotification(IN ULONG luhDevNotify); +CMAPI +CONFIGRET +WINAPI +CMP_WaitServicesAvailable(IN HMACHINE hMachine); */ CMAPI diff --git a/include/psdk/windowsx.h b/include/psdk/windowsx.h index 0ed21e8fe04..dc813389899 100644 --- a/include/psdk/windowsx.h +++ b/include/psdk/windowsx.h @@ -1,7 +1,6 @@ #ifndef _WINDOWSX_H #define _WINDOWSX_H -#define WM_CTLCOLOR 25 #define Button_Enable(hwndCtl,fEnable) EnableWindow((hwndCtl),(fEnable)) #define Button_GetCheck(hwndCtl) ((int)(DWORD)SendMessage((hwndCtl),BM_GETCHECK,0,0)) #define Button_GetState(hwndCtl) ((int)(DWORD)SendMessage((hwndCtl),BM_GETSTATE,0,0)) diff --git a/include/psdk/winuser.h b/include/psdk/winuser.h index 769c0e12129..c0d0ea295cb 100644 --- a/include/psdk/winuser.h +++ b/include/psdk/winuser.h @@ -17,8 +17,6 @@ extern "C" { #define WINUSERAPI #endif - -#define WC_DIALOG MAKEINTATOM(0x8002) #define FALT 16 #define FCONTROL 8 #define FNOINVERT 2 @@ -300,9 +298,6 @@ extern "C" { #define ES_LOWERCASE 16 #define ES_MULTILINE 4 #define ES_NOHIDESEL 256 -#ifdef _WINE -#define ES_COMBO 0x200 /* Undocumented. Parent is a combobox */ -#endif #define ES_NUMBER 0x2000 #define ES_OEMCONVERT 0x400 #define ES_PASSWORD 32 @@ -390,7 +385,6 @@ extern "C" { #define WS_EX_COMPOSITED 0x2000000 /* XP */ #define WS_EX_CONTEXTHELP 0x400 #define WS_EX_CONTROLPARENT 0x10000 -#define WS_EX_DRAGDETECT 0x00000002L #define WS_EX_DLGMODALFRAME 1 #define WS_EX_LAYERED 0x80000 /* w2k */ #define WS_EX_LAYOUTRTL 0x400000 /* w98, w2k */ @@ -870,8 +864,6 @@ extern "C" { #endif #define QS_SENDMESSAGE 64 #define QS_TIMER 16 -/* Extra (undocumented) queue wake bits - see "Undoc. Windows" */ -#define QS_SMRESULT 0x8000 #define USER_TIMER_MAXIMUM 2147483647 #define USER_TIMER_MINIMUM 10 @@ -1213,10 +1205,6 @@ extern "C" { #define SWP_NOSENDCHANGING 1024 #define SWP_DEFERERASE 8192 #define SWP_ASYNCWINDOWPOS 16384 -/* undocumented SWP flags - from SDK 3.1 */ -#define SWP_NOCLIENTSIZE 0x0800 -#define SWP_NOCLIENTMOVE 0x1000 -#define SWP_STATECHANGED 0x8000 #define HSHELL_WINDOWCREATED 1 #define HSHELL_WINDOWDESTROYED 2 @@ -1575,9 +1563,6 @@ extern "C" { #define WM_ACTIVATE 6 #define WM_SETFOCUS 7 #define WM_KILLFOCUS 8 -#ifdef _WINE -#define WM_SETVISIBLE 9 -#endif #define WM_ENABLE 10 #define WM_SETREDRAW 11 #define WM_SETTEXT 12 @@ -1617,8 +1602,6 @@ extern "C" { #define WM_GETFONT 49 #define WM_SETHOTKEY 50 #define WM_GETHOTKEY 51 -#define WM_ISACTIVEICON 53 -#define WM_QUERYPARKICON 54 #define WM_QUERYDRAGICON 55 #define WM_COMPAREITEM 57 #if (WINVER >= 0x0500) @@ -1673,7 +1656,6 @@ extern "C" { #define WM_NCXBUTTONDBLCLK 173 #endif /* (_WIN32_WINNT >= 0x0500) */ -#define WM_KEYF1 0x004d #define WM_KEYFIRST 256 #define WM_KEYDOWN 256 #define WM_KEYUP 257 @@ -1707,7 +1689,6 @@ extern "C" { #define WM_VSCROLL 277 #define WM_INITMENU 278 #define WM_INITMENUPOPUP 279 -#define WM_SYSTIMER 280 #define WM_MENUSELECT 287 #define WM_MENUCHAR 288 #define WM_ENTERIDLE 289 @@ -1727,15 +1708,6 @@ extern "C" { #endif /* _WIN32_WCE */ #endif /* (WINVER >= 0x0500) */ -/* D&D messages */ -#define WM_DROPOBJECT 0x022A -#define WM_QUERYDROPOBJECT 0x022B -#define WM_BEGINDRAG 0x022C -#define WM_DRAGLOOP 0x022D -#define WM_DRAGSELECT 0x022E -#define WM_DRAGMOVE 0x022F - -#define WM_CTLCOLOR 25 #define WM_CTLCOLORMSGBOX 306 #define WM_CTLCOLOREDIT 307 #define WM_CTLCOLORLISTBOX 308 @@ -1746,7 +1718,6 @@ extern "C" { #define MN_GETHMENU 481 #define WM_MOUSEFIRST 512 #define WM_MOUSEMOVE 512 -#define WM_LBTRACKPOINT 0x0131 #define WM_LBUTTONDOWN 513 #define WM_LBUTTONUP 514 #define WM_LBUTTONDBLCLK 515 @@ -1978,10 +1949,6 @@ extern "C" { #define EN_VSCROLL 1538 #define LB_ADDFILE 406 #define LB_ADDSTRING 384 -#ifdef _WINE -#define LB_CARETON 419 -#define LB_CARETOFF 420 -#endif #define LB_DELETESTRING 386 #define LB_DIR 397 #define LB_FINDSTRING 399 @@ -2075,9 +2042,6 @@ extern "C" { #define DCX_INTERSECTRGN 128 #define DCX_VALIDATE 0x200000 #define DCX_EXCLUDEUPDATE 0x100 -#ifdef _WINE -#define DCX_USESTYLE 0x10000 -#endif #define GMDI_GOINTOPOPUPS 2 #define GMDI_USEDISABLED 1 #define FKF_AVAILABLE 2 @@ -4942,6 +4906,10 @@ typedef MONITORINFOEXA MONITORINFOEX, *LPMONITORINFOEX; #endif /* UNICODE */ #endif /* RC_INVOKED */ +#ifdef _WINE +#include "reactos/undocuser.h" +#endif + #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/include/reactos/asm.inc b/include/reactos/asm.inc index 4274221fc19..45c9068abf4 100644 --- a/include/reactos/asm.inc +++ b/include/reactos/asm.inc @@ -5,6 +5,8 @@ * PURPOSE: ASM macros for for GAS and MASM/ML64 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org) */ +#ifndef _ASM_INC_ +#define _ASM_INC_ #ifdef _USE_ML @@ -53,10 +55,6 @@ ENDM #define lidt lidt fword ptr ds: -ljmp MACRO segment, offset - DB 0 -ENDM - .code64 MACRO .code ENDM @@ -115,9 +113,9 @@ ENDM // FIXME ENDM -ljmp MACRO segment, offset +//ljmp MACRO segment, offset // FIXME -ENDM +//ENDM UNIMPLEMENTED MACRO name ENDM @@ -176,9 +174,9 @@ ENDM #define REPEAT .rept #define ENDR .endr -.macro ljmp segment, offset - jmp far ptr \segment:\offset -.endm +//.macro ljmp segment, offset +// jmp far ptr \segment:\offset +//.endm /* MASM compatible EXTERN */ .macro EXTERN name @@ -260,3 +258,5 @@ code = 1 #define elseif .elseif #endif + +#endif /* _ASM_INC_ */ diff --git a/include/reactos/ksamd64.inc b/include/reactos/ksamd64.inc new file mode 100644 index 00000000000..ff308023213 --- /dev/null +++ b/include/reactos/ksamd64.inc @@ -0,0 +1,1074 @@ + +/* Pointer size */ +SizeofPointer = 0x8 + +/* Breakpoints */ +BREAKPOINT_BREAK = 0x0 +BREAKPOINT_PRINT = 0x1 +BREAKPOINT_PROMPT = 0x2 +BREAKPOINT_LOAD_SYMBOLS = 0x3 +BREAKPOINT_UNLOAD_SYMBOLS = 0x4 +BREAKPOINT_COMMAND_STRING = 0x5 + +/* Context Frame Flags */ +CONTEXT_FULL = 0x10000b +CONTEXT_CONTROL = 0x100001 +CONTEXT_INTEGER = 0x100002 +CONTEXT_SEGMENTS = 0x100004 +CONTEXT_FLOATING_POINT = 0x100008 +CONTEXT_DEBUG_REGISTERS = 0x100010 + +/* Exception flags */ +EXCEPTION_NONCONTINUABLE = 0x1 +EXCEPTION_UNWINDING = 0x2 +EXCEPTION_EXIT_UNWIND = 0x4 +EXCEPTION_STACK_INVALID = 0x8 +EXCEPTION_NESTED_CALL = 0x10 +EXCEPTION_TARGET_UNWIND = 0x20 +EXCEPTION_COLLIDED_UNWIND = 0x20 +EXCEPTION_UNWIND = 0x6 +EXCEPTION_EXECUTE_HANDLER = 0x1 +EXCEPTION_CONTINUE_SEARCH = 0x0 +EXCEPTION_CONTINUE_EXECUTION = 0xffffffff + +/* Exception types */ +ExceptionContinueExecution = 0x0 +ExceptionContinueSearch = 0x1 +ExceptionNestedException = 0x2 +ExceptionCollidedUnwind = 0x3 + +/* Lock Queue */ +LOCK_QUEUE_WAIT = 0x1 +LOCK_QUEUE_OWNER = 0x2 +LockQueueDispatcherLock = 0x0 + +/* Process states */ +ProcessInMemory = 0x0 +ProcessOutOfMemory = 0x1 +ProcessInTransition = 0x2 + +/* Processor mode */ +KernelMode = 0x0 +UserMode = 0x1 + +/* Status codes */ +STATUS_ACCESS_VIOLATION = 0xc0000005 +STATUS_ASSERTION_FAILURE = 0xc0000420 +STATUS_ARRAY_BOUNDS_EXCEEDED = 0xc000008c +STATUS_BAD_COMPRESSION_BUFFER = 0xc0000242 +STATUS_BREAKPOINT = 0x80000003 +STATUS_CALLBACK_POP_STACK = 0xc0000423 +STATUS_DATATYPE_MISALIGNMENT = 0x80000002 +STATUS_FLOAT_DENORMAL_OPERAND = 0xc000008d +STATUS_FLOAT_DIVIDE_BY_ZERO = 0xc000008e +STATUS_FLOAT_INEXACT_RESULT = 0xc000008f +STATUS_FLOAT_INVALID_OPERATION = 0xc0000090 +STATUS_FLOAT_OVERFLOW = 0xc0000091 +STATUS_FLOAT_STACK_CHECK = 0xc0000092 +STATUS_FLOAT_UNDERFLOW = 0xc0000093 +STATUS_FLOAT_MULTIPLE_FAULTS = 0xc00002b4 +STATUS_FLOAT_MULTIPLE_TRAPS = 0xc00002b5 +STATUS_GUARD_PAGE_VIOLATION = 0x80000001 +STATUS_ILLEGAL_FLOAT_CONTEXT = 0xc000014a +STATUS_ILLEGAL_INSTRUCTION = 0xc000001d +STATUS_INSTRUCTION_MISALIGNMENT = 0xc00000aa +STATUS_INVALID_HANDLE = 0xc0000008 +STATUS_INVALID_LOCK_SEQUENCE = 0xc000001e +STATUS_INVALID_OWNER = 0xc000005a +STATUS_INVALID_PARAMETER = 0xc000000d +STATUS_INVALID_PARAMETER_1 = 0xc00000ef +STATUS_INVALID_SYSTEM_SERVICE = 0xc000001c +STATUS_INTEGER_DIVIDE_BY_ZERO = 0xc0000094 +STATUS_INTEGER_OVERFLOW = 0xc0000095 +STATUS_IN_PAGE_ERROR = 0xc0000006 +STATUS_KERNEL_APC = 0x100 +STATUS_LONGJUMP = 0x80000026 +STATUS_NO_CALLBACK_ACTIVE = 0xc0000258 +STATUS_NO_EVENT_PAIR = 0xc000014e +STATUS_PRIVILEGED_INSTRUCTION = 0xc0000096 +STATUS_SINGLE_STEP = 0x80000004 +STATUS_STACK_BUFFER_OVERRUN = 0xc0000409 +STATUS_STACK_OVERFLOW = 0xc00000fd +STATUS_SUCCESS = 0x0 +STATUS_THREAD_IS_TERMINATING = 0xc000004b +STATUS_TIMEOUT = 0x102 +STATUS_UNWIND = 0xc0000027 +STATUS_UNWIND_CONSOLIDATE = 0x80000029 +STATUS_USER_APC = 0xc0 +STATUS_WAKE_SYSTEM_DEBUGGER = 0x80000007 + +/* TLS defines */ +TLS_MINIMUM_AVAILABLE = 0x40 +TLS_EXPANSION_SLOTS = 0x400 + +/* Thread states */ +Initialized = 0x0 +Ready = 0x1 +Running = 0x2 +Standby = 0x3 +Terminated = 0x4 +Waiting = 0x5 + +/* Wait type / reason */ +WrExecutive = 0x7 +WrMutex = 0x1d +WrDispatchInt = 0x1f +WrQuantumEnd = 0x1e +WrEventPair = 0xe +WaitAny = 0x1 +WaitAll = 0x0 + +/* Interrupt object types */ +InLevelSensitive = 0x0 +InLatched = 0x1 + +/* Bug Check Codes */ +APC_INDEX_MISMATCH = 0x1 +INVALID_AFFINITY_SET = 0x3 +INVALID_DATA_ACCESS_TRAP = 0x4 +IRQL_NOT_GREATER_OR_EQUAL = 0x9 +IRQL_NOT_LESS_OR_EQUAL = 0xa +NO_USER_MODE_CONTEXT = 0xe +SPIN_LOCK_ALREADY_OWNED = 0xf +SPIN_LOCK_NOT_OWNED = 0x10 +THREAD_NOT_MUTEX_OWNER = 0x11 +TRAP_CAUSE_UNKNOWN = 0x12 +KMODE_EXCEPTION_NOT_HANDLED = 0x1e +KERNEL_APC_PENDING_DURING_EXIT = 0x20 +PANIC_STACK_SWITCH = 0x2b +DATA_BUS_ERROR = 0x2e +INSTRUCTION_BUS_ERROR = 0x2f +SYSTEM_EXIT_OWNED_MUTEX = 0x39 +PAGE_FAULT_WITH_INTERRUPTS_OFF = 0x49 +IRQL_GT_ZERO_AT_SYSTEM_SERVICE = 0x4a +DATA_COHERENCY_EXCEPTION = 0x55 +INSTRUCTION_COHERENCY_EXCEPTION = 0x56 +HAL1_INITIALIZATION_FAILED = 0x61 +UNEXPECTED_KERNEL_MODE_TRAP = 0x7f +NMI_HARDWARE_FAILURE = 0x80 +SPIN_LOCK_INIT_FAILURE = 0x81 +ATTEMPTED_SWITCH_FROM_DPC = 0xb8 + +/* IRQL */ +PASSIVE_LEVEL = 0x0 +APC_LEVEL = 0x1 +DISPATCH_LEVEL = 0x2 +CLOCK_LEVEL = 0xd +IPI_LEVEL = 0xe +POWER_LEVEL = 0xe +PROFILE_LEVEL = 0xf +HIGH_LEVEL = 0xf +#ifdef NT_UP +SYNCH_LEVEL = 0x2 +#else +SYNCH_LEVEL = 0xc +#endif + +/* Stack sizes */ +KERNEL_STACK_SIZE = 0x6000 +KERNEL_LARGE_STACK_SIZE = 0x12000 +KERNEL_LARGE_STACK_COMMIT = 0x6000 +KERNEL_MCA_EXCEPTION_STACK_SIZE = 0x2000 +NMI_STACK_SIZE = 0x2000 + +/* Miscellaneous Definitions */ +LOW_REALTIME_PRIORITY = 0x10 +CLOCK_QUANTUM_DECREMENT = 0x3 +WAIT_QUANTUM_DECREMENT = 0x1 +MAXIMUM_PROCESSORS = 0x40 +INITIAL_STALL_COUNT = 0x64 +KI_EXCEPTION_ACCESS_VIOLATION = 0x10000004 +Executive = 0x0 +FALSE = 0x0 +TRUE = 0x1 +DBG_STATUS_CONTROL_C = 0x1 +USER_SHARED_DATA = 0x7ffe0000 +PAGE_SIZE = 0x1000 +MAXIMUM_IDTVECTOR = 0xff +PRIMARY_VECTOR_BASE = 0x30 +RPL_MASK = 0x3 +MODE_MASK = 0x1 +NUMBER_SERVICE_TABLES = 0x2 +SERVICE_NUMBER_MASK = 0xfff +SERVICE_TABLE_SHIFT = 0x7 +SERVICE_TABLE_MASK = 0x20 +SERVICE_TABLE_TEST = 0x20 + +/* KAPC */ +ApType = 0x0 +ApSize = 0x2 +ApThread = 0x8 +ApApcListEntry = 0x10 +ApKernelRoutine = 0x20 +ApRundownRoutine = 0x28 +ApNormalRoutine = 0x30 +ApNormalContext = 0x38 +ApSystemArgument1 = 0x40 +ApSystemArgument2 = 0x48 +ApApcStateIndex = 0x50 +ApApcMode = 0x51 +ApInserted = 0x52 +ApcObjectLength = 0x58 + +/* KAPC_STATE */ +AsApcListHead = 0x0 +AsProcess = 0x20 +AsKernelApcInProgress = 0x28 +AsKernelApcPending = 0x29 +AsUserApcPending = 0x2a + +/* CLIENT_ID */ +CidUniqueProcess = 0x0 +CidUniqueThread = 0x8 + +/* RTL_CRITICAL_SECTION */ +CsDebugInfo = 0x0 +CsLockCount = 0x8 +CsRecursionCount = 0xc +CsOwningThread = 0x10 +CsLockSemaphore = 0x18 +CsSpinCount = 0x20 + +/* RTL_CRITICAL_SECTION_DEBUG */ +CsType = 0x0 +CsCreatorBackTraceIndex = 0x2 +CsCriticalSection = 0x8 +CsProcessLocksList = 0x10 +CsEntryCount = 0x20 +CsContentionCount = 0x24 + +/* KDEVICE_QUEUE_ENTRY */ +DeDeviceListEntry = 0x0 +DeSortKey = 0x10 +DeInserted = 0x14 +DeviceQueueEntryLength = 0x18 + +/* KDPC */ +DpType = 0x0 +DpImportance = 0x1 +DpNumber = 0x2 +DpDpcListEntry = 0x8 +DpDeferredRoutine = 0x18 +DpDeferredContext = 0x20 +DpSystemArgument1 = 0x28 +DpSystemArgument2 = 0x30 +DpDpcData = 0x38 +DpcObjectLength = 0x40 + +/* KDEVICE_QUEUE */ +DvType = 0x0 +DvSize = 0x2 +DvDeviceListHead = 0x8 +DvSpinLock = 0x18 +DvBusy = 0x20 +DeviceQueueObjectLength = 0x28 + +/* EXCEPTION_RECORD */ +ErExceptionCode = 0x0 +ErExceptionFlags = 0x4 +ErExceptionRecord = 0x8 +ErExceptionAddress = 0x10 +ErNumberParameters = 0x18 +ErExceptionInformation = 0x20 +ExceptionRecordLength = 0x98 +EXCEPTION_RECORD_LENGTH = 0x98 + +/* EPROCESS */ +EpDebugPort = 0x110 +EpVdmObjects = 0x1f0 +ExecutiveProcessObjectLength = 0x3a0 + +/* KEVENT */ +EvType = 0x0 +EvSize = 0x2 +EvSignalState = 0x4 +EvWaitListHead = 0x8 +EventObjectLength = 0x18 + +/* FAST_MUTEX */ +FmCount = 0x0 +FmOwner = 0x8 +FmContention = 0x10 +FmOldIrql = 0x30 + +/* KINTERRUPT */ +InType = 0x0 +InSize = 0x2 +InInterruptListEntry = 0x8 +InServiceRoutine = 0x18 +InServiceContext = 0x20 +InSpinLock = 0x28 +InTickCount = 0x30 +InActualLock = 0x38 +InDispatchAddress = 0x40 +InVector = 0x48 +InIrql = 0x4c +InSynchronizeIrql = 0x4d +InFloatingSave = 0x4e +InConnected = 0x4f +InNumber = 0x50 +InShareVector = 0x51 +InMode = 0x54 +InServiceCount = 0x58 +InDispatchCount = 0x5c +InDispatchCode = 0x60 +InterruptObjectLength = 0x208 + +/* IO_STATUS_BLOCK */ +IoStatus = 0x0 +IoPointer = 0x0 +IoInformation = 0x8 + +/* KNODE */ +KnPfnDereferenceSListHead = 0x10 +KnProcessorMask = 0x20 +KnColor = 0x28 +KnSeed = 0x2c +KnNodeNumber = 0x2d +KnFlags = 0x2e +knMmShiftedColor = 0x32 +KnFreeCount = 0x36 +KnPfnDeferredList = 0x3e +KNODE_SIZE = 0x46 + +/* KSPIN_LOCK_QUEUE */ +LqNext = 0x0 +LqLock = 0x8 + +/* KLOCK_QUEUE_HANDLE */ +LqhNext = 0x0 +LqhLock = 0x8 +LqhOldIrql = 0x10 +LOCK_QUEUE_HEADER_SIZE = 0x18 + +/* LARGE_INTEGER */ +LiLowPart = 0x0 +LiHighPart = 0x4 + +/* LIST_ENTRY */ +LsFlink = 0x0 +LsBlink = 0x8 + +/* PEB */ +PeKernelCallbackTable = 0x58 +ProcessEnvironmentBlockLength = 0x358 + +/* KPROFILE */ +PfType = 0x0 +PfSize = 0x2 +PfProfileListEntry = 0x8 +PfProcess = 0x18 +PfRangeBase = 0x20 +PfRangeLimit = 0x28 +PfBucketShift = 0x30 +PfBuffer = 0x38 +PfSegment = 0x40 +PfAffinity = 0x48 +PfSource = 0x50 +PfStarted = 0x54 +ProfileObjectLength = 0x58 + +/* PORT_MESSAGE */ +PmLength = 0x0 +PmZeroInit = 0x4 +PmClientId = 0x8 +PmProcess = 0x8 +PmThread = 0x10 +PmMessageId = 0x18 +PmClientViewSize = 0x1c +PortMessageLength = 0x24 + +/* KPROCESS */ +PrType = 0x0 +PrSize = 0x2 +PrSignalState = 0x4 +PrProfileListHead = 0x18 +PrDirectoryTableBase = 0x28 +PrActiveProcessors = 0x30 +PrKernelTime = 0x34 +PrUserTime = 0x38 +PrReadyListHead = 0x40 +PrSwapListEntry = 0x50 +PrThreadListHead = 0x60 +PrProcessLock = 0x70 +PrAffinity = 0x78 +PrProcessFlags = 0x80 +PrBasePriority = 0x84 +PrQuantumReset = 0x85 +PrState = 0x86 +PrStackCount = 0x8c +KernelProcessObjectLength = 0xa0 + +/* KQUEUE */ +QuType = 0x0 +QuSize = 0x2 +QuSignalState = 0x4 +QuEntryListHead = 0x18 +QuCurrentCount = 0x28 +QuMaximumCount = 0x2c +QuThreadListHead = 0x30 +QueueObjectLength = 0x40 + +/* STRING */ +StrLength = 0x0 +StrMaximumLength = 0x2 +StrBuffer = 0x8 + +/* TEB */ +TeCmTeb = 0x0 +TeStackBase = 0x8 +TeStackLimit = 0x10 +TeFiberData = 0x20 +TeSelf = 0x30 +TeEnvironmentPointer = 0x38 +TeClientId = 0x40 +TeActiveRpcHandle = 0x50 +TeThreadLocalStoragePointer = 0x58 +TeCountOfOwnedCriticalSections = 0x6c +TePeb = 0x60 +TeCsrClientThread = 0x70 +TeWOW32Reserved = 0x100 +TeExceptionCode = 0x2c0 +TeActivationContextStackPointer = 0x2c8 +TeGdiClientPID = 0x7f0 +TeGdiClientTID = 0x7f4 +TeGdiThreadLocalInfo = 0x7f8 +TeglDispatchTable = 0x9f0 +TeglReserved1 = 0x1138 +TeglReserved2 = 0x1220 +TeglSectionInfo = 0x1228 +TeglSection = 0x1230 +TeglTable = 0x1238 +TeglCurrentRC = 0x1240 +TeglContext = 0x1248 +TeDeallocationStack = 0x1478 +TeTlsSlots = 0x1480 +TeTlsExpansionSlots = 0x1780 +TeLastErrorValue = 0x68 +TeVdm = 0x1690 +TeInstrumentation = 0x16b8 +TeGdiBatchCount = 0x1740 +TeGuaranteedStackBytes = 0x1748 +TeFlsData = 0x17c8 +ThreadEnvironmentBlockLength = 0x17d8 + +/* TIME_FIELDS */ +TfSecond = 0xa +TfMinute = 0x8 +TfHour = 0x6 +TfWeekday = 0xe +TfDay = 0x4 +TfMonth = 0x2 +TfYear = 0x0 +TfMilliseconds = 0xc + +/* KTHREAD */ +ThType = 0x0 +ThSize = 0x2 +ThLock = 0x0 +ThDebugActive = 0x3 +ThSignalState = 0x4 +ThInitialStack = 0x28 +ThStackLimit = 0x30 +ThKernelStack = 0x38 +ThThreadLock = 0x40 +ThAlerted = 0x9e +ThApcState = 0x48 +ThPriority = 0x9b +ThSwapBusy = 0x9d +ThNextProcessor = 0x60 +ThDeferredProcessor = 0x61 +ThApcQueueLock = 0x78 +ThContextSwitches = 0x80 +ThState = 0x84 +ThNpxState = 0x85 +ThWaitIrql = 0x86 +ThWaitMode = 0x87 +ThWaitStatus = 0x88 +ThWaitBlockList = 0x90 +ThGateObject = 0x90 +ThWaitListEntry = 0xa0 +ThSwapListEntry = 0xa0 +ThQueue = 0xb0 +ThWaitTime = 0xb8 +ThCombinedApcDisable = 0xbc +ThKernelApcDisable = 0xbc +ThSpecialApcDisable = 0xbe +ThTeb = 0xc0 +ThTimer = 0xc8 +ThThreadFlags = 0xf0 +ThServiceTable = 0x1e8 +ThWaitBlock = 0x108 +ThResourceIndex = 0x14f +ThQueueListEntry = 0x1c8 +ThTrapFrame = 0x1d8 +ThCallbackStack = 0x1e0 +ThApcStateIndex = 0x1f0 +ThIdealProcessor = 0x1f1 +ThBasePriority = 0x1f5 +ThPriorityDecrement = 0x1f6 +ThAdjustReason = 0x62 +ThAdjustIncrement = 0x63 +ThPreviousMode = 0x137 +ThSaturation = 0x1f7 +ThFreezeCount = 0x237 +ThUserAffinity = 0x1f8 +ThProcess = 0x200 +ThAffinity = 0x208 +ThUserIdealProcessor = 0x239 +ThApcStatePointer = 0x210 +ThSavedApcState = 0x220 +ThWaitReason = 0x9a +ThSuspendCount = 0x238 +ThWin32Thread = 0x250 +ThStackBase = 0x258 +ThSuspendApc = 0x260 +ThPowerState = 0x28f +ThKernelTime = 0x264 +ThLegoData = 0x288 +ThLargeStack = 0x167 +ThUserTime = 0x290 +ThSuspendSemaphore = 0x2b8 +ThSListFaultCount = 0x2cc +ThThreadListEntry = 0x2d8 +ThMutantListHead = 0x18 +ThSListFaultAddress = 0x2e8 +KernelThreadObjectLength = 0x2f0 +ExecutiveThreadObjectLength = 0x3f8 + +/* KTIMER */ +TiType = 0x0 +TiSize = 0x2 +TiInserted = 0x3 +TiSignalState = 0x4 +TiDueTime = 0x18 +TiTimerListEntry = 0x20 +TiDpc = 0x30 +TiPeriod = 0x3c +TimerObjectLength = 0x40 + +/* TIME */ + +/* KUSER_SHARED_DATA */ +UsTickCountMultiplier = 0x4 +UsInterruptTime = 0x8 +UsSystemTime = 0x14 +UsTimeZoneBias = 0x20 +UsImageNumberLow = 0x2c +UsImageNumberHigh = 0x2e +UsNtSystemRoot = 0x30 +UsMaxStackTraceDepth = 0x238 +UsCryptoExponent = 0x23c +UsTimeZoneId = 0x240 +UsLargePageMinimum = 0x244 +UsReserved2 = 0x248 +UsNtProductType = 0x264 +UsProductTypeIsValid = 0x268 +UsNtMajorVersion = 0x26c +UsNtMinorVersion = 0x270 +UsProcessorFeatures = 0x274 +UsReserved1 = 0x2b4 +UsReserved3 = 0x2b8 +UsTimeSlip = 0x2bc +UsAlternativeArchitecture = 0x2c0 +UsSystemExpirationDate = 0x2c8 +UsSuiteMask = 0x2d0 +UsKdDebuggerEnabled = 0x2d4 +UsActiveConsoleId = 0x2d8 +UsDismountCount = 0x2dc +UsComPlusPackage = 0x2e0 +UsLastSystemRITEventTickCount = 0x2e4 +UsNumberOfPhysicalPages = 0x2e8 +UsSafeBootMode = 0x2ec +UsTestRetInstruction = 0x2f8 +UsSystemCall = 0x300 +UsSystemCallReturn = 0x304 +UsSystemCallPad = 0x308 +UsTickCount = 0x320 +UsTickCountQuad = 0x320 +UsWow64SharedInformation = 0x340 + +/* KWAIT_BLOCK */ +WbWaitListEntry = 0x0 +WbThread = 0x10 +WbObject = 0x18 +WbNextWaitBlock = 0x20 +WbWaitKey = 0x28 +WbWaitType = 0x2a + +/* CR0 flags */ +CR0_PE = 0x1 +CR0_MP = 0x2 +CR0_EM = 0x4 +CR0_TS = 0x8 +CR0_ET = 0x10 +CR0_NE = 0x20 +CR0_WP = 0x10000 +CR0_AM = 0x40000 +CR0_NW = 0x20000000 +CR0_CD = 0x40000000 +CR0_PG = 0x80000000 + +/* CR4 flags */ +CR4_VME = 0x1 +CR4_PVI = 0x2 +CR4_TSD = 0x4 +CR4_DE = 0x8 +CR4_PSE = 0x10 +CR4_PAE = 0x20 +CR4_MCE = 0x40 +CR4_PGE = 0x80 +CR4_FXSR = 0x200 +CR4_XMMEXCPT = 0x400 +CR4_CHANNELS = 0x800 + +/* KeFeatureBits flags */ +KF_RDTSC = 0x2 +KF_CR4 = 0x4 +KF_GLOBAL_PAGE = 0x10 +KF_LARGE_PAGE = 0x20 +KF_CMPXCHG8B = 0x80 +KF_FAST_SYSCALL = 0x1000 + +/* Machine type definitions */ +MACHINE_TYPE_ISA = 0x0 +MACHINE_TYPE_EISA = 0x1 +MACHINE_TYPE_MCA = 0x2 + +/* EFLAGS */ +EFLAGS_TF_MASK = 0x100 +EFLAGS_TF_SHIFT = 0x8 +EFLAGS_IF_MASK = 0x200 +EFLAGS_IF_SHIFT = 0x9 +EFLAGS_ID_MASK = 0x200000 + +/* Hypervisor Enlightenment Definitions */ + +/* KDGT selectors */ +KGDT64_NULL = 0x0 +KGDT64_R0_CODE = 0x10 +KGDT64_R0_DATA = 0x18 +KGDT64_R3_CMCODE = 0x20 +KGDT64_R3_DATA = 0x28 +KGDT64_R3_CODE = 0x30 +KGDT64_SYS_TSS = 0x40 +KGDT64_R3_CMTEB = 0x50 + +/* Machine Specific Register Numbers */ +MSR_EFER = 0xc0000080 +MSR_STAR = 0xc0000081 +MSR_LSTAR = 0xc0000082 +MSR_CSTAR = 0xc0000083 +MSR_SYSCALL_MASK = 0xc0000084 +MSR_FS_BASE = 0xc0000100 +MSR_GS_BASE = 0xc0000101 +MSR_GS_SWAP = 0xc0000102 +MSR_MCG_STATUS = 0x17a +MSR_AMD_ACCESS = 0x9c5a203a + +/* Flags for MSR_EFER */ +MSR_LMA = 0x400 +MSR_LME = 0x100 +MSR_SCE = 0x1 +MSR_NXE = 0x800 +MSR_PAT = 0x277 +MSR_DEGUG_CTL = 0x1d9 +MSR_LAST_BRANCH_FROM = 0x1db +MSR_LAST_BRANCH_TO = 0x1dc +MSR_LAST_EXCEPTION_FROM = 0x1dd +MSR_LAST_EXCEPTION_TO = 0x1de + +/* Flags for MSR_DEGUG_CTL */ + +/* Fatal exception codes */ +EXCEPTION_DIVIDED_BY_ZERO = 0x0 +EXCEPTION_DEBUG = 0x1 +EXCEPTION_NMI = 0x2 +EXCEPTION_INT3 = 0x3 +EXCEPTION_BOUND_CHECK = 0x5 +EXCEPTION_INVALID_OPCODE = 0x6 +EXCEPTION_NPX_NOT_AVAILABLE = 0x7 +EXCEPTION_DOUBLE_FAULT = 0x8 +EXCEPTION_NPX_OVERRUN = 0x9 +EXCEPTION_INVALID_TSS = 0xa +EXCEPTION_SEGMENT_NOT_PRESENT = 0xb +EXCEPTION_STACK_FAULT = 0xc +EXCEPTION_GP_FAULT = 0xd +EXCEPTION_RESERVED_TRAP = 0xf +EXCEPTION_NPX_ERROR = 0x10 +EXCEPTION_ALIGNMENT_CHECK = 0x11 + +/* Argument Home Address */ +P1Home = 0x0 +P2Home = 0x0 +P3Home = 0x0 +P4Home = 0x0 + +/* CONTEXT */ +CONTEXT_P1Home = 0x0 +CONTEXT_P2Home = 0x8 +CONTEXT_P3Home = 0x10 +CONTEXT_P4Home = 0x18 +CONTEXT_P5Home = 0x20 +CONTEXT_P6Home = 0x28 +CONTEXT_ContextFlags = 0x30 +CONTEXT_MxCsr = 0x34 +CONTEXT_SegCs = 0x38 +CONTEXT_SegDs = 0x3a +CONTEXT_SegEs = 0x3c +CONTEXT_SegFs = 0x3e +CONTEXT_SegGs = 0x40 +CONTEXT_SegSs = 0x42 +CONTEXT_EFlags = 0x44 +CONTEXT_Dr0 = 0x48 +CONTEXT_Dr1 = 0x50 +CONTEXT_Dr2 = 0x58 +CONTEXT_Dr3 = 0x60 +CONTEXT_Dr6 = 0x68 +CONTEXT_Dr7 = 0x70 +CONTEXT_Rax = 0x78 +CONTEXT_Rcx = 0x80 +CONTEXT_Rdx = 0x88 +CONTEXT_Rbx = 0x90 +CONTEXT_Rsp = 0x98 +CONTEXT_Rbp = 0xa0 +CONTEXT_Rsi = 0xa8 +CONTEXT_Rdi = 0xb0 +CONTEXT_R8 = 0xb8 +CONTEXT_R9 = 0xc0 +CONTEXT_R10 = 0xc8 +CONTEXT_R11 = 0xd0 +CONTEXT_R12 = 0xd8 +CONTEXT_R13 = 0xe0 +CONTEXT_R14 = 0xe8 +CONTEXT_R15 = 0xf0 +CONTEXT_Rip = 0xf8 +CONTEXT_FltSave = 0x100 +CONTEXT_Xmm0 = 0x1a0 +CONTEXT_Xmm1 = 0x1b0 +CONTEXT_Xmm2 = 0x1c0 +CONTEXT_Xmm3 = 0x1d0 +CONTEXT_Xmm4 = 0x1e0 +CONTEXT_Xmm5 = 0x1f0 +CONTEXT_Xmm6 = 0x200 +CONTEXT_Xmm7 = 0x210 +CONTEXT_Xmm8 = 0x220 +CONTEXT_Xmm9 = 0x230 +CONTEXT_Xmm10 = 0x240 +CONTEXT_Xmm11 = 0x250 +CONTEXT_Xmm12 = 0x260 +CONTEXT_Xmm13 = 0x270 +CONTEXT_Xmm14 = 0x280 +CONTEXT_Xmm15 = 0x290 +CONTEXT_DebugControl = 0x4a8 +CONTEXT_LastBranchToRip = 0x4b0 +CONTEXT_LastBranchFromRip = 0x4b8 +CONTEXT_LastExceptionToRip = 0x4c0 +CONTEXT_LastExceptionFromRip = 0x4c8 +CONTEXT_VectorControl = 0x4a0 +CONTEXT_VectorRegister = 0x300 +CONTEXT_FRAME_LENGTH = 0x4d0 + +/* DISPATCHER_CONTEXT */ +DcControlPc = 0x0 +DcImageBase = 0x8 +DcFunctionEntry = 0x10 +DcEstablisherFrame = 0x18 +DcTargetIp = 0x20 +DcContextRecord = 0x28 +DcLanguageHandler = 0x30 +DcHandlerData = 0x38 +DcHistoryTable = 0x40 +DcScopeIndex = 0x48 + +/* KEXCEPTION_FRAME */ +KEXCEPTION_FRAME_P1Home = 0x0 +KEXCEPTION_FRAME_P2Home = 0x8 +KEXCEPTION_FRAME_P3Home = 0x10 +KEXCEPTION_FRAME_P4Home = 0x18 +KEXCEPTION_FRAME_P5 = 0x20 +KEXCEPTION_FRAME_Xmm6 = 0x30 +KEXCEPTION_FRAME_Xmm7 = 0x40 +KEXCEPTION_FRAME_Xmm8 = 0x50 +KEXCEPTION_FRAME_Xmm9 = 0x60 +KEXCEPTION_FRAME_Xmm10 = 0x70 +KEXCEPTION_FRAME_Xmm11 = 0x80 +KEXCEPTION_FRAME_Xmm12 = 0x90 +KEXCEPTION_FRAME_Xmm13 = 0xa0 +KEXCEPTION_FRAME_Xmm14 = 0xb0 +KEXCEPTION_FRAME_Xmm15 = 0xc0 +KEXCEPTION_FRAME_MxCsr = 0xf0 +KEXCEPTION_FRAME_Rbp = 0xf8 +KEXCEPTION_FRAME_Rbx = 0x100 +KEXCEPTION_FRAME_Rdi = 0x108 +KEXCEPTION_FRAME_Rsi = 0x110 +KEXCEPTION_FRAME_R12 = 0x118 +KEXCEPTION_FRAME_R13 = 0x120 +KEXCEPTION_FRAME_R14 = 0x128 +KEXCEPTION_FRAME_R15 = 0x130 +KEXCEPTION_FRAME_Return = 0x138 +KEXCEPTION_FRAME_InitialStack = 0x28 +KEXCEPTION_FRAME_TrapFrame = 0xd0 +KEXCEPTION_FRAME_CallbackStack = 0xd8 +KEXCEPTION_FRAME_OutputBuffer = 0xe0 +KEXCEPTION_FRAME_OutputLength = 0xe8 +KEXCEPTION_FRAME_LENGTH = 0x140 + +/* JUMP_BUFFER */ +JbFrame = 0x0 +JbRbx = 0x8 +JbRsp = 0x10 +JbRbp = 0x18 +JbRsi = 0x20 +JbRdi = 0x28 +JbR12 = 0x30 +JbR13 = 0x38 +JbR14 = 0x40 +JbR15 = 0x48 +JbRip = 0x50 +JbXmm6 = 0x60 +JbXmm7 = 0x70 +JbXmm8 = 0x80 +JbXmm9 = 0x90 +JbXmm10 = 0xa0 +JbXmm11 = 0xb0 +JbXmm12 = 0xc0 +JbXmm13 = 0xd0 +JbXmm14 = 0xe0 +JbXmm15 = 0xf0 + +/* KGDTENTRY64 */ +KgdtBaseLow = 0x2 +KgdtBaseMiddle = 0x4 +KgdtBaseHigh = 0x7 +KgdtBaseUpper = 0x8 +KgdtLimitHigh = 0x6 +KgdtLimitLow = 0x0 + +/* KPRCB */ +PbMxCsr = 0x0 +PbNumber = 0x4 +PbInterruptRequest = 0x6 +PbIdleHalt = 0x7 +PbCurrentThread = 0x8 +PbNextThread = 0x10 +PbIdleThread = 0x18 +PbNestingLevel = 0x5 +PbRspBase = 0x28 +PbPrcbLock = 0x30 +PbSetMember = 0x38 +PbProcessorState = 0x40 +PbCpuType = 0x5f0 +PbCpuID = 0x5f1 +PbCpuStep = 0x5f2 +PbHalReserved = 0x5f8 +PbMinorVersion = 0x638 +PbMajorVersion = 0x63a +PbBuildType = 0x63c +PbCpuVendor = 0x63d +PbApicMask = 0x640 +PbCFlushSize = 0x644 +PbAcpiReserved = 0x648 +PbInitialApicId = 0x63e +PbLockQueue = 0x670 +PbPPLookasideList = 0x880 +PbPPNPagedLookasideList = 0x980 +PbPPPagedLookasideList = 0xb80 +PbPacketBarrier = 0xd80 +PbDeferredReadyListHead = 0xd88 +PbLookasideIrpFloat = 0xdc4 +PbTargetSet = 0xe00 +PbIpiFrozen = 0xe08 +PbRequestMailbox = 0xe80 +PbSenderSummary = 0x2680 +PbDpcStack = 0x2740 +PbMaximumDpcQueueDepth = 0x2750 +PbDpcRequestRate = 0x2754 +PbMinimumDpcRate = 0x2758 +PbDpcInterruptRequested = 0x275c +PbDpcThreadRequested = 0x275d +PbDpcRoutineActive = 0x275e +PbDpcThreadActive = 0x275f +PbTimerHand = 0x2760 +PbTimerRequest = 0x2768 +PbTickOffset = 0x2770 +PbMasterOffset = 0x2774 +PbDpcLastCount = 0x2778 +PbQuantumEnd = 0x277d +PbDpcSetEventRequest = 0x2780 +PbIdleSchedule = 0x277f +PbReadySummary = 0x2818 +PbDispatcherReadyListHead = 0x2820 +PbInterruptCount = 0x2a20 +PbKernelTime = 0x2a24 +PbUserTime = 0x2a28 +PbDpcTime = 0x2a2c +PbInterruptTime = 0x2a30 +PbAdjustDpcThreshold = 0x2a34 +PbSkipTick = 0x2a38 +PbPollSlot = 0x2a3a +PbParentNode = 0x2a48 +PbMultiThreadProcessorSet = 0x2a50 +PbMultiThreadSetMaster = 0x2a58 +PbPageColor = 0x2a6c +PbNodeColor = 0x2a70 +PbNodeShiftedColor = 0x2a74 +PbSecondaryColorMask = 0x2a78 +PbSleeping = 0x2a60 +PbVendorString = 0x2abc +PbPowerState = 0x2ad8 +ProcessorBlockLength = 0x2c88 + +/* KPCR */ +PcUserRsp = 0x10 +PcSelf = 0x18 +PcCurrentPrcb = 0x20 +PcLockArray = 0x28 +PcIrql = 0x50 +PcStallScaleFactor = 0x64 +PcHalReserved = 0xc0 + +/* KPROCESSOR_STATE */ +PsSpecialRegisters = 0x0 +PsCr0 = 0x0 +PsCr2 = 0x8 +PsCr3 = 0x10 +PsCr4 = 0x18 +PsKernelDr0 = 0x20 +PsKernelDr1 = 0x28 +PsKernelDr2 = 0x30 +PsKernelDr3 = 0x38 +PsKernelDr6 = 0x40 +PsKernelDr7 = 0x48 +PsGdtr = 0x50 +PsIdtr = 0x60 +PsTr = 0x70 +PsLdtr = 0x72 +PsMxCsr = 0x74 +PsContextFrame = 0xe0 +PsDebugControl = 0x78 +PsLastBranchToRip = 0x80 +PsLastBranchFromRip = 0x88 +PsLastExceptionToRip = 0x90 +PsLastExceptionFromRip = 0x98 +PsCr8 = 0xa0 +ProcessorStateLength = 0x5b0 + +/* KSTART_FRAME */ +SfP1Home = 0x0 +SfP2Home = 0x8 +SfP3Home = 0x10 +SfP4Home = 0x18 +SfReturn = 0x28 +KSTART_FRAME_LENGTH = 0x30 + +/* KSPECIAL_REGISTERS */ +SrKernelDr0 = 0x20 +SrKernelDr1 = 0x28 +SrKernelDr2 = 0x30 +SrKernelDr3 = 0x38 +SrKernelDr6 = 0x40 +SrKernelDr7 = 0x48 +SrGdtr = 0x50 +SrIdtr = 0x60 +SrTr = 0x70 +SrMxCsr = 0x74 +SrMsrGsBase = 0xa8 +SrMsrGsSwap = 0xb0 +SrMsrStar = 0xb8 +SrMsrLStar = 0xc0 +SrMsrCStar = 0xc8 +SrMsrSyscallMask = 0xd0 + +/* KSYSTEM_TIME */ +StLowTime = 0x0 +StHigh1Time = 0x4 +StHigh2Time = 0x8 + +/* KSWITCH_FRAME */ +SwP5Home = 0x20 +SwApcBypass = 0x28 +SwRbp = 0x30 +SwReturn = 0x38 +SwitchFrameLength = 0x40 +KSWITCH_FRAME_LENGTH = 0x40 + +/* KTRAP_FRAME */ +KTRAP_FRAME_P1Home = 0x0 +KTRAP_FRAME_P2Home = 0x8 +KTRAP_FRAME_P3Home = 0x10 +KTRAP_FRAME_P4Home = 0x18 +KTRAP_FRAME_P5 = 0x20 +KTRAP_FRAME_PreviousMode = 0x28 +KTRAP_FRAME_PreviousIrql = 0x29 +KTRAP_FRAME_FaultIndicator = 0x2a +KTRAP_FRAME_ExceptionActive = 0x2b +KTRAP_FRAME_MxCsr = 0x2c +KTRAP_FRAME_Rax = 0x30 +KTRAP_FRAME_Rcx = 0x38 +KTRAP_FRAME_Rdx = 0x40 +KTRAP_FRAME_R8 = 0x48 +KTRAP_FRAME_R9 = 0x50 +KTRAP_FRAME_R10 = 0x58 +KTRAP_FRAME_R11 = 0x60 +KTRAP_FRAME_GsBase = 0x68 +KTRAP_FRAME_GsSwap = 0x68 +KTRAP_FRAME_Xmm0 = 0x70 +KTRAP_FRAME_Xmm1 = 0x80 +KTRAP_FRAME_Xmm2 = 0x90 +KTRAP_FRAME_Xmm3 = 0xa0 +KTRAP_FRAME_Xmm4 = 0xb0 +KTRAP_FRAME_Xmm5 = 0xc0 +KTRAP_FRAME_FaultAddress = 0xd0 +KTRAP_FRAME_TimeStampCKCL = 0xd0 +KTRAP_FRAME_Dr0 = 0xd8 +KTRAP_FRAME_Dr1 = 0xe0 +KTRAP_FRAME_Dr2 = 0xe8 +KTRAP_FRAME_Dr3 = 0xf0 +KTRAP_FRAME_Dr6 = 0xf8 +KTRAP_FRAME_Dr7 = 0x100 +KTRAP_FRAME_DebugControl = 0x108 +KTRAP_FRAME_LastBranchToRip = 0x110 +KTRAP_FRAME_LastBranchFromRip = 0x118 +KTRAP_FRAME_LastExceptionToRip = 0x120 +KTRAP_FRAME_LastExceptionFromRip = 0x128 +KTRAP_FRAME_LastBranchControl = 0x108 +KTRAP_FRAME_LastBranchMSR = 0x110 +KTRAP_FRAME_SegDs = 0x130 +KTRAP_FRAME_SegEs = 0x132 +KTRAP_FRAME_SegFs = 0x134 +KTRAP_FRAME_SegGs = 0x136 +KTRAP_FRAME_TrapFrame = 0x138 +KTRAP_FRAME_Rbx = 0x140 +KTRAP_FRAME_Rdi = 0x148 +KTRAP_FRAME_Rsi = 0x150 +KTRAP_FRAME_Rbp = 0x158 +KTRAP_FRAME_ErrorCode = 0x160 +KTRAP_FRAME_TimeStampKlog = 0x160 +KTRAP_FRAME_Rip = 0x168 +KTRAP_FRAME_SegCs = 0x170 +KTRAP_FRAME_Logging = 0x173 +KTRAP_FRAME_EFlags = 0x178 +KTRAP_FRAME_Rsp = 0x180 +KTRAP_FRAME_SegSs = 0x188 +KTRAP_FRAME_CodePatchCycle = 0x18c +KTRAP_FRAME_LENGTH = 0x190 + +/* KTSS */ +TssRsp0 = 0x4 +TssRsp1 = 0xc +TssRsp2 = 0x14 +TssPanicStack = 0x24 +TssMcaStack = 0x2c +TssNmiStack = 0x34 +TssIoMapBase = 0x66 +TssLength = 0x68 + +/* EXCEPTION_RECORD */ +EXCEPTION_RECORD_ExceptionCode = 0x0 +EXCEPTION_RECORD_ExceptionFlags = 0x4 +EXCEPTION_RECORD_ExceptionRecord = 0x8 +EXCEPTION_RECORD_ExceptionAddress = 0x10 +EXCEPTION_RECORD_NumberParameters = 0x18 +EXCEPTION_RECORD_ExceptionInformation = 0x20 +KTHREAD_WAIT_IRQL = 0x86 diff --git a/include/reactos/undocuser.h b/include/reactos/undocuser.h new file mode 100644 index 00000000000..dcb0b0474d3 --- /dev/null +++ b/include/reactos/undocuser.h @@ -0,0 +1,175 @@ +#ifndef _UNDOCUSER_H +#define _UNDOCUSER_H + +/* Built in class atoms */ +#define WC_MENU (MAKEINTATOM(0x8000)) +#define WC_DESKTOP (MAKEINTATOM(0x8001)) +#define WC_DIALOG (MAKEINTATOM(0x8002)) +#define WC_SWITCH (MAKEINTATOM(0x8003)) +#define WC_ICONTITLE (MAKEINTATOM(0x8004)) + +/* Non SDK Styles */ +#define ES_COMBO 0x200 /* Parent is a combobox */ +#define WS_MAXIMIZED WS_MAXIMIZE +#define WS_MINIMIZED WS_MINIMIZE + +/* Non SDK ExStyles */ +#define WS_EX_DRAGDETECT 0x00000002 +#define WS_EX_MAKEVISIBLEWHENUNGHOSTED 0x00000800 +#define WS_EX_FORCELEGACYRESIZENCMETR 0x00800000 +#define WS_EX_UISTATEACTIVE 0x04000000 +#define WS_EX_REDIRECTED 0x20000000 +#define WS_EX_UISTATEKBACCELHIDDEN 0x40000000 +#define WS_EX_UISTATEFOCUSRECTHIDDEN 0x80000000 +#define WS_EX_SETANSICREATOR 0x80000000 // For WNDS_ANSICREATOR + +/* Non SDK Window Message types. */ +#define WM_SETVISIBLE 0x00000009 +#define WM_CTLCOLOR 0x00000019 +#define WM_ALTTABACTIVE 0x00000029 +#define WM_ISACTIVEICON 0x00000035 +#define WM_QUERYPARKICON 0x00000036 +#define WM_CLIENTSHUTDOWN 0x0000003B +#define WM_COPYGLOBALDATA 0x00000049 +#define WM_LOGONNOTIFY 0x0000004c +#define WM_KEYF1 0x0000004d +#define WM_SYSTIMER 0x00000118 +#define WM_LBTRACKPOINT 0x00000131 +#define LB_CARETON 0x000001a3 +#define LB_CARETOFF 0x000001a4 +#define WM_DROPOBJECT 0x0000022A +#define WM_QUERYDROPOBJECT 0x0000022B +#define WM_BEGINDRAG 0x0000022C +#define WM_DRAGLOOP 0x0000022D +#define WM_DRAGSELECT 0x0000022E +#define WM_DRAGMOVE 0x0000022F +#define WM_POPUPSYSTEMMENU 0x00000313 +#define WM_CBT 0x000003FF // ReactOS only. +#define WM_MAXIMUM 0x0001FFFF + +/* Non SDK DCE types.*/ +#define DCX_USESTYLE 0x00010000 +#define DCX_KEEPCLIPRGN 0x00040000 +#define DCX_KEEPLAYOUT 0x40000000 +#define DCX_PROCESSOWNED 0x80000000 + +/* Caret timer ID */ +#define IDCARETTIMER (0xffff) + +/* SetWindowPos undocumented flags */ +#define SWP_NOCLIENTSIZE 0x0800 +#define SWP_NOCLIENTMOVE 0x1000 +#define SWP_STATECHANGED 0x8000 + +/* Non SDK Queue state flags. */ +#define QS_SMRESULT 0x8000 /* see "Undoc. Windows" */ + +// +// Definitions used by WM_CLIENTSHUTDOWN +// +// Client Shutdown messages +#define MCS_SHUTDOWNTIMERS 1 +#define MCS_QUERYENDSESSION 2 +// Client Shutdown returns +#define MCSR_GOODFORSHUTDOWN 1 +#define MCSR_SHUTDOWNFINISHED 2 +#define MCSR_DONOTSHUTDOWN 3 + +// +// Definitions used by WM_LOGONNOTIFY +// +#define LN_START_TASK_MANAGER 0x4 +#define LN_LOCK_WORKSTATION 0x5 +#define LN_UNLOCK_WORKSTATION 0x6 +#define LN_MESSAGE_BEEP 0x9 + +#define CW_USEDEFAULT16 ((short)0x8000) + +#define SBRG_SCROLLBAR 0 /* the scrollbar itself */ +#define SBRG_TOPRIGHTBTN 1 /* the top or right button */ +#define SBRG_PAGEUPRIGHT 2 /* the page up or page right region */ +#define SBRG_SCROLLBOX 3 /* the scroll box */ +#define SBRG_PAGEDOWNLEFT 4 /* the page down or page left region */ +#define SBRG_BOTTOMLEFTBTN 5 /* the bottom or left button */ + + +BOOL WINAPI KillSystemTimer(HWND,UINT_PTR); +UINT_PTR WINAPI SetSystemTimer(HWND,UINT_PTR,UINT,TIMERPROC); +DWORD_PTR WINAPI SetSysColorsTemp(const COLORREF *, const HBRUSH *, DWORD_PTR); +BOOL WINAPI SetDeskWallPaper(LPCSTR); +VOID WINAPI ScrollChildren(HWND,UINT,WPARAM,LPARAM); +void WINAPI CalcChildScroll(HWND, INT); +BOOL WINAPI RegisterLogonProcess(DWORD,BOOL); +DWORD WINAPI GetAppCompatFlags(HTASK hTask); +DWORD WINAPI GetAppCompatFlags2(HTASK hTask); +LONG WINAPI CsrBroadcastSystemMessageExW(DWORD dwflags, + LPDWORD lpdwRecipients, + UINT uiMessage, + WPARAM wParam, + LPARAM lParam, + PBSMINFO pBSMInfo); +BOOL WINAPI CliImmSetHotKey(DWORD dwID, UINT uModifiers, UINT uVirtualKey, HKL hKl); +HWND WINAPI GetTaskmanWindow(VOID); +HWND WINAPI GetProgmanWindow(VOID); + +// +// User api hook +// + +typedef struct _USERAPIHOOKINFO +{ + DWORD m_size; + LPCWSTR m_dllname1; + LPCWSTR m_funname1; + LPCWSTR m_dllname2; + LPCWSTR m_funname2; +} USERAPIHOOKINFO,*PUSERAPIHOOKINFO; + +typedef enum _UAPIHK +{ + uahLoadInit, + uahStop, + uahShutdown +} UAPIHK, *PUAPIHK; + +typedef DWORD (CALLBACK * USERAPIHOOKPROC)(UAPIHK State, ULONG_PTR Info); + +typedef LRESULT(CALLBACK *WNDPROC_OWP)(HWND,UINT,WPARAM,LPARAM,ULONG_PTR,PDWORD); + +typedef struct _UAHOWP +{ + BYTE* MsgBitArray; + DWORD Size; +} UAHOWP, *PUAHOWP; + +typedef struct tagUSERAPIHOOK +{ + DWORD size; + WNDPROC DefWindowProcA; + WNDPROC DefWindowProcW; + UAHOWP DefWndProcArray; + FARPROC GetScrollInfo; + FARPROC SetScrollInfo; + FARPROC EnableScrollBar; + FARPROC AdjustWindowRectEx; + FARPROC SetWindowRgn; + WNDPROC_OWP PreWndProc; + WNDPROC_OWP PostWndProc; + UAHOWP WndProcArray; + WNDPROC_OWP PreDefDlgProc; + WNDPROC_OWP PostDefDlgProc; + UAHOWP DlgProcArray; + FARPROC GetSystemMetrics; + FARPROC SystemParametersInfoA; + FARPROC SystemParametersInfoW; + FARPROC ForceResetUserApiHook; + FARPROC DrawFrameControl; + FARPROC DrawCaption; + FARPROC MDIRedrawFrame; + FARPROC GetRealWindowOwner; +} USERAPIHOOK, *PUSERAPIHOOK; + +BOOL WINAPI RegisterUserApiHook(PUSERAPIHOOKINFO puah); +BOOL WINAPI UnregisterUserApiHook(VOID); + +#endif \ No newline at end of file diff --git a/include/reactos/win32k/ntuser.h b/include/reactos/win32k/ntuser.h index 674ab242db0..a334a04ff30 100644 --- a/include/reactos/win32k/ntuser.h +++ b/include/reactos/win32k/ntuser.h @@ -466,19 +466,6 @@ typedef struct _SBINFOEX #define WNDS2_SHELLHOOKREGISTERED 0X40000000 #define WNDS2_WMCREATEMSGPROCESSED 0X80000000 -/* Non SDK ExStyles */ -#define WS_EX_MAKEVISIBLEWHENUNGHOSTED 0x00000800 -#define WS_EX_FORCELEGACYRESIZENCMETR 0x00800000 -#define WS_EX_UISTATEACTIVE 0x04000000 -#define WS_EX_REDIRECTED 0X20000000 -#define WS_EX_UISTATEKBACCELHIDDEN 0X40000000 -#define WS_EX_UISTATEFOCUSRECTHIDDEN 0X80000000 -#define WS_EX_SETANSICREATOR 0x80000000 // For WNDS_ANSICREATOR - -/* Non SDK Styles */ -#define WS_MAXIMIZED WS_MAXIMIZE -#define WS_MINIMIZED WS_MINIMIZE - /* ExStyles2 */ #define WS_EX2_CLIPBOARDLISTENER 0X00000001 #define WS_EX2_LAYEREDINVALIDATE 0X00000002 @@ -860,29 +847,6 @@ typedef struct _USERCONNECT SHAREDINFO siClient; } USERCONNECT, *PUSERCONNECT; -// -// Non SDK Window Message types. -// -#define WM_CLIENTSHUTDOWN 59 -#define WM_COPYGLOBALDATA 73 -#define WM_SYSTIMER 280 -#define WM_POPUPSYSTEMMENU 787 -#define WM_CBT 1023 // ReactOS only. -#define WM_MAXIMUM 0x0001FFFF - -// -// Non SDK DCE types. -// -#define DCX_USESTYLE 0x00010000 -#define DCX_KEEPCLIPRGN 0x00040000 -#define DCX_KEEPLAYOUT 0x40000000 -#define DCX_PROCESSOWNED 0x80000000 - -// -// Non SDK Queue message types. -// -#define QS_SMRESULT 0x8000 - DWORD NTAPI NtUserAssociateInputContext( diff --git a/lib/rtl/CMakeLists.txt b/lib/rtl/CMakeLists.txt index c47d77bfb40..c992a615ffc 100644 --- a/lib/rtl/CMakeLists.txt +++ b/lib/rtl/CMakeLists.txt @@ -50,9 +50,7 @@ list(APPEND SOURCE security.c slist.c sid.c - sprintf.c srw.c - swprintf.c splaytree.c thread.c time.c diff --git a/lib/rtl/heap.c b/lib/rtl/heap.c index 2c28b6a76d7..7454ddc49c4 100644 --- a/lib/rtl/heap.c +++ b/lib/rtl/heap.c @@ -238,7 +238,7 @@ RtlpInsertFreeBlockHelper(PHEAP Heap, /* Check if PreviousSize of the next entry matches ours */ if (!(FreeEntry->Flags & HEAP_ENTRY_LAST_ENTRY)) { - ASSERT(((PHEAP_ENTRY)FreeEntry + BlockSize)->PreviousSize = BlockSize); + ASSERT(((PHEAP_ENTRY)FreeEntry + BlockSize)->PreviousSize == BlockSize); } /* Insert it either into dedicated or non-dedicated list */ diff --git a/lib/rtl/sprintf.c b/lib/rtl/sprintf.c deleted file mode 100644 index 51461147d0a..00000000000 --- a/lib/rtl/sprintf.c +++ /dev/null @@ -1,747 +0,0 @@ - -#ifndef USE_NEW_SPRINTF -/* - * PROGRAMMERS: David Welch - * Eric Kohl - * - * TODO: - * - Verify the implementation of '%Z'. - */ - -/* - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -#include - -#define ZEROPAD 1 /* pad with zero */ -#define SIGN 2 /* unsigned/signed long */ -#define PLUS 4 /* show plus */ -#define SPACE 8 /* space if plus */ -#define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ -#define REMOVEHEX 256 /* use 256 as remve 0x frim BASE 16 */ -typedef struct { - unsigned int mantissal:32; - unsigned int mantissah:20; - unsigned int exponent:11; - unsigned int sign:1; -} double_t; - -static -__inline -int -_isinf(double __x) -{ - union - { - double* __x; - double_t* x; - } x; - - x.__x = &__x; - return ( x.x->exponent == 0x7ff && ( x.x->mantissah == 0 && x.x->mantissal == 0 )); -} - -static -__inline -int -_isnan(double __x) -{ - union - { - double* __x; - double_t* x; - } x; - x.__x = &__x; - return ( x.x->exponent == 0x7ff && ( x.x->mantissah != 0 || x.x->mantissal != 0 )); -} - - -static -__inline -int -do_div(long long *n, int base) -{ - int a; - a = ((unsigned long long) *n) % (unsigned) base; - *n = ((unsigned long long) *n) / (unsigned) base; - return a; -} - - -static int skip_atoi(const char **s) -{ - int i=0; - - while (isdigit(**s)) - i = i*10 + *((*s)++) - '0'; - return i; -} - - -static char * -number(char * buf, char * end, long long num, int base, int size, int precision, int type) -{ - char c,sign,tmp[66]; - const char *digits; - const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz"; - const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - int i; - - digits = (type & LARGE) ? large_digits : small_digits; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = '-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = '+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - - if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) { - if (base == 16) - size -= 2; - - } - i = 0; - if ((num == 0) && (precision !=0)) - tmp[i++] = '0'; - else while (num != 0) - tmp[i++] = digits[do_div(&num,base)]; - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) { - while(size-->0) { - if (buf <= end) - *buf = ' '; - ++buf; - } - } - if (sign) { - if (buf <= end) - *buf = sign; - ++buf; - } - - if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) { - if (base==16) { - if (buf <= end) - *buf = '0'; - ++buf; - if (buf <= end) - *buf = digits[33]; - ++buf; - } - } - - if (!(type & LEFT)) { - while (size-- > 0) { - if (buf <= end) - *buf = c; - ++buf; - } - } - while (i < precision--) { - if (buf <= end) - *buf = '0'; - ++buf; - } - while (i-- > 0) { - if (buf <= end) - *buf = tmp[i]; - ++buf; - } - while (size-- > 0) { - if (buf <= end) - *buf = ' '; - ++buf; - } - - return buf; -} - -static char * -numberf(char * buf, char * end, double num, int base, int size, int precision, int type) -{ - char c,sign,tmp[66]; - const char *digits; - const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz"; - const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - int i; - long long x; - - /* FIXME - the float version of number is direcly copy of number - */ - - digits = (type & LARGE) ? large_digits : small_digits; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = '-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = '+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - if (type & SPECIAL) { - if (base == 16) - size -= 2; - else if (base == 8) - size--; - } - i = 0; - if (num == 0) - tmp[i++] = '0'; - else while (num != 0) - { - x = num; - tmp[i++] = digits[do_div(&x,base)]; -#ifndef _M_ARM // Missing __floatdidf in CeGCC 0.55 -- GCC 4.4 - num=x; -#endif - } - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) { - while(size-->0) { - if (buf <= end) - *buf = ' '; - ++buf; - } - } - if (sign) { - if (buf <= end) - *buf = sign; - ++buf; - } - if (type & SPECIAL) { - if (base==8) { - if (buf <= end) - *buf = '0'; - ++buf; - } else if (base==16) { - if (buf <= end) - *buf = '0'; - ++buf; - if (buf <= end) - *buf = digits[33]; - ++buf; - } - } - if (!(type & LEFT)) { - while (size-- > 0) { - if (buf <= end) - *buf = c; - ++buf; - } - } - while (i < precision--) { - if (buf <= end) - *buf = '0'; - ++buf; - } - while (i-- > 0) { - if (buf <= end) - *buf = tmp[i]; - ++buf; - } - while (size-- > 0) { - if (buf <= end) - *buf = ' '; - ++buf; - } - return buf; -} - -static char* -string(char* buf, char* end, const char* s, int len, int field_width, int precision, int flags) -{ - int i; - char c; - - c = (flags & ZEROPAD) ? '0' : ' '; - - if (s == NULL) - { - s = ""; - len = 6; - } - else - { - if (len == -1) - { - len = 0; - while ((unsigned int)len < (unsigned int)precision && s[len]) - len++; - } - else - { - if ((unsigned int)len > (unsigned int)precision) - len = precision; - } - } - if (!(flags & LEFT)) - while (len < field_width--) - { - if (buf <= end) - *buf = c; - ++buf; - } - for (i = 0; i < len; ++i) - { - if (buf <= end) - *buf = *s++; - ++buf; - } - while (len < field_width--) - { - if (buf <= end) - *buf = ' '; - ++buf; - } - return buf; -} - -static char* -stringw(char* buf, char* end, const wchar_t* sw, int len, int field_width, int precision, int flags) -{ - int i; - char c; - - c = (flags & ZEROPAD) ? '0' : ' '; - - if (sw == NULL) - { - sw = L""; - len = 6; - } - else - { - if (len == -1) - { - len = 0; - while ((unsigned int)len < (unsigned int)precision && sw[len]) - len++; - } - else - { - if ((unsigned int)len > (unsigned int)precision) - len = precision; - } - } - if (!(flags & LEFT)) - while (len < field_width--) - { - if (buf <= end) - *buf = c; - buf++; - } - for (i = 0; i < len; ++i) - { - if (buf <= end) - *buf = (unsigned char)(*sw++); - buf++; - } - while (len < field_width--) - { - if (buf <= end) - *buf = ' '; - buf++; - } - return buf; -} - -/* - * @implemented - */ -int __cdecl _vsnprintf(char *buf, size_t cnt, const char *fmt, va_list args) -{ - int len; - unsigned long long num; - double _double; - - int base; - char *str, *end; - const char *s; - const wchar_t *sw; - - int flags; /* flags to number() */ - - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max - number of chars for from string */ - int qualifier; /* 'h', 'l', 'L', 'I' or 'w' for integer fields */ - - /* clear the string buffer with zero so we do not need NULL terment it at end */ - - str = buf; - end = buf + cnt - 1; - if (end < buf - 1) { - end = ((char *) -1); - cnt = end - buf + 1; - } - - for ( ; *fmt ; ++fmt) { - if (*fmt != '%') { - if (str <= end) - *str = *fmt; - ++str; - continue; - } - - /* process flags */ - flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; - } - - /* get field width */ - field_width = -1; - if (isdigit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if (field_width < 0) { - field_width = -field_width; - flags |= LEFT; - } - } - - /* get the precision */ - precision = -1; - if (*fmt == '.') { - ++fmt; - if (isdigit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if (precision < 0) - precision = 0; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'l' && *(fmt+1) == 'l') { - qualifier = 'I'; - fmt += 2; - } else if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'w') { - qualifier = *fmt; - ++fmt; - } else if (*fmt == 'I' && *(fmt+1) == '6' && *(fmt+2) == '4') { - qualifier = *fmt; - fmt += 3; - } else if (*fmt == 'I' && *(fmt+1) == '3' && *(fmt+2) == '2') { - qualifier = 'l'; - fmt += 3; - } else if (*fmt == 'F' && *(fmt+1) == 'p') { - fmt += 1; - flags |= REMOVEHEX; - } - - /* default base */ - base = 10; - - switch (*fmt) { - case 'c': /* finished */ - if (qualifier == 'l' || qualifier == 'w') { - wchar_t sw1[2]; - /* print unicode string */ - sw1[0] = (wchar_t) va_arg(args, int); - sw1[1] = 0; - str = stringw(str, end, (wchar_t *)&sw1, -1, field_width, precision, flags); - } else { - char s1[2]; - /* print ascii string */ - s1[0] = ( unsigned char) va_arg(args, int); - s1[1] = 0; - str = string(str, end, (char *)&s1, -1, field_width, precision, flags); - } - continue; - - case 'C': /* finished */ - if (!(flags & LEFT)) - while (--field_width > 0) { - if (str <= end) - *str = ' '; - ++str; - } - if (qualifier == 'h') { - if (str <= end) - *str = (unsigned char) va_arg(args, int); - ++str; - } else { - if (str <= end) - *str = (unsigned char)(wchar_t) va_arg(args, int); - ++str; - } - while (--field_width > 0) { - if (str <= end) - *str = ' '; - ++str; - } - continue; - - case 's': /* finished */ - if (qualifier == 'l' || qualifier == 'w') { - /* print unicode string */ - sw = va_arg(args, wchar_t *); - str = stringw(str, end, sw, -1, field_width, precision, flags); - } else { - /* print ascii string */ - s = va_arg(args, char *); - str = string(str, end, s, -1, field_width, precision, flags); - } - continue; - - case 'S': - if (qualifier == 'h') { - /* print ascii string */ - s = va_arg(args, char *); - str = string(str, end, s, -1, field_width, precision, flags); - } else { - /* print unicode string */ - sw = va_arg(args, wchar_t *); - str = stringw(str, end, sw, -1, field_width, precision, flags); - } - continue; - - case 'Z': - if (qualifier == 'w') { - /* print counted unicode string */ - PUNICODE_STRING pus = va_arg(args, PUNICODE_STRING); - if ((pus == NULL) || (pus->Buffer == NULL)) { - sw = NULL; - len = -1; - } else { - sw = pus->Buffer; - len = pus->Length / sizeof(WCHAR); - } - str = stringw(str, end, sw, len, field_width, precision, flags); - } else { - /* print counted ascii string */ - PANSI_STRING pus = va_arg(args, PANSI_STRING); - if ((pus == NULL) || (pus->Buffer == NULL)) { - s = NULL; - len = -1; - } else { - s = pus->Buffer; - len = pus->Length; - } - str = string(str, end, s, len, field_width, precision, flags); - } - continue; - - case 'p': - if ((flags & LARGE) == 0) - flags |= LARGE; - - if (field_width == -1) { - field_width = 2 * sizeof(void *); - flags |= ZEROPAD; - } - str = number(str, end, - (ULONG_PTR) va_arg(args, void *), 16, - field_width, precision, flags); - continue; - - case 'n': - /* FIXME: What does C99 say about the overflow case here? */ - if (qualifier == 'l') { - long * ip = va_arg(args, long *); - *ip = (str - buf); - } else { - int * ip = va_arg(args, int *); - *ip = (str - buf); - } - continue; - - /* float number formats - set up the flags and "break" */ - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - _double = (double)va_arg(args, double); - if ( _isnan(_double) ) { - s = "Nan"; - len = 3; - while ( len > 0 ) { - if (str <= end) - *str = *s++; - ++str; - len --; - } - } else if ( _isinf(_double) < 0 ) { - s = "-Inf"; - len = 4; - while ( len > 0 ) { - if (str <= end) - *str = *s++; - ++str; - len --; - } - } else if ( _isinf(_double) > 0 ) { - s = "+Inf"; - len = 4; - while ( len > 0 ) { - if (str <= end) - *str = *s++; - ++str; - len --; - } - } else { - if ( precision == -1 ) - precision = 6; - str = numberf(str, end, (int)_double, base, field_width, precision, flags); - } - - continue; - - - /* integer number formats - set up the flags and "break" */ - case 'o': - base = 8; - break; - - case 'b': - base = 2; - break; - - case 'X': - flags |= LARGE; - case 'x': - base = 16; - break; - - case 'd': - case 'i': - flags |= SIGN; - case 'u': - break; - - default: - if (*fmt) { - if (str <= end) - *str = *fmt; - ++str; - } else - --fmt; - continue; - } - - if (qualifier == 'I') - num = va_arg(args, unsigned long long); - else if (qualifier == 'l') { - if (flags & SIGN) - num = va_arg(args, long); - else - num = va_arg(args, unsigned long); - } - else if (qualifier == 'h') { - if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } - else { - if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } - str = number(str, end, num, base, field_width, precision, flags); - } - if (str <= end) - *str = '\0'; - else if (cnt > 0) - /* don't write out a null byte if the buf size is zero */ - *end = '\0'; - return str-buf; -} - - -/* - * @implemented - */ -int sprintf(char * buf, const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=_vsnprintf(buf,MAXLONG,fmt,args); - va_end(args); - return i; -} - - -/* - * @implemented - */ -int _snprintf(char * buf, size_t cnt, const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=_vsnprintf(buf,cnt,fmt,args); - va_end(args); - return i; -} - - -/* - * @implemented - */ -int __cdecl vsprintf(char *buf, const char *fmt, va_list args) -{ - return _vsnprintf(buf,MAXLONG,fmt,args); -} - -/* EOF */ -#endif - diff --git a/lib/rtl/srw.c b/lib/rtl/srw.c index 3c37a83b433..ff7b755a548 100644 --- a/lib/rtl/srw.c +++ b/lib/rtl/srw.c @@ -131,7 +131,7 @@ RtlpReleaseWaitBlockLockExclusive(IN OUT PRTL_SRWLOCK SRWLock, } } - (void)InterlockedExchange((PLONG)&SRWLock->Ptr, NewValue); + (void)_InterlockedExchangePointer(&SRWLock->Ptr, (PVOID)NewValue); if (FirstWaitBlock->Exclusive) { @@ -186,7 +186,7 @@ RtlpReleaseWaitBlockLockLastShared(IN OUT PRTL_SRWLOCK SRWLock, NewValue = RTL_SRWLOCK_OWNED; } - (void)InterlockedExchange((PLONG)&SRWLock->Ptr, NewValue); + (void)_InterlockedExchangePointer(&SRWLock->Ptr, (PVOID)NewValue); (void)InterlockedOr(&FirstWaitBlock->Wake, TRUE); @@ -420,9 +420,9 @@ RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock) NewValue = (CurrentValue >> RTL_SRWLOCK_BITS) + 1; NewValue = (NewValue << RTL_SRWLOCK_BITS) | (CurrentValue & RTL_SRWLOCK_MASK); - if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr, - NewValue, - CurrentValue) == CurrentValue) + if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { /* Successfully incremented the shared count, we acquired the lock */ break; @@ -499,9 +499,9 @@ RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock) ASSERT_SRW_WAITBLOCK(&StackWaitBlock); NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED; - if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr, - NewValue, - CurrentValue) == CurrentValue) + if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { RtlpAcquireSRWLockSharedWait(SRWLock, &StackWaitBlock, @@ -521,9 +521,9 @@ RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock) RTL_SRWLOCK_SHARED nor the RTL_SRWLOCK_OWNED bit is set */ ASSERT(!(CurrentValue & RTL_SRWLOCK_CONTENDED)); - if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr, - NewValue, - CurrentValue) == CurrentValue) + if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { /* Successfully set the shared count, we acquired the lock */ break; @@ -580,9 +580,9 @@ RtlReleaseSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock) NewValue = (NewValue << RTL_SRWLOCK_BITS) | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_OWNED; } - if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr, - NewValue, - CurrentValue) == CurrentValue) + if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { /* Successfully released the lock */ break; @@ -639,9 +639,9 @@ RtlAcquireSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock) NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_CONTENDED | RTL_SRWLOCK_OWNED; - if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr, - NewValue, - CurrentValue) == CurrentValue) + if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { RtlpAcquireSRWLockExclusiveWait(SRWLock, &StackWaitBlock); @@ -697,9 +697,9 @@ AddWaitBlock: ASSERT_SRW_WAITBLOCK(&StackWaitBlock); NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED; - if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr, - NewValue, - CurrentValue) == CurrentValue) + if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { RtlpAcquireSRWLockExclusiveWait(SRWLock, &StackWaitBlock); @@ -767,9 +767,9 @@ RtlReleaseSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock) ASSERT(!(CurrentValue & ~RTL_SRWLOCK_OWNED)); NewValue = 0; - if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr, - NewValue, - CurrentValue) == CurrentValue) + if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { /* We released the lock */ break; diff --git a/lib/rtl/swprintf.c b/lib/rtl/swprintf.c deleted file mode 100644 index 20d975ff757..00000000000 --- a/lib/rtl/swprintf.c +++ /dev/null @@ -1,744 +0,0 @@ -#ifndef USE_NEW_SPRINTF -/* - * PROGRAMMERS: David Welch - * Eric Kohl - * - * TODO: - * - Verify the implementation of '%Z'. - */ - -/* - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -#include - -#define ZEROPAD 1 /* pad with zero */ -#define SIGN 2 /* unsigned/signed long */ -#define PLUS 4 /* show plus */ -#define SPACE 8 /* space if plus */ -#define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ -#define REMOVEHEX 256 /* use 256 as remve 0x frim BASE 16 */ -typedef struct { - unsigned int mantissal:32; - unsigned int mantissah:20; - unsigned int exponent:11; - unsigned int sign:1; -} double_t; - -static -__inline -int -_isinf(double __x) -{ - union - { - double* __x; - double_t* x; - } x; - - x.__x = &__x; - return ( x.x->exponent == 0x7ff && ( x.x->mantissah == 0 && x.x->mantissal == 0 )); -} - -static -__inline -int -_isnan(double __x) -{ - union - { - double* __x; - double_t* x; - } x; - x.__x = &__x; - return ( x.x->exponent == 0x7ff && ( x.x->mantissah != 0 || x.x->mantissal != 0 )); -} - - -static -__inline -int -do_div(long long *n, int base) -{ - int a; - a = ((unsigned long long) *n) % (unsigned) base; - *n = ((unsigned long long) *n) / (unsigned) base; - return a; -} - - -static int skip_atoi(const wchar_t **s) -{ - int i=0; - - while (iswdigit(**s)) - i = i*10 + *((*s)++) - L'0'; - return i; -} - - -static wchar_t * -number(wchar_t * buf, wchar_t * end, long long num, int base, int size, int precision, int type) -{ - wchar_t c, sign, tmp[66]; - const wchar_t *digits; - const wchar_t *small_digits = L"0123456789abcdefghijklmnopqrstuvwxyz"; - const wchar_t *large_digits = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - int i; - - digits = (type & LARGE) ? large_digits : small_digits; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? L'0' : L' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = L'-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = L'+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - - if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) { - if (base == 16) - size -= 2; - } - i = 0; - if ((num == 0) && (precision !=0)) - tmp[i++] = L'0'; - else while (num != 0) - tmp[i++] = digits[do_div(&num,base)]; - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) { - while(size-->0) { - if (buf <= end) - *buf = L' '; - ++buf; - } - } - if (sign) { - if (buf <= end) - *buf = sign; - ++buf; - } - - if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) { - if (base==16) { - if (buf <= end) - *buf = L'0'; - ++buf; - if (buf <= end) - *buf = digits[33]; - ++buf; - } - } - if (!(type & LEFT)) { - while (size-- > 0) { - if (buf <= end) - *buf = c; - ++buf; - } - } - while (i < precision--) { - if (buf <= end) - *buf = L'0'; - ++buf; - } - while (i-- > 0) { - if (buf <= end) - *buf = tmp[i]; - ++buf; - } - while (size-- > 0) { - if (buf <= end) - *buf = L' '; - ++buf; - } - - - return buf; -} - -static wchar_t * -numberf(wchar_t * buf, wchar_t * end, double num, int base, int size, int precision, int type) -{ - wchar_t c, sign, tmp[66]; - const wchar_t *digits; - const wchar_t *small_digits = L"0123456789abcdefghijklmnopqrstuvwxyz"; - const wchar_t *large_digits = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - int i; - long long x; - - /* FIXME - the float version of number is direcly copy of number - */ - - - digits = (type & LARGE) ? large_digits : small_digits; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? L'0' : L' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = L'-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = L'+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - if (type & SPECIAL) { - if (base == 16) - size -= 2; - else if (base == 8) - size--; - } - i = 0; - if (num == 0) - tmp[i++] = L'0'; - else while (num != 0) - { - x = num; - tmp[i++] = digits[do_div(&x,base)]; -#ifndef _M_ARM // Missing __floatdidf in CeGCC 0.55 -- GCC 4.4 - num = x; -#endif - } - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) { - while(size-->0) { - if (buf <= end) - *buf = L' '; - ++buf; - } - } - if (sign) { - if (buf <= end) - *buf = sign; - ++buf; - } - if (type & SPECIAL) { - if (base==8) { - if (buf <= end) - *buf = L'0'; - ++buf; - } else if (base==16) { - if (buf <= end) - *buf = L'0'; - ++buf; - if (buf <= end) - *buf = digits[33]; - ++buf; - } - } - if (!(type & LEFT)) { - while (size-- > 0) { - if (buf <= end) - *buf = c; - ++buf; - } - } - while (i < precision--) { - if (buf <= end) - *buf = L'0'; - ++buf; - } - while (i-- > 0) { - if (buf <= end) - *buf = tmp[i]; - ++buf; - } - while (size-- > 0) { - if (buf <= end) - *buf = L' '; - ++buf; - } - return buf; -} - -static wchar_t* -string(wchar_t* buf, wchar_t* end, const char* s, int len, int field_width, int precision, int flags) -{ - int i; - wchar_t c; - - c = (flags & ZEROPAD) ? L'0' : L' '; - - if (s == NULL) - { - s = ""; - len = 6; - } - else - { - if (len == -1) - { - len = 0; - while ((unsigned int)len < (unsigned int)precision && s[len]) - len++; - } - else - { - if ((unsigned int)len > (unsigned int)precision) - len = precision; - } - } - if (!(flags & LEFT)) - while (len < field_width--) - { - if (buf <= end) - *buf = c; - ++buf; - } - for (i = 0; i < len; ++i) - { - if (buf <= end) - *buf = *s++; - ++buf; - } - while (len < field_width--) - { - if (buf <= end) - *buf = L' '; - ++buf; - } - return buf; -} - -static wchar_t* -stringw(wchar_t* buf, wchar_t* end, const wchar_t* sw, int len, int field_width, int precision, int flags) -{ - int i; - wchar_t c; - - c = (flags & ZEROPAD) ? L'0' : L' '; - - if (sw == NULL) - { - sw = L""; - len = 6; - } - else - { - if (len == -1) - { - len = 0; - while ((unsigned int)len < (unsigned int)precision && sw[len]) - len++; - } - else - { - if ((unsigned int)len > (unsigned int)precision) - len = precision; - } - } - if (!(flags & LEFT)) - while (len < field_width--) - { - if (buf <= end) - *buf = c; - buf++; - } - for (i = 0; i < len; ++i) - { - if (buf <= end) - *buf = *sw++; - buf++; - } - while (len < field_width--) - { - if (buf <= end) - *buf = L' '; - buf++; - } - return buf; -} - -/* - * @implemented - */ -int __cdecl _vsnwprintf(wchar_t *buf, size_t cnt, const wchar_t *fmt, va_list args) -{ - int len; - unsigned long long num; - int base; - wchar_t * str, * end; - const char *s; - const wchar_t *sw; - const wchar_t *ss; - double _double; - - int flags; /* flags to number() */ - - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max - number of chars for from string */ - int qualifier; /* 'h', 'l', 'L', 'w' or 'I' for integer fields */ - - str = buf; - end = buf + cnt - 1; - if (end < buf - 1) { - end = ((wchar_t *) -1); - cnt = end - buf + 1; - } - - for ( ; *fmt ; ++fmt) { - if (*fmt != L'%') { - if (str <= end) - *str = *fmt; - ++str; - continue; - } - - /* process flags */ - flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case L'-': flags |= LEFT; goto repeat; - case L'+': flags |= PLUS; goto repeat; - case L' ': flags |= SPACE; goto repeat; - case L'#': flags |= SPECIAL; goto repeat; - case L'0': flags |= ZEROPAD; goto repeat; - } - - /* get field width */ - field_width = -1; - if (iswdigit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == L'*') { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if (field_width < 0) { - field_width = -field_width; - flags |= LEFT; - } - } - - /* get the precision */ - precision = -1; - if (*fmt == L'.') { - ++fmt; - if (iswdigit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == L'*') { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if (precision < 0) - precision = 0; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == L'l' && *(fmt+1) == L'l') { - qualifier = L'I'; - fmt += 2; - } else if (*fmt == L'h' || *fmt == L'l' || *fmt == L'L' || *fmt == L'w') { - qualifier = *fmt; - ++fmt; - } else if (*fmt == L'I' && *(fmt+1) == L'6' && *(fmt+2) == L'4') { - qualifier = *fmt; - fmt += 3; - } else if (*fmt == L'I' && *(fmt+1) == L'3' && *(fmt+2) == L'2') { - qualifier = L'l'; - fmt += 3; - } else if (*fmt == L'F' && *(fmt+1) == L'p') { - fmt += 1; - flags |= REMOVEHEX; - } - - /* default base */ - base = 10; - - switch (*fmt) { - case L'c': - if (qualifier == 'h' || qualifier == 'w') { - wchar_t sw1[2]; - /* print unicode string */ - sw1[0] = (wchar_t) va_arg(args, int); - sw1[1] = 0; - str = stringw(str, end, (wchar_t *)&sw1, -1, field_width, precision, flags); - } else { - char s1[2]; - /* print ascii string */ - s1[0] = ( unsigned char) va_arg(args, int); - s1[1] = 0; - str = string(str, end, (char *)&s1, -1, field_width, precision, flags); - } - - continue; - - case L'C': - if (!(flags & LEFT)) - while (--field_width > 0) { - if (str <= end) - *str = L' '; - ++str; - } - if (qualifier == 'l' || qualifier == 'w') { - if (str <= end) - *str = (wchar_t) va_arg(args, int); - ++str; - } else { - if (str <= end) - *str = (wchar_t) va_arg(args, int); - ++str; - } - while (--field_width > 0) { - if (str <= end) - *str = L' '; - ++str; - } - continue; - - case L's': - if (qualifier == 'h') { - /* print ascii string */ - s = va_arg(args, char *); - str = string(str, end, s, -1, field_width, precision, flags); - } else { - /* print unicode string */ - sw = va_arg(args, wchar_t *); - str = stringw(str, end, sw, -1, field_width, precision, flags); - } - continue; - - case L'S': - if (qualifier == 'l' || qualifier == 'w') { - /* print unicode string */ - sw = va_arg(args, wchar_t *); - str = stringw(str, end, sw, -1, field_width, precision, flags); - } else { - /* print ascii string */ - s = va_arg(args, char *); - str = string(str, end, s, -1, field_width, precision, flags); - } - continue; - - case L'Z': - if (qualifier == 'h') { - /* print counted ascii string */ - PANSI_STRING pus = va_arg(args, PANSI_STRING); - if ((pus == NULL) || (pus->Buffer == NULL)) { - s = NULL; - len = -1; - } else { - s = pus->Buffer; - len = pus->Length; - } - str = string(str, end, s, len, field_width, precision, flags); - } else { - /* print counted unicode string */ - PUNICODE_STRING pus = va_arg(args, PUNICODE_STRING); - if ((pus == NULL) || (pus->Buffer == NULL)) { - sw = NULL; - len = -1; - } else { - sw = pus->Buffer; - len = pus->Length / sizeof(WCHAR); - } - str = stringw(str, end, sw, len, field_width, precision, flags); - } - continue; - - case L'p': - if ((flags & LARGE) == 0) - flags |= LARGE; - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - str = number(str, end, - (ULONG_PTR) va_arg(args, void *), 16, - field_width, precision, flags); - continue; - - case L'n': - /* FIXME: What does C99 say about the overflow case here? */ - if (qualifier == 'l') { - long * ip = va_arg(args, long *); - *ip = (str - buf); - } else { - int * ip = va_arg(args, int *); - *ip = (str - buf); - } - continue; - /* float number formats - set up the flags and "break" */ - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - _double = (double)va_arg(args, double); - - if ( _isnan(_double) ) { - ss = L"Nan"; - len = 3; - while ( len > 0 ) { - if (str <= end) - *str = *ss++; - ++str; - len --; - } - } else if ( _isinf(_double) < 0 ) { - ss = L"-Inf"; - len = 4; - while ( len > 0 ) { - if (str <= end) - *str = *ss++; - ++str; - len --; - } - } else if ( _isinf(_double) > 0 ) { - ss = L"+Inf"; - len = 4; - while ( len > 0 ) { - if (str <= end) - *str = *ss++; - ++str; - len --; - } - } else { - if ( precision == -1 ) - precision = 6; - str = numberf(str, end, _double, base, field_width, precision, flags); - } - - continue; - - - - /* integer number formats - set up the flags and "break" */ - case L'o': - base = 8; - break; - - case L'b': - base = 2; - break; - - case L'X': - flags |= LARGE; - case L'x': - base = 16; - break; - - case L'd': - case L'i': - flags |= SIGN; - case L'u': - break; - - default: - if (*fmt) { - if (str <= end) - *str = *fmt; - ++str; - } else - --fmt; - continue; - } - - if (qualifier == L'I') - num = va_arg(args, unsigned long long); - else if (qualifier == L'l') { - if (flags & SIGN) - num = va_arg(args, long); - else - num = va_arg(args, unsigned long); - } - else if (qualifier == L'h') { - if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } - else { - if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } - str = number(str, end, num, base, field_width, precision, flags); - } - if (str <= end) - *str = L'\0'; - else if (cnt > 0) - /* don't write out a null byte if the buf size is zero */ - *end = L'\0'; - return str-buf; -} - - -/* - * @implemented - */ -int swprintf(wchar_t *buf, const wchar_t *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=_vsnwprintf(buf,MAXLONG,fmt,args); - va_end(args); - return i; -} - - -/* - * @implemented - */ -int __cdecl _snwprintf(wchar_t *buf, size_t cnt, const wchar_t *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=_vsnwprintf(buf,cnt,fmt,args); - va_end(args); - return i; -} - - -/* - * @implemented - */ -int __cdecl vswprintf(wchar_t *buf, const wchar_t *fmt, va_list args) -{ - return _vsnwprintf(buf,MAXLONG,fmt,args); -} - -/* EOF */ -#endif diff --git a/lib/sdk/crt/CMakeLists.txt b/lib/sdk/crt/CMakeLists.txt index f3c3c58ac9d..388e3edfee4 100644 --- a/lib/sdk/crt/CMakeLists.txt +++ b/lib/sdk/crt/CMakeLists.txt @@ -5,7 +5,6 @@ add_definitions(-D_CRTBLD) list(APPEND CRT_SOURCE conio/cgets.c - conio/cprintf.c conio/cputs.c conio/getch.c conio/getche.c @@ -54,6 +53,7 @@ list(APPEND CRT_SOURCE math/ldiv.c math/logf.c math/modf.c + math/powf.c math/rand.c math/sqrtf.c math/s_modf.c @@ -128,6 +128,26 @@ list(APPEND CRT_SOURCE misc/purecall.c misc/stubs.c misc/tls.c + printf/_cprintf.c + printf/_snprintf.c + printf/_snwprintf.c + printf/_vcprintf.c + printf/_vsnprintf.c + printf/_vsnwprintf.c + printf/fprintf.c + printf/fwprintf.c + printf/printf.c + printf/sprintf.c + printf/streamout.c + printf/swprintf.c + printf/vfprintf.c + printf/vfwprintf.c + printf/vprintf.c + printf/vsprintf.c + printf/vswprintf.c + printf/vwprintf.c + printf/wprintf.c + printf/wstreamout.c process/_cwait.c process/_system.c process/dll.c @@ -142,13 +162,15 @@ list(APPEND CRT_SOURCE search/lsearch.c signal/signal.c signal/xcptinfo.c + stdio/_flsbuf.c + stdio/_flswbuf.c stdio/access.c stdio/file.c stdio/find.c stdio/find64.c stdio/findi64.c stdio/fmode.c - stdio/lnx_sprintf.c + stdio/lock_file.c stdio/perror.c stdio/popen.c stdio/stat.c @@ -427,6 +449,18 @@ list(APPEND LIBCNTPR_SOURCE mem/memccpy.c mem/memcmp.c mem/memicmp.c + printf/_snprintf.c + printf/_snwprintf.c + printf/_vcprintf.c + printf/_vsnprintf.c + printf/_vsnwprintf.c + printf/sprintf.c + printf/streamout.c + printf/swprintf.c + printf/vprintf.c + printf/vsprintf.c + printf/vswprintf.c + printf/wstreamout.c search/bsearch.c search/lfind.c stdlib/qsort.c @@ -588,3 +622,16 @@ if(MSVC) add_library(msvcsup ${MSVCSUP_SOURCE}) add_dependencies(msvcsup psdk buildno_header asm) endif() + +add_definitions(-D_USER32_WSPRINTF) +add_library(user32_wsprintf + printf/streamout.c + printf/wstreamout.c + printf/wsprintfA.c + printf/wsprintfW.c + printf/wvsprintfA.c + printf/wvsprintfW.c + printf/wvsnprintfA.c + printf/wvsnprintfW.c + string/mbstowcs_nt.c + string/wcstombs_nt.c) \ No newline at end of file diff --git a/lib/sdk/crt/conio/cprintf.c b/lib/sdk/crt/conio/cprintf.c deleted file mode 100644 index 100e6ae63cf..00000000000 --- a/lib/sdk/crt/conio/cprintf.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * COPYRIGHT: Winehq - * PROJECT: wine - * FILE: msvcrt/conio/cprintf.c - * PURPOSE: C Runtime - * PROGRAMMER: Magnus Olsen (Imported from wine cvs 2006-05-23) - */ -#ifndef USE_NEW_SPRINTF - -#include - -/* - * @implemented - */ -int -_cprintf(const char *fmt, ...) -{ - char buf[2048], *mem = buf; - int written, resize = sizeof(buf), retval; - va_list valist; - - va_start( valist, fmt ); - - while ((written = _vsnprintf( mem, resize, fmt, valist )) == -1 || - written > resize) - { - resize = (written == -1 ? resize * 2 : written + 1); - if (mem != buf) - free (mem); - if (!(mem = (char *)malloc(resize))) - return EOF; - - va_end ( valist ); - va_start( valist, fmt ); - } - va_end ( valist ); - retval = _cputs( mem ); - if (mem != buf) - free (mem); - return retval; -} - -#endif diff --git a/lib/sdk/crt/printf/_snprintf.c b/lib/sdk/crt/printf/_snprintf.c index c8af4898015..061865efe11 100644 --- a/lib/sdk/crt/printf/_snprintf.c +++ b/lib/sdk/crt/printf/_snprintf.c @@ -6,34 +6,7 @@ * PROGRAMMER: Timo Kreuzer */ -#include -#include -#include - -int _cdecl streamout(FILE *stream, const char *format, va_list argptr); - -int -_cdecl -_snprintf(char *buffer, size_t count, const char *format, ...) -{ - va_list argptr; - int result; - FILE stream; - - stream._base = buffer; - stream._ptr = stream._base; - stream._charbuf = 0; - stream._bufsiz = count; - stream._cnt = stream._bufsiz; - stream._flag = 0; - stream._tmpfname = 0; - - va_start(argptr, format); - result = streamout(&stream, format, argptr); - va_end(argptr); - - *stream._ptr = '\0'; - return result; -} - +#define _sxprintf _snprintf +#define USE_COUNT 1 +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/_snwprintf.c b/lib/sdk/crt/printf/_snwprintf.c index 5a4a951d2eb..98ceeb6fdcd 100644 --- a/lib/sdk/crt/printf/_snwprintf.c +++ b/lib/sdk/crt/printf/_snwprintf.c @@ -6,37 +6,8 @@ * PROGRAMMER: Timo Kreuzer */ -#include -#include +#define _sxprintf _snwprintf +#define USE_COUNT 1 +#define _UNICODE -int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr); - -int -__cdecl -_snwprintf( - wchar_t *buffer, - size_t count, - const wchar_t *format, - ...) -{ - va_list argptr; - int result; - FILE stream; - - stream._base = (char*)buffer; - stream._ptr = stream._base; - stream._bufsiz = count * sizeof(wchar_t); - stream._cnt = stream._bufsiz; - stream._flag = _IOSTRG | _IOWRT; - stream._tmpfname = 0; - stream._charbuf = 0; - - va_start(argptr, format); - result = wstreamout(&stream, format, argptr); - va_end(argptr); - - /* Only zero terminate if there is enough space left */ - if (stream._cnt >= sizeof(wchar_t)) *(wchar_t*)stream._ptr = L'\0'; - - return result; -} +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/_sxprintf.c b/lib/sdk/crt/printf/_sxprintf.c new file mode 100644 index 00000000000..0b6c19658fa --- /dev/null +++ b/lib/sdk/crt/printf/_sxprintf.c @@ -0,0 +1,72 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/printf/swprintf.c + * PURPOSE: Implementation of swprintf + * PROGRAMMER: Timo Kreuzer + */ + +#include +#include +#include +#include + +#ifdef _UNICODE +#define _tstreamout wstreamout +#else +#define _tstreamout streamout +#endif + +int _cdecl _tstreamout(FILE *stream, const TCHAR *format, va_list argptr); + +int +#if defined(USER32_WSPRINTF) && defined(_M_IX86) +_stdcall +#else +_cdecl +#endif +_sxprintf( + TCHAR *buffer, +#if USE_COUNT + size_t count, +#endif + const TCHAR *format, +#if USE_VARARGS + va_list argptr) +#else + ...) +#endif +{ +#if !USE_VARARGS + va_list argptr; +#endif + int result; + FILE stream; + + stream._base = (char*)buffer; + stream._ptr = stream._base; + stream._charbuf = 0; +#if USE_COUNT + stream._cnt = count * sizeof(TCHAR); +#else + stream._cnt = INT_MAX; +#endif + stream._bufsiz = 0; + stream._flag = _IOSTRG | _IOWRT; + stream._tmpfname = 0; + +#if !USE_VARARGS + va_start(argptr, format); +#endif + result = _tstreamout(&stream, format, argptr); +#if !USE_VARARGS + va_end(argptr); +#endif + + /* Only zero terminate if there is enough space left */ + if (stream._cnt >= sizeof(TCHAR)) *(TCHAR*)stream._ptr = _T('\0'); + + return result; +} + + diff --git a/lib/sdk/crt/printf/_vsnprintf.c b/lib/sdk/crt/printf/_vsnprintf.c index c94ffc60a8b..0c68887bd99 100644 --- a/lib/sdk/crt/printf/_vsnprintf.c +++ b/lib/sdk/crt/printf/_vsnprintf.c @@ -6,32 +6,8 @@ * PROGRAMMER: Timo Kreuzer */ -#include -#include +#define _sxprintf _vsnprintf +#define USE_COUNT 1 +#define USE_VARARGS 1 -int _cdecl streamout(FILE *stream, const char *format, va_list argptr); - -int -__cdecl -_vsnprintf( - char *buffer, - size_t count, - const char *format, - va_list argptr) -{ - int result; - FILE stream; - - stream._base = buffer; - stream._ptr = stream._base; - stream._bufsiz = count; - stream._cnt = stream._bufsiz; - stream._flag = _IOSTRG | _IOWRT; - stream._tmpfname = 0; - stream._charbuf = 0; - - result = streamout(&stream, format, argptr); - *stream._ptr = '\0'; - - return result; -} +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/_vsnwprintf.c b/lib/sdk/crt/printf/_vsnwprintf.c index 77e12303136..9df26ad8dec 100644 --- a/lib/sdk/crt/printf/_vsnwprintf.c +++ b/lib/sdk/crt/printf/_vsnwprintf.c @@ -6,32 +6,9 @@ * PROGRAMMER: Timo Kreuzer */ -#include -#include +#define _sxprintf _vsnwprintf +#define USE_COUNT 1 +#define USE_VARARGS 1 +#define _UNICODE -int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr); - -int -__cdecl -_vsnwprintf( - wchar_t *buffer, - size_t count, - const wchar_t *format, - va_list argptr) -{ - int result; - FILE stream; - - stream._base = (char*)buffer; - stream._ptr = stream._base; - stream._bufsiz = count * sizeof(wchar_t); - stream._cnt = stream._bufsiz; - stream._flag = _IOSTRG | _IOWRT; - stream._tmpfname = 0; - stream._charbuf = 0; - - result = wstreamout(&stream, format, argptr); - *(wchar_t*)stream._ptr = L'\0'; - - return result; -} +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/printf.c b/lib/sdk/crt/printf/printf.c index a9f83f1046c..467a8be553f 100644 --- a/lib/sdk/crt/printf/printf.c +++ b/lib/sdk/crt/printf/printf.c @@ -22,6 +22,7 @@ printf(const char *format, ...) va_start(argptr, format); result = streamout(stdout, format, argptr); va_end(argptr); + return result; } diff --git a/lib/sdk/crt/printf/sprintf.c b/lib/sdk/crt/printf/sprintf.c index 33c60926c72..2e515c68f57 100644 --- a/lib/sdk/crt/printf/sprintf.c +++ b/lib/sdk/crt/printf/sprintf.c @@ -6,33 +6,7 @@ * PROGRAMMER: Timo Kreuzer */ -#include -#include -#include - -int _cdecl streamout(FILE *stream, const char *format, va_list argptr); - -int -_cdecl -sprintf(char *buffer, const char *format, ...) -{ - va_list argptr; - int result; - FILE stream; - - stream._base = buffer; - stream._ptr = stream._base; - stream._charbuf = 0; - stream._bufsiz = INT_MAX; - stream._cnt = stream._bufsiz; - stream._flag = 0; - stream._tmpfname = 0; - - va_start(argptr, format); - result = streamout(&stream, format, argptr); - va_end(argptr); - - *stream._ptr = '\0'; - return result; -} +#define _sxprintf sprintf +#define USE_COUNT 0 +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/streamout.c b/lib/sdk/crt/printf/streamout.c index ee7755dc626..1aa3e6f4b2c 100644 --- a/lib/sdk/crt/printf/streamout.c +++ b/lib/sdk/crt/printf/streamout.c @@ -14,8 +14,15 @@ #include #ifdef _UNICODE -#define streamout wstreamout -#define format_float format_floatw +# define streamout wstreamout +# define format_float format_floatw +# define _flsbuf _flswbuf +int __cdecl _flswbuf(int ch, FILE *stream); +#endif + +#ifdef _LIBCNT_ +# undef _flsbuf +# define _flsbuf(chr, stream) _TEOF #endif #define MB_CUR_MAX 10 @@ -67,11 +74,10 @@ enum (flags & FLAG_LONGDOUBLE) ? va_arg(argptr, long double) : \ va_arg(argptr, double) -#ifdef _LIBCNT_ -# define _flsbuf(chr, stream) 0 -#endif +#define get_exp(f) floor(f == 0 ? 0 : (f >= 0 ? log10(f) : log10(-f))) +#define round(x) floor((x) + 0.5) -#define get_exp(f) floor(f > 0 ? log10(f) : log10(-f)) +#ifndef _USER32_WSPRINTF void #ifdef _LIBCNT @@ -92,30 +98,56 @@ format_float( static const TCHAR _nan[] = _T("#QNAN"); static const TCHAR _infinity[] = _T("#INF"); const TCHAR *digits = digits_l; - int exponent = 0; - long double fpval; - int num_digits, val32, base = 10; - __int64 val64; + int exponent = 0, sign; + long double fpval, fpval2; + int padding = 0, num_digits, val32, base = 10; + /* Normalize the precision */ if (precision < 0) precision = 6; - else if (precision > 512) precision = 512; + else if (precision > 17) + { + padding = precision - 17; + precision = 17; + } + /* Get the float value and calculate the exponent */ fpval = va_arg_ffp(*argptr, flags); exponent = get_exp(fpval); + sign = fpval < 0 ? -1 : 1; switch (chr) { case _T('G'): digits = digits_u; case _T('g'): + if (precision > 0) precision--; if (exponent < -4 || exponent >= precision) goto case_e; + + /* Shift the decimal point and round */ + fpval2 = round(sign * fpval * pow(10., precision)); + + /* Skip trailing zeroes */ + while (precision && (unsigned __int64)fpval2 % 10 == 0) + { + precision--; + fpval2 /= 10; + } break; case _T('E'): digits = digits_u; case _T('e'): case_e: - fpval /= pow(10., exponent); + /* Shift the decimal point and round */ + fpval2 = round(sign * fpval * pow(10., precision - exponent)); + + /* Compensate for changed exponent through rounding */ + if (fpval2 >= (unsigned __int64)pow(10., precision + 1)) + { + exponent++; + fpval2 = round(sign * fpval * pow(10., precision - exponent)); + } + val32 = exponent >= 0 ? exponent : -exponent; // FIXME: handle length of exponent field: @@ -128,7 +160,7 @@ format_float( } /* Sign for the exponent */ - *--(*string) = exponent > 0 ? _T('+') : _T('-'); + *--(*string) = exponent >= 0 ? _T('+') : _T('-'); /* Add 'e' or 'E' separator */ *--(*string) = digits[0xe]; @@ -141,16 +173,15 @@ format_float( // FIXME: TODO case _T('f'): + default: + /* Shift the decimal point and round */ + fpval2 = round(sign * fpval * pow(10., precision)); break; } - /* CHECKME: Windows seems to handle a max of 17 digits(?) */ - num_digits = precision <= 17 ? precision: 17; - /* Handle sign */ if (fpval < 0) { - fpval = -fpval; *prefix = _T("-"); } else if (flags & FLAG_FORCE_SIGN) @@ -163,46 +194,58 @@ format_float( { (*string) -= sizeof(_nan) / sizeof(TCHAR) - 1; _tcscpy((*string), _nan); - val64 = 1; + fpval2 = 1; } else if (!_finite(fpval)) { (*string) -= sizeof(_infinity) / sizeof(TCHAR) - 1; _tcscpy((*string), _infinity); - val64 = 1; + fpval2 = 1; } else { - fpval *= pow(10., precision); - val64 = (__int64)(fpval + 0.5); + /* Zero padding */ + while (padding-- > 0) *--(*string) = _T('0'); + /* Digits after the decimal point */ + num_digits = precision; while (num_digits-- > 0) { - *--(*string) = digits[val64 % 10]; - val64 /= 10; + *--(*string) = digits[(unsigned __int64)fpval2 % 10]; + fpval2 /= base; } } + if (precision > 0 || flags & FLAG_SPECIAL) *--(*string) = _T('.'); /* Digits before the decimal point */ do { - *--(*string) = digits[val64 % base]; - val64 /= base; + *--(*string) = digits[(unsigned __int64)fpval2 % base]; + fpval2 /= base; } - while (val64); + while ((unsigned __int64)fpval2); } +#endif static int streamout_char(FILE *stream, int chr) { - /* Flush the buffer if neccessary */ + /* Check if the buffer is full */ if (stream->_cnt < sizeof(TCHAR)) { - return _flsbuf(chr, stream) != EOF; +#ifdef _USER32_WSPRINTF + return _TEOF; +#else + /* Strings are done now */ + if (stream->_flag & _IOSTRG) return _TEOF; + + /* Flush buffer for files */ + return _flsbuf(chr, stream) != _TEOF; +#endif } *(TCHAR*)stream->_ptr = chr; @@ -270,6 +313,11 @@ streamout_wstring(FILE *stream, const wchar_t *string, int count) #define streamout_string streamout_astring #endif +#ifdef _USER32_WSPRINTF +# define USE_MULTISIZE 0 +#else +# define USE_MULTISIZE 1 +#endif int _cdecl @@ -363,22 +411,18 @@ streamout(FILE *stream, const TCHAR *format, va_list argptr) else precision = -1; /* Handle argument size prefix */ - while (1) + do { if (chr == _T('h')) flags |= FLAG_SHORT; else if (chr == _T('w')) flags |= FLAG_WIDECHAR; else if (chr == _T('L')) flags |= 0; // FIXME: long double + else if (chr == _T('F')) flags |= 0; // FIXME: what is that? else if (chr == _T('l')) { - flags |= FLAG_LONG; -#if SUPPORT_LL - if (format[0] == _T('l')) - { - format++; - flags |= FLAG_INT64; + /* Check if this is the 2nd 'l' in a row */ + if (format[-2] == 'l') flags |= FLAG_INT64; + else flags |= FLAG_LONG; } -#endif - } else if (chr == _T('I')) { if (format[0] == _T('3') && format[1] == _T('2')) @@ -401,6 +445,7 @@ streamout(FILE *stream, const TCHAR *format, va_list argptr) else break; chr = *format++; } + while (USE_MULTISIZE); /* Handle the format specifier */ digits = digits_l; @@ -479,8 +524,10 @@ streamout(FILE *stream, const TCHAR *format, va_list argptr) else len = strlen((char*)string); if (precision >= 0 && len > precision) len = precision; + precision = 0; break; +#ifndef _USER32_WSPRINTF case _T('G'): case _T('E'): case _T('A'): @@ -498,6 +545,7 @@ streamout(FILE *stream, const TCHAR *format, va_list argptr) len = _tcslen(string); precision = 0; break; +#endif case _T('d'): case _T('i'): @@ -517,9 +565,12 @@ streamout(FILE *stream, const TCHAR *format, va_list argptr) case _T('o'): base = 8; - if (flags & FLAG_SPECIAL) prefix = _T("0"); + if (flags & FLAG_SPECIAL) + { + prefix = _T("0"); + if (precision > 0) precision--; + } goto case_unsigned; - /* Fall through */ case _T('p'): precision = 2 * sizeof(void*); @@ -587,7 +638,7 @@ streamout(FILE *stream, const TCHAR *format, va_list argptr) if (prefix) { written = streamout_string(stream, prefix, prefixlen); - if (written == -1) return -3; + if (written == -1) return -1; written_all += written; } @@ -604,7 +655,7 @@ streamout(FILE *stream, const TCHAR *format, va_list argptr) written = streamout_wstring(stream, (wchar_t*)string, len); else written = streamout_astring(stream, (char*)string, len); - if (written == -1) return -5; + if (written == -1) return -1; written_all += written; #if 0 && SUPPORT_FLOAT @@ -629,7 +680,7 @@ streamout(FILE *stream, const TCHAR *format, va_list argptr) } - if (written == -1) return -8; + if (written == -1) return -1; return written_all; } diff --git a/lib/sdk/crt/printf/swprintf.c b/lib/sdk/crt/printf/swprintf.c index 115c1e6da56..edb8f78584e 100644 --- a/lib/sdk/crt/printf/swprintf.c +++ b/lib/sdk/crt/printf/swprintf.c @@ -6,34 +6,8 @@ * PROGRAMMER: Timo Kreuzer */ -#include -#include -#include - -int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr); - -int -_cdecl -swprintf(wchar_t *buffer, const wchar_t *format, ...) -{ - va_list argptr; - int result; - FILE stream; - - stream._base = (char*)buffer; - stream._ptr = stream._base; - stream._charbuf = 0; - stream._bufsiz = INT_MAX; - stream._cnt = stream._bufsiz; - stream._flag = 0; - stream._tmpfname = 0; - - va_start(argptr, format); - result = wstreamout(&stream, format, argptr); - va_end(argptr); - - *(wchar_t*)stream._ptr = '\0'; - return result; -} - +#define _sxprintf swprintf +#define USE_COUNT 0 +#define _UNICODE +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/vsprintf.c b/lib/sdk/crt/printf/vsprintf.c index 12a3d535835..0f4d4b85bd6 100644 --- a/lib/sdk/crt/printf/vsprintf.c +++ b/lib/sdk/crt/printf/vsprintf.c @@ -6,32 +6,8 @@ * PROGRAMMER: Timo Kreuzer */ -#include -#include -#include +#define _sxprintf vsprintf +#define USE_COUNT 0 +#define USE_VARARGS 1 -int _cdecl streamout(FILE *stream, const char *format, va_list argptr); - -int -__cdecl -vsprintf( - char *buffer, - const char *format, - va_list argptr) -{ - int result; - FILE stream; - - stream._base = buffer; - stream._ptr = stream._base; - stream._charbuf = 0; - stream._bufsiz = INT_MAX; - stream._cnt = stream._bufsiz; - stream._flag = _IOSTRG|_IOWRT|_IOMYBUF; - stream._tmpfname = 0; - - result = streamout(&stream, format, argptr); - *stream._ptr = '\0'; - - return result; -} +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/vswprintf.c b/lib/sdk/crt/printf/vswprintf.c index 4bba6ba3b2c..99502b31ee0 100644 --- a/lib/sdk/crt/printf/vswprintf.c +++ b/lib/sdk/crt/printf/vswprintf.c @@ -6,13 +6,9 @@ * PROGRAMMER: Timo Kreuzer */ -#include -#include -#include +#define _sxprintf vswprintf +#define USE_COUNT 0 +#define USE_VARARGS 1 +#define _UNICODE -int -__cdecl -vswprintf(wchar_t *buffer, const wchar_t *format, va_list argptr) -{ - return _vsnwprintf(buffer, INT_MAX, format, argptr); -} +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/wsprintfA.c b/lib/sdk/crt/printf/wsprintfA.c new file mode 100644 index 00000000000..28379abebd7 --- /dev/null +++ b/lib/sdk/crt/printf/wsprintfA.c @@ -0,0 +1,13 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/printf/wsprintfA.c + * PURPOSE: Implementation of wsprintfA + * PROGRAMMER: Timo Kreuzer + */ + +#define _sxprintf wsprintfA +#define USE_COUNT 0 +#define USER32_WSPRINTF + +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/wsprintfW.c b/lib/sdk/crt/printf/wsprintfW.c new file mode 100644 index 00000000000..0c5076c74d5 --- /dev/null +++ b/lib/sdk/crt/printf/wsprintfW.c @@ -0,0 +1,14 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/printf/wsprintfW.c + * PURPOSE: Implementation of wsprintfW + * PROGRAMMER: Timo Kreuzer + */ + +#define _sxprintf wsprintfW +#define USE_COUNT 0 +#define _UNICODE +#define USER32_WSPRINTF + +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/wvsnprintfA.c b/lib/sdk/crt/printf/wvsnprintfA.c new file mode 100644 index 00000000000..b81d19cd450 --- /dev/null +++ b/lib/sdk/crt/printf/wvsnprintfA.c @@ -0,0 +1,14 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/printf/wvsnprintfA.c + * PURPOSE: Implementation of wvsnprintfA + * PROGRAMMER: Timo Kreuzer + */ + +#define _sxprintf wvsnprintfA +#define USE_COUNT 1 +#define USE_VARARGS 1 +#define USER32_WSPRINTF + +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/wvsnprintfW.c b/lib/sdk/crt/printf/wvsnprintfW.c new file mode 100644 index 00000000000..cd042b1aaba --- /dev/null +++ b/lib/sdk/crt/printf/wvsnprintfW.c @@ -0,0 +1,14 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/printf/wvsnprintfW.c + * PURPOSE: Implementation of wvsnprintfW + * PROGRAMMER: Timo Kreuzer + */ + +#define _sxprintf wvsnprintfW +#define USE_COUNT 1 +#define USE_VARARGS 1 +#define USER32_WSPRINTF + +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/wvsprintfA.c b/lib/sdk/crt/printf/wvsprintfA.c new file mode 100644 index 00000000000..7be026bece5 --- /dev/null +++ b/lib/sdk/crt/printf/wvsprintfA.c @@ -0,0 +1,14 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/printf/wvsprintfA.c + * PURPOSE: Implementation of wvsprintfA + * PROGRAMMER: Timo Kreuzer + */ + +#define _sxprintf wvsprintfA +#define USE_COUNT 0 +#define USE_VARARGS 1 +#define USER32_WSPRINTF + +#include "_sxprintf.c" diff --git a/lib/sdk/crt/printf/wvsprintfW.c b/lib/sdk/crt/printf/wvsprintfW.c new file mode 100644 index 00000000000..bf9ced2a480 --- /dev/null +++ b/lib/sdk/crt/printf/wvsprintfW.c @@ -0,0 +1,14 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/printf/wvsprintfW.c + * PURPOSE: Implementation of wvsprintfW + * PROGRAMMER: Timo Kreuzer + */ + +#define _sxprintf wvsprintfW +#define USE_COUNT 0 +#define USE_VARARGS 1 +#define USER32_WSPRINTF + +#include "_sxprintf.c" diff --git a/lib/sdk/crt/stdio/_flsbuf.c b/lib/sdk/crt/stdio/_flsbuf.c new file mode 100644 index 00000000000..eb31137a7a5 --- /dev/null +++ b/lib/sdk/crt/stdio/_flsbuf.c @@ -0,0 +1,82 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/stdio/_flsbuf.c + * PURPOSE: Implementation of _flsbuf / _flswbuf + * PROGRAMMER: Timo Kreuzer + */ + +#include +#include +#include + +void __cdecl alloc_buffer(FILE *stream); + +int __cdecl +_flsbuf(int ch, FILE *stream) +{ + int count, written; + + /* Check if the stream supports flushing */ + if ((stream->_flag & _IOSTRG) || !(stream->_flag & (_IORW|_IOWRT))) + { + stream->_flag |= _IOERR; + return EOF; + } + + /* Is this was a read buffer */ + if (stream->_flag & _IOREAD) + { + /* Must be at the end of the file */ + if (!(stream->_flag & _IOEOF)) + { + stream->_flag |= _IOERR; + stream->_cnt = 0; + return EOF; + } + + /* Reset buffer */ + stream->_ptr = stream->_base; + } + + /* Fixup flags */ + stream->_flag &= ~(_IOREAD|_IOEOF); + stream->_flag |= _IOWRT; + + /* If we have no buffer, try to allocate one */ + if (!stream->_base && stream != stdout && stream != stderr) + { + alloc_buffer(stream); + } + + /* Check if we have a buffer now */ + if (stream->_base) + { + /* We have one, check if there is something to write */ + count = stream->_ptr - stream->_base; + if (count > 0) + written = _write(stream->_file, stream->_base, count); + else + written = 0; + + /* Reset buffer and put the char into it */ + stream->_ptr = stream->_base + sizeof(TCHAR); + stream->_cnt = stream->_bufsiz - sizeof(TCHAR); + *(TCHAR*)stream->_base = ch; + } + else + { + /* There is no buffer, write the char directly */ + count = sizeof(TCHAR); + written = _write(stream->_file, &ch, sizeof(TCHAR)); + } + + /* Check for failure */ + if (written != count) + { + stream->_flag |= _IOERR; + return EOF; + } + + return ch & (sizeof(TCHAR) > sizeof(char) ? 0xffff : 0xff); +} diff --git a/lib/sdk/crt/stdio/_flswbuf.c b/lib/sdk/crt/stdio/_flswbuf.c new file mode 100644 index 00000000000..83aeca6910a --- /dev/null +++ b/lib/sdk/crt/stdio/_flswbuf.c @@ -0,0 +1,11 @@ +/* + * COPYRIGHT: GNU GPL, see COPYING in the top level directory + * PROJECT: ReactOS crt library + * FILE: lib/sdk/crt/stdio/_flswbuf + * PURPOSE: Implementation of _flswbuf + * PROGRAMMER: Timo Kreuzer + */ + +#define _UNICODE +#define _flsbuf _flswbuf +#include "_flsbuf.c" diff --git a/lib/sdk/crt/stdio/file.c b/lib/sdk/crt/stdio/file.c index eb20be7cf3f..a66da9de9d4 100644 --- a/lib/sdk/crt/stdio/file.c +++ b/lib/sdk/crt/stdio/file.c @@ -88,7 +88,7 @@ int *__p___mb_cur_max(void); typedef struct { HANDLE handle; unsigned char wxflag; - DWORD unkn[7]; /* critical section and init flag */ + DWORD unkn[7]; /* critical section and init flag */ } ioinfo; ioinfo fdesc[MAX_FILES]; @@ -292,12 +292,12 @@ unsigned create_io_inherit_block(WORD *size, BYTE **block) *handle_ptr = INVALID_HANDLE_VALUE; } wxflag_ptr++; handle_ptr++; - } + } return TRUE; } -/* INTERNAL: Set up all file descriptors, - * as well as default streams (stdin, stderr and stdout) +/* INTERNAL: Set up all file descriptors, + * as well as default streams (stdin, stderr and stdout) */ void msvcrt_init_io(void) { @@ -342,7 +342,7 @@ void msvcrt_init_io(void) { #ifndef __REACTOS__ DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE), - GetCurrentProcess(), &fdesc[0].handle, 0, TRUE, + GetCurrentProcess(), &fdesc[0].handle, 0, TRUE, DUPLICATE_SAME_ACCESS); #else fdesc[0].handle = GetStdHandle(STD_INPUT_HANDLE); @@ -355,7 +355,7 @@ void msvcrt_init_io(void) { #ifndef __REACTOS__ DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE), - GetCurrentProcess(), &fdesc[1].handle, 0, TRUE, + GetCurrentProcess(), &fdesc[1].handle, 0, TRUE, DUPLICATE_SAME_ACCESS); #else fdesc[1].handle = GetStdHandle(STD_OUTPUT_HANDLE); @@ -368,7 +368,7 @@ void msvcrt_init_io(void) { #ifndef __REACTOS__ DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE), - GetCurrentProcess(), &fdesc[2].handle, 0, TRUE, + GetCurrentProcess(), &fdesc[2].handle, 0, TRUE, DUPLICATE_SAME_ACCESS); #else fdesc[2].handle = GetStdHandle(STD_ERROR_HANDLE); @@ -409,7 +409,7 @@ static int flush_buffer(FILE* file) } /* INTERNAL: Allocate stdio file buffer */ -static void alloc_buffer(FILE* file) +void alloc_buffer(FILE* file) { file->_base = calloc(BUFSIZ,1); if(file->_base) { @@ -722,7 +722,7 @@ int CDECL _dup2(int od, int nd) int CDECL _dup(int od) { int fd, ret; - + LOCK_FILES(); fd = fdstart; if (_dup2(od, fd) == 0) @@ -1393,7 +1393,7 @@ int CDECL _sopen( const char *path, int oflags, int shflags, ... ) else creation = OPEN_EXISTING; } - + switch( shflags ) { case _SH_DENYRW: @@ -2030,12 +2030,12 @@ wint_t CDECL fgetwc(FILE* file) wcp = (char *)&wc; for(i=0; i_cnt>0) + if (file->_cnt>0) { file->_cnt--; chp = file->_ptr++; wcp[i] = *chp; - } + } else { j = _filbuf(file); @@ -2050,7 +2050,7 @@ wint_t CDECL fgetwc(FILE* file) } return wc; } - + c = fgetc(file); if ((*__p___mb_cur_max() > 1) && isleadbyte(c)) { @@ -2290,37 +2290,6 @@ int CDECL fputc(int c, FILE* file) } } -/********************************************************************* - * _flsbuf (MSVCRT.@) - */ -int CDECL _flsbuf(int c, FILE* file) -{ - /* Flush output buffer */ - if(file->_bufsiz == 0 && !(file->_flag & _IONBF)) { - alloc_buffer(file); - } - if(!(file->_flag & _IOWRT)) { - if(file->_flag & _IORW) { - file->_flag |= _IOWRT; - } else { - return EOF; - } - } - if(file->_bufsiz) { - int res=flush_buffer(file); - return res?res : fputc(c, file); - } else { - unsigned char cc=c; - int len; - /* set _cnt to 0 for unbuffered FILEs */ - file->_cnt = 0; - len = _write(file->_file, &cc, 1); - if (len == 1) return c & 0xff; - file->_flag |= _IOERR; - return EOF; - } -} - /********************************************************************* * _fputchar (MSVCRT.@) */ @@ -2487,7 +2456,7 @@ int CDECL fsetpos(FILE* file, const fpos_t *pos) /* Discard buffered input */ file->_cnt = 0; file->_ptr = file->_base; - + /* Reset direction of i/o */ if(file->_flag & _IORW) { file->_flag &= ~(_IOREAD|_IOWRT); @@ -2560,7 +2529,7 @@ int CDECL fputs(const char *s, FILE* file) if (!(fdesc[file->_file].wxflag & WX_TEXT)) return fwrite(s,sizeof(*s),len,file) == len ? 0 : EOF; for (i=0; i resize) - { - resize = (written == -1 ? resize * 2 : written + 1); - if (mem != buf) - free (mem); - if (!(mem = malloc(resize))) - return EOF; - } - retval = fwrite(mem, sizeof(*mem), written, file); - if (mem != buf) - free (mem); - return retval; -} - -/********************************************************************* - * vfwprintf (MSVCRT.@) - * FIXME: - * Is final char included in written (then resize is too big) or not - * (then we must test for equality too)? - */ -int CDECL vfwprintf(FILE* file, const wchar_t *format, va_list valist) -{ - wchar_t buf[2048], *mem = buf; - int written, resize = sizeof(buf) / sizeof(wchar_t), retval; - /* See vfprintf comments */ - while ((written = _vsnwprintf(mem, resize, format, valist)) == -1 || - written > resize) - { - resize = (written == -1 ? resize * 2 : written + sizeof(wchar_t)); - if (mem != buf) - free (mem); - if (!(mem = malloc(resize*sizeof(*mem)))) - return EOF; - } - - /* Check if outputting to a text-file */ - if (fdesc[file->_file].wxflag & WX_TEXT) - { - /* Convert each character and stop at the first invalid character. Behavior verified by tests under WinXP SP2 */ - char chMultiByte[MB_LEN_MAX]; - int nReturn; - wchar_t *p; - - retval = 0; - - for (p = mem; *p; p++) - { - nReturn = wctomb(chMultiByte, *p); - - if(nReturn == -1) - break; - - retval += fwrite(chMultiByte, 1, nReturn, file); - } - } - else - { - retval = fwrite(mem, sizeof(*mem), written, file); - } - - if (mem != buf) - free (mem); - - return retval; -} - -/********************************************************************* - * vprintf (MSVCRT.@) - */ -int CDECL vprintf(const char *format, va_list valist) -{ - return vfprintf(stdout,format,valist); -} - -/********************************************************************* - * vwprintf (MSVCRT.@) - */ -int CDECL vwprintf(const wchar_t *format, va_list valist) -{ - return vfwprintf(stdout,format,valist); -} - -/********************************************************************* - * fprintf (MSVCRT.@) - */ -int CDECL fprintf(FILE* file, const char *format, ...) -{ - va_list valist; - int res; - va_start(valist, format); - res = vfprintf(file, format, valist); - va_end(valist); - return res; -} - -/********************************************************************* - * fwprintf (MSVCRT.@) - */ -int CDECL fwprintf(FILE* file, const wchar_t *format, ...) -{ - va_list valist; - int res; - va_start(valist, format); - res = vfwprintf(file, format, valist); - va_end(valist); - return res; -} - -/********************************************************************* - * printf (MSVCRT.@) - */ -int CDECL printf(const char *format, ...) -{ - va_list valist; - int res; - va_start(valist, format); - res = vfprintf(stdout, format, valist); - va_end(valist); - return res; -} -#endif - /********************************************************************* * ungetc (MSVCRT.@) */ @@ -2986,21 +2819,6 @@ wint_t CDECL ungetwc(wint_t wc, FILE * file) return mwc; } -#ifndef USE_NEW_SPRINTF -/********************************************************************* - * wprintf (MSVCRT.@) - */ -int CDECL wprintf(const wchar_t *format, ...) -{ - va_list valist; - int res; - va_start(valist, format); - res = vwprintf(format, valist); - va_end(valist); - return res; -} -#endif - /********************************************************************* * _getmaxstdio (MSVCRT.@) */ diff --git a/lib/sdk/crt/stdio/lnx_sprintf.c b/lib/sdk/crt/stdio/lnx_sprintf.c deleted file mode 100644 index 29d150d68e5..00000000000 --- a/lib/sdk/crt/stdio/lnx_sprintf.c +++ /dev/null @@ -1,882 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PURPOSE: CRT's vsnprintf - * FILE: lib/sdk/crt/stdio/lnx_printf.c - * PROGRAMERS: David Welch - Eric Kohl - Gregor Schneider - * TODO: - * - Verify the implementation of '%Z'. - */ - -/* - * Parts from linux/lib/vsprintf.c - * Lars Wirzenius & Linus Torvalds - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ -#ifndef USE_NEW_SPRINTF -#include - -#include -#include - -#define ZEROPAD 1 /* pad with zero */ -#define SIGN 2 /* unsigned/signed */ -#define PLUS 4 /* show plus */ -#define SPACE 8 /* space if plus */ -#define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ -#define ZEROTRUNC 128 /* truncate zero's */ -#define REMOVEHEX 256 /* remove 0x from BASE 16 */ - -static -__inline -int -do_div(long long *n, int base) -{ - int a; - a = ((unsigned long long) *n) % (unsigned) base; - *n = ((unsigned long long) *n) / (unsigned) base; - return a; -} - - -static int skip_atoi(const char **s) -{ - int i=0; - - while (isdigit(**s)) - i = i*10 + *((*s)++) - '0'; - return i; -} - - -static char * -number(char * buf, char * end, long long num, int base, int size, int precision, int type) -{ - char c,sign,tmp[66]; - const char *digits; - const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz"; - const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - int i; - - digits = (type & LARGE) ? large_digits : small_digits; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = '-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = '+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - - if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) { - if (base == 16) - size -= 2; - } - i = 0; - if ((num == 0) && (precision !=0)) - tmp[i++] = '0'; - else while (num != 0) - tmp[i++] = digits[do_div(&num,base)]; - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) { - while(size-->0) { - if (buf <= end) - *buf = ' '; - ++buf; - } - } - if (sign) { - if (buf <= end) - *buf = sign; - ++buf; - } - - if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) { - if (base==16) { - if (buf <= end) - *buf = '0'; - ++buf; - if (buf <= end) - *buf = digits[33]; - ++buf; - } - } - - if (!(type & LEFT)) { - while (size-- > 0) { - if (buf <= end) - *buf = c; - ++buf; - } - } - while (i < precision--) { - if (buf <= end) - *buf = '0'; - ++buf; - } - while (i-- > 0) { - if (buf <= end) - *buf = tmp[i]; - ++buf; - } - while (size-- > 0) { - if (buf <= end) - *buf = ' '; - ++buf; - } - - return buf; -} - -typedef struct { - unsigned int mantissal:32; - unsigned int mantissah:20; - unsigned int exponent:11; - unsigned int sign:1; -} ieee_double_t; - -static __inline void fracrnd(double *number, int prec) -{ - /* Shifts fractional digits to decimal places and compares to round table */ - /* Only suitable to determine the exponent with more precision, not for normal rounding */ - /* Incoming numbers are expected to range from approx -10.0 to 10.0 */ - int lpos = 1, ubound, sign = 1; - long decimal = abs((long)*number); - double frac = (*number - decimal) * 10; - long rt[] = - { - 0, - 9, - 99, - 999, - 9999, - 99999, - 999999, - 9999999, - 99999999, - 999999999 - }; - - if (*number < 0) - { - sign = -1; - } - ubound = min(prec, sizeof(rt)/sizeof(*rt) - 1); - while ((long)frac % 10 != 0 && lpos < ubound) - { - frac *= 10; - lpos++; - } - if (abs((long)frac) == rt[lpos]) - { - *number = sign * (decimal + 1); - } -} - -static char * -numberf(char * buf, char * end, double num, char exp_sign, int size, int precision, int type) -{ - double exponent = 0.0; - double e = 0.0; - long ie; - - int i = 0; - int j = 0; - int ro = 0; - int isize; - - double num2, frac, intr; - double p; - - char c, sign, digits[66]; - char *tmp; - - union - { - double* __n; - ieee_double_t* n; - } n; - - n.__n = # - - if ( exp_sign == 'g' || exp_sign == 'G' || exp_sign == 'e' || exp_sign == 'E' ) - { - ie = ((unsigned int)n.n->exponent - (unsigned int)0x3ff); - if (num != 0.0) - { - exponent = ie/3.321928; - } - } - - if ( exp_sign == 'g' || exp_sign == 'G' ) - { - type |= ZEROTRUNC; - if ( exponent < -4 || fabs(exponent) >= precision ) - exp_sign -= 2; // g -> e and G -> E - else - exp_sign = 'f'; - if (type & SPECIAL) precision--; - } - - if ( exp_sign == 'e' || exp_sign == 'E' ) - { - if (num != 0.0) - { - /* Find a suitable exponent */ - frac = modf(exponent, &e); - num2 = num/pow(10.0L, (long double)e); - /* Check if rounding is possible */ - fracrnd(&num2, precision); - if (num2 < 1.0 && num2 > -1.0) - { - e--; - } - else if (num2 <= -10.0 || num2 >= 10.0) - { - e++; - } - } - - /* size-5 because "e+abc" is going to follow */ - buf = numberf(buf, end, num/pow(10.0L,(long double)e), 'f', size-5, precision, type); - isize = 4; - while(*(buf-1) == ' ') - { - isize++; - --buf; - } - - if (buf <= end) - *buf = exp_sign; - ++buf; - size--; - - ie = (long)e; - type = LEFT | SIGN | PLUS; - buf = number(buf, end, ie, 10, isize, 3, type); - return buf; - } - - if ( exp_sign == 'f' ) - { - if (type & LEFT) - type &= ~ZEROPAD; - - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - - if (num < 0) - { - sign = '-'; - num = fabs(num); - size--; - } - else if (type & PLUS) - { - sign = '+'; - size--; - } - else if (type & SPACE) - { - sign = ' '; - size--; - } - - frac = modf(num,&intr); - - // # flags forces a . and prevents truncation of trailing zero's - if ( precision > 0 ) - { - i = precision-1; - while ( i >= 0 ) - { - frac*=10.0L; - frac = modf(frac, &p); - digits[i] = (int)p + '0'; - i--; - } - - i = precision; - size -= precision; - } - - if ( precision >= 1 || type & SPECIAL) - { - digits[i++] = '.'; - size--; - } - - ro = 0; - if ( frac > 0.5 ) - { - ro = 1; - } - - if ( intr == 0.0 ) - { - digits[i++] = '0'; - size--; - } - else - { - while ( intr > 0.0 ) - { - p = intr; - intr/=10.0L; - modf(intr, &intr); - - p -= 10.0*intr; - - digits[i++] = (int)p + '0'; - size--; - } - } - - j = 0; - while ( j < i && ro == 1) - { - if ( digits[j] >= '0' && digits[j] <= '8' ) - { - digits[j]++; - ro = 0; - } - else if ( digits[j] == '9' ) - { - digits[j] = '0'; - } - j++; - } - if ( ro == 1 ) - digits[i++] = '1'; - - digits[i] = 0; - - if (!(type & (ZEROPAD+LEFT))) - { - while(size-->0) - { - if (buf <= end) - *buf = ' '; - ++buf; - } - } - if (sign) - { - if (buf <= end) - *buf = sign; - ++buf; - } - - if (!(type & (ZEROPAD+LEFT))) - { - while(size-->0) - { - if (buf <= end) - *buf = ' '; - ++buf; - } - } - - if (!(type & LEFT)) - { - while (size-- > 0) - { - if (buf <= end) - *buf = c; - ++buf; - } - } - - tmp = digits; - if ( type & ZEROTRUNC && ((type & SPECIAL) != SPECIAL) ) - { - j = 0; - while ( j < i && ( *tmp == '0' || *tmp == '.' )) - { - tmp++; - i--; - } - } - while (i-- > 0) - { - if (buf <= end) - *buf = tmp[i]; - ++buf; - } - while (size-- > 0) - { - if (buf <= end) - *buf = ' '; - buf++; - } - } - return buf; -} - -static char* -string(char* buf, char* end, const char* s, int len, int field_width, int precision, int flags) -{ - int i; - char c; - - c = (flags & ZEROPAD) ? '0' : ' '; - - if (s == NULL) - { - s = ""; - len = 6; - } - else - { - if (len == -1) - { - len = 0; - while ((unsigned int)len < (unsigned int)precision && s[len]) - len++; - } - else - { - if ((unsigned int)len > (unsigned int)precision) - len = precision; - } - } - if (!(flags & LEFT)) - while (len < field_width--) - { - if (buf <= end) - *buf = c; - ++buf; - } - for (i = 0; i < len; ++i) - { - if (buf <= end) - *buf = *s++; - ++buf; - } - while (len < field_width--) - { - if (buf <= end) - *buf = ' '; - ++buf; - } - return buf; -} - -static char* -stringw(char* buf, char* end, const wchar_t* sw, int len, int field_width, int precision, int flags) -{ - int i; - char c; - - c = (flags & ZEROPAD) ? '0' : ' '; - - if (sw == NULL) - { - sw = L""; - len = 6; - } - else - { - if (len == -1) - { - len = 0; - while ((unsigned int)len < (unsigned int)precision && sw[len]) - len++; - } - else - { - if ((unsigned int)len > (unsigned int)precision) - len = precision; - } - } - if (!(flags & LEFT)) - while (len < field_width--) - { - if (buf <= end) - *buf = c; - buf++; - } - for (i = 0; i < len; ++i) - { - if (buf <= end) - *buf = (unsigned char)(*sw++); - buf++; - } - while (len < field_width--) - { - if (buf <= end) - *buf = ' '; - buf++; - } - return buf; -} - -/* - * @implemented - */ -int __cdecl lnx_vsnprintf(char *buf, size_t cnt, const char *fmt, va_list args) -{ - int len; - unsigned long long num; - double _double; - - int base; - char *str, *end; - const char *s; - const wchar_t *sw; - - int flags; /* flags to number() */ - - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max - number of chars for from string */ - int qualifier; /* 'h', 'l', 'L', 'I' or 'w' for integer fields */ - - str = buf; - end = buf + cnt - 1; - if (end < buf - 1) { - end = ((char *) -1); - cnt = end - buf + 1; - } - - for ( ; *fmt ; ++fmt) { - if (*fmt != '%') { - if (str <= end) - *str = *fmt; - ++str; - continue; - } - - /* process flags */ - flags = 0; -repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; - } - - /* get field width */ - field_width = -1; - if (isdigit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if (field_width < 0) { - field_width = -field_width; - flags |= LEFT; - } - } - - /* get the precision */ - precision = -1; - if (*fmt == '.') { - ++fmt; - if (isdigit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if (precision < 0) - precision = 0; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'w') { - qualifier = *fmt; - ++fmt; - } else if (*fmt == 'I' && *(fmt+1) == '6' && *(fmt+2) == '4') { - qualifier = *fmt; - fmt += 3; - } else if (*fmt == 'I' && *(fmt+1) == '3' && *(fmt+2) == '2') { - qualifier = 'l'; - fmt += 3; - } else if (*fmt == 'F' && *(fmt+1) == 'p') { - fmt += 1; - flags |= REMOVEHEX; - } - - /* default base */ - base = 10; - - switch (*fmt) { - case 'c': /* finished */ - if (qualifier == 'l' || qualifier == 'w') { - wchar_t sw1[2]; - /* print unicode string */ - sw1[0] = (wchar_t) va_arg(args, int); - sw1[1] = 0; - str = stringw(str, end, (wchar_t *)&sw1, -1, field_width, precision, flags); - } else { - char s1[2]; - /* print ascii string */ - s1[0] = ( unsigned char) va_arg(args, int); - s1[1] = 0; - str = string(str, end, (char *)&s1, -1, field_width, precision, flags); - } - continue; - - case 'C': /* finished */ - if (!(flags & LEFT)) - while (--field_width > 0) { - if (str <= end) - *str = ' '; - ++str; - } - if (qualifier == 'h') { - if (str <= end) - *str = (unsigned char) va_arg(args, int); - ++str; - } else { - if (str <= end) - *str = (unsigned char)(wchar_t) va_arg(args, int); - ++str; - } - while (--field_width > 0) { - if (str <= end) - *str = ' '; - ++str; - } - continue; - - case 's': /* finished */ - if (qualifier == 'l' || qualifier == 'w') { - /* print unicode string */ - sw = va_arg(args, wchar_t *); - str = stringw(str, end, sw, -1, field_width, precision, flags); - } else { - /* print ascii string */ - s = va_arg(args, char *); - str = string(str, end, s, -1, field_width, precision, flags); - } - continue; - - case 'S': - if (qualifier == 'h') { - /* print ascii string */ - s = va_arg(args, char *); - str = string(str, end, s, -1, field_width, precision, flags); - } else { - /* print unicode string */ - sw = va_arg(args, wchar_t *); - str = stringw(str, end, sw, -1, field_width, precision, flags); - } - continue; - - case 'Z': - if (qualifier == 'w') { - /* print counted unicode string */ - PUNICODE_STRING pus = va_arg(args, PUNICODE_STRING); - if ((pus == NULL) || (pus->Buffer == NULL)) { - sw = NULL; - len = -1; - } else { - sw = pus->Buffer; - len = pus->Length / sizeof(WCHAR); - } - str = stringw(str, end, sw, len, field_width, precision, flags); - } else { - /* print counted ascii string */ - PANSI_STRING pus = va_arg(args, PANSI_STRING); - if ((pus == NULL) || (pus->Buffer == NULL)) { - s = NULL; - len = -1; - } else { - s = pus->Buffer; - len = pus->Length; - } - str = string(str, end, s, len, field_width, precision, flags); - } - continue; - - case 'p': - if ((flags & LARGE) == 0) - flags |= LARGE; - - if (field_width == -1) { - field_width = 2 * sizeof(void *); - flags |= ZEROPAD; - } - str = number(str, end, - (uintptr_t) va_arg(args, void *), 16, - field_width, precision, flags); - continue; - - case 'n': - /* FIXME: What does C99 say about the overflow case here? */ - if (qualifier == 'l') { - long * ip = va_arg(args, long *); - *ip = (str - buf); - } else { - int * ip = va_arg(args, int *); - *ip = (str - buf); - } - continue; - - /* float number formats - set up the flags and "break" */ - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - _double = (double)va_arg(args, double); - if ( _isnan(_double) ) { - s = "Nan"; - len = 3; - while ( len > 0 ) { - if (str <= end) - *str = *s++; - ++str; - len --; - } - } else if ( _isinf(_double) < 0 ) { - s = "-Inf"; - len = 4; - while ( len > 0 ) { - if (str <= end) - *str = *s++; - ++str; - len --; - } - } else if ( _isinf(_double) > 0 ) { - s = "+Inf"; - len = 4; - while ( len > 0 ) { - if (str <= end) - *str = *s++; - ++str; - len --; - } - } else { - if ( precision == -1 ) - precision = 6; - str = numberf(str, end, _double, *fmt, field_width, precision, flags); - } - continue; - - /* integer number formats - set up the flags and "break" */ - case 'o': - base = 8; - break; - - case 'b': - base = 2; - break; - - case 'X': - flags |= LARGE; - case 'x': - base = 16; - break; - - case 'd': - case 'i': - flags |= SIGN; - case 'u': - break; - - default: - if (*fmt) { - if (str <= end) - *str = *fmt; - ++str; - } else - --fmt; - continue; - } - - if (qualifier == 'I') - num = va_arg(args, unsigned long long); - else if (qualifier == 'l') { - if (flags & SIGN) - num = va_arg(args, long); - else - num = va_arg(args, unsigned long); - } - else if (qualifier == 'h') { - if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } - else { - if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } - str = number(str, end, num, base, field_width, precision, flags); - } - if (str <= end) - *str = '\0'; - else if (cnt > 0) - /* don't write out a null byte if the buf size is zero */ - *end = '\0'; - return str-buf; -} - - -/* - * @implemented - */ -int lnx_sprintf(char * buf, const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=lnx_vsnprintf(buf,MAXLONG,fmt,args); - va_end(args); - return i; -} - -#if 0 -/* - * @implemented - */ -int _snprintf(char * buf, size_t cnt, const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=_vsnprintf(buf,cnt,fmt,args); - va_end(args); - return i; -} - - -/* - * @implemented - */ -int __cdecl vsprintf(char *buf, const char *fmt, va_list args) -{ - return _vsnprintf(buf,MAXLONG,fmt,args); -} -#endif -/* EOF */ -#endif diff --git a/lib/sdk/crt/stdlib/ecvt.c b/lib/sdk/crt/stdlib/ecvt.c index 948ee2c50ce..eaba52c7e62 100644 --- a/lib/sdk/crt/stdlib/ecvt.c +++ b/lib/sdk/crt/stdlib/ecvt.c @@ -18,6 +18,7 @@ _ecvt (double value, int ndigits, int *decpt, int *sign) static char ecvtbuf[DBL_MAX_10_EXP + 10]; char *cvtbuf, *s, *d; + if (ndigits < 0) ndigits = 0; s = cvtbuf = (char*)malloc(ndigits + NUMBER_EFMT); d = ecvtbuf; diff --git a/lib/sdk/crt/string/strtoull.c b/lib/sdk/crt/string/strtoull.c index b3f4b476114..3a2553afbbb 100644 --- a/lib/sdk/crt/string/strtoull.c +++ b/lib/sdk/crt/string/strtoull.c @@ -54,6 +54,9 @@ strtoull(const char *nptr, char **endptr, int base) if (any < 0) { acc = ULLONG_MAX; +#ifndef _LIBCNT_ + __set_errno(ERANGE); +#endif } else if (neg) acc = -acc; diff --git a/lib/sdk/crt/string/wcs.c b/lib/sdk/crt/string/wcs.c index e2f2a6af612..dcef8c4cca5 100644 --- a/lib/sdk/crt/string/wcs.c +++ b/lib/sdk/crt/string/wcs.c @@ -213,677 +213,6 @@ double CDECL wcstod(const wchar_t* lpszStr, wchar_t** end) TRACE("returning %g\n", ret); return ret; } - -typedef struct pf_output_t -{ - int used; - int len; - BOOL unicode; - union { - LPWSTR W; - LPSTR A; - } buf; -} pf_output; - -typedef struct pf_flags_t -{ - char Sign, LeftAlign, Alternate, PadZero; - int FieldLength, Precision; - char IntegerLength, IntegerDouble; - char WideString; - char Format; -} pf_flags; - -/* - * writes a string of characters to the output - * returns -1 if the string doesn't fit in the output buffer - * return the length of the string if all characters were written - */ -static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len ) -{ - int space = out->len - out->used; - - if( len < 0 ) - len = strlenW( str ); - if( out->unicode ) - { - LPWSTR p = out->buf.W + out->used; - - if( space >= len ) - { - memcpy( p, str, len*sizeof(WCHAR) ); - out->used += len; - return len; - } - if( space > 0 ) - memcpy( p, str, space*sizeof(WCHAR) ); - out->used += len; - } - else - { - int n = WideCharToMultiByte( CP_ACP, 0, str, len, NULL, 0, NULL, NULL ); - LPSTR p = out->buf.A + out->used; - - if( space >= n ) - { - WideCharToMultiByte( CP_ACP, 0, str, len, p, n, NULL, NULL ); - out->used += n; - return len; - } - if( space > 0 ) - WideCharToMultiByte( CP_ACP, 0, str, len, p, space, NULL, NULL ); - out->used += n; - } - return -1; -} - -static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len ) -{ - int space = out->len - out->used; - - if( len < 0 ) - len = strlen( str ); - if( !out->unicode ) - { - LPSTR p = out->buf.A + out->used; - - if( space >= len ) - { - memcpy( p, str, len ); - out->used += len; - return len; - } - if( space > 0 ) - memcpy( p, str, space ); - out->used += len; - } - else - { - int n = MultiByteToWideChar( CP_ACP, 0, str, len, NULL, 0 ); - LPWSTR p = out->buf.W + out->used; - - if( space >= n ) - { - MultiByteToWideChar( CP_ACP, 0, str, len, p, n ); - out->used += n; - return len; - } - if( space > 0 ) - MultiByteToWideChar( CP_ACP, 0, str, len, p, space ); - out->used += n; - } - return -1; -} - -/* pf_fill: takes care of signs, alignment, zero and field padding */ -static inline int pf_fill( pf_output *out, int len, pf_flags *flags, char left ) -{ - int i, r = 0; - - if( flags->Sign && !( flags->Format == 'd' || flags->Format == 'i' ) ) - flags->Sign = 0; - - if( left && flags->Sign ) - { - flags->FieldLength--; - if( flags->PadZero ) - r = pf_output_stringA( out, &flags->Sign, 1 ); - } - - if( ( !left && flags->LeftAlign ) || - ( left && !flags->LeftAlign )) - { - for( i=0; (i<(flags->FieldLength-len)) && (r>=0); i++ ) - { - if( left && flags->PadZero ) - r = pf_output_stringA( out, "0", 1 ); - else - r = pf_output_stringA( out, " ", 1 ); - } - } - - if( left && flags->Sign && !flags->PadZero ) - r = pf_output_stringA( out, &flags->Sign, 1 ); - - return r; -} - -static inline int pf_output_format_W( pf_output *out, LPCWSTR str, - int len, pf_flags *flags ) -{ - int r = 0; - - if( len < 0 ) - len = strlenW( str ); - - if (flags->Precision >= 0 && flags->Precision < len) - len = flags->Precision; - - r = pf_fill( out, len, flags, 1 ); - - if( r>=0 ) - r = pf_output_stringW( out, str, len ); - - if( r>=0 ) - r = pf_fill( out, len, flags, 0 ); - - return r; -} - -static inline int pf_output_format_A( pf_output *out, LPCSTR str, - int len, pf_flags *flags ) -{ - int r = 0; - - if( len < 0 ) - len = strlen( str ); - - if (flags->Precision >= 0 && flags->Precision < len) - len = flags->Precision; - - r = pf_fill( out, len, flags, 1 ); - - if( r>=0 ) - r = pf_output_stringA( out, str, len ); - - if( r>=0 ) - r = pf_fill( out, len, flags, 0 ); - - return r; -} - -#ifndef USE_NEW_SPRINTF -static int pf_handle_string_format( pf_output *out, const void* str, int len, - pf_flags *flags, BOOL capital_letter) -{ - if(str == NULL) /* catch NULL pointer */ - return pf_output_format_A( out, "(null)", -1, flags); - - /* prefixes take priority over %c,%s vs. %C,%S, so we handle them first */ - if(flags->WideString || flags->IntegerLength == 'l') - return pf_output_format_W( out, str, len, flags); - if(flags->IntegerLength == 'h') - return pf_output_format_A( out, str, len, flags); - - /* %s,%c -> chars in ansi functions & wchars in unicode - * %S,%C -> wchars in ansi functions & chars in unicode */ - if( capital_letter == out->unicode) /* either both TRUE or both FALSE */ - return pf_output_format_A( out, str, len, flags); - else - return pf_output_format_W( out, str, len, flags); -} - -static inline BOOL pf_is_integer_format( char fmt ) -{ - static const char float_fmts[] = "diouxX"; - if (!fmt) - return FALSE; - return strchr( float_fmts, fmt ) ? TRUE : FALSE; -} - -static inline BOOL pf_is_double_format( char fmt ) -{ - static const char float_fmts[] = "aeEfgG"; - if (!fmt) - return FALSE; - return strchr( float_fmts, fmt ) ? TRUE : FALSE; -} - -static inline BOOL pf_is_valid_format( char fmt ) -{ - static const char float_fmts[] = "acCdeEfgGinouxX"; - if (!fmt) - return FALSE; - return strchr( float_fmts, fmt ) ? TRUE : FALSE; -} - -static void pf_rebuild_format_string( char *p, pf_flags *flags ) -{ - *p++ = '%'; - if( flags->Sign ) - *p++ = flags->Sign; - if( flags->LeftAlign ) - *p++ = flags->LeftAlign; - if( flags->Alternate ) - *p++ = flags->Alternate; - if( flags->PadZero ) - *p++ = flags->PadZero; - if( flags->FieldLength ) - { - lnx_sprintf(p, "%d", flags->FieldLength); - p += strlen(p); - } - if( flags->Precision >= 0 ) - { - lnx_sprintf(p, ".%d", flags->Precision); - p += strlen(p); - } - *p++ = flags->Format; - *p++ = 0; -} - -/* pf_integer_conv: prints x to buf, including alternate formats and - additional precision digits, but not field characters or the sign */ -static void pf_integer_conv( char *buf, unsigned int buf_len, pf_flags *flags, - LONGLONG x ) -{ - unsigned int base; - const char *digits; - - int i, j, k; - char number[40], *tmp = number; - - if( buf_len > sizeof number ) - tmp = HeapAlloc( GetProcessHeap(), 0, buf_len ); - - base = 10; - if( flags->Format == 'o' ) - base = 8; - else if( flags->Format == 'x' || flags->Format == 'X' ) - base = 16; - - if( flags->Format == 'X' ) - digits = "0123456789ABCDEFX"; - else - digits = "0123456789abcdefx"; - - if( x < 0 && ( flags->Format == 'd' || flags->Format == 'i' ) ) - { - x = -x; - flags->Sign = '-'; - } - - /* Do conversion (backwards) */ - i = 0; - if( x == 0 && flags->Precision ) - tmp[i++] = '0'; - else - while( x != 0 ) - { - j = (ULONGLONG) x % base; - x = (ULONGLONG) x / base; - tmp[i++] = digits[j]; - } - k = flags->Precision - i; - while( k-- > 0 ) - tmp[i++] = '0'; - if( flags->Alternate ) - { - if( base == 16 ) - { - tmp[i++] = digits[16]; - tmp[i++] = '0'; - } - else if( base == 8 && tmp[i-1] != '0' ) - tmp[i++] = '0'; - } - - /* Reverse for buf */ - j = 0; - while( i-- > 0 ) - buf[j++] = tmp[i]; - buf[j] = '\0'; - - /* Adjust precision so pf_fill won't truncate the number later */ - flags->Precision = strlen( buf ); - - if( tmp != number ) - HeapFree( GetProcessHeap(), 0, tmp ); - - return; -} - -/********************************************************************* - * pf_vsnprintf (INTERNAL) - * - * implements both A and W vsnprintf functions - */ -static int pf_vsnprintf( pf_output *out, const WCHAR *format, va_list valist ) -{ - int r; - LPCWSTR q, p = format; - pf_flags flags; - - TRACE("format is %s\n",debugstr_w(format)); - while (*p) - { - q = strchrW( p, '%' ); - - /* there's no % characters left, output the rest of the string */ - if( !q ) - { - r = pf_output_stringW(out, p, -1); - if( r<0 ) - return r; - p += r; - continue; - } - - /* there's characters before the %, output them */ - if( q != p ) - { - r = pf_output_stringW(out, p, q - p); - if( r<0 ) - return r; - p = q; - } - - /* we must be at a % now, skip over it */ - assert( *p == '%' ); - p++; - - /* output a single % character */ - if( *p == '%' ) - { - r = pf_output_stringW(out, p++, 1); - if( r<0 ) - return r; - continue; - } - - /* parse the flags */ - memset( &flags, 0, sizeof flags ); - while (*p) - { - if( *p == '+' || *p == ' ' ) - { - if ( flags.Sign != '+' ) - flags.Sign = *p; - } - else if( *p == '-' ) - flags.LeftAlign = *p; - else if( *p == '0' ) - flags.PadZero = *p; - else if( *p == '#' ) - flags.Alternate = *p; - else - break; - p++; - } - - /* deal with the field width specifier */ - flags.FieldLength = 0; - if( *p == '*' ) - { - flags.FieldLength = va_arg( valist, int ); - if (flags.FieldLength < 0) - { - flags.LeftAlign = '-'; - flags.FieldLength = -flags.FieldLength; - } - p++; - } - else while( isdigit(*p) ) - { - flags.FieldLength *= 10; - flags.FieldLength += *p++ - '0'; - } - - /* deal with precision */ - flags.Precision = -1; - if( *p == '.' ) - { - flags.Precision = 0; - p++; - if( *p == '*' ) - { - flags.Precision = va_arg( valist, int ); - p++; - } - else while( isdigit(*p) ) - { - flags.Precision *= 10; - flags.Precision += *p++ - '0'; - } - } - - /* deal with integer width modifier */ - while( *p ) - { - if( *p == 'h' || *p == 'l' || *p == 'L' ) - { - flags.IntegerLength = *p; - p++; - } - else if( *p == 'I' ) - { - if( *(p+1) == '6' && *(p+2) == '4' ) - { - flags.IntegerDouble++; - p += 3; - } - else if( *(p+1) == '3' && *(p+2) == '2' ) - p += 3; - else if( isdigit(*(p+1)) || *(p+1) == 0 ) - break; - else - p++; - } - else if( *p == 'w' ) - flags.WideString = *p++; - else if( *p == 'F' ) - p++; /* ignore */ - else - break; - } - - flags.Format = *p; - r = 0; - - /* output a string */ - if( flags.Format == 's' || flags.Format == 'S' ) - r = pf_handle_string_format( out, va_arg(valist, const void*), -1, - &flags, (flags.Format == 'S') ); - - /* output a single character */ - else if( flags.Format == 'c' || flags.Format == 'C' ) - { - INT ch = va_arg( valist, int ); - - r = pf_handle_string_format( out, &ch, 1, &flags, (flags.Format == 'C') ); - } - - /* output a pointer */ - else if( flags.Format == 'p' ) - { - char pointer[11]; - - flags.PadZero = 0; - if( flags.Alternate ) - lnx_sprintf(pointer, "0X%08lX", va_arg(valist, long)); - else - lnx_sprintf(pointer, "%08lX", va_arg(valist, long)); - r = pf_output_format_A( out, pointer, -1, &flags ); - } - - /* deal with %n */ - else if( flags.Format == 'n' ) - { - int *x = va_arg(valist, int *); - *x = out->used; - } - - /* deal with 64-bit integers */ - else if( pf_is_integer_format( flags.Format ) && flags.IntegerDouble ) - { - char number[40], *x = number; - - /* Estimate largest possible required buffer size: - * Chooses the larger of the field or precision - * Includes extra bytes: 1 byte for null, 1 byte for sign, - 4 bytes for exponent, 2 bytes for alternate formats, 1 byte - for a decimal, and 1 byte for an additional float digit. */ - unsigned x_len = ((flags.FieldLength > flags.Precision) ? - flags.FieldLength : flags.Precision) + 10; - - if( x_len >= sizeof number) - x = HeapAlloc( GetProcessHeap(), 0, x_len ); - - pf_integer_conv( x, x_len, &flags, va_arg(valist, LONGLONG) ); - - r = pf_output_format_A( out, x, -1, &flags ); - if( x != number ) - HeapFree( GetProcessHeap(), 0, x ); - } - - /* deal with integers and floats using libc's printf */ - else if( pf_is_valid_format( flags.Format ) ) - { - char fmt[20], number[40], *x = number; - - /* Estimate largest possible required buffer size: - * Chooses the larger of the field or precision - * Includes extra bytes: 1 byte for null, 1 byte for sign, - 4 bytes for exponent, 2 bytes for alternate formats, 1 byte - for a decimal, and 1 byte for an additional float digit. */ - unsigned x_len = ((flags.FieldLength > flags.Precision) ? - flags.FieldLength : flags.Precision) + 10; - - if( x_len >= sizeof number) - x = HeapAlloc( GetProcessHeap(), 0, x_len ); - - pf_rebuild_format_string( fmt, &flags ); - - if( pf_is_double_format( flags.Format ) ) - lnx_sprintf( x, fmt, va_arg(valist, double) ); - else - lnx_sprintf( x, fmt, va_arg(valist, int) ); - - r = pf_output_stringA( out, x, -1 ); - if( x != number ) - HeapFree( GetProcessHeap(), 0, x ); - } - else - continue; - - if( r<0 ) - return r; - p++; - } - - /* check we reached the end, and null terminate the string */ - assert( *p == 0 ); - pf_output_stringW( out, p, 1 ); - - return out->used - 1; -} - -/********************************************************************* - * _vsnprintf (MSVCRT.@) - */ -int CDECL _vsnprintf( char *str, size_t len, - const char *format, va_list valist ) -{ - DWORD sz; - LPWSTR formatW = NULL; - pf_output out; - int r; - - out.unicode = FALSE; - out.buf.A = str; - out.used = 0; - out.len = len; - - if( format ) - { - sz = MultiByteToWideChar( CP_ACP, 0, format, -1, NULL, 0 ); - formatW = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) ); - MultiByteToWideChar( CP_ACP, 0, format, -1, formatW, sz ); - } - - r = pf_vsnprintf( &out, formatW, valist ); - - HeapFree( GetProcessHeap(), 0, formatW ); - - return r; -} - -/********************************************************************* - * vsprintf (MSVCRT.@) - */ -int CDECL vsprintf( char *str, const char *format, va_list valist) -{ - return _vsnprintf(str, INT_MAX, format, valist); -} - -/********************************************************************* - * _snprintf (MSVCRT.@) - */ -int CDECL _snprintf(char *str, size_t len, const char *format, ...) -{ - int retval; - va_list valist; - va_start(valist, format); - retval = _vsnprintf(str, len, format, valist); - va_end(valist); - return retval; -} - -/********************************************************************* - * _vsnwsprintf (MSVCRT.@) - */ -int CDECL _vsnwprintf( wchar_t *str, size_t len, - const wchar_t *format, va_list valist ) -{ - pf_output out; - - out.unicode = TRUE; - out.buf.W = str; - out.used = 0; - out.len = len; - - return pf_vsnprintf( &out, format, valist ); -} - -/********************************************************************* - * _snwprintf (MSVCRT.@) - */ -int CDECL _snwprintf( wchar_t *str, size_t len, const wchar_t *format, ...) -{ - int retval; - va_list valist; - va_start(valist, format); - retval = _vsnwprintf(str, len, format, valist); - va_end(valist); - return retval; -} - -/********************************************************************* - * sprintf (MSVCRT.@) - */ -int CDECL sprintf( char *str, const char *format, ... ) -{ - va_list ap; - int r; - - va_start( ap, format ); - r = _vsnprintf( str, INT_MAX, format, ap ); - va_end( ap ); - return r; -} - -/********************************************************************* - * swprintf (MSVCRT.@) - */ -int CDECL swprintf( wchar_t *str, const wchar_t *format, ... ) -{ - va_list ap; - int r; - - va_start( ap, format ); - r = _vsnwprintf( str, INT_MAX, format, ap ); - va_end( ap ); - return r; -} - -/********************************************************************* - * vswprintf (MSVCRT.@) - */ -int CDECL vswprintf( wchar_t* str, const wchar_t* format, va_list args ) -{ - return _vsnwprintf( str, INT_MAX, format, args ); -} -#endif #endif /********************************************************************* @@ -1052,97 +381,6 @@ size_t CDECL wcstombs(char *mbstr, const wchar_t *wcstr, size_t count) } #endif -#ifndef __REACTOS__ -/********************************************************************* - * iswalnum (MSVCRT.@) - */ -INT CDECL iswalnum( wchar_t wc ) -{ - return isalnumW( wc ); -} - -/********************************************************************* - * iswalpha (MSVCRT.@) - */ -INT CDECL iswalpha( wchar_t wc ) -{ - return isalphaW( wc ); -} - -/********************************************************************* - * iswcntrl (MSVCRT.@) - */ -INT CDECL iswcntrl( wchar_t wc ) -{ - return iscntrlW( wc ); -} - -/********************************************************************* - * iswdigit (MSVCRT.@) - */ -INT CDECL iswdigit( wchar_t wc ) -{ - return isdigitW( wc ); -} - -/********************************************************************* - * iswgraph (MSVCRT.@) - */ -INT CDECL iswgraph( wchar_t wc ) -{ - return isgraphW( wc ); -} - -/********************************************************************* - * iswlower (MSVCRT.@) - */ -INT CDECL iswlower( wchar_t wc ) -{ - return islowerW( wc ); -} - -/********************************************************************* - * iswprint (MSVCRT.@) - */ -INT CDECL iswprint( wchar_t wc ) -{ - return isprintW( wc ); -} - -/********************************************************************* - * iswpunct (MSVCRT.@) - */ -INT CDECL iswpunct( wchar_t wc ) -{ - return ispunctW( wc ); -} - -/********************************************************************* - * iswspace (MSVCRT.@) - */ -INT CDECL iswspace( wchar_t wc ) -{ - return isspaceW( wc ); -} - -/********************************************************************* - * iswupper (MSVCRT.@) - */ -INT CDECL iswupper( wchar_t wc ) -{ - return isupperW( wc ); -} - -/********************************************************************* - * iswxdigit (MSVCRT.@) - */ -INT CDECL iswxdigit( wchar_t wc ) -{ - return isxdigitW( wc ); -} - -#endif - /********************************************************************* * wcscpy_s (MSVCRT.@) */ diff --git a/ntoskrnl/include/internal/i386/mm.h b/ntoskrnl/include/internal/i386/mm.h index 0ff6b5667c0..51e4d32e278 100644 --- a/ntoskrnl/include/internal/i386/mm.h +++ b/ntoskrnl/include/internal/i386/mm.h @@ -39,10 +39,12 @@ PULONG MmGetPageDirectory(VOID); // Convert a PTE into a corresponding address // #define MiPteToAddress(PTE) ((PVOID)((ULONG)(PTE) << 10)) -#define MiPdeToAddress(PDE) ((PVOID)((ULONG)(PDE) << 10)) +#define MiPdeToAddress(PDE) ((PVOID)((ULONG)(PDE) << 20)) +#define MiPdeToPte(PDE) ((PMMPTE)MiPteToAddress(PDE)) +#define MiPteToPde(PTE) ((PMMPDE)MiAddressToPte(PTE)) #define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE)) -#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (1024 * PAGE_SIZE))) +#define ADDR_TO_PDE_OFFSET(v) (((ULONG)(v)) / (1024 * PAGE_SIZE)) #define ADDR_TO_PTE_OFFSET(v) ((((ULONG)(v)) % (1024 * PAGE_SIZE)) / PAGE_SIZE) #define MiGetPdeOffset ADDR_TO_PDE_OFFSET diff --git a/ntoskrnl/mm/ARM3/pagfault.c b/ntoskrnl/mm/ARM3/pagfault.c index 789fdeb82b9..f3f2b6c129f 100644 --- a/ntoskrnl/mm/ARM3/pagfault.c +++ b/ntoskrnl/mm/ARM3/pagfault.c @@ -683,7 +683,7 @@ MmArmAccessFault(IN BOOLEAN StoreInstruction, // // Is the PDE valid? // - if (!PointerPde->u.Hard.Valid == 0) + if (PointerPde->u.Hard.Valid == 0) { // // Debug spew (eww!) diff --git a/ntoskrnl/mm/ARM3/pool.c b/ntoskrnl/mm/ARM3/pool.c index 76b84db1e40..f22091b5848 100644 --- a/ntoskrnl/mm/ARM3/pool.c +++ b/ntoskrnl/mm/ARM3/pool.c @@ -463,7 +463,7 @@ MiAllocatePoolPages(IN POOL_TYPE PoolType, // Get the first PTE in expansion space // PointerPde = MmPagedPoolInfo.NextPdeForPagedPoolExpansion; - BaseVa = MiPdeToAddress(PointerPde); + BaseVa = MiPdeToPte(PointerPde); BaseVaStart = BaseVa; // @@ -497,7 +497,7 @@ MiAllocatePoolPages(IN POOL_TYPE PoolType, MmSystemPageDirectory[(PointerPde - MiAddressToPde(NULL)) / PDE_COUNT]); /* Write the actual PDE now */ - MI_WRITE_VALID_PDE(PointerPde, TempPde); +// MI_WRITE_VALID_PDE(PointerPde, TempPde); #endif // // Move on to the next expansion address diff --git a/ntoskrnl/mm/ARM3/syspte.c b/ntoskrnl/mm/ARM3/syspte.c index ecb915161fd..298e18aec88 100644 --- a/ntoskrnl/mm/ARM3/syspte.c +++ b/ntoskrnl/mm/ARM3/syspte.c @@ -4,6 +4,7 @@ * FILE: ntoskrnl/mm/ARM3/syspte.c * PURPOSE: ARM Memory Manager System PTE Allocator * PROGRAMMERS: ReactOS Portable Systems Group + * Roel Messiant (roel.messiant@reactos.org) */ /* INCLUDES *******************************************************************/ @@ -26,6 +27,55 @@ ULONG MmTotalSystemPtes; /* PRIVATE FUNCTIONS **********************************************************/ +// +// The free System Page Table Entries are stored in a bunch of clusters, +// each consisting of one or more PTEs. These PTE clusters are connected +// in a singly linked list, ordered by increasing cluster size. +// +// A cluster consisting of a single PTE is marked by having the OneEntry flag +// of its PTE set. The forward link is contained in the NextEntry field. +// +// Clusters containing multiple PTEs have the OneEntry flag of their first PTE +// reset. The NextEntry field of the first PTE contains the forward link, and +// the size of the cluster is stored in the NextEntry field of its second PTE. +// +// Reserving PTEs currently happens by walking the linked list until a cluster +// is found that contains the requested amount of PTEs or more. This cluster +// is removed from the list, and the requested amount of PTEs is taken from the +// tail of this cluster. If any PTEs remain in the cluster, the linked list is +// walked again until a second cluster is found that contains the same amount +// of PTEs or more. The first cluster is then inserted in front of the second +// one. +// +// Releasing PTEs currently happens by walking the whole linked list, recording +// the first cluster that contains the amount of PTEs to release or more. When +// a cluster is found that is adjacent to the PTEs being released, this cluster +// is removed from the list and subsequently added to the PTEs being released. +// This ensures no two clusters are adjacent, which maximizes their size. +// After the walk is complete, a new cluster is created that contains the PTEs +// being released, which is then inserted in front of the recorded cluster. +// + +/* This definition does not belong here and is most likely platform-dependent */ +#define MM_EMPTY_LIST (ULONG) (0xFFFFF) + +ULONG +FORCEINLINE +MI_GET_CLUSTER_SIZE(IN PMMPTE Pte) +{ + // + // First check for a single PTE + // + if (Pte->u.List.OneEntry) + return 1; + + // + // Then read the size from the trailing PTE + // + Pte++; + return Pte->u.List.NextEntry; +} + PMMPTE NTAPI MiReserveAlignedSystemPtes(IN ULONG NumberOfPtes, @@ -33,8 +83,8 @@ MiReserveAlignedSystemPtes(IN ULONG NumberOfPtes, IN ULONG Alignment) { KIRQL OldIrql; - PMMPTE PointerPte, NextPte, PreviousPte; - ULONG_PTR ClusterSize; + PMMPTE PreviousPte, NextPte, ReturnPte; + ULONG ClusterSize; // // Sanity check @@ -42,125 +92,146 @@ MiReserveAlignedSystemPtes(IN ULONG NumberOfPtes, ASSERT(Alignment <= PAGE_SIZE); // - // Lock the system PTE space + // Acquire the System PTE lock // OldIrql = KeAcquireQueuedSpinLock(LockQueueSystemSpaceLock); // - // Get the first free cluster and make sure we have PTEs available + // Find the last cluster in the list that doesn't contain enough PTEs // - PointerPte = &MmFirstFreeSystemPte[SystemPtePoolType]; - if (PointerPte->u.List.NextEntry == ((ULONG)0xFFFFF)) + PreviousPte = &MmFirstFreeSystemPte[SystemPtePoolType]; + + while (PreviousPte->u.List.NextEntry != MM_EMPTY_LIST) { // - // Fail + // Get the next cluster and its size // + NextPte = MmSystemPteBase + PreviousPte->u.List.NextEntry; + ClusterSize = MI_GET_CLUSTER_SIZE(NextPte); + + // + // Check if this cluster contains enough PTEs + // + if (NumberOfPtes <= ClusterSize) + break; + + // + // On to the next cluster + // + PreviousPte = NextPte; + } + + // + // Make sure we didn't reach the end of the cluster list + // + if (PreviousPte->u.List.NextEntry == MM_EMPTY_LIST) + { + // + // Release the System PTE lock and return failure + // KeReleaseQueuedSpinLock(LockQueueSystemSpaceLock, OldIrql); return NULL; } - // - // Now move to the first free system PTE cluster - // - PreviousPte = PointerPte; - PointerPte = MmSystemPteBase + PointerPte->u.List.NextEntry; + // + // Unlink the cluster + // + PreviousPte->u.List.NextEntry = NextPte->u.List.NextEntry; - // - // Loop each cluster - // - while (TRUE) - { - // - // Check if we're done to only one PTE left - // - if (!PointerPte->u.List.OneEntry) - { - // - // Keep track of the next cluster in case we have to relink - // - NextPte = PointerPte + 1; - - // - // Can this cluster satisfy the request? - // - ClusterSize = (ULONG_PTR)NextPte->u.List.NextEntry; - if (NumberOfPtes < ClusterSize) - { // - // It can, and it will leave just one PTE left + // Check if the reservation spans the whole cluster // - if ((ClusterSize - NumberOfPtes) == 1) + if (ClusterSize == NumberOfPtes) { // - // This cluster becomes a single system PTE entry + // Return the first PTE of this cluster // - PointerPte->u.List.OneEntry = 1; + ReturnPte = NextPte; + + // + // Zero the cluster + // + if (NextPte->u.List.OneEntry == 0) + { + NextPte->u.Long = 0; + NextPte++; } + NextPte->u.Long = 0; + } else { // - // Otherwise, the next cluster aborbs what's left + // Divide the cluster into two parts // - NextPte->u.List.NextEntry = ClusterSize - NumberOfPtes; - } + ClusterSize -= NumberOfPtes; + ReturnPte = NextPte + ClusterSize; // - // Decrement the free count and move to the next starting PTE + // Set the size of the first cluster, zero the second if needed // - MmTotalFreeSystemPtes[SystemPtePoolType] -= NumberOfPtes; - PointerPte += (ClusterSize - NumberOfPtes); - break; + if (ClusterSize == 1) + { + NextPte->u.List.OneEntry = 1; + ReturnPte->u.Long = 0; } + else + { + NextPte++; + NextPte->u.List.NextEntry = ClusterSize; + } // - // Did we find exactly what you wanted? + // Step through the cluster list to find out where to insert the first // - if (NumberOfPtes == ClusterSize) + PreviousPte = &MmFirstFreeSystemPte[SystemPtePoolType]; + + while (PreviousPte->u.List.NextEntry != MM_EMPTY_LIST) { // - // Yes, fixup the cluster and decrease free system PTE count + // Get the next cluster // - PreviousPte->u.List.NextEntry = PointerPte->u.List.NextEntry; - MmTotalFreeSystemPtes[SystemPtePoolType] -= NumberOfPtes; + NextPte = MmSystemPteBase + PreviousPte->u.List.NextEntry; + + // + // Check if the cluster to insert is smaller or of equal size + // + if (ClusterSize <= MI_GET_CLUSTER_SIZE(NextPte)) break; + + // + // On to the next cluster + // + PreviousPte = NextPte; } - } - else if (NumberOfPtes == 1) - { + // - // We have one PTE in this cluster, and it's all you want + // Retrieve the first cluster and link it back into the cluster list // - PreviousPte->u.List.NextEntry = PointerPte->u.List.NextEntry; - MmTotalFreeSystemPtes[SystemPtePoolType]--; - break; + NextPte = ReturnPte - ClusterSize; + + NextPte->u.List.NextEntry = PreviousPte->u.List.NextEntry; + PreviousPte->u.List.NextEntry = NextPte - MmSystemPteBase; } // - // We couldn't find what you wanted -- is this the last cluster? + // Decrease availability // - if (PointerPte->u.List.NextEntry == ((ULONG)0xFFFFF)) - { + MmTotalFreeSystemPtes[SystemPtePoolType] -= NumberOfPtes; + // - // Fail + // Release the System PTE lock // KeReleaseQueuedSpinLock(LockQueueSystemSpaceLock, OldIrql); - return NULL; - } // - // Go to the next cluster + // Flush the TLB // - PreviousPte = PointerPte; - PointerPte = MmSystemPteBase + PointerPte->u.List.NextEntry; - ASSERT(PointerPte > PreviousPte); - } - - // - // Release the lock, flush the TLB and return the first PTE - // - KeReleaseQueuedSpinLock(LockQueueSystemSpaceLock, OldIrql); KeFlushProcessTb(); - return PointerPte; + + // + // Return the reserved PTEs + // + return ReturnPte; } PMMPTE @@ -199,24 +270,23 @@ MiReleaseSystemPtes(IN PMMPTE StartingPte, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType) { KIRQL OldIrql; - ULONG_PTR ClusterSize, CurrentSize; - PMMPTE CurrentPte, NextPte, PointerPte; + ULONG_PTR ClusterSize; + PMMPTE PreviousPte, NextPte, InsertPte; // // Check to make sure the PTE address is within bounds // ASSERT(NumberOfPtes != 0); ASSERT(StartingPte >= MmSystemPtesStart[SystemPtePoolType]); - ASSERT(StartingPte <= MmSystemPtesEnd[SystemPtePoolType]); + ASSERT(StartingPte + NumberOfPtes - 1 <= MmSystemPtesEnd[SystemPtePoolType]); // // Zero PTEs // RtlZeroMemory(StartingPte, NumberOfPtes * sizeof(MMPTE)); - CurrentSize = (ULONG_PTR)(StartingPte - MmSystemPteBase); // - // Acquire the system PTE lock + // Acquire the System PTE lock // OldIrql = KeAcquireQueuedSpinLock(LockQueueSystemSpaceLock); @@ -226,141 +296,94 @@ MiReleaseSystemPtes(IN PMMPTE StartingPte, MmTotalFreeSystemPtes[SystemPtePoolType] += NumberOfPtes; // - // Get the free cluster and start going through them + // Step through the cluster list to find where to insert the PTEs // - CurrentPte = &MmFirstFreeSystemPte[SystemPtePoolType]; - while (TRUE) + PreviousPte = &MmFirstFreeSystemPte[SystemPtePoolType]; + InsertPte = NULL; + + while (PreviousPte->u.List.NextEntry != MM_EMPTY_LIST) { // - // Get the first real cluster of PTEs and check if it's ours + // Get the next cluster and its size // - PointerPte = MmSystemPteBase + CurrentPte->u.List.NextEntry; - if (CurrentSize < CurrentPte->u.List.NextEntry) - { - // - // Sanity check - // - ASSERT(((StartingPte + NumberOfPtes) <= PointerPte) || - (CurrentPte->u.List.NextEntry == ((ULONG)0xFFFFF))); + NextPte = MmSystemPteBase + PreviousPte->u.List.NextEntry; + ClusterSize = MI_GET_CLUSTER_SIZE(NextPte); // - // Get the next cluster in case it's the one + // Check if this cluster is adjacent to the PTEs being released // - NextPte = CurrentPte + 1; - - // - // Check if this was actually a single-PTE entry - // - if (CurrentPte->u.List.OneEntry) + if ((NextPte + ClusterSize == StartingPte) || + (StartingPte + NumberOfPtes == NextPte)) { // - // We only have one page + // Add the PTEs in the cluster to the PTEs being released // - ClusterSize = 1; + NumberOfPtes += ClusterSize; + + if (NextPte < StartingPte) + StartingPte = NextPte; + + // + // Unlink this cluster and zero it + // + PreviousPte->u.List.NextEntry = NextPte->u.List.NextEntry; + + if (NextPte->u.List.OneEntry == 0) + { + NextPte->u.Long = 0; + NextPte++; + } + NextPte->u.Long = 0; + + // + // Invalidate the previously found insertion location, if any + // + InsertPte = NULL; } else { // - // The next cluster will have the page count + // Check if the insertion location is right before this cluster // - ClusterSize = (ULONG_PTR)NextPte->u.List.NextEntry; - } - - // - // So check if this cluster actually describes the entire mapping - // - if ((CurrentPte + ClusterSize) == StartingPte) - { - // - // It does -- collapse the free PTEs into the next cluster - // - NumberOfPtes += ClusterSize; - NextPte->u.List.NextEntry = NumberOfPtes; - CurrentPte->u.List.OneEntry = 0; + if ((InsertPte == NULL) && (NumberOfPtes <= ClusterSize)) + InsertPte = PreviousPte; // - // Make another pass + // On to the next cluster // - StartingPte = CurrentPte; - } - else - { - // - // There's still PTEs left -- make us into a cluster - // - StartingPte->u.List.NextEntry = CurrentPte->u.List.NextEntry; - CurrentPte->u.List.NextEntry = CurrentSize; - - // - // Is there just one page left? - // - if (NumberOfPtes == 1) - { - // - // Then this actually becomes a single PTE entry - // - StartingPte->u.List.OneEntry = 1; + PreviousPte = NextPte; } - else - { + } + // - // Otherwise, create a new cluster for the remaining pages + // If no insertion location was found, use the tail of the list // - StartingPte->u.List.OneEntry = 0; - NextPte = StartingPte + 1; - NextPte->u.List.NextEntry = NumberOfPtes; - } - } + if (InsertPte == NULL) + InsertPte = PreviousPte; // - // Now check if we've arrived at yet another cluster + // Create a new cluster using the PTEs being released // - if ((StartingPte + NumberOfPtes) == PointerPte) + if (NumberOfPtes != 1) { - // - // We'll collapse the next cluster into us - // - StartingPte->u.List.NextEntry = PointerPte->u.List.NextEntry; StartingPte->u.List.OneEntry = 0; - NextPte = StartingPte + 1; - // - // Check if the cluster only had one page - // - if (PointerPte->u.List.OneEntry) - { - // - // So will we... - // - ClusterSize = 1; + NextPte = StartingPte + 1; + NextPte->u.List.NextEntry = NumberOfPtes; } else - { - // - // Otherwise, grab the page count from the next-next cluster - // - PointerPte++; - ClusterSize = (ULONG_PTR)PointerPte->u.List.NextEntry; - } + StartingPte->u.List.OneEntry = 1; // - // And create the final combined cluster + // Link the new cluster into the cluster list at the insertion location // - NextPte->u.List.NextEntry = NumberOfPtes + ClusterSize; - } + StartingPte->u.List.NextEntry = InsertPte->u.List.NextEntry; + InsertPte->u.List.NextEntry = StartingPte - MmSystemPteBase; // - // We released the PTEs into their cluster (and optimized the list) + // Release the System PTE lock // KeReleaseQueuedSpinLock(LockQueueSystemSpaceLock, OldIrql); - break; - } - - // - // Try the next cluster of PTEs... - // - CurrentPte = PointerPte; - } } VOID @@ -392,7 +415,7 @@ MiInitializeSystemPtes(IN PMMPTE StartingPte, // // Make the first entry free and link it // - StartingPte->u.List.NextEntry = ((ULONG)0xFFFFF); + StartingPte->u.List.NextEntry = MM_EMPTY_LIST; MmFirstFreeSystemPte[PoolType].u.Long = 0; MmFirstFreeSystemPte[PoolType].u.List.NextEntry = StartingPte - MmSystemPteBase; diff --git a/ntoskrnl/mm/ARM3/virtual.c b/ntoskrnl/mm/ARM3/virtual.c index 8222af3fe8c..485ee21a5b0 100644 --- a/ntoskrnl/mm/ARM3/virtual.c +++ b/ntoskrnl/mm/ARM3/virtual.c @@ -1127,7 +1127,7 @@ MiQueryAddressState(IN PVOID Va, if (!PointerPde->u.Long) { /* No address in this range used yet, move to the next PDE range */ - *NextVa = MiPteToAddress(MiPdeToAddress(PointerPde + 1)); + *NextVa = MiPdeToAddress(PointerPde + 1); break; } @@ -1135,7 +1135,7 @@ MiQueryAddressState(IN PVOID Va, if (!PointerPde->u.Hard.Valid) { /* It isn't, go ahead and do the fault */ - LockChange = MiMakeSystemAddressValid(MiPdeToAddress(PointerPde), + LockChange = MiMakeSystemAddressValid(MiPdeToPte(PointerPde), TargetProcess); } diff --git a/ntoskrnl/ps/process.c b/ntoskrnl/ps/process.c index 01f9a77b17a..d65e4ed26c6 100644 --- a/ntoskrnl/ps/process.c +++ b/ntoskrnl/ps/process.c @@ -127,7 +127,7 @@ PEPROCESS NTAPI PsGetNextProcess(IN PEPROCESS OldProcess) { - PLIST_ENTRY Entry, ListHead; + PLIST_ENTRY Entry; PEPROCESS FoundProcess = NULL; PAGED_CODE(); PSTRACE(PS_PROCESS_DEBUG, "Process: %p\n", OldProcess); @@ -147,11 +147,10 @@ PsGetNextProcess(IN PEPROCESS OldProcess) Entry = PsActiveProcessHead.Flink; } - /* Set the list head and start looping */ - ListHead = &PsActiveProcessHead; - while (ListHead != Entry) + /* Loop the process list */ + while (Entry != &PsActiveProcessHead) { - /* Get the Thread */ + /* Get the process */ FoundProcess = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks); /* Reference the process */ @@ -165,7 +164,7 @@ PsGetNextProcess(IN PEPROCESS OldProcess) /* Release the lock */ KeReleaseGuardedMutex(&PspActiveProcessMutex); - /* Reference the Process we had referenced earlier */ + /* Dereference the Process we had referenced earlier */ if (OldProcess) ObDereferenceObject(OldProcess); return FoundProcess; } @@ -621,7 +620,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle, SeAuditProcessCreationInfo. ImageFileName); if (!NT_SUCCESS(Status)) goto CleanupWithRef; - + // // We need a PEB // @@ -641,7 +640,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle, ASSERTMSG("No support for cloning yet\n", FALSE); } else - { + { /* This is the initial system process */ Flags &= ~PS_LARGE_PAGES; Status = MmInitializeProcessAddressSpace(Process, @@ -713,7 +712,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle, RtlZeroMemory(&InitialPeb, sizeof(INITIAL_PEB)); InitialPeb.Mutant = (HANDLE)-1; InitialPeb.ImageUsesLargePages = 0; // FIXME: Not yet supported - + // // Create it only if we have an image section // @@ -850,7 +849,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle, /* Run the Notification Routines */ PspRunCreateProcessNotifyRoutines(Process, TRUE); - + /* If 12 processes have been created, enough of user-mode is ready */ if (++ProcessCount == 12) Ki386PerfEnd(); diff --git a/ntoskrnl/ps/psmgr.c b/ntoskrnl/ps/psmgr.c index 156982ed565..93d9cfa4966 100644 --- a/ntoskrnl/ps/psmgr.c +++ b/ntoskrnl/ps/psmgr.c @@ -212,7 +212,7 @@ PspLookupKernelUserEntryPoints(VOID) if (KeFeatureBits & KF_FAST_SYSCALL) { /* Get user-mode sysenter stub */ - SharedUserdata->SystemCall = (PsNtosImageBase >> (PAGE_SHIFT + 1)); + SharedUserData->SystemCall = (PsNtosImageBase >> (PAGE_SHIFT + 1)); Status = PspLookupSystemDllEntryPoint("KiFastSystemCall", (PVOID)&SharedUserData-> SystemCall); diff --git a/ntoskrnl/se/priv.c b/ntoskrnl/se/priv.c index 603194259e0..ca1fe9ad137 100644 --- a/ntoskrnl/se/priv.c +++ b/ntoskrnl/se/priv.c @@ -118,54 +118,46 @@ SepPrivilegeCheck(PTOKEN Token, { ULONG i; ULONG j; - ULONG k; + ULONG Required; DPRINT("SepPrivilegeCheck() called\n"); PAGED_CODE(); if (PreviousMode == KernelMode) - { return TRUE; - } - k = 0; - if (PrivilegeCount > 0) + /* Get the number of privileges that are required to match */ + Required = (PrivilegeControl & PRIVILEGE_SET_ALL_NECESSARY) ? PrivilegeCount : 1; + + /* Loop all requested privileges until we found the required ones */ + for (i = 0; i < PrivilegeCount && Required > 0; i++) { - for (i = 0; i < Token->PrivilegeCount; i++) + /* Loop the privileges of the token */ + for (j = 0; j < Token->PrivilegeCount; j++) { - for (j = 0; j < PrivilegeCount; j++) + /* Check if the LUIDs match */ + if (Token->Privileges[j].Luid.LowPart == Privileges[i].Luid.LowPart && + Token->Privileges[j].Luid.HighPart == Privileges[i].Luid.HighPart) { - if (Token->Privileges[i].Luid.LowPart == Privileges[j].Luid.LowPart && - Token->Privileges[i].Luid.HighPart == Privileges[j].Luid.HighPart) - { - DPRINT("Found privilege\n"); - DPRINT("Privilege attributes %lx\n", - Token->Privileges[i].Attributes); + DPRINT("Found privilege. Attributes: %lx\n", + Token->Privileges[j].Attributes); - if (Token->Privileges[i].Attributes & SE_PRIVILEGE_ENABLED) + /* Check if the privilege is enabled */ + if (Token->Privileges[j].Attributes & SE_PRIVILEGE_ENABLED) { - Privileges[j].Attributes |= SE_PRIVILEGE_USED_FOR_ACCESS; - k++; + Privileges[i].Attributes |= SE_PRIVILEGE_USED_FOR_ACCESS; + Required--; } + + /* Leave the inner loop */ + break; } } } - } - if ((PrivilegeControl & PRIVILEGE_SET_ALL_NECESSARY) && - PrivilegeCount == k) - { - return TRUE; - } - - if (k > 0 && - !(PrivilegeControl & PRIVILEGE_SET_ALL_NECESSARY)) - { - return TRUE; - } - - return FALSE; + /* Return whether we found all required privileges */ + return (Required == 0); } NTSTATUS diff --git a/subsystems/win32/win32k/eng/clip.c b/subsystems/win32/win32k/eng/clip.c index 0235d0f27b7..adc6a2b95b2 100644 --- a/subsystems/win32/win32k/eng/clip.c +++ b/subsystems/win32/win32k/eng/clip.c @@ -224,7 +224,7 @@ IntEngCreateClipRegion(ULONG count, PRECTL pRect, PRECTL rcBounds) { RECTL *dest; - Clip = EngAllocMem(0, sizeof(CLIPGDI) + ((count - 1) * sizeof(RECTL)), TAG_CLIPOBJ); + Clip = EngAllocMem(0, sizeof(CLIPGDI) + ((count - 1) * sizeof(RECTL)), GDITAG_CLIPOBJ); if(Clip != NULL) { @@ -245,7 +245,7 @@ IntEngCreateClipRegion(ULONG count, PRECTL pRect, PRECTL rcBounds) } else { - Clip = EngAllocMem(0, sizeof(CLIPGDI), TAG_CLIPOBJ); + Clip = EngAllocMem(0, sizeof(CLIPGDI), GDITAG_CLIPOBJ); if(Clip != NULL) { @@ -274,7 +274,7 @@ IntEngCreateClipRegion(ULONG count, PRECTL pRect, PRECTL rcBounds) CLIPOBJ * APIENTRY EngCreateClip(VOID) { - CLIPGDI *Clip = EngAllocMem(FL_ZERO_MEMORY, sizeof(CLIPGDI), TAG_CLIPOBJ); + CLIPGDI *Clip = EngAllocMem(FL_ZERO_MEMORY, sizeof(CLIPGDI), GDITAG_CLIPOBJ); if(Clip != NULL) { return GDIToObj(Clip, CLIP); @@ -409,7 +409,7 @@ ClipobjToSpans( *Count = Boundary->bottom - Boundary->top; if (*Count > 0) { - *Spans = ExAllocatePoolWithTag(PagedPool, *Count * sizeof(SPAN), TAG_CLIP); + *Spans = ExAllocatePoolWithTag(PagedPool, *Count * sizeof(SPAN), GDITAG_CLIPOBJ); if (NULL == *Spans) { *Count = 0; @@ -444,12 +444,12 @@ ClipobjToSpans( } if (NewCount != *Count) { - NewSpans = ExAllocatePoolWithTag(PagedPool, NewCount * sizeof(SPAN), TAG_CLIP); + NewSpans = ExAllocatePoolWithTag(PagedPool, NewCount * sizeof(SPAN), GDITAG_CLIPOBJ); if (NULL == NewSpans) { if (NULL != *Spans) { - ExFreePoolWithTag(*Spans, TAG_CLIP); + ExFreePoolWithTag(*Spans, GDITAG_CLIPOBJ); *Spans = NULL; } *Count = 0; @@ -463,7 +463,7 @@ ClipobjToSpans( { *dest++ = *src++; } - ExFreePoolWithTag(*Spans, TAG_CLIP); + ExFreePoolWithTag(*Spans, GDITAG_CLIPOBJ); } *Spans = NewSpans; } diff --git a/subsystems/win32/win32k/eng/engevent.c b/subsystems/win32/win32k/eng/engevent.c index 3773c305029..e916cf5f901 100644 --- a/subsystems/win32/win32k/eng/engevent.c +++ b/subsystems/win32/win32k/eng/engevent.c @@ -14,9 +14,6 @@ #define NDEBUG #include -/* Dfsm - - Eng event allocation (ENG_KEVENTALLOC,ENG_ALLOC) in ntgdi\gre */ -#define TAG_GRE_EVENT 'msfD' - /* PUBLIC FUNCTIONS ***********************************************************/ BOOL @@ -29,7 +26,7 @@ EngCreateEvent(OUT PEVENT* Event) /* Allocate memory for the event structure */ EngEvent = ExAllocatePoolWithTag(NonPagedPool, sizeof(ENG_EVENT) + sizeof(KEVENT), - TAG_GRE_EVENT); + GDITAG_ENG_EVENT); if (EngEvent) { /* Set KEVENT pointer */ @@ -48,7 +45,7 @@ EngCreateEvent(OUT PEVENT* Event) else { /* Out of memory */ - DPRINT("EngCreateEvent() failed\n"); + DPRINT("EngCreateEvent() failed\n"); Result = FALSE; } @@ -117,13 +114,13 @@ EngMapEvent(IN HDEV hDev, /* Allocate memory for the event structure */ EngEvent = ExAllocatePoolWithTag(NonPagedPool, sizeof(ENG_EVENT), - TAG_GRE_EVENT); + GDITAG_ENG_EVENT); if (!EngEvent) return NULL; - + /* Zero it out */ EngEvent->fFlags = 0; EngEvent->pKEvent = NULL; - + /* Create a handle, and have Ob fill out the pKEvent field */ Status = ObReferenceObjectByHandle(EngEvent, EVENT_ALL_ACCESS, @@ -143,7 +140,7 @@ EngMapEvent(IN HDEV hDev, ExFreePool(EngEvent); EngEvent = NULL; } - + /* Support legacy interface */ if (Reserved1) *(PVOID*)Reserved1 = EngEvent; return EngEvent; @@ -155,10 +152,10 @@ EngUnmapEvent(IN PEVENT Event) { /* Must be a usermapped event */ if (!(Event->fFlags & ENG_EVENT_USERMAPPED)) return FALSE; - + /* Dereference the object, destroying it */ ObDereferenceObject(Event->pKEvent); - + /* Free the Eng object */ ExFreePool(Event); return TRUE; diff --git a/subsystems/win32/win32k/eng/engwindow.c b/subsystems/win32/win32k/eng/engwindow.c index 11eae9ef8e0..74f9ec99bb2 100644 --- a/subsystems/win32/win32k/eng/engwindow.c +++ b/subsystems/win32/win32k/eng/engwindow.c @@ -226,7 +226,7 @@ EngCreateWnd( } /* Create WNDOBJ */ - WndObjInt = EngAllocMem(0, sizeof (WNDGDI), TAG_WNDOBJ); + WndObjInt = EngAllocMem(0, sizeof (WNDGDI), GDITAG_WNDOBJ); if (WndObjInt == NULL) { DPRINT1("Failed to allocate memory for a WND structure!\n"); diff --git a/subsystems/win32/win32k/eng/i386/floatobj.S b/subsystems/win32/win32k/eng/i386/floatobj.S index c046bcfbeec..1f635b290b7 100644 --- a/subsystems/win32/win32k/eng/i386/floatobj.S +++ b/subsystems/win32/win32k/eng/i386/floatobj.S @@ -1,4 +1,4 @@ -/* +/* * COPYRIGHT: LGPL, see LGPL.txt in the top level directory * PROJECT: ReactOS Win32 subsystem * PURPOSE: FLOATOBJ floating point emulation functions for x86 @@ -98,7 +98,7 @@ PUBLIC _FLOATOBJ_SetFloat@8 jz SetFloat0 /* If it's all zero, ... */ shl ecx, 7 /* Put the bits for the mantissa in place */ - + cdq /* Fill edx with the sign from the FLOATL in eax */ and ecx, HEX(7fffffff) /* Mask out invalid field in the mantissa */ @@ -818,7 +818,8 @@ PUBLIC _FLOATOBJ_DivLong@8 push [ebp + PARAM1] /* Push the FLOATOBJ param on the stack */ call _FLOATOBJ_Div@8 /* Divide */ - pop ebp /* Cleanup and return */ + mov esp, ebp /* Cleanup and return */ + pop ebp ret 8 diff --git a/subsystems/win32/win32k/eng/semaphor.c b/subsystems/win32/win32k/eng/semaphor.c index ce9780fc0bf..8a8a04578bf 100644 --- a/subsystems/win32/win32k/eng/semaphor.c +++ b/subsystems/win32/win32k/eng/semaphor.c @@ -11,12 +11,12 @@ APIENTRY EngCreateSemaphore ( VOID ) { // www.osr.com/ddk/graphics/gdifncs_95lz.htm - PERESOURCE psem = ExAllocatePoolWithTag( NonPagedPool, sizeof(ERESOURCE), TAG_GSEM ); + PERESOURCE psem = ExAllocatePoolWithTag( NonPagedPool, sizeof(ERESOURCE), GDITAG_SEMAPHORE ); if ( !psem ) return NULL; if ( !NT_SUCCESS(ExInitializeResourceLite ( psem )) ) { - ExFreePoolWithTag ( psem, TAG_GSEM ); + ExFreePoolWithTag ( psem, GDITAG_SEMAPHORE ); return NULL; } return (HSEMAPHORE)psem; @@ -94,7 +94,7 @@ EngDeleteSemaphore ( IN HSEMAPHORE hsem ) ExDeleteResourceLite((PERESOURCE)hsem); - ExFreePoolWithTag( (PVOID)hsem, TAG_GSEM); + ExFreePoolWithTag( (PVOID)hsem, GDITAG_SEMAPHORE); } /* diff --git a/subsystems/win32/win32k/eng/surface.c b/subsystems/win32/win32k/eng/surface.c index 622b99da2d5..6493671a6d8 100644 --- a/subsystems/win32/win32k/eng/surface.c +++ b/subsystems/win32/win32k/eng/surface.c @@ -37,28 +37,19 @@ gajBitsPerFormat[11] = }; -ULONG FASTCALL BitmapFormat(WORD Bits, DWORD Compression) +ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression) { - switch (Compression) + switch (iCompression) { case BI_RGB: /* Fall through */ case BI_BITFIELDS: - switch (Bits) - { - case 1: - return BMF_1BPP; - case 4: - return BMF_4BPP; - case 8: - return BMF_8BPP; - case 16: - return BMF_16BPP; - case 24: - return BMF_24BPP; - case 32: - return BMF_32BPP; - } + if (cBits <= 1) return BMF_1BPP; + if (cBits <= 4) return BMF_4BPP; + if (cBits <= 8) return BMF_8BPP; + if (cBits <= 16) return BMF_16BPP; + if (cBits <= 24) return BMF_24BPP; + if (cBits <= 32) return BMF_32BPP; return 0; case BI_RLE4: diff --git a/subsystems/win32/win32k/eng/xlate.c b/subsystems/win32/win32k/eng/xlate.c index f15d757cb3d..ce2b90a8a58 100644 --- a/subsystems/win32/win32k/eng/xlate.c +++ b/subsystems/win32/win32k/eng/xlate.c @@ -446,7 +446,7 @@ EXLATEOBJ_vInitialize( { pexlo->xlo.pulXlate = EngAllocMem(0, cEntries * sizeof(ULONG), - TAG_XLATEOBJ); + GDITAG_PXLATE); if (!pexlo->xlo.pulXlate) { DPRINT1("Could not allocate pulXlate buffer.\n"); diff --git a/subsystems/win32/win32k/include/bitmaps.h b/subsystems/win32/win32k/include/bitmaps.h index 802028d4afa..7310766ff99 100644 --- a/subsystems/win32/win32k/include/bitmaps.h +++ b/subsystems/win32/win32k/include/bitmaps.h @@ -11,7 +11,6 @@ typedef struct tagBITMAPV5INFO INT APIENTRY BITMAP_GetObject(SURFACE * bmp, INT count, LPVOID buffer); HBITMAP FASTCALL IntCreateBitmap(IN SIZEL Size, IN LONG Width, IN ULONG Format, IN ULONG Flags, IN PVOID Bits); HBITMAP FASTCALL BITMAP_CopyBitmap (HBITMAP hBitmap); -UINT FASTCALL BITMAP_GetRealBitsPixel(UINT nBitsPixel); HBITMAP APIENTRY diff --git a/subsystems/win32/win32k/include/caret.h b/subsystems/win32/win32k/include/caret.h index 605718828d7..9722d37ceb0 100644 --- a/subsystems/win32/win32k/include/caret.h +++ b/subsystems/win32/win32k/include/caret.h @@ -3,8 +3,6 @@ #include #include -#define IDCARETTIMER (0xffff) - BOOL FASTCALL co_IntDestroyCaret(PTHREADINFO Win32Thread); diff --git a/subsystems/win32/win32k/include/coord.h b/subsystems/win32/win32k/include/coord.h index 83f3a355eaa..af678a0efb8 100644 --- a/subsystems/win32/win32k/include/coord.h +++ b/subsystems/win32/win32k/include/coord.h @@ -1,13 +1,80 @@ #pragma once #include +#include -#define IntDPtoLP(dc, pp, c) XFORMOBJ_bApplyXform((XFORMOBJ*)&(dc)->dclevel.mxDeviceToWorld, XF_LTOL, c, pp, pp); -#define IntLPtoDP(dc, pp, c) XFORMOBJ_bApplyXform((XFORMOBJ*)&(dc)->dclevel.mxWorldToDevice, XF_LTOL, c, pp, pp); -#define CoordDPtoLP(dc, pp) XFORMOBJ_bApplyXform((XFORMOBJ*)&(dc)->dclevel.mxDeviceToWorld, XF_LTOL, 1, pp, pp); -#define CoordLPtoDP(dc, pp) XFORMOBJ_bApplyXform((XFORMOBJ*)&(dc)->dclevel.mxWorldToDevice, XF_LTOL, 1, pp, pp); -#define XForm2MatrixS(m, x) XFORMOBJ_iSetXform((XFORMOBJ*)m, (XFORML*)x) -#define MatrixS2XForm(x, m) XFORMOBJ_iGetXform((XFORMOBJ*)m, (XFORML*)x) +#define IntLPtoDP(pdc, ppt, count) DC_vXformWorldToDevice(pdc, count, (PPOINTL)(ppt), (PPOINTL)(ppt)); +#define CoordLPtoDP(pdc, ppt) DC_vXformWorldToDevice(pdc, 1, (PPOINTL)(ppt), (PPOINTL)(ppt)); +#define IntDPtoLP(pdc, ppt, count) DC_vXformDeviceToWorld(pdc, count, (PPOINTL)(ppt), (PPOINTL)(ppt)); +#define CoordDPtoLP(pdc, ppt) DC_vXformDeviceToWorld(pdc, 1, (PPOINTL)(ppt), (PPOINTL)(ppt)); + +#define XForm2MatrixS(m, x) XFormToMatrix(m, (XFORML*)x) +#define MatrixS2XForm(x, m) MatrixToXForm((XFORML*)x, m) + +FORCEINLINE +void +XFormToMatrix( + MATRIX *pmx, + const XFORML *pxform) +{ + XFORMOBJ xo; + XFORMOBJ_vInit(&xo, pmx); + XFORMOBJ_iSetXform(&xo, pxform); +} + +FORCEINLINE +void +MatrixToXForm( + XFORML *pxform, + const MATRIX *pmx) +{ + XFORMOBJ xo; + XFORMOBJ_vInit(&xo, (MATRIX*)pmx); + XFORMOBJ_iGetXform(&xo, pxform); +} + +FORCEINLINE +void +InvertXform( + XFORML *pxformDest, + const XFORML *pxformSource) +{ + XFORMOBJ xo; + MATRIX mx; + + XFORMOBJ_vInit(&xo, &mx); + XFORMOBJ_iSetXform(&xo, pxformSource); + XFORMOBJ_iInverse(&xo, &xo); + XFORMOBJ_iGetXform(&xo, pxformDest); +} + +FORCEINLINE +void +DC_vXformDeviceToWorld( + IN PDC pdc, + IN ULONG cNumPoints, + IN PPOINTL pptlDest, + IN PPOINTL pptlSource) +{ + XFORMOBJ xo; + + XFORMOBJ_vInit(&xo, &pdc->dclevel.mxDeviceToWorld); + XFORMOBJ_bApplyXform(&xo, XF_LTOL, cNumPoints, pptlDest, pptlSource); +} + +FORCEINLINE +void +DC_vXformWorldToDevice( + IN PDC pdc, + IN ULONG cNumPoints, + IN PPOINTL pptlDest, + IN PPOINTL pptlSource) +{ + XFORMOBJ xo; + + XFORMOBJ_vInit(&xo, &pdc->dclevel.mxWorldToDevice); + XFORMOBJ_bApplyXform(&xo, XF_LTOL, cNumPoints, pptlDest, pptlSource); +} int APIENTRY IntGdiSetMapMode(PDC, int); @@ -20,4 +87,4 @@ IntGdiModifyWorldTransform(PDC pDc, VOID FASTCALL IntMirrorWindowOrg(PDC); void FASTCALL IntFixIsotropicMapping(PDC); LONG FASTCALL IntCalcFillOrigin(PDC); -PPOINTL FASTCALL IntptlBrushOrigin(PDC pdc,LONG,LONG); \ No newline at end of file +PPOINTL FASTCALL IntptlBrushOrigin(PDC pdc,LONG,LONG); diff --git a/subsystems/win32/win32k/include/dc.h b/subsystems/win32/win32k/include/dc.h index b1f8cd1838a..2d94c245ca3 100644 --- a/subsystems/win32/win32k/include/dc.h +++ b/subsystems/win32/win32k/include/dc.h @@ -76,8 +76,8 @@ typedef struct _DCLEVEL HGDIOBJ hPath; /* HPATH */ FLONG flPath; LINEATTRS laPath; /* 0x20 bytes */ - PVOID prgnClip; /* PROSRGNDATA */ - PVOID prgnMeta; + PREGION prgnClip; + PREGION prgnMeta; COLORADJUSTMENT ca; FLONG flFontState; UNIVERSAL_FONT_ID ufi; @@ -126,9 +126,9 @@ typedef struct _DC RECTL erclWindow; RECTL erclBounds; RECTL erclBoundsApp; - PROSRGNDATA prgnAPI; /* PROSRGNDATA */ - PROSRGNDATA prgnVis; /* Visible region (must never be 0) */ - PROSRGNDATA prgnRao; + PREGION prgnAPI; + PREGION prgnVis; /* Visible region (must never be 0) */ + PREGION prgnRao; POINTL ptlFillOrigin; EBRUSHOBJ eboFill; EBRUSHOBJ eboLine; diff --git a/subsystems/win32/win32k/include/gdifloat.h b/subsystems/win32/win32k/include/gdifloat.h index 5f789887784..024b50771d0 100644 --- a/subsystems/win32/win32k/include/gdifloat.h +++ b/subsystems/win32/win32k/include/gdifloat.h @@ -4,6 +4,7 @@ #include #include "dc.h" #include "math.h" +#include "xformobj.h" #include #include FT_FREETYPE_H diff --git a/subsystems/win32/win32k/include/monitor.h b/subsystems/win32/win32k/include/monitor.h index 04a9a3ffc36..729f28d0a91 100644 --- a/subsystems/win32/win32k/include/monitor.h +++ b/subsystems/win32/win32k/include/monitor.h @@ -40,6 +40,7 @@ NTSTATUS CleanupMonitorImpl(); NTSTATUS IntAttachMonitor(PDEVOBJ *pGdiDevice, ULONG DisplayNumber); NTSTATUS IntDetachMonitor(PDEVOBJ *pGdiDevice); +NTSTATUS IntResetMonitorSize(IN PDEVOBJ *pGdiDevice); PMONITOR FASTCALL UserGetMonitorObject(IN HMONITOR); PMONITOR FASTCALL IntGetPrimaryMonitor(VOID); diff --git a/subsystems/win32/win32k/include/msgqueue.h b/subsystems/win32/win32k/include/msgqueue.h index f359f600011..ed80d369dc3 100644 --- a/subsystems/win32/win32k/include/msgqueue.h +++ b/subsystems/win32/win32k/include/msgqueue.h @@ -247,7 +247,7 @@ VOID APIENTRY MsqRemoveWindowMessagesFromQueue(PVOID pWindow); /* F*(&$ headers, ObDereferenceObject((MsgQueue)->NewMessages); \ if ((MsgQueue)->NewMessagesHandle != NULL) \ ZwClose((MsgQueue)->NewMessagesHandle); \ - ExFreePool((MsgQueue)); \ + ExFreePoolWithTag((MsgQueue), USERTAG_Q); \ } \ } while(0) diff --git a/subsystems/win32/win32k/include/object.h b/subsystems/win32/win32k/include/object.h index 437611aa09d..692ad1c0a1c 100644 --- a/subsystems/win32/win32k/include/object.h +++ b/subsystems/win32/win32k/include/object.h @@ -67,8 +67,6 @@ typedef struct _USER_REFERENCE_ENTRY PVOID obj; } USER_REFERENCE_ENTRY, *PUSER_REFERENCE_ENTRY; -#include - #define USER_ASSERT(exp,file,line) \ if (!(exp)) {RtlAssert(#exp,(PVOID)file,line,"");} diff --git a/subsystems/win32/win32k/include/surface.h b/subsystems/win32/win32k/include/surface.h index 485f3dc72b3..26e512d9c29 100644 --- a/subsystems/win32/win32k/include/surface.h +++ b/subsystems/win32/win32k/include/surface.h @@ -125,7 +125,7 @@ SURFACE_bSetBitmapBits( #define GDIDEV(SurfObj) ((PDEVOBJ *)((SurfObj)->hdev)) #define GDIDEVFUNCS(SurfObj) ((PDEVOBJ *)((SurfObj)->hdev))->DriverFunctions -ULONG FASTCALL BitmapFormat (WORD Bits, DWORD Compression); +ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression); extern UCHAR gajBitsPerFormat[]; #define BitsPerFormat(Format) gajBitsPerFormat[Format] diff --git a/subsystems/win32/win32k/include/tags.h b/subsystems/win32/win32k/include/tags.h index 64e8de62874..644d0cd3a33 100644 --- a/subsystems/win32/win32k/include/tags.h +++ b/subsystems/win32/win32k/include/tags.h @@ -1,48 +1,35 @@ #pragma once #define TAG_STRING ' RTS' /* string */ -#define TAG_RTLREGISTRY 'vrqR' /* RTL registry */ - -/* ntuser */ -#define TAG_MOUSE 'SUOM' /* mouse */ -#define TAG_KEYBOARD ' DBK' /* keyboard */ -#define TAG_ACCEL 'LCCA' /* accelerator */ -#define TAG_HOOK 'KHNW' /* hook */ -#define TAG_HOTKEY 'KTOH' /* hotkey */ -#define TAG_MENUITEM 'INEM' /* menu item */ +#define TAG_HOOK 'ohsU' /* hook */ +#define TAG_MENUITEM 'emsU' /* menu item */ #define TAG_MSG 'GSEM' /* message */ -#define TAG_MSGQ 'QGSM' /* message queue */ #define TAG_USRMSG 'GSMU' /* user message */ -#define TAG_WNDPROP 'PRPW' /* window property */ -#define TAG_WNAM 'MANW' /* window name */ -#define TAG_WINLIST 'SLNW' /* window handle list */ -#define TAG_WININTLIST 'PINW' /* window internal pos */ -#define TAG_WINPROCLST 'LPNW' /* window proc list */ #define TAG_SBARINFO 'NIBS' /* scrollbar info */ -#define TAG_TIMER 'RMIT' /* timer entry */ -#define TAG_TIMERTD 'TMIT' /* timer thread dereference list */ #define TAG_TIMERBMP 'BMIT' /* timers bitmap */ -#define TAG_CALLBACK 'KCBC' /* callback memory */ #define TAG_WINSTA 'ATSW' /* window station */ -#define TAG_PDCE 'cdsU' /* dce */ -#define TAG_ATTACHINFO 'iasU' /* Attach Info Input */ -#define TAG_INPUT 'yssU' /* Input */ +#define TAG_FONT 'ETNF' /* font entry */ +#define TAG_BEZIER 'RZEB' /* bezier */ +#define TAG_SHAPE 'phSG' /* shape */ +#define TAG_COLORMAP 'MLOC' /* color map */ +#define TAG_GDIHNDTBLE 'bthG' /* gdi handle table */ +#define TAG_DIB ' BID' /* dib */ /* gdi objects from the handle table */ -#define TAG_DC '1alG' /* dc */ -#define TAG_REGION '4alG' /* region */ -#define TAG_SURFACE '5alG' /* bitmap */ +#define TAG_DC GDITAG_HMGR_LOOKASIDE_DC_TYPE +#define TAG_REGION GDITAG_HMGR_LOOKASIDE_RGN_TYPE +#define TAG_SURFACE GDITAG_HMGR_LOOKASIDE_SURF_TYPE #define TAG_CLIENTOBJ '60hG' #define TAG_PATH '70hG' -#define TAG_PALETTE '8alG' +#define TAG_PALETTE GDITAG_HMGR_LOOKASIDE_PAL_TYPE #define TAG_ICMLCS '90hG' -#define TAG_LFONT ':alG' +#define TAG_LFONT GDITAG_HMGR_LOOKASIDE_LFONT_TYPE #define TAG_RFONT ';0gG' /* correct? */ #define TAG_PFE '<0hG' #define TAG_PFT '=0hG' /* correct? */ #define TAG_ICMCXF '>0hG' /* correct? */ #define TAG_SPRITE '?0hG' /* correct? */ -#define TAG_BRUSH '@alG' +#define TAG_BRUSH GDITAG_HMGR_LOOKASIDE_BRUSH_TYPE #define TAG_UMPD 'A0hG' /* correct? */ #define TAG_SPACE 'c0hG' /* correct? */ #define TAG_META 'E0hG' /* correct? */ @@ -56,50 +43,15 @@ #define TAG_DCIOBJ 'M0hG' /* correct? */ #define TAG_SPOOL 'N0hG' /* correct? */ -/* other gdi objects */ -#define TAG_BEZIER 'RZEB' /* bezier */ -#define TAG_BITMAP 'PMTB' /* bitmap */ -#define TAG_PATBLT 'TLBP' /* patblt */ -#define TAG_CLIP 'PILC' /* clipping */ -#define TAG_COORD 'DROC' /* coords */ -#define TAG_GDIDEV 'vedG' /* gdi dev support*/ -#define TAG_GDIPDEV 'veDG' /* gdi PDev */ -#define TAG_GDIHNDTBLE 'HIDG' /* gdi handle table */ -#define TAG_GDIICM 'mciG' /* gdi Icm */ -#define TAG_DIB ' BID' /* dib */ -#define TAG_COLORMAP 'MLOC' /* color map */ -#define TAG_SHAPE 'PAHS' /* shape */ -#define TAG_PALETTEMAP 'MLAP' /* palette mapping */ -#define TAG_PRINT 'TNRP' /* print */ -#define TAG_GDITEXT 'OTXT' /* text */ -#define TAG_PENSTYLES 'ytsG' /* pen styles */ - -/* Eng objects */ -#define TAG_CLIPOBJ 'OPLC' /* clip object */ -#define TAG_DRIVEROBJ 'OVRD' /* driver object */ -#define TAG_DFSM 'msfD' /* Eng event allocation */ -#define TAG_EPATH 'tapG' /* path object */ -#define TAG_FONT 'ETNF' /* font entry */ -#define TAG_FONTOBJ 'tnfG' /* font object */ -#define TAG_WNDOBJ 'ODNW' /* window object */ -#define TAG_XLATEOBJ 'OALX' /* xlate object */ -#define TAG_GSEM 'mesG' /* Gdi Semaphore */ - -/* misc */ -#define TAG_DRIVER 'VRDG' /* video drivers */ -#define TAG_FNTFILE 'FTNF' /* font file */ -#define TAG_SSECTPOOL 'PCSS' /* shared section pool */ -#define TAG_PFF 'ffpG' /* physical font file */ - /* Dx internal tags rember I do not known if it right namees */ #define TAG_DXPVMLIST 'LPXD' /* pmvlist for the driver */ #define TAG_DXFOURCC 'OFXD' /* pdwFourCC for the driver */ -#define TAG_DDRAW '1 hD' +#define TAG_DDRAW '1 hD' #define TAG_DDSURF '2 hD' #define TAG_EDDGBL 'GDDE' /* ? edd_directdraw_global ??*/ /* Official tags */ -#define GDITAG_ATM_FONT 'Adbe' +#define GDITAG_ATM_FONT 'ebdA' #define GDITAG_BMP_FONT 'dfmB' #define GDITAG_ENG_EVENT 'msfD' #define GDITAG_DWM_HWND_LOOKUP 'LmwD' @@ -234,6 +186,7 @@ #define GDITAG_VF_FONT 'dftV' #define GDITAG_W32PIDLOCK 'l23W' #define GDITAG_HANDLEPUSHLOCK 'lpHG' + #define USERTAG_SERVICE_TABLE 'lacU' #define USERTAG_MONITOR_MARGIN 'mamU' #define USERTAG_REDIRECT 'rdrU' diff --git a/subsystems/win32/win32k/include/xformobj.h b/subsystems/win32/win32k/include/xformobj.h index d9f05f7214e..0e264922443 100644 --- a/subsystems/win32/win32k/include/xformobj.h +++ b/subsystems/win32/win32k/include/xformobj.h @@ -1,10 +1,43 @@ #pragma once +typedef struct _EXFORMOBJ +{ + MATRIX *pmx; +} EXFORMOBJ; + +#define XFORMOBJ EXFORMOBJ +#define XFORMOBJ_iGetXform EXFORMOBJ_iGetXform +#define XFORMOBJ_iGetFloatObjXform EXFORMOBJ_iGetFloatObjXform +#define XFORMOBJ_bApplyXform EXFORMOBJ_bApplyXform +#define XFORMOBJ_vInit EXFORMOBJ_vInit +#define XFORMOBJ_pmx EXFORMOBJ_pmx +#define XFORMOBJ_iSetXform EXFORMOBJ_iSetXform +#define XFORMOBJ_iCombine EXFORMOBJ_iCombine +#define XFORMOBJ_iCombineXform EXFORMOBJ_iCombineXform +#define XFORMOBJ_iInverse EXFORMOBJ_iInverse + +FORCEINLINE +VOID +XFORMOBJ_vInit( + OUT XFORMOBJ *pxo, + IN MATRIX *pmx) +{ + pxo->pmx = pmx; +} + +FORCEINLINE +MATRIX* +XFORMOBJ_pmx( + IN XFORMOBJ *pxo) +{ + return pxo->pmx; +} + ULONG INTERNAL_CALL XFORMOBJ_iSetXform( OUT XFORMOBJ *pxo, - IN XFORML * pxform); + IN const XFORML *pxform); ULONG INTERNAL_CALL @@ -23,6 +56,21 @@ XFORMOBJ_iCombineXform( ULONG INTERNAL_CALL -XFORMOBJ_Inverse( +XFORMOBJ_iInverse( OUT XFORMOBJ *pxoDst, IN XFORMOBJ *pxoSrc); + +ULONG +APIENTRY +XFORMOBJ_iGetXform( + IN XFORMOBJ *pxo, + OUT XFORML *pxform); + +BOOL +APIENTRY +XFORMOBJ_bApplyXform( + IN XFORMOBJ *pxo, + IN ULONG iMode, + IN ULONG cPoints, + IN PVOID pvIn, + OUT PVOID pvOut); diff --git a/subsystems/win32/win32k/ntuser/accelerator.c b/subsystems/win32/win32k/ntuser/accelerator.c index 94b52d05af4..78f1fd005b5 100644 --- a/subsystems/win32/win32k/ntuser/accelerator.c +++ b/subsystems/win32/win32k/ntuser/accelerator.c @@ -370,7 +370,7 @@ NtUserCreateAcceleratorTable( Accel->Count = EntriesCount; if (Accel->Count > 0) { - Accel->Table = ExAllocatePoolWithTag(PagedPool, EntriesCount * sizeof(ACCEL), TAG_ACCEL); + Accel->Table = ExAllocatePoolWithTag(PagedPool, EntriesCount * sizeof(ACCEL), USERTAG_ACCEL); if (Accel->Table == NULL) { UserDereferenceObject(Accel); @@ -388,10 +388,10 @@ NtUserCreateAcceleratorTable( } else { - RtlMultiByteToUnicodeN(&Accel->Table[Index].key, - sizeof(WCHAR), - NULL, - (PCSTR)&Entries[Index].key, + RtlMultiByteToUnicodeN(&Accel->Table[Index].key, + sizeof(WCHAR), + NULL, + (PCSTR)&Entries[Index].key, sizeof(CHAR)); } @@ -438,7 +438,7 @@ NtUserDestroyAcceleratorTable( if (Accel->Table != NULL) { - ExFreePoolWithTag(Accel->Table, TAG_ACCEL); + ExFreePoolWithTag(Accel->Table, USERTAG_ACCEL); Accel->Table = NULL; } diff --git a/subsystems/win32/win32k/ntuser/callback.c b/subsystems/win32/win32k/ntuser/callback.c index bb087f074f5..45e9f6accc0 100644 --- a/subsystems/win32/win32k/ntuser/callback.c +++ b/subsystems/win32/win32k/ntuser/callback.c @@ -35,7 +35,7 @@ IntCbAllocateMemory(ULONG Size) PTHREADINFO W32Thread; if(!(Mem = ExAllocatePoolWithTag(PagedPool, Size + sizeof(INT_CALLBACK_HEADER), - TAG_CALLBACK))) + USERTAG_CALLBACK))) { return NULL; } @@ -67,7 +67,7 @@ IntCbFreeMemory(PVOID Data) RemoveEntryList(&Mem->ListEntry); /* free memory */ - ExFreePoolWithTag(Mem, TAG_CALLBACK); + ExFreePoolWithTag(Mem, USERTAG_CALLBACK); } VOID FASTCALL @@ -475,15 +475,15 @@ co_IntCallHookProc(INT HookId, case WH_MOUSE: RtlCopyMemory(Extra, (PVOID) lParam, sizeof(MOUSEHOOKSTRUCT)); Common->lParam = (LPARAM) (Extra - (PCHAR) Common); - break; + break; case WH_CALLWNDPROC: RtlCopyMemory(Extra, (PVOID) lParam, sizeof(CWPSTRUCT)); Common->lParam = (LPARAM) (Extra - (PCHAR) Common); - break; + break; case WH_CALLWNDPROCRET: RtlCopyMemory(Extra, (PVOID) lParam, sizeof(CWPRETSTRUCT)); Common->lParam = (LPARAM) (Extra - (PCHAR) Common); - break; + break; case WH_MSGFILTER: case WH_SYSMSGFILTER: case WH_GETMESSAGE: @@ -494,7 +494,7 @@ co_IntCallHookProc(INT HookId, case WH_FOREGROUNDIDLE: case WH_KEYBOARD: case WH_SHELL: - break; + break; } ResultPointer = NULL; @@ -618,7 +618,7 @@ co_IntCallEventProc(HWINEVENTHOOK hook, UserEnterCo(); IntCbFreeMemory(Argument); - + if (!NT_SUCCESS(Status)) { return 0; @@ -654,7 +654,7 @@ co_IntCallLoadMenu( HINSTANCE hModule, Common = (PLOADMENU_CALLBACK_ARGUMENTS) Argument; // Help Intersource check and MenuName is now 4 bytes + so zero it. - RtlZeroMemory(Common, ArgumentLength); + RtlZeroMemory(Common, ArgumentLength); Common->hModule = hModule; if (pMenuName->Length) diff --git a/subsystems/win32/win32k/ntuser/cursoricon.c b/subsystems/win32/win32k/ntuser/cursoricon.c index a2ee81234a8..1fd9f03ca42 100644 --- a/subsystems/win32/win32k/ntuser/cursoricon.c +++ b/subsystems/win32/win32k/ntuser/cursoricon.c @@ -99,7 +99,7 @@ PCURICON_OBJECT FASTCALL UserGetCurIconObject(HCURSOR hCurIcon) return CurIcon; } -HCURSOR +PCURICON_OBJECT FASTCALL UserSetCursor( PCURICON_OBJECT NewCursor, @@ -107,22 +107,17 @@ UserSetCursor( { PSYSTEM_CURSORINFO CurInfo; PCURICON_OBJECT OldCursor; - HCURSOR hOldCursor = (HCURSOR)0; HDC hdcScreen; CurInfo = IntGetSysCursorInfo(); OldCursor = CurInfo->CurrentCursorObject; - if (OldCursor) - { - hOldCursor = (HCURSOR)OldCursor->Self; - } /* Is the new cursor the same as the old cursor? */ if (OldCursor == NewCursor) { /* Nothing to to do in this case */ - return hOldCursor; + return OldCursor; } /* Get the screen DC */ @@ -134,8 +129,6 @@ UserSetCursor( /* Do we have a new cursor? */ if (NewCursor) { - UserReferenceObject(NewCursor); - CurInfo->ShowingCursor = 1; CurInfo->CurrentCursorObject = NewCursor; @@ -147,8 +140,6 @@ UserSetCursor( NewCursor->IconInfo.yHotspot, gpsi->ptCursor.x, gpsi->ptCursor.y); - - } else { @@ -164,14 +155,8 @@ UserSetCursor( CurInfo->ShowingCursor = 0; } - /* OldCursor is not in use anymore */ - if (OldCursor) - { - UserDereferenceObject(OldCursor); - } - - /* Return handle of the old cursor */ - return hOldCursor; + /* Return the old cursor */ + return OldCursor; } BOOL UserSetCursorPos( INT x, INT y, BOOL SendMouseMoveMsg) @@ -734,7 +719,7 @@ NtUserClipCursor( prcl = &rclLocal; } - + UserEnterExclusive(); /* Call the internal function */ @@ -873,38 +858,36 @@ APIENTRY NtUserSetCursor( HCURSOR hCursor) { - PCURICON_OBJECT CurIcon; - HICON OldCursor; - DECLARE_RETURN(HCURSOR); + PCURICON_OBJECT pcurOld, pcurNew; + HCURSOR hOldCursor = NULL; DPRINT("Enter NtUserSetCursor\n"); UserEnterExclusive(); if (hCursor) { - if (!(CurIcon = UserGetCurIconObject(hCursor))) + pcurNew = UserGetCurIconObject(hCursor); + if (!pcurNew) { - RETURN(NULL); + EngSetLastError(ERROR_INVALID_CURSOR_HANDLE); + goto leave; } } else { - CurIcon = NULL; + pcurNew = NULL; } - OldCursor = UserSetCursor(CurIcon, FALSE); - - if (CurIcon) + pcurOld = UserSetCursor(pcurNew, FALSE); + if (pcurOld) { - UserDereferenceObject(CurIcon); + hOldCursor = (HCURSOR)pcurOld->Self; + UserDereferenceObject(pcurOld); } - RETURN(OldCursor); - -CLEANUP: - DPRINT("Leave NtUserSetCursor, ret=%i\n",_ret_); +leave: UserLeave(); - END_CLEANUP; + return hOldCursor; } diff --git a/subsystems/win32/win32k/ntuser/display.c b/subsystems/win32/win32k/ntuser/display.c index e50b0032d8e..7e0f25cf22d 100644 --- a/subsystems/win32/win32k/ntuser/display.c +++ b/subsystems/win32/win32k/ntuser/display.c @@ -739,15 +739,16 @@ UserChangeDisplaySettings( if (!(flags & CDS_NORESET)) { ULONG ulResult; + PVOID pvOldCursor; /* Remove mouse pointer */ - UserSetCursor(NULL, TRUE); + pvOldCursor = UserSetCursor(NULL, TRUE); /* Do the mode switch */ ulResult = PDEVOBJ_bSwitchMode(ppdev, pdm); /* Restore mouse pointer, no hooks called */ - UserSetCursorPos(gpsi->ptCursor.x, gpsi->ptCursor.y, FALSE); + UserSetCursor(pvOldCursor, TRUE); /* Check for failure */ if (!ulResult) @@ -764,6 +765,9 @@ UserChangeDisplaySettings( //IntvGetDeviceCaps(&PrimarySurface, &GdiHandleTable->DevCaps); + /* Set new size of the monitor */ + IntResetMonitorSize(ppdev); + /* Remove all cursor clipping */ UserClipCursor(NULL); diff --git a/subsystems/win32/win32k/ntuser/hotkey.c b/subsystems/win32/win32k/ntuser/hotkey.c index 0b8a68efc84..1d5322e1a8a 100644 --- a/subsystems/win32/win32k/ntuser/hotkey.c +++ b/subsystems/win32/win32k/ntuser/hotkey.c @@ -192,7 +192,7 @@ NtUserRegisterHotKey(HWND hWnd, RETURN( FALSE); } - HotKeyItem = ExAllocatePoolWithTag (PagedPool, sizeof(HOT_KEY_ITEM), TAG_HOTKEY); + HotKeyItem = ExAllocatePoolWithTag (PagedPool, sizeof(HOT_KEY_ITEM), USERTAG_HOTKEY); if (HotKeyItem == NULL) { RETURN( FALSE); @@ -235,7 +235,7 @@ NtUserUnregisterHotKey(HWND hWnd, int id) if (HotKeyItem->hWnd == hWnd && HotKeyItem->id == id) { RemoveEntryList (&HotKeyItem->ListEntry); - ExFreePool (HotKeyItem); + ExFreePoolWithTag(HotKeyItem, USERTAG_HOTKEY); RETURN( TRUE); } diff --git a/subsystems/win32/win32k/ntuser/input.c b/subsystems/win32/win32k/ntuser/input.c index e431ba7694a..04fc11531be 100644 --- a/subsystems/win32/win32k/ntuser/input.c +++ b/subsystems/win32/win32k/ntuser/input.c @@ -376,7 +376,7 @@ IntKeyboardGetIndicatorTrans(HANDLE KeyboardDeviceHandle, Ret = ExAllocatePoolWithTag(PagedPool, Size, - TAG_KEYBOARD); + USERTAG_KBDTABLE); while (Ret) { @@ -392,13 +392,13 @@ IntKeyboardGetIndicatorTrans(HANDLE KeyboardDeviceHandle, if (Status != STATUS_BUFFER_TOO_SMALL) break; - ExFreePoolWithTag(Ret, TAG_KEYBOARD); + ExFreePoolWithTag(Ret, USERTAG_KBDTABLE); Size += sizeof(KEYBOARD_INDICATOR_TRANSLATION); Ret = ExAllocatePoolWithTag(PagedPool, Size, - TAG_KEYBOARD); + USERTAG_KBDTABLE); } if (!Ret) @@ -406,7 +406,7 @@ IntKeyboardGetIndicatorTrans(HANDLE KeyboardDeviceHandle, if (Status != STATUS_SUCCESS) { - ExFreePoolWithTag(Ret, TAG_KEYBOARD); + ExFreePoolWithTag(Ret, USERTAG_KBDTABLE); return Status; } @@ -942,7 +942,7 @@ InitInputImpl(VOID) KeInitializeEvent(&InputThreadsStart, NotificationEvent, FALSE); - MasterTimer = ExAllocatePoolWithTag(NonPagedPool, sizeof(KTIMER), TAG_INPUT); + MasterTimer = ExAllocatePoolWithTag(NonPagedPool, sizeof(KTIMER), USERTAG_SYSTEM); if (!MasterTimer) { DPRINT1("Win32K: Failed making Raw Input thread a win32 thread.\n"); @@ -1423,7 +1423,7 @@ UserAttachThreadInput( PTHREADINFO pti, PTHREADINFO ptiTo, BOOL fAttach) /* If Attach set, allocate and link. */ if ( fAttach ) { - pai = ExAllocatePoolWithTag(PagedPool, sizeof(ATTACHINFO), TAG_ATTACHINFO); + pai = ExAllocatePoolWithTag(PagedPool, sizeof(ATTACHINFO), USERTAG_ATTACHINFO); if ( !pai ) return FALSE; pai->paiNext = gpai; @@ -1451,7 +1451,7 @@ UserAttachThreadInput( PTHREADINFO pti, PTHREADINFO ptiTo, BOOL fAttach) if (paiprev) paiprev->paiNext = pai->paiNext; - ExFreePoolWithTag(pai, TAG_ATTACHINFO); + ExFreePoolWithTag(pai, USERTAG_ATTACHINFO); } return TRUE; diff --git a/subsystems/win32/win32k/ntuser/kbdlayout.c b/subsystems/win32/win32k/ntuser/kbdlayout.c index dc5c1393b53..f48233bb044 100644 --- a/subsystems/win32/win32k/ntuser/kbdlayout.c +++ b/subsystems/win32/win32k/ntuser/kbdlayout.c @@ -196,7 +196,7 @@ static PKBL UserLoadDllAndCreateKbl(DWORD LocaleId) ULONG hKl; LANGID langid; - NewKbl = ExAllocatePoolWithTag(PagedPool, sizeof(KBL), TAG_KEYBOARD); + NewKbl = ExAllocatePoolWithTag(PagedPool, sizeof(KBL), USERTAG_KBDLAYOUT); if(!NewKbl) { @@ -209,7 +209,7 @@ static PKBL UserLoadDllAndCreateKbl(DWORD LocaleId) if(!UserLoadKbdDll(NewKbl->Name, &NewKbl->hModule, &NewKbl->KBTables)) { DPRINT("%s: failed to load %x dll!\n", __FUNCTION__, LocaleId); - ExFreePoolWithTag(NewKbl, TAG_KEYBOARD); + ExFreePoolWithTag(NewKbl, USERTAG_KBDLAYOUT); return NULL; } @@ -398,7 +398,7 @@ BOOL UserUnloadKbl(PKBL pKbl) //Unload the layout EngUnloadImage(pKbl->hModule); RemoveEntryList(&pKbl->List); - ExFreePoolWithTag(pKbl, TAG_KEYBOARD); + ExFreePoolWithTag(pKbl, USERTAG_KBDLAYOUT); } return TRUE; diff --git a/subsystems/win32/win32k/ntuser/message.c b/subsystems/win32/win32k/ntuser/message.c index 97f89a339f6..9abaa04d357 100644 --- a/subsystems/win32/win32k/ntuser/message.c +++ b/subsystems/win32/win32k/ntuser/message.c @@ -566,10 +566,10 @@ IdlePing(VOID) if (ForegroundQueue) ptiForeground = ForegroundQueue->Thread->Tcb.Win32Thread; - + pti = PsGetCurrentThreadWin32Thread(); - if ( pti ) + if ( pti ) { pti->pClientInfo->cSpins = 0; // Reset spins. @@ -696,7 +696,7 @@ IntDispatchMessage(PMSG pMsg) (LPARAM)Time, 0); } - return retval; + return retval; } else { @@ -713,7 +713,7 @@ IntDispatchMessage(PMSG pMsg) // Need a window! if ( !Window ) return 0; - /* Since we are doing a callback on the same thread right away, there is + /* Since we are doing a callback on the same thread right away, there is no need to copy the lparam to kernel mode and then back to usermode. We just pretend it isn't a pointer */ @@ -842,12 +842,12 @@ co_IntPeekMessage( PMSG Msg, } if ((ProcessMask & QS_INPUT) && - co_MsqPeekHardwareMessage( ThreadQueue, - RemoveMessages, - Window, - MsgFilterMin, + co_MsqPeekHardwareMessage( ThreadQueue, + RemoveMessages, + Window, + MsgFilterMin, MsgFilterMax, - ProcessMask, + ProcessMask, Msg)) { return TRUE; @@ -1124,9 +1124,9 @@ UserPostMessage( HWND Wnd, EngSetLastError(ERROR_INVALID_PARAMETER); return FALSE; } - co_IntSendMessageNoWait(KernelModeMsg.hwnd, - KernelModeMsg.message, - KernelModeMsg.wParam, + co_IntSendMessageNoWait(KernelModeMsg.hwnd, + KernelModeMsg.message, + KernelModeMsg.wParam, KernelModeMsg.lParam); if (MsgMemoryEntry && KernelModeMsg.lParam) @@ -1164,7 +1164,7 @@ UserPostMessage( HWND Wnd, { UserPostMessage(List[i], Msg, wParam, lParam); } - ExFreePoolWithTag(List,TAG_WINLIST);//ExFreePool(List); + ExFreePoolWithTag(List, USERTAG_WINDOWLIST); } } else @@ -1190,13 +1190,13 @@ UserPostMessage( HWND Wnd, /* FIXME - last error code? */ return FALSE; } - + if (WM_QUIT == Msg) { MsqPostQuitMessage(Window->head.pti->MessageQueue, wParam); } else - { + { MsqPostMessage(Window->head.pti->MessageQueue, &Message, FALSE, QS_POSTMESSAGE); } } @@ -1401,7 +1401,7 @@ co_IntSendMessageTimeout( HWND hWnd, return (LRESULT) TRUE; } -LRESULT FASTCALL +LRESULT FASTCALL co_IntSendMessageNoWait(HWND hWnd, UINT Msg, WPARAM wParam, @@ -1538,7 +1538,7 @@ co_IntSendMessageWithCallBack( HWND hWnd, Message->QS_Flags = QS_SENDMESSAGE; MsqWakeQueue(Window->head.pti->MessageQueue, QS_SENDMESSAGE, FALSE); - + InsertTailList(&Window->head.pti->MessageQueue->SentMessagesListHead, &Message->ListEntry); IntDereferenceMessageQueue(Window->head.pti->MessageQueue); @@ -1689,9 +1689,9 @@ IntGetQueueStatus(DWORD Changes) // wine: Changes &= (QS_ALLINPUT|QS_ALLPOSTMESSAGE|QS_SMRESULT); - /* High word, types of messages currently in the queue. + /* High word, types of messages currently in the queue. Low word, types of messages that have been added to the queue and that - are still in the queue + are still in the queue */ Result = MAKELONG(pti->pcti->fsChangeBits & Changes, pti->pcti->fsWakeBits & Changes); @@ -1762,7 +1762,7 @@ NtUserPostThreadMessage(DWORD idThread, ret = UserPostThreadMessage( idThread, Msg, wParam, lParam); UserLeave(); - + return ret; } @@ -1776,7 +1776,7 @@ NtUserWaitMessage(VOID) ret = co_IntWaitMessage(NULL, 0, 0); DPRINT("NtUserWaitMessage Leave\n"); UserLeave(); - + return ret; } @@ -1859,7 +1859,7 @@ NtUserPeekMessage( PMSG pMsg, } _SEH2_END; } - + return Ret; } @@ -1963,7 +1963,7 @@ NtUserTranslateMessage(LPMSG lpMsg, UINT flags) BOOL APIENTRY NtUserMessageCall( HWND hWnd, - UINT Msg, + UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ResultInfo, @@ -2076,7 +2076,7 @@ NtUserMessageCall( HWND hWnd, { CALL_BACK_INFO CallBackInfo; ULONG_PTR uResult; - + _SEH2_TRY { ProbeForRead((PVOID)ResultInfo, sizeof(CALL_BACK_INFO), 1); @@ -2133,7 +2133,7 @@ NtUserMessageCall( HWND hWnd, } _SEH2_END; } - + Ret = co_IntDoSendMessage( hWnd, Msg, wParam, lParam, &dsm ); if (pdsm) diff --git a/subsystems/win32/win32k/ntuser/monitor.c b/subsystems/win32/win32k/ntuser/monitor.c index 9dd49ef08b8..d744d6ee563 100644 --- a/subsystems/win32/win32k/ntuser/monitor.c +++ b/subsystems/win32/win32k/ntuser/monitor.c @@ -246,6 +246,51 @@ IntDetachMonitor(IN PDEVOBJ *pGdiDevice) return STATUS_SUCCESS; } +/* IntResetMonitorSize + * + * Reset size of the monitor using atached device + * + * Arguments + * + * PMONITOR + * pGdiDevice Pointer to the PDEVOBJ, which size has changed + * + * Return value + * Returns a NTSTATUS + */ +NTSTATUS +IntResetMonitorSize(IN PDEVOBJ *pGdiDevice) +{ + PMONITOR Monitor; + + for (Monitor = gMonitorList; Monitor != NULL; Monitor = Monitor->Next) + { + if (Monitor->GdiDevice == pGdiDevice) + break; + } + + if (Monitor == NULL) + { + /* no monitor for given device found */ + return STATUS_INVALID_PARAMETER; + } + + Monitor->rcMonitor.left = 0; + Monitor->rcMonitor.top = 0; + Monitor->rcMonitor.right = Monitor->rcMonitor.left + Monitor->GdiDevice->gdiinfo.ulHorzRes; + Monitor->rcMonitor.bottom = Monitor->rcMonitor.top + Monitor->GdiDevice->gdiinfo.ulVertRes; + Monitor->rcWork = Monitor->rcMonitor; + + if (Monitor->hrgnMonitor) + REGION_FreeRgnByHandle(Monitor->hrgnMonitor); + + Monitor->hrgnMonitor = IntSysCreateRectRgnIndirect( &Monitor->rcMonitor ); + + IntGdiSetRegionOwner(Monitor->hrgnMonitor, GDI_OBJ_HMGR_PUBLIC); + + return STATUS_SUCCESS; +} + /* IntGetPrimaryMonitor * * Returns a PMONITOR for the primary monitor diff --git a/subsystems/win32/win32k/ntuser/msgqueue.c b/subsystems/win32/win32k/ntuser/msgqueue.c index 232fe21e8c3..6947db56004 100644 --- a/subsystems/win32/win32k/ntuser/msgqueue.c +++ b/subsystems/win32/win32k/ntuser/msgqueue.c @@ -121,7 +121,7 @@ ClearMsgBitsMask(PUSER_MESSAGE_QUEUE Queue, UINT MessageBits) pti = Queue->Thread->Tcb.Win32Thread; if (MessageBits & QS_KEY) - { + { if (--Queue->nCntsQBits[QSRosKey] == 0) ClrMask |= QS_KEY; } if (MessageBits & QS_MOUSEMOVE) // ReactOS hard coded. @@ -244,7 +244,7 @@ co_MsqInsertMouseMessage(MSG* Msg) pwnd != NULL; pwnd = pwnd->spwndNext ) { - if((pwnd->style & WS_VISIBLE) && + if((pwnd->style & WS_VISIBLE) && IntPtInWindow(pwnd, Msg->pt.x, Msg->pt.y)) { Msg->hwnd = pwnd->head.h; @@ -869,7 +869,7 @@ static void MsqSendParentNotify( PWND pwnd, WORD event, WORD idChild, POINT pt ) if (pwndParent == pwndDesktop) break; pt.x += pwnd->rcClient.left - pwndParent->rcClient.left; pt.y += pwnd->rcClient.top - pwndParent->rcClient.top; - + pwnd = pwndParent; co_IntSendMessage( UserHMGetHandle(pwnd), WM_PARENTNOTIFY, MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) ); @@ -911,7 +911,7 @@ BOOL co_IntProcessMouseMessage(MSG* msg, BOOL* RemoveMessages, UINT first, UINT } DPRINT("Got mouse message for 0x%x, hittest: 0x%x\n", msg->hwnd, hittest ); - + if (pwndMsg == NULL || pwndMsg->head.pti != pti) { /* Remove and ignore the message */ @@ -981,7 +981,7 @@ BOOL co_IntProcessMouseMessage(MSG* msg, BOOL* RemoveMessages, UINT first, UINT } } - if (!((first == 0 && last == 0) || (message >= first || message <= last))) + if (!((first == 0 && last == 0) || (message >= first || message <= last))) { DPRINT("Message out of range!!!\n"); RETURN(FALSE); @@ -1104,8 +1104,8 @@ BOOL co_IntProcessMouseMessage(MSG* msg, BOOL* RemoveMessages, UINT first, UINT if (pwndTop && pwndTop != pwndDesktop) { - LONG ret = co_IntSendMessage( msg->hwnd, - WM_MOUSEACTIVATE, + LONG ret = co_IntSendMessage( msg->hwnd, + WM_MOUSEACTIVATE, (WPARAM)UserHMGetHandle(pwndTop), MAKELONG( hittest, msg->message)); switch(ret) @@ -1259,7 +1259,7 @@ co_MsqPeekHardwareMessage(IN PUSER_MESSAGE_QUEUE MessageQueue, CurrentMessage = CONTAINING_RECORD(CurrentEntry, USER_MESSAGE, ListEntry); - do + do { if (IsListEmpty(CurrentEntry)) break; if (!CurrentMessage) break; @@ -1305,7 +1305,7 @@ MsqPeekMessage(IN PUSER_MESSAGE_QUEUE MessageQueue, PLIST_ENTRY CurrentEntry; PUSER_MESSAGE CurrentMessage; PLIST_ENTRY ListHead; - + CurrentEntry = MessageQueue->PostedMessagesListHead.Flink; ListHead = &MessageQueue->PostedMessagesListHead; @@ -1351,7 +1351,7 @@ co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWND WndFilter, ret = KeWaitForSingleObject(MessageQueue->NewMessages, Executive, UserMode, - FALSE, + FALSE, NULL); UserEnterCo(); return ret; @@ -1414,7 +1414,7 @@ MsqCleanupMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue) PUSER_MESSAGE CurrentMessage; PUSER_SENT_MESSAGE CurrentSentMessage; PTHREADINFO pti; - + pti = MessageQueue->Thread->Tcb.Win32Thread; @@ -1437,7 +1437,7 @@ MsqCleanupMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue) DPRINT("Notify the sender and remove a message from the queue that had not been dispatched\n"); /* remove the message from the dispatching list if needed */ - if ((!(CurrentSentMessage->HookMessage & MSQ_SENTNOWAIT)) + if ((!(CurrentSentMessage->HookMessage & MSQ_SENTNOWAIT)) && (CurrentSentMessage->DispatchingListEntry.Flink != NULL)) { RemoveEntryList(&CurrentSentMessage->DispatchingListEntry); @@ -1539,7 +1539,7 @@ MsqCreateMessageQueue(struct _ETHREAD *Thread) MessageQueue = (PUSER_MESSAGE_QUEUE)ExAllocatePoolWithTag(NonPagedPool, sizeof(USER_MESSAGE_QUEUE) + sizeof(THRDCARETINFO), - TAG_MSGQ); + USERTAG_Q); if (!MessageQueue) { diff --git a/subsystems/win32/win32k/ntuser/windc.c b/subsystems/win32/win32k/ntuser/windc.c index e5534172c6b..89f44f76fe0 100644 --- a/subsystems/win32/win32k/ntuser/windc.c +++ b/subsystems/win32/win32k/ntuser/windc.c @@ -82,14 +82,14 @@ DceAllocDCE(PWND Window OPTIONAL, DCE_TYPE Type) { PDCE pDce; - pDce = ExAllocatePoolWithTag(PagedPool, sizeof(DCE), TAG_PDCE); + pDce = ExAllocatePoolWithTag(PagedPool, sizeof(DCE), USERTAG_DCE); if(!pDce) return NULL; pDce->hDC = DceCreateDisplayDC(); if (!pDce->hDC) { - ExFreePoolWithTag(pDce, TAG_PDCE); + ExFreePoolWithTag(pDce, USERTAG_DCE); return NULL; } DCECount++; @@ -246,7 +246,7 @@ DceReleaseDC(DCE* dce, BOOL EndPaint) } while (pLE != &LEDce ); } -#endif +#endif } return 1; // Released! } @@ -461,7 +461,7 @@ UserGetDCEx(PWND Wnd OPTIONAL, HANDLE ClipRegion, ULONG Flags) if (!Dce) break; // // The way I understand this, you can have more than one DC per window. -// Only one Owned if one was requested and saved and one Cached. +// Only one Owned if one was requested and saved and one Cached. // if ((Dce->DCXFlags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE) { @@ -510,7 +510,7 @@ UserGetDCEx(PWND Wnd OPTIONAL, HANDLE ClipRegion, ULONG Flags) KeLeaveCriticalRegion(); if ( (Flags & (DCX_INTERSECTRGN|DCX_EXCLUDERGN)) && - (Dce->DCXFlags & (DCX_INTERSECTRGN|DCX_EXCLUDERGN)) ) + (Dce->DCXFlags & (DCX_INTERSECTRGN|DCX_EXCLUDERGN)) ) { DceDeleteClipRgn(Dce); } @@ -593,7 +593,7 @@ UserGetDCEx(PWND Wnd OPTIONAL, HANDLE ClipRegion, ULONG Flags) NtGdiSetLayout(Dce->hDC, -1, LAYOUT_RTL); } - if (Dce->DCXFlags & DCX_PROCESSOWNED) + if (Dce->DCXFlags & DCX_PROCESSOWNED) { ppi = PsGetCurrentProcessWin32Process(); ppi->W32PF_flags |= W32PF_OWNDCCLEANUP; @@ -657,7 +657,7 @@ DceFreeDCE(PDCE pdce, BOOLEAN Force) return NULL; } - ExFreePoolWithTag(pdce, TAG_PDCE); + ExFreePoolWithTag(pdce, USERTAG_DCE); DCECount--; DPRINT("Freed DCE's! %d \n", DCECount); diff --git a/subsystems/win32/win32k/ntuser/window.c b/subsystems/win32/win32k/ntuser/window.c index a231bdb7e17..9f120a00b61 100644 --- a/subsystems/win32/win32k/ntuser/window.c +++ b/subsystems/win32/win32k/ntuser/window.c @@ -15,9 +15,6 @@ #define NDEBUG #include -/* dialog resources appear to pass this in 16 bits, handle them properly */ -#define CW_USEDEFAULT16 (0x8000) - #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x ))) /* PRIVATE FUNCTIONS **********************************************************/ @@ -201,7 +198,7 @@ IntWinListChildren(PWND Window) for (Child = Window->spwndChild; Child; Child = Child->spwndNext) ++NumChildren; - List = ExAllocatePoolWithTag(PagedPool, (NumChildren + 1) * sizeof(HWND), TAG_WINLIST); + List = ExAllocatePoolWithTag(PagedPool, (NumChildren + 1) * sizeof(HWND), USERTAG_WINDOWLIST); if(!List) { DPRINT1("Failed to allocate memory for children array\n"); @@ -297,7 +294,7 @@ UserFreeWindowInfo(PTHREADINFO ti, PWND Wnd) PCLIENTINFO ClientInfo = GetWin32ClientInfo(); if (!Wnd) return; - + if (ClientInfo->CallbackWnd.pWnd == DesktopHeapAddressToUser(Wnd)) { ClientInfo->CallbackWnd.hWnd = NULL; @@ -942,8 +939,8 @@ IntIsWindowVisible(PWND BaseWindow) } -/* - link the window into siblings list +/* + link the window into siblings list children and parent are kept in place. */ VOID FASTCALL @@ -975,14 +972,14 @@ VOID FASTCALL IntLinkHwnd(PWND Wnd, HWND hWndPrev) { if (hWndPrev == HWND_NOTOPMOST) { - if (!(Wnd->ExStyle & WS_EX_TOPMOST) && + if (!(Wnd->ExStyle & WS_EX_TOPMOST) && (Wnd->ExStyle2 & WS_EX2_LINKED)) return; /* nothing to do */ Wnd->ExStyle &= ~WS_EX_TOPMOST; hWndPrev = HWND_TOP; /* fallback to the HWND_TOP case */ } IntUnlinkWindow(Wnd); /* unlink it from the previous location */ - + if (hWndPrev == HWND_BOTTOM) { /* Link in the bottom of the list */ @@ -1042,7 +1039,7 @@ VOID FASTCALL IntLinkHwnd(PWND Wnd, HWND hWndPrev) IntLinkWindow(Wnd, WndInsertAfter); /* Fix the WS_EX_TOPMOST flag */ - if (!(WndInsertAfter->ExStyle & WS_EX_TOPMOST)) + if (!(WndInsertAfter->ExStyle & WS_EX_TOPMOST)) { Wnd->ExStyle &= ~WS_EX_TOPMOST; } @@ -1253,13 +1250,13 @@ IntUnlinkWindow(PWND Wnd) { if (Wnd->spwndNext) Wnd->spwndNext->spwndPrev = Wnd->spwndPrev; - + if (Wnd->spwndPrev) Wnd->spwndPrev->spwndNext = Wnd->spwndNext; if (Wnd->spwndParent && Wnd->spwndParent->spwndChild == Wnd) Wnd->spwndParent->spwndChild = Wnd->spwndNext; - + Wnd->spwndPrev = Wnd->spwndNext = NULL; } @@ -1556,7 +1553,7 @@ static void IntSendParentNotify( PWND pWindow, UINT msg ) { co_IntSendMessage( pWindow->spwndParent->head.h, WM_PARENTNOTIFY, - MAKEWPARAM( msg, pWindow->IDMenu), + MAKEWPARAM( msg, pWindow->IDMenu), (LPARAM)pWindow->head.h ); } } @@ -1645,8 +1642,8 @@ IntFixWindowCoordinates(CREATESTRUCTW* Cs, PWND ParentWindow, DWORD* dwShowMode) } /* Allocates and initializes a window*/ -PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs, - PLARGE_STRING WindowName, +PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs, + PLARGE_STRING WindowName, PCLS Class, PWND ParentWindow, PWND OwnerWindow) @@ -1670,7 +1667,7 @@ PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs, Cs->dwExStyle |= WS_EX_LAYOUTRTL; } else - {/* + {/* Note from MSDN http://msdn.microsoft.com/en-us/library/aa913269.aspx : Dialog boxes and message boxes do not inherit layout, so you must @@ -1684,7 +1681,7 @@ PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs, Cs->dwExStyle |= WS_EX_LAYOUTRTL; } } - } + } } /* Automatically add WS_EX_WINDOWEDGE */ @@ -1762,7 +1759,7 @@ PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs, if (bUnicodeWindow) { if (GETPFNCLIENTA(pWnd->pcls->fnid) == pWnd->lpfnWndProc) - pWnd->lpfnWndProc = GETPFNCLIENTW(pWnd->pcls->fnid); + pWnd->lpfnWndProc = GETPFNCLIENTW(pWnd->pcls->fnid); } else { @@ -1807,7 +1804,7 @@ PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs, } /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx, - then my testing shows that windows (2k and XP) creates a CallProc for it immediately + then my testing shows that windows (2k and XP) creates a CallProc for it immediately Dont understand why it does this. */ if (Class->atomClassName == gpsi->atomSysClass[ICLS_EDIT]) { @@ -1916,7 +1913,7 @@ AllocError: if(pWnd) UserDereferenceObject(pWnd); - + SetLastNtError(STATUS_INSUFFICIENT_RESOURCES); return NULL; } @@ -1995,17 +1992,17 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs, OwnerWindow = UserGetAncestor(OwnerWindow, GA_ROOT); /* Fix the position and the size of the window */ - if (ParentWindow) + if (ParentWindow) { UserRefObjectCo(ParentWindow, &ParentRef); IntFixWindowCoordinates(Cs, ParentWindow, &dwShowMode); } /* Allocate and initialize the new window */ - Window = IntCreateWindow(Cs, - WindowName, - Class, - ParentWindow, + Window = IntCreateWindow(Cs, + WindowName, + Class, + ParentWindow, OwnerWindow); if(!Window) { @@ -2075,7 +2072,7 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs, UnicodeString.MaximumLength = Name.Length + sizeof(UNICODE_NULL); pszName = UserHeapAlloc(UnicodeString.MaximumLength); RtlZeroMemory(pszName, UnicodeString.MaximumLength); - UnicodeString.Buffer = (PWSTR)pszName; + UnicodeString.Buffer = (PWSTR)pszName; RtlCopyUnicodeString(&UnicodeString, &Name); } if (pszName) pCsw->lpszName = UserHeapAddressToUser(pszName); @@ -2124,7 +2121,7 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs, Window->rcWindow.bottom = Cs->y + Size.cy; if (0 != (Window->style & WS_CHILD) && ParentWindow) { - RECTL_vOffsetRect(&Window->rcWindow, + RECTL_vOffsetRect(&Window->rcWindow, ParentWindow->rcClient.left, ParentWindow->rcClient.top); } @@ -2243,7 +2240,7 @@ CLEANUP: { DPRINT("co_UserCreateWindowEx(): Error Created window!\n"); /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */ - if (Window) + if (Window) co_UserDestroyWindow(Window); else if (Class) IntDereferenceClass(Class, pti->pDeskInfo, pti->ppi); @@ -2434,7 +2431,7 @@ cleanup: return hwnd; } - + BOOLEAN FASTCALL co_UserDestroyWindow(PWND Window) { @@ -2661,7 +2658,7 @@ IntFindWindow(PWND Parent, CurrentWindowName.Buffer = Child->strName.Buffer; CurrentWindowName.Length = Child->strName.Length; CurrentWindowName.MaximumLength = Child->strName.MaximumLength; - if(!CheckWindowName || + if(!CheckWindowName || (Child->strName.Length < 0xFFFF && !RtlCompareUnicodeString(WindowName, &CurrentWindowName, TRUE))) { @@ -2838,8 +2835,8 @@ NtUserFindWindowEx(HWND hwndParent, ustr.Buffer = TopLevelWindow->strName.Buffer; ustr.Length = TopLevelWindow->strName.Length; ustr.MaximumLength = TopLevelWindow->strName.MaximumLength; - WindowMatches = !CheckWindowName || - (TopLevelWindow->strName.Length < 0xFFFF && + WindowMatches = !CheckWindowName || + (TopLevelWindow->strName.Length < 0xFFFF && !RtlCompareUnicodeString(&WindowName, &ustr, TRUE)); ClassMatches = (ClassAtom == (RTL_ATOM)0) || ClassAtom == TopLevelWindow->pcls->atomClassName; @@ -3073,7 +3070,7 @@ NtUserGetInternalWindowPos( HWND hWnd, sizeof(POINT), 1); } - + } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -3082,7 +3079,7 @@ NtUserGetInternalWindowPos( HWND hWnd, } _SEH2_END; - wndpl.length = sizeof(WINDOWPLACEMENT); + wndpl.length = sizeof(WINDOWPLACEMENT); if (IntGetWindowPlacement(Window, &wndpl) && !Hit) { @@ -3096,7 +3093,7 @@ NtUserGetInternalWindowPos( HWND hWnd, { RtlCopyMemory(ptIcon, &wndpl.ptMinPosition, sizeof(POINT)); } - + } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -3893,7 +3890,7 @@ NtUserSetWindowFNID(HWND hWnd, RETURN( FALSE); } } - + Wnd->fnid |= fnID; RETURN( TRUE); diff --git a/subsystems/win32/win32k/objects/bitblt.c b/subsystems/win32/win32k/objects/bitblt.c index f84533d63e5..f4843c2c0b2 100644 --- a/subsystems/win32/win32k/objects/bitblt.c +++ b/subsystems/win32/win32k/objects/bitblt.c @@ -489,8 +489,8 @@ SwapROP3_SrcDst(BYTE bRop3) * 1 0 1 0 1101xax = 111ax = 11x = 0 * 1 1 0 1 0110xax = 011ax = 01x = 1 * 1 1 1 1 1111xax = 110ax = 10x = 1 - * - * Operation index = 11001010 = 0xCA = PSaDPnao = DPSDxax + * + * Operation index = 11001010 = 0xCA = PSaDPnao = DPSDxax * ^ no, this is not random letters, its reverse Polish notation */ @@ -1062,7 +1062,7 @@ NtGdiPolyPatBlt( if (cRects > 0) { - rb = ExAllocatePoolWithTag(PagedPool, sizeof(PATRECT) * cRects, TAG_PATBLT); + rb = ExAllocatePoolWithTag(PagedPool, sizeof(PATRECT) * cRects, GDITAG_PLGBLT_DATA); if (!rb) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -1085,7 +1085,7 @@ NtGdiPolyPatBlt( if (!NT_SUCCESS(Status)) { - ExFreePoolWithTag(rb, TAG_PATBLT); + ExFreePoolWithTag(rb, GDITAG_PLGBLT_DATA); SetLastNtError(Status); return FALSE; } @@ -1094,7 +1094,7 @@ NtGdiPolyPatBlt( Ret = IntGdiPolyPatBlt(hDC, dwRop, rb, cRects, Mode); if (cRects > 0) - ExFreePoolWithTag(rb, TAG_PATBLT); + ExFreePoolWithTag(rb, GDITAG_PLGBLT_DATA); return Ret; } diff --git a/subsystems/win32/win32k/objects/bitmaps.c b/subsystems/win32/win32k/objects/bitmaps.c index 573101fcf5e..ca6cde6d47b 100644 --- a/subsystems/win32/win32k/objects/bitmaps.c +++ b/subsystems/win32/win32k/objects/bitmaps.c @@ -107,6 +107,12 @@ GreCreateBitmapEx( sizl.cy = nHeight; pvCompressedBits = pvBits; pvBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB); + if (!pvBits) + { + EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); + SURFACE_FreeSurfaceByHandle(hbmp); + return NULL; + } DecompressBitmap(sizl, pvCompressedBits, pvBits, pso->lDelta, iFormat); fjBitmap |= BMF_RLE_HACK; } @@ -119,6 +125,7 @@ GreCreateBitmapEx( { /* Bail out if that failed */ DPRINT1("SURFACE_bSetBitmapBits failed.\n"); + EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); SURFACE_FreeSurfaceByHandle(hbmp); return NULL; } @@ -161,49 +168,36 @@ NtGdiCreateBitmap( IN OPTIONAL LPBYTE pUnsafeBits) { HBITMAP hbmp; - ULONG cjWidthBytes, iFormat; + ULONG cRealBpp, cjWidthBytes, iFormat; + ULONGLONG cjSize; - /* NOTE: Windows also doesn't store nr. of planes separately! */ - cBitsPixel = BITMAP_GetRealBitsPixel(cBitsPixel * cPlanes); + /* Calculate bitmap format and real bits per pixel. */ + iFormat = BitmapFormat(cBitsPixel * cPlanes, BI_RGB); + cRealBpp = gajBitsPerFormat[iFormat]; - /* Calculate bitmap format */ - iFormat = BitmapFormat(cBitsPixel, BI_RGB); + /* Calculate width and image size in bytes */ + cjWidthBytes = WIDTH_BYTES_ALIGN16(nWidth, cRealBpp); + cjSize = cjWidthBytes * nHeight; - /* Check parameters */ - if (iFormat == 0 || nWidth <= 0 || nHeight <= 0) + /* Check parameters (possible overflow of cjWidthBytes!) */ + if (iFormat == 0 || nWidth <= 0 || nWidth >= 0x8000000 || nHeight <= 0 || + cBitsPixel > 32 || cPlanes > 32 || cjSize >= 0x100000000ULL) { - DPRINT1("Width = %d, Height = %d BitsPixel = %d\n", - nWidth, nHeight, cBitsPixel); + DPRINT1("Invalid bitmap format! Width=%d, Height=%d, Bpp=%d, Planes=%d\n", + nWidth, nHeight, cBitsPixel, cPlanes); EngSetLastError(ERROR_INVALID_PARAMETER); return NULL; } - if(WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel)*nHeight >= 0x8000000) - { - /* I just can't get enough, I just can't get enough */ - EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); - return NULL; - } + /* Call internal function. */ + hbmp = GreCreateBitmapEx(nWidth, nHeight, 0, iFormat, 0, 0, NULL, DDB_SURFACE); - /* Make sure that cjBits will not overflow */ - cjWidthBytes = WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel); - if ((ULONGLONG)cjWidthBytes * nHeight >= 0x100000000ULL) - { - DPRINT1("Width = %d, Height = %d BitsPixel = %d\n", - nWidth, nHeight, cBitsPixel); - EngSetLastError(ERROR_INVALID_PARAMETER); - return NULL; - } - - /* cBitsPixel = cBitsPixel * cPlanes now! */ - hbmp = GreCreateBitmap(nWidth, nHeight, 1, cBitsPixel, NULL); - - if (pUnsafeBits) + if (pUnsafeBits && hbmp) { PSURFACE psurf = SURFACE_LockSurface(hbmp); _SEH2_TRY { - ProbeForRead(pUnsafeBits, cjWidthBytes * nHeight, 1); + ProbeForRead(pUnsafeBits, cjSize, 1); UnsafeSetBitmapBits(psurf, 0, pUnsafeBits); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) @@ -834,25 +828,6 @@ NtGdiSetPixel( /* Internal Functions */ -UINT FASTCALL -BITMAP_GetRealBitsPixel(UINT nBitsPixel) -{ - if (nBitsPixel <= 1) - return 1; - if (nBitsPixel <= 4) - return 4; - if (nBitsPixel <= 8) - return 8; - if (nBitsPixel <= 16) - return 16; - if (nBitsPixel <= 24) - return 24; - if (nBitsPixel <= 32) - return 32; - - return 0; -} - HBITMAP FASTCALL BITMAP_CopyBitmap(HBITMAP hBitmap) { diff --git a/subsystems/win32/win32k/objects/cliprgn.c b/subsystems/win32/win32k/objects/cliprgn.c index 264f68ec1a3..95e0e5cced9 100644 --- a/subsystems/win32/win32k/objects/cliprgn.c +++ b/subsystems/win32/win32k/objects/cliprgn.c @@ -483,13 +483,13 @@ IntGdiSetMetaRgn(PDC pDC) RGN_AND); if ( Ret ) { - GDIOBJ_ShareUnlockObjByPtr(pDC->dclevel.prgnMeta); + GDIOBJ_ShareUnlockObjByPtr(&pDC->dclevel.prgnMeta->BaseObject); if (!((PROSRGNDATA)pDC->dclevel.prgnMeta)->BaseObject.ulShareCount) REGION_Delete(pDC->dclevel.prgnMeta); pDC->dclevel.prgnMeta = TempRgn; - GDIOBJ_ShareUnlockObjByPtr(pDC->dclevel.prgnClip); + GDIOBJ_ShareUnlockObjByPtr(&pDC->dclevel.prgnClip->BaseObject); if (!((PROSRGNDATA)pDC->dclevel.prgnClip)->BaseObject.ulShareCount) REGION_Delete(pDC->dclevel.prgnClip); diff --git a/subsystems/win32/win32k/objects/coord.c b/subsystems/win32/win32k/objects/coord.c index 6e9ceafb736..c00d67cdf74 100644 --- a/subsystems/win32/win32k/objects/coord.c +++ b/subsystems/win32/win32k/objects/coord.c @@ -1,24 +1,5 @@ /* - * ReactOS W32 Subsystem - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -/* - * - * COPYRIGHT: See COPYING in the top level directory + * COPYRIGHT: GNU GPL, See COPYING in the top level directory * PROJECT: ReactOS kernel * PURPOSE: Coordinate systems * FILE: subsys/win32k/objects/coord.c @@ -35,13 +16,13 @@ /* FUNCTIONS *****************************************************************/ void FASTCALL -IntFixIsotropicMapping(PDC dc) +IntFixIsotropicMapping(PDC pdc) { PDC_ATTR pdcattr; LONG fx, fy, s; /* Get a pointer to the DC_ATTR */ - pdcattr = dc->pdcattr; + pdcattr = pdc->pdcattr; /* Check if all values are valid */ if (pdcattr->szlWindowExt.cx == 0 || pdcattr->szlWindowExt.cy == 0 || @@ -66,6 +47,76 @@ IntFixIsotropicMapping(PDC dc) } } +// FIXME: Don't use floating point in the kernel! +void IntWindowToViewPort(PDC_ATTR pdcattr, LPXFORM xformWnd2Vport) +{ + FLOAT scaleX, scaleY; + + scaleX = (pdcattr->szlWindowExt.cx ? (FLOAT)pdcattr->szlViewportExt.cx / (FLOAT)pdcattr->szlWindowExt.cx : 0.0f); + scaleY = (pdcattr->szlWindowExt.cy ? (FLOAT)pdcattr->szlViewportExt.cy / (FLOAT)pdcattr->szlWindowExt.cy : 0.0f); + xformWnd2Vport->eM11 = scaleX; + xformWnd2Vport->eM12 = 0.0; + xformWnd2Vport->eM21 = 0.0; + xformWnd2Vport->eM22 = scaleY; + xformWnd2Vport->eDx = (FLOAT)pdcattr->ptlViewportOrg.x - scaleX * (FLOAT)pdcattr->ptlWindowOrg.x; + xformWnd2Vport->eDy = (FLOAT)pdcattr->ptlViewportOrg.y - scaleY * (FLOAT)pdcattr->ptlWindowOrg.y; +} + +// FIXME: Use XFORMOBJECT! +VOID FASTCALL +DC_UpdateXforms(PDC dc) +{ + XFORM xformWnd2Vport; + PDC_ATTR pdcattr = dc->pdcattr; + XFORM xformWorld2Vport, xformWorld2Wnd, xformVport2World; + + /* Construct a transformation to do the window-to-viewport conversion */ + IntWindowToViewPort(pdcattr, &xformWnd2Vport); + + /* Combine with the world transformation */ + MatrixS2XForm(&xformWorld2Vport, &dc->dclevel.mxWorldToDevice); + MatrixS2XForm(&xformWorld2Wnd, &dc->dclevel.mxWorldToPage); + IntGdiCombineTransform(&xformWorld2Vport, &xformWorld2Wnd, &xformWnd2Vport); + + /* Create inverse of world-to-viewport transformation */ + MatrixS2XForm(&xformVport2World, &dc->dclevel.mxDeviceToWorld); + if (DC_InvertXform(&xformWorld2Vport, &xformVport2World)) + { + pdcattr->flXform &= ~DEVICE_TO_WORLD_INVALID; + } + else + { + pdcattr->flXform |= DEVICE_TO_WORLD_INVALID; + } + + /* Update transformation matrices */ + XForm2MatrixS(&dc->dclevel.mxWorldToDevice, &xformWorld2Vport); + XForm2MatrixS(&dc->dclevel.mxDeviceToWorld, &xformVport2World); +} + +VOID +FASTCALL +DC_vUpdateViewportExt(PDC pdc) +{ + PDC_ATTR pdcattr; + + /* Get a pointer to the dc attribute */ + pdcattr = pdc->pdcattr; + + /* Check if we need to recalculate */ + if (pdcattr->flXform & PAGE_EXTENTS_CHANGED) + { + /* Check if we need to do isotropic fixup */ + if (pdcattr->iMapMode == MM_ISOTROPIC) + { + IntFixIsotropicMapping(pdc); + } + + /* Update xforms, CHECKME: really done here? */ + DC_UpdateXforms(pdc); + } +} + // FIXME: don't use floating point in the kernel! use XFORMOBJ function BOOL FASTCALL IntGdiCombineTransform( @@ -74,6 +125,7 @@ IntGdiCombineTransform( LPXFORM xform2) { XFORM xformTemp; + /* Check for illegal parameters */ if (!XFormResult || !xform1 || !xform2) { @@ -94,7 +146,9 @@ IntGdiCombineTransform( } // FIXME: should be XFORML and use XFORMOBJ functions -BOOL APIENTRY NtGdiCombineTransform( +BOOL +APIENTRY +NtGdiCombineTransform( LPXFORM UnsafeXFormResult, LPXFORM Unsafexform1, LPXFORM Unsafexform2) @@ -119,6 +173,170 @@ BOOL APIENTRY NtGdiCombineTransform( return Ret; } +// FIXME: Should be XFORML and use XFORMOBJ functions directly +BOOL +APIENTRY +NtGdiGetTransform( + HDC hDC, + DWORD iXform, + LPXFORM XForm) +{ + PDC pdc; + NTSTATUS Status = STATUS_SUCCESS; + + if (!XForm) + { + EngSetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + pdc = DC_LockDc(hDC); + if (!pdc) + { + EngSetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + + _SEH2_TRY + { + ProbeForWrite(XForm, sizeof(XFORM), 1); + switch (iXform) + { + case GdiWorldSpaceToPageSpace: + MatrixS2XForm(XForm, &pdc->dclevel.mxWorldToPage); + break; + + case GdiWorldSpaceToDeviceSpace: + MatrixS2XForm(XForm, &pdc->dclevel.mxWorldToDevice); + break; + + case GdiPageSpaceToDeviceSpace: + IntWindowToViewPort(pdc->pdcattr, XForm); + break; + + case GdiDeviceSpaceToWorldSpace: + MatrixS2XForm(XForm, &pdc->dclevel.mxDeviceToWorld); + break; + + default: + DPRINT1("Unknown transform %lu\n", iXform); + Status = STATUS_INVALID_PARAMETER; + break; + } + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Status = _SEH2_GetExceptionCode(); + } + _SEH2_END; + + DC_UnlockDc(pdc); + return NT_SUCCESS(Status); +} + + +/*! + * Converts points from logical coordinates into device coordinates. + * Conversion depends on the mapping mode, + * world transfrom, viewport origin settings for the given device context. + * \param hDC device context. + * \param Points an array of POINT structures (in/out). + * \param Count number of elements in the array of POINT structures. + * \return TRUE if success, FALSE otherwise. +*/ +BOOL +APIENTRY +NtGdiTransformPoints( + HDC hDC, + PPOINT UnsafePtsIn, + PPOINT UnsafePtOut, + INT Count, + INT iMode) +{ + PDC pdc; + LPPOINT Points; + ULONG Size; + BOOL ret; + + pdc = DC_LockDc(hDC); + if (!pdc) + { + EngSetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + + if (!UnsafePtsIn || !UnsafePtOut || Count <= 0) + { + DC_UnlockDc(pdc); + EngSetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + Size = Count * sizeof(POINT); + + // FIXME: It would be wise to have a small stack buffer as optimization + Points = ExAllocatePoolWithTag(PagedPool, Size, GDITAG_TEMP); + if (!Points) + { + DC_UnlockDc(pdc); + EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + _SEH2_TRY + { + ProbeForWrite(UnsafePtOut, Size, 1); + ProbeForRead(UnsafePtsIn, Size, 1); + RtlCopyMemory(Points, UnsafePtsIn, Size); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastNtError(_SEH2_GetExceptionCode()); + ret = FALSE; + _SEH2_YIELD(goto leave;) + } + _SEH2_END; + + switch (iMode) + { + case GdiDpToLp: + IntDPtoLP(pdc, Points, Count); + break; + + case GdiLpToDp: + IntLPtoDP(pdc, Points, Count); + break; + + case 2: // Not supported yet. Need testing. + default: + { + EngSetLastError(ERROR_INVALID_PARAMETER); + ret = FALSE; + goto leave; + } + } + + _SEH2_TRY + { + /* pointer was already probed! */ + RtlCopyMemory(UnsafePtOut, Points, Size); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastNtError(_SEH2_GetExceptionCode()); + ret = FALSE; + } + _SEH2_END; + +// +// If we are getting called that means User XForms is a mess! +// +leave: + DC_UnlockDc(pdc); + ExFreePoolWithTag(Points, GDITAG_TEMP); + return ret; +} + // FIXME: Don't use floating point in the kernel BOOL FASTCALL @@ -165,196 +383,6 @@ IntGdiModifyWorldTransform( return TRUE; } -// FIXME: Don't use floating point in the kernel! -void IntWindowToViewPort(PDC_ATTR pdcattr, LPXFORM xformWnd2Vport) -{ - FLOAT scaleX, scaleY; - - scaleX = (pdcattr->szlWindowExt.cx ? (FLOAT)pdcattr->szlViewportExt.cx / (FLOAT)pdcattr->szlWindowExt.cx : 0.0f); - scaleY = (pdcattr->szlWindowExt.cy ? (FLOAT)pdcattr->szlViewportExt.cy / (FLOAT)pdcattr->szlWindowExt.cy : 0.0f); - xformWnd2Vport->eM11 = scaleX; - xformWnd2Vport->eM12 = 0.0; - xformWnd2Vport->eM21 = 0.0; - xformWnd2Vport->eM22 = scaleY; - xformWnd2Vport->eDx = (FLOAT)pdcattr->ptlViewportOrg.x - scaleX * (FLOAT)pdcattr->ptlWindowOrg.x; - xformWnd2Vport->eDy = (FLOAT)pdcattr->ptlViewportOrg.y - scaleY * (FLOAT)pdcattr->ptlWindowOrg.y; -} - -// FIXME: Should be XFORML and use XFORMOBJ functions directly -BOOL -APIENTRY -NtGdiGetTransform( - HDC hDC, - DWORD iXform, - LPXFORM XForm) -{ - PDC dc; - NTSTATUS Status = STATUS_SUCCESS; - - dc = DC_LockDc(hDC); - if (!dc) - { - EngSetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!XForm) - { - DC_UnlockDc(dc); - EngSetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - _SEH2_TRY - { - ProbeForWrite(XForm, sizeof(XFORM), 1); - switch (iXform) - { - case GdiWorldSpaceToPageSpace: - MatrixS2XForm(XForm, &dc->dclevel.mxWorldToPage); - break; - - case GdiWorldSpaceToDeviceSpace: - MatrixS2XForm(XForm, &dc->dclevel.mxWorldToDevice); - break; - - case GdiPageSpaceToDeviceSpace: - IntWindowToViewPort(dc->pdcattr, XForm); - break; - - case GdiDeviceSpaceToWorldSpace: - MatrixS2XForm(XForm, &dc->dclevel.mxDeviceToWorld); - break; - - default: - DPRINT1("Unknown transform %lu\n", iXform); - Status = STATUS_INVALID_PARAMETER; - break; - } - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - Status = _SEH2_GetExceptionCode(); - } - _SEH2_END; - - DC_UnlockDc(dc); - return NT_SUCCESS(Status); -} - - -/*! - * Converts points from logical coordinates into device coordinates. Conversion depends on the mapping mode, - * world transfrom, viewport origin settings for the given device context. - * \param hDC device context. - * \param Points an array of POINT structures (in/out). - * \param Count number of elements in the array of POINT structures. - * \return TRUE if success. -*/ -BOOL -APIENTRY -NtGdiTransformPoints( - HDC hDC, - PPOINT UnsafePtsIn, - PPOINT UnsafePtOut, - INT Count, - INT iMode) -{ - PDC dc; - NTSTATUS Status = STATUS_SUCCESS; - LPPOINT Points; - ULONG Size; - - dc = DC_LockDc(hDC); - if (!dc) - { - EngSetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - - if (!UnsafePtsIn || !UnsafePtOut || Count <= 0) - { - DC_UnlockDc(dc); - EngSetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - Size = Count * sizeof(POINT); - - // FIXME: It would be wise to have a small stack buffer as optimization - Points = ExAllocatePoolWithTag(PagedPool, Size, TAG_COORD); - if (!Points) - { - DC_UnlockDc(dc); - EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - - _SEH2_TRY - { - ProbeForWrite(UnsafePtOut, Size, 1); - ProbeForRead(UnsafePtsIn, Size, 1); - RtlCopyMemory(Points, UnsafePtsIn, Size); - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - Status = _SEH2_GetExceptionCode(); - } - _SEH2_END; - - if (!NT_SUCCESS(Status)) - { - DC_UnlockDc(dc); - ExFreePoolWithTag(Points, TAG_COORD); - SetLastNtError(Status); - return FALSE; - } - - switch (iMode) - { - case GdiDpToLp: - IntDPtoLP(dc, Points, Count); - break; - - case GdiLpToDp: - IntLPtoDP(dc, Points, Count); - break; - - case 2: // Not supported yet. Need testing. - default: - { - DC_UnlockDc(dc); - ExFreePoolWithTag(Points, TAG_COORD); - EngSetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - } - - _SEH2_TRY - { - /* pointer was already probed! */ - RtlCopyMemory(UnsafePtOut, Points, Size); - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - Status = _SEH2_GetExceptionCode(); - } - _SEH2_END; - - if (!NT_SUCCESS(Status)) - { - DC_UnlockDc(dc); - ExFreePoolWithTag(Points, TAG_COORD); - SetLastNtError(Status); - return FALSE; - } -// -// If we are getting called that means User XForms is a mess! -// - DC_UnlockDc(dc); - ExFreePoolWithTag(Points, TAG_COORD); - return TRUE; -} - BOOL APIENTRY NtGdiModifyWorldTransform( @@ -363,7 +391,7 @@ NtGdiModifyWorldTransform( DWORD Mode) { PDC dc; - XFORM SafeXForm; + XFORM SafeXForm; //FIXME: use XFORML BOOL Ret = TRUE; dc = DC_LockDc(hDC); @@ -528,31 +556,6 @@ NtGdiScaleViewportExtEx( } pdcattr = pDC->pdcattr; - if (pSize) - { - NTSTATUS Status = STATUS_SUCCESS; - - _SEH2_TRY - { - ProbeForWrite(pSize, sizeof(LPSIZE), 1); - - pSize->cx = pdcattr->szlViewportExt.cx; - pSize->cy = pdcattr->szlViewportExt.cy; - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - Status = _SEH2_GetExceptionCode(); - } - _SEH2_END; - - if (!NT_SUCCESS(Status)) - { - SetLastNtError(Status); - DC_UnlockDc(pDC); - return FALSE; - } - } - if (pdcattr->iMapMode > MM_TWIPS) { if (Xdenom && Ydenom) @@ -586,6 +589,23 @@ NtGdiScaleViewportExtEx( else Ret = TRUE; + if (pSize) + { + _SEH2_TRY + { + ProbeForWrite(pSize, sizeof(LPSIZE), 1); + + pSize->cx = pdcattr->szlViewportExt.cx; + pSize->cy = pdcattr->szlViewportExt.cy; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastNtError(_SEH2_GetExceptionCode()); + Ret = FALSE; + } + _SEH2_END; + } + DC_UnlockDc(pDC); return Ret; } @@ -1057,7 +1077,7 @@ NtGdiSetVirtualResolution( cxVirtualDeviceMm = NtGdiGetDeviceCaps(hdc, HORZSIZE); cyVirtualDeviceMm = NtGdiGetDeviceCaps(hdc, VERTSIZE); } - else if (cxVirtualDevicePixel == 0 || cyVirtualDevicePixel == 0 || + else if (cxVirtualDevicePixel == 0 || cyVirtualDevicePixel == 0 || cxVirtualDeviceMm == 0 || cyVirtualDeviceMm == 0) { return FALSE; @@ -1102,37 +1122,6 @@ DC_InvertXform(const XFORM *xformSrc, return TRUE; } -VOID FASTCALL -DC_UpdateXforms(PDC dc) -{ - XFORM xformWnd2Vport; - PDC_ATTR pdcattr = dc->pdcattr; - XFORM xformWorld2Vport, xformWorld2Wnd, xformVport2World; - - /* Construct a transformation to do the window-to-viewport conversion */ - IntWindowToViewPort(pdcattr, &xformWnd2Vport); - - /* Combine with the world transformation */ - MatrixS2XForm(&xformWorld2Vport, &dc->dclevel.mxWorldToDevice); - MatrixS2XForm(&xformWorld2Wnd, &dc->dclevel.mxWorldToPage); - IntGdiCombineTransform(&xformWorld2Vport, &xformWorld2Wnd, &xformWnd2Vport); - - /* Create inverse of world-to-viewport transformation */ - MatrixS2XForm(&xformVport2World, &dc->dclevel.mxDeviceToWorld); - if (DC_InvertXform(&xformWorld2Vport, &xformVport2World)) - { - pdcattr->flXform &= ~DEVICE_TO_WORLD_INVALID; - } - else - { - pdcattr->flXform |= DEVICE_TO_WORLD_INVALID; - } - - /* Update transformation matrices */ - XForm2MatrixS(&dc->dclevel.mxWorldToDevice, &xformWorld2Vport); - XForm2MatrixS(&dc->dclevel.mxDeviceToWorld, &xformVport2World); -} - LONG FASTCALL IntCalcFillOrigin(PDC pdc) { @@ -1152,49 +1141,6 @@ IntptlBrushOrigin(PDC pdc, LONG x, LONG y ) return &pdc->dclevel.ptlBrushOrigin; } -VOID -APIENTRY -GdiSetDCOrg(HDC hDC, LONG Left, LONG Top, PRECTL prc) -{ - PDC pdc; - - pdc = DC_LockDc(hDC); - if (!pdc) return; - - pdc->ptlDCOrig.x = Left; - pdc->ptlDCOrig.y = Top; - - IntCalcFillOrigin(pdc); - - if (prc) pdc->erclWindow = *prc; - - DC_UnlockDc(pdc); -} - -// FIXME: remove me -BOOL FASTCALL -IntGdiGetDCOrg(PDC pDc, PPOINTL ppt) -{ - *ppt = pDc->ptlDCOrig; - return TRUE; -} - -// FIXME: remove me -BOOL APIENTRY -GdiGetDCOrgEx(HDC hDC, PPOINTL ppt, PRECTL prc) -{ - PDC pdc; - - pdc = DC_LockDc(hDC); - if (!pdc) return FALSE; - - *prc = pdc->erclWindow; - *ppt = pdc->ptlDCOrig; - - DC_UnlockDc(pdc); - return TRUE; -} - static VOID FASTCALL DC_vGetAspectRatioFilter(PDC pDC, LPSIZE AspectRatio) @@ -1213,29 +1159,6 @@ DC_vGetAspectRatioFilter(PDC pDC, LPSIZE AspectRatio) } } -VOID -FASTCALL -DC_vUpdateViewportExt(PDC pdc) -{ - PDC_ATTR pdcattr; - - /* Get a pointer to the dc attribute */ - pdcattr = pdc->pdcattr; - - /* Check if we need to recalculate */ - if (pdcattr->flXform & PAGE_EXTENTS_CHANGED) - { - /* Check if we need to do isotropic fixup */ - if (pdcattr->iMapMode == MM_ISOTROPIC) - { - IntFixIsotropicMapping(pdc); - } - - /* Update xforms, CHECKME: really done here? */ - DC_UpdateXforms(pdc); - } -} - BOOL APIENTRY NtGdiGetDCPoint( HDC hDC, @@ -1322,28 +1245,4 @@ NtGdiGetDCPoint( return Ret; } - -DWORD -APIENTRY -NtGdiGetBoundsRect( - IN HDC hdc, - OUT LPRECT prc, - IN DWORD f) -{ - DPRINT1("stub\n"); - return DCB_RESET; /* bounding rectangle always empty */ -} - -DWORD -APIENTRY -NtGdiSetBoundsRect( - IN HDC hdc, - IN LPRECT prc, - IN DWORD f) -{ - DPRINT1("stub\n"); - return DCB_DISABLE; /* bounding rectangle always empty */ -} - - /* EOF */ diff --git a/subsystems/win32/win32k/objects/dcobjs.c b/subsystems/win32/win32k/objects/dcobjs.c index e4bc928b935..75cde4146ab 100644 --- a/subsystems/win32/win32k/objects/dcobjs.c +++ b/subsystems/win32/win32k/objects/dcobjs.c @@ -457,6 +457,79 @@ NtGdiGetDCObject(HDC hDC, INT ObjectType) return SelObject; } +/* See wine, msdn, osr and Feng Yuan - Windows Graphics Programming Win32 Gdi And Directdraw + + 1st: http://www.codeproject.com/gdi/cliprgnguide.asp is wrong! + + The intersection of the clip with the meta region is not Rao it's API! + Go back and read 7.2 Clipping pages 418-19: + Rao = API & Vis: + 1) The Rao region is the intersection of the API region and the system region, + named after the Microsoft engineer who initially proposed it. + 2) The Rao region can be calculated from the API region and the system region. + + API: + API region is the intersection of the meta region and the clipping region, + clearly named after the fact that it is controlled by GDI API calls. +*/ +INT +APIENTRY +NtGdiGetRandomRgn( + HDC hdc, + HRGN hrgnDest, + INT iCode) +{ + INT ret = 0; + PDC pdc; + HRGN hrgnSrc = NULL; + POINTL ptlOrg; + + pdc = DC_LockDc(hdc); + if (!pdc) + { + EngSetLastError(ERROR_INVALID_HANDLE); + return -1; + } + + switch (iCode) + { + case CLIPRGN: + hrgnSrc = pdc->rosdc.hClipRgn; +// if (pdc->dclevel.prgnClip) hrgnSrc = pdc->dclevel.prgnClip->BaseObject.hHmgr; + break; + case METARGN: + if (pdc->dclevel.prgnMeta) + hrgnSrc = pdc->dclevel.prgnMeta->BaseObject.hHmgr; + break; + case APIRGN: + if (pdc->prgnAPI) hrgnSrc = pdc->prgnAPI->BaseObject.hHmgr; +// else if (pdc->dclevel.prgnClip) hrgnSrc = pdc->dclevel.prgnClip->BaseObject.hHmgr; + else if (pdc->rosdc.hClipRgn) hrgnSrc = pdc->rosdc.hClipRgn; + else if (pdc->dclevel.prgnMeta) hrgnSrc = pdc->dclevel.prgnMeta->BaseObject.hHmgr; + break; + case SYSRGN: + if (pdc->prgnVis) hrgnSrc = pdc->prgnVis->BaseObject.hHmgr; + break; + default: + hrgnSrc = NULL; + } + + if (hrgnSrc) + { + ret = NtGdiCombineRgn(hrgnDest, hrgnSrc, 0, RGN_COPY) == ERROR ? -1 : 1; + } + + if (iCode == SYSRGN) + { + ptlOrg = pdc->ptlDCOrig; + NtGdiOffsetRgn(hrgnDest, ptlOrg.x, ptlOrg.y ); + } + + DC_UnlockDc(pdc); + + return ret; +} + ULONG APIENTRY NtGdiEnumObjects( diff --git a/subsystems/win32/win32k/objects/dcutil.c b/subsystems/win32/win32k/objects/dcutil.c index 83a490b651b..4b172c01892 100644 --- a/subsystems/win32/win32k/objects/dcutil.c +++ b/subsystems/win32/win32k/objects/dcutil.c @@ -464,3 +464,92 @@ NtGdiGetAndSetDCDword( DC_UnlockDc(pdc); return Ret; } + +DWORD +APIENTRY +NtGdiGetBoundsRect( + IN HDC hdc, + OUT LPRECT prc, + IN DWORD flags) +{ + DWORD ret; + PDC pdc; + + /* Lock the DC */ + if (!(pdc = DC_LockDc(hdc))) return 0; + + /* Get the return value */ + ret = pdc->fs & DC_ACCUM_APP ? DCB_ENABLE : DCB_DISABLE; + ret |= RECTL_bIsEmptyRect(&pdc->erclBoundsApp) ? DCB_RESET : DCB_SET; + + /* Copy the rect to the caller */ + _SEH2_TRY + { + ProbeForWrite(prc, sizeof(RECT), 1); + *prc = pdc->erclBoundsApp; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + ret = 0; + } + _SEH2_END; + + if (flags & DCB_RESET) + { + RECTL_vSetEmptyRect(&pdc->erclBoundsApp); + } + + DC_UnlockDc(pdc); + return ret; +} + + +DWORD +APIENTRY +NtGdiSetBoundsRect( + IN HDC hdc, + IN LPRECT prc, + IN DWORD flags) +{ + DWORD ret; + PDC pdc; + RECTL rcl; + + /* Verify arguments */ + if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0; + + /* Lock the DC */ + if (!(pdc = DC_LockDc(hdc))) return 0; + + /* Get the return value */ + ret = pdc->fs & DC_ACCUM_APP ? DCB_ENABLE : DCB_DISABLE; + ret |= RECTL_bIsEmptyRect(&pdc->erclBoundsApp) ? DCB_RESET : DCB_SET; + + if (flags & DCB_RESET) + { + RECTL_vSetEmptyRect(&pdc->erclBoundsApp); + } + + if (flags & DCB_ACCUMULATE) + { + /* Capture the rect */ + _SEH2_TRY + { + ProbeForRead(prc, sizeof(RECT), 1); + rcl = *prc; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + _SEH2_YIELD(return 0;) + } + _SEH2_END; + + RECTL_vMakeWellOrdered(&rcl); + RECTL_bUnionRect(&pdc->erclBoundsApp, &pdc->erclBoundsApp, &rcl); + } + + if (flags & DCB_ENABLE) pdc->fs |= DC_ACCUM_APP; + if (flags & DCB_DISABLE) pdc->fs &= ~DC_ACCUM_APP; + DC_UnlockDc( pdc ); + return ret; +} diff --git a/subsystems/win32/win32k/objects/dibobj.c b/subsystems/win32/win32k/objects/dibobj.c index 0a28887e85b..820b2b1fa54 100644 --- a/subsystems/win32/win32k/objects/dibobj.c +++ b/subsystems/win32/win32k/objects/dibobj.c @@ -1028,9 +1028,10 @@ NtGdiStretchDIBitsInternal( WORD planes, bpp; DWORD compr, size; HBITMAP hBitmap; - BOOL fastpath = FALSE; - NTSTATUS Status = STATUS_SUCCESS; - PBYTE safeBits ; + HBITMAP hOldBitmap; + HDC hdcMem; + PVOID pvBits; + PBYTE safeBits; if (!Bits || !BitsInfo) return 0; @@ -1053,25 +1054,20 @@ NtGdiStretchDIBitsInternal( { ProbeForRead(BitsInfo, cjMaxInfo, 1); ProbeForRead(Bits, cjMaxBits, 1); - if (DIB_GetBitmapInfo( &BitsInfo->bmiHeader, &width, &height, &planes, &bpp, &compr, &size ) == -1) + if (DIB_GetBitmapInfo(&BitsInfo->bmiHeader, &width, &height, &planes, &bpp, &compr, &size) == -1) { DPRINT1("Invalid bitmap\n"); - Status = STATUS_INVALID_PARAMETER; + _SEH2_YIELD(goto cleanup;) } RtlCopyMemory(safeBits, Bits, cjMaxBits); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - Status = _SEH2_GetExceptionCode(); + DPRINT1("Error, failed to read the DIB bits\n"); + _SEH2_YIELD(goto cleanup;) } _SEH2_END - if(!NT_SUCCESS(Status)) - { - DPRINT1("Error, failed to read the DIB bits\n"); - goto cleanup; - } - if (width < 0) { DPRINT1("Bitmap has a negative width\n"); @@ -1086,30 +1082,22 @@ NtGdiStretchDIBitsInternal( ROP == SRCCOPY) { BITMAP bmp; - if (IntGdiGetObject(hBitmap, sizeof(bmp), &bmp) == sizeof(bmp)) - { - if (bmp.bmBitsPixel == bpp && + ret = IntGdiGetObject(hBitmap, sizeof(bmp), &bmp) == sizeof(bmp); + if (ret && + bmp.bmBitsPixel == bpp && bmp.bmWidth == SrcWidth && bmp.bmHeight == SrcHeight && bmp.bmPlanes == planes) - fastpath = TRUE; - } - } - - if (fastpath) { /* fast path */ - DPRINT1("using fast path\n"); - ret = IntSetDIBits( pdc, hBitmap, 0, height, safeBits, BitsInfo, Usage); + ret = IntSetDIBits(pdc, hBitmap, 0, height, safeBits, BitsInfo, Usage); + goto cleanup; + } } - else - { - /* slow path - need to use StretchBlt */ - HBITMAP hOldBitmap; - HDC hdcMem; - PVOID pvBits; - hdcMem = NtGdiCreateCompatibleDC( hDC ); + /* slow path - need to use StretchBlt */ + + hdcMem = NtGdiCreateCompatibleDC(hDC); hBitmap = DIB_CreateDIBSection(pdc, BitsInfo, Usage, &pvBits, NULL, 0, 0); if(!hBitmap) { @@ -1117,21 +1105,22 @@ NtGdiStretchDIBitsInternal( NtGdiDeleteObjectApp(hdcMem); goto cleanup; } + RtlCopyMemory(pvBits, safeBits, cjMaxBits); - hOldBitmap = NtGdiSelectBitmap( hdcMem, hBitmap ); + hOldBitmap = NtGdiSelectBitmap(hdcMem, hBitmap); /* Origin for DIBitmap may be bottom left (positive biHeight) or top left (negative biHeight) */ - ret = NtGdiStretchBlt( hDC, XDest, YDest, DestWidth, DestHeight, + ret = NtGdiStretchBlt(hDC, XDest, YDest, DestWidth, DestHeight, hdcMem, XSrc, abs(height) - SrcHeight - YSrc, - SrcWidth, SrcHeight, ROP, 0 ); - + SrcWidth, SrcHeight, ROP, 0); + if(ret) ret = SrcHeight; - NtGdiSelectBitmap( hdcMem, hOldBitmap ); - NtGdiDeleteObjectApp( hdcMem ); - GreDeleteObject( hBitmap ); - } + NtGdiSelectBitmap(hdcMem, hOldBitmap); + NtGdiDeleteObjectApp(hdcMem); + GreDeleteObject(hBitmap); + cleanup: ExFreePoolWithTag(safeBits, TAG_DIB); DC_UnlockDc(pdc); @@ -1435,7 +1424,7 @@ DIB_CreateDIBSection( // Get storage location for DIB bits. Only use biSizeImage if it's valid and // we're dealing with a compressed bitmap. Otherwise, use width * height. - totalSize = bi->biSizeImage && bi->biCompression != BI_RGB + totalSize = bi->biSizeImage && bi->biCompression != BI_RGB && bi->biCompression != BI_BITFIELDS ? bi->biSizeImage : (ULONG)(bm.bmWidthBytes * effHeight); if (section) @@ -1552,6 +1541,7 @@ DIB_CreateDIBSection( bmp->dwOffset = offset; bmp->flags = API_BITMAP; bmp->biClrImportant = bi->biClrImportant; + bmp->SurfObj.fjBitmap &= ~BMF_DONT_FREE; /* HACK */ if(hpal != (HPALETTE)0xFFFFFFFF) diff --git a/subsystems/win32/win32k/objects/font.c b/subsystems/win32/win32k/objects/font.c index 11209049ec6..e3230e65927 100644 --- a/subsystems/win32/win32k/objects/font.c +++ b/subsystems/win32/win32k/objects/font.c @@ -5,7 +5,7 @@ * PURPOSE: Font * PROGRAMMER: */ - + /** Includes ******************************************************************/ #include @@ -60,7 +60,7 @@ GreGetKerningPairs( EngSetLastError(ERROR_INSUFFICIENT_BUFFER); return 0; } - pKP = ExAllocatePoolWithTag(PagedPool, Count * sizeof(KERNINGPAIR), TAG_GDITEXT); + pKP = ExAllocatePoolWithTag(PagedPool, Count * sizeof(KERNINGPAIR), GDITAG_TEXT); if (!pKP) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -70,11 +70,24 @@ GreGetKerningPairs( RtlCopyMemory(krnpair, pKP, Count * sizeof(KERNINGPAIR)); - ExFreePoolWithTag(pKP,TAG_GDITEXT); + ExFreePoolWithTag(pKP,GDITAG_TEXT); } return Count; } +/* + + It is recommended that an application use the GetFontLanguageInfo function + to determine whether the GCP_DIACRITIC, GCP_DBCS, GCP_USEKERNING, GCP_LIGATE, + GCP_REORDER, GCP_GLYPHSHAPE, and GCP_KASHIDA values are valid for the + currently selected font. If not valid, GetCharacterPlacement ignores the + value. + + M$ must use a preset "compiled in" support for each language based releases. + ReactOS uses FreeType, this will need to be supported. ATM this is hard coded + for GCPCLASS_LATIN! + + */ #if 0 DWORD FASTCALL @@ -86,16 +99,166 @@ GreGetCharacterPlacementW( LPGCP_RESULTSW pgcpw, DWORD dwFlags) { + GCP_RESULTSW gcpwSave; + UINT i, nSet, cSet; + INT *tmpDxCaretPos; + LONG Cx; SIZE Size = {0,0}; + + DPRINT1("GreGCPW Start\n"); if (!pgcpw) { - if (GreGetTextExtentW( hdc, pwsz, nCount, &Size, 0)) + if (GreGetTextExtentW( hdc, pwsz, nCount, &Size, 1)) return MAKELONG(Size.cx, Size.cy); return 0; } - UNIMPLEMENTED; + + DPRINT1("GreGCPW 1\n"); + + RtlCopyMemory(&gcpwSave, pgcpw, sizeof(GCP_RESULTSW)); + + cSet = nSet = nCount; + + if ( nCount > gcpwSave.nGlyphs ) cSet = gcpwSave.nGlyphs; + + /* GCP_JUSTIFY may only be used in conjunction with GCP_MAXEXTENT. */ + if ( dwFlags & GCP_JUSTIFY) dwFlags |= GCP_MAXEXTENT; + + if ( !gcpwSave.lpDx && gcpwSave.lpCaretPos ) + tmpDxCaretPos = gcpwSave.lpCaretPos; + else + tmpDxCaretPos = gcpwSave.lpDx; + + if ( !GreGetTextExtentExW( hdc, + pwsz, + cSet, + nMaxExtent, + ((dwFlags & GCP_MAXEXTENT) ? (PULONG) &cSet : NULL), + (PULONG) tmpDxCaretPos, + &Size, + 0) ) + { return 0; + } + + DPRINT1("GreGCPW 2\n"); + + nSet = cSet; + + if ( tmpDxCaretPos && nSet > 0) + { + for (i = (nSet - 1); i > 0; i--) + { + tmpDxCaretPos[i] -= tmpDxCaretPos[i - 1]; + } + } + + if ( !(dwFlags & GCP_MAXEXTENT) || nSet ) + { + if ( (dwFlags & GCP_USEKERNING) && + ( gcpwSave.lpDx || + gcpwSave.lpCaretPos ) && + nSet >= 2 ) + { + DWORD Count; + LPKERNINGPAIR pKP; + + Count = GreGetKerningPairs( hdc, 0, NULL); + if (Count) + { + pKP = ExAllocatePoolWithTag(PagedPool, Count * sizeof(KERNINGPAIR), GDITAG_TEXT); + if (pKP) + { + if ( GreGetKerningPairs( hdc, Count, pKP) != Count) + { + ExFreePoolWithTag( pKP, GDITAG_TEXT); + return 0; + } + + if ( (ULONG_PTR)(pKP) < ((ULONG_PTR)(pKP) + (ULONG_PTR)(Count * sizeof(KERNINGPAIR))) ) + { + DPRINT1("We Need to Do Something HERE!\n"); + } + + ExFreePoolWithTag( pKP, GDITAG_TEXT); + + if ( dwFlags & GCP_MAXEXTENT ) + { + if ( Size.cx > nMaxExtent ) + { + for (Cx = Size.cx; nSet > 0; nSet--) + { + Cx -= tmpDxCaretPos[nSet - 1]; + Size.cx = Cx; + if ( Cx <= nMaxExtent ) break; + } + } + if ( !nSet ) + { + pgcpw->nGlyphs = 0; + pgcpw->nMaxFit = 0; + return 0; + } + } + } + } + } + + if ( (dwFlags & GCP_JUSTIFY) && + ( gcpwSave.lpDx || + gcpwSave.lpCaretPos ) && + nSet ) + { + DPRINT1("We Need to Do Something HERE 2!\n"); + } + + if ( gcpwSave.lpDx && gcpwSave.lpCaretPos ) + RtlCopyMemory( gcpwSave.lpCaretPos, gcpwSave.lpDx, nSet * sizeof(LONG)); + + if ( gcpwSave.lpCaretPos ) + { + int pos = 0; + i = 0; + if ( nSet > 0 ) + { + do + { + Cx = gcpwSave.lpCaretPos[i]; + gcpwSave.lpCaretPos[i] = pos; + pos += Cx; + ++i; + } + while ( i < nSet ); + } + } + + if ( gcpwSave.lpOutString ) + RtlCopyMemory(gcpwSave.lpOutString, pwsz, nSet * sizeof(WCHAR)); + + if ( gcpwSave.lpClass ) + RtlFillMemory(gcpwSave.lpClass, nSet, GCPCLASS_LATIN); + + if ( gcpwSave.lpOrder ) + { + for (i = 0; i < nSet; i++) + gcpwSave.lpOrder[i] = i; + } + + if ( gcpwSave.lpGlyphs ) + { + if ( GreGetGlyphIndicesW( hdc, pwsz, nSet, gcpwSave.lpGlyphs, 0, 0) == GDI_ERROR ) + { + nSet = 0; + Size.cx = 0; + Size.cy = 0; + } + } + pgcpw->nGlyphs = nSet; + pgcpw->nMaxFit = nSet; + } + DPRINT1("GreGCPW Exit\n"); + return MAKELONG(Size.cx, Size.cy); } #endif @@ -359,6 +522,14 @@ NtGdiGetCharacterPlacementW( { UNIMPLEMENTED; return 0; +#if 0 + return GreGetCharacterPlacementW( hdc, + pwsz, + nCount, + nMaxExtent, + pgcpw, + dwFlags); +#endif } DWORD @@ -449,7 +620,7 @@ NtGdiGetFontUnicodeRanges( hFont = pdcattr->hlfntNew; TextObj = RealizeFontInit(hFont); - + if ( TextObj == NULL) { EngSetLastError(ERROR_INVALID_HANDLE); @@ -461,7 +632,7 @@ NtGdiGetFontUnicodeRanges( if (Size && pgs) { - pgsSafe = ExAllocatePoolWithTag(PagedPool, Size, TAG_GDITEXT); + pgsSafe = ExAllocatePoolWithTag(PagedPool, Size, GDITAG_TEXT); if (!pgsSafe) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -472,7 +643,7 @@ NtGdiGetFontUnicodeRanges( Size = ftGetFontUnicodeRanges( FontGdi, pgsSafe); if (Size) - { + { _SEH2_TRY { ProbeForWrite(pgs, Size, 1); @@ -486,7 +657,7 @@ NtGdiGetFontUnicodeRanges( if (!NT_SUCCESS(Status)) Size = 0; } - ExFreePoolWithTag(pgsSafe, TAG_GDITEXT); + ExFreePoolWithTag(pgsSafe, GDITAG_TEXT); } Exit: TEXTOBJ_UnlockText(TextObj); @@ -521,7 +692,7 @@ NtGdiGetGlyphOutline( if (UnsafeBuf && cjBuf) { - pvBuf = ExAllocatePoolWithTag(PagedPool, cjBuf, TAG_GDITEXT); + pvBuf = ExAllocatePoolWithTag(PagedPool, cjBuf, GDITAG_TEXT); if (!pvBuf) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -551,7 +722,7 @@ NtGdiGetGlyphOutline( } _SEH2_END - ExFreePoolWithTag(pvBuf, TAG_GDITEXT); + ExFreePoolWithTag(pvBuf, GDITAG_TEXT); } if (pgm) @@ -622,7 +793,7 @@ NtGdiGetKerningPairs(HDC hDC, EngSetLastError(ERROR_INSUFFICIENT_BUFFER); return 0; } - pKP = ExAllocatePoolWithTag(PagedPool, Count * sizeof(KERNINGPAIR), TAG_GDITEXT); + pKP = ExAllocatePoolWithTag(PagedPool, Count * sizeof(KERNINGPAIR), GDITAG_TEXT); if (!pKP) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -643,8 +814,8 @@ NtGdiGetKerningPairs(HDC hDC, { EngSetLastError(ERROR_INVALID_PARAMETER); Count = 0; - } - ExFreePoolWithTag(pKP,TAG_GDITEXT); + } + ExFreePoolWithTag(pKP,GDITAG_TEXT); } return Count; } @@ -693,7 +864,7 @@ NtGdiGetOutlineTextMetricsInternalW (HDC hDC, EngSetLastError(ERROR_INSUFFICIENT_BUFFER); return 0; } - potm = ExAllocatePoolWithTag(PagedPool, Size, TAG_GDITEXT); + potm = ExAllocatePoolWithTag(PagedPool, Size, GDITAG_TEXT); if (!potm) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -719,7 +890,7 @@ NtGdiGetOutlineTextMetricsInternalW (HDC hDC, Size = 0; } } - ExFreePoolWithTag(potm,TAG_GDITEXT); + ExFreePoolWithTag(potm,GDITAG_TEXT); return Size; } diff --git a/subsystems/win32/win32k/objects/freetype.c b/subsystems/win32/win32k/objects/freetype.c index 376d1178d8e..21a0883c2da 100644 --- a/subsystems/win32/win32k/objects/freetype.c +++ b/subsystems/win32/win32k/objects/freetype.c @@ -372,7 +372,7 @@ IntGdiAddFontResource(PUNICODE_STRING FileName, DWORD Characteristics) return 0; } - FontGDI = EngAllocMem(FL_ZERO_MEMORY, sizeof(FONTGDI), TAG_FONTOBJ); + FontGDI = EngAllocMem(FL_ZERO_MEMORY, sizeof(FONTGDI), GDITAG_RFONT); if (FontGDI == NULL) { FT_Done_Face(Face); @@ -382,7 +382,7 @@ IntGdiAddFontResource(PUNICODE_STRING FileName, DWORD Characteristics) return 0; } - FontGDI->Filename = ExAllocatePoolWithTag(PagedPool, FileName->Length + sizeof(WCHAR), TAG_PFF); + FontGDI->Filename = ExAllocatePoolWithTag(PagedPool, FileName->Length + sizeof(WCHAR), GDITAG_PFF); if (FontGDI->Filename == NULL) { EngFreeMem(FontGDI); @@ -1019,7 +1019,7 @@ FontFamilyFillInfo(PFONTFAMILYINFO Info, PCWSTR FaceName, PFONTGDI FontGDI) RtlZeroMemory(Info, sizeof(FONTFAMILYINFO)); Size = IntGetOutlineTextMetrics(FontGDI, 0, NULL); - Otm = ExAllocatePoolWithTag(PagedPool, Size, TAG_GDITEXT); + Otm = ExAllocatePoolWithTag(PagedPool, Size, GDITAG_TEXT); if (!Otm) { return; @@ -1076,7 +1076,7 @@ FontFamilyFillInfo(PFONTFAMILYINFO Info, PCWSTR FaceName, PFONTGDI FontGDI) if (0 == (TM->tmPitchAndFamily & TMPF_VECTOR)) Info->FontType |= RASTER_FONTTYPE; - ExFreePoolWithTag(Otm, TAG_GDITEXT); + ExFreePoolWithTag(Otm, GDITAG_TEXT); wcsncpy(Info->EnumLogFontEx.elfLogFont.lfFaceName, FaceName, LF_FACESIZE); wcsncpy(Info->EnumLogFontEx.elfFullName, FaceName, LF_FULLFACESIZE); @@ -1548,7 +1548,7 @@ ftGdiGetGlyphOutline( orientation = FT_IS_SCALABLE(ft_face) ? TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfOrientation: 0; Size = IntGetOutlineTextMetrics(FontGDI, 0, NULL); - potm = ExAllocatePoolWithTag(PagedPool, Size, TAG_GDITEXT); + potm = ExAllocatePoolWithTag(PagedPool, Size, GDITAG_TEXT); if (!potm) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -1615,7 +1615,7 @@ ftGdiGetGlyphOutline( { DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index); IntUnLockFreeType; - if (potm) ExFreePoolWithTag(potm, TAG_GDITEXT); + if (potm) ExFreePoolWithTag(potm, GDITAG_TEXT); return GDI_ERROR; } IntUnLockFreeType; @@ -1693,7 +1693,7 @@ ftGdiGetGlyphOutline( needsTransform = TRUE; } - if (potm) ExFreePoolWithTag(potm, TAG_GDITEXT); /* It looks like we are finished with potm ATM.*/ + if (potm) ExFreePoolWithTag(potm, GDITAG_TEXT); /* It looks like we are finished with potm ATM.*/ if (!needsTransform) { @@ -2601,7 +2601,7 @@ GetFontScore(LOGFONTW *LogFont, PUNICODE_STRING FaceName, PFONTGDI FontGDI) } Size = IntGetOutlineTextMetrics(FontGDI, 0, NULL); - Otm = ExAllocatePoolWithTag(PagedPool, Size, TAG_GDITEXT); + Otm = ExAllocatePoolWithTag(PagedPool, Size, GDITAG_TEXT); if (NULL == Otm) { return Score; @@ -3075,7 +3075,7 @@ NtGdiGetFontFamilyInfo(HDC Dc, } /* Allocate space for a safe copy */ - Info = ExAllocatePoolWithTag(PagedPool, Size * sizeof(FONTFAMILYINFO), TAG_GDITEXT); + Info = ExAllocatePoolWithTag(PagedPool, Size * sizeof(FONTFAMILYINFO), GDITAG_TEXT); if (NULL == Info) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -3682,7 +3682,7 @@ NtGdiExtTextOutW( if (BufSize > STACK_TEXT_BUFFER_SIZE) { /* It's not, allocate a temp buffer */ - Buffer = ExAllocatePoolWithTag(PagedPool, BufSize, TAG_GDITEXT); + Buffer = ExAllocatePoolWithTag(PagedPool, BufSize, GDITAG_TEXT); if (!Buffer) { return FALSE; @@ -3753,7 +3753,7 @@ cleanup: /* If we allocated a buffer, free it */ if (Buffer != LocalBuffer) { - ExFreePoolWithTag(Buffer, TAG_GDITEXT); + ExFreePoolWithTag(Buffer, GDITAG_TEXT); } return Result; @@ -3812,7 +3812,7 @@ NtGdiGetCharABCWidthsW( } BufferSize = Count * sizeof(ABC); // Same size! - SafeBuff = ExAllocatePoolWithTag(PagedPool, BufferSize, TAG_GDITEXT); + SafeBuff = ExAllocatePoolWithTag(PagedPool, BufferSize, GDITAG_TEXT); if (!fl) SafeBuffF = (LPABCFLOAT) SafeBuff; if (SafeBuff == NULL) { @@ -3979,7 +3979,7 @@ NtGdiGetCharWidthW( } BufferSize = Count * sizeof(INT); // Same size! - SafeBuff = ExAllocatePoolWithTag(PagedPool, BufferSize, TAG_GDITEXT); + SafeBuff = ExAllocatePoolWithTag(PagedPool, BufferSize, GDITAG_TEXT); if (!fl) SafeBuffF = (PFLOAT) SafeBuff; if (SafeBuff == NULL) { @@ -4114,7 +4114,7 @@ GreGetGlyphIndicesW( FontGDI = ObjToGDI(TextObj->Font, FONT); TEXTOBJ_UnlockText(TextObj); - Buffer = ExAllocatePoolWithTag(PagedPool, cwc*sizeof(WORD), TAG_GDITEXT); + Buffer = ExAllocatePoolWithTag(PagedPool, cwc*sizeof(WORD), GDITAG_TEXT); if (!Buffer) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -4125,7 +4125,7 @@ GreGetGlyphIndicesW( else { Size = IntGetOutlineTextMetrics(FontGDI, 0, NULL); - potm = ExAllocatePoolWithTag(PagedPool, Size, TAG_GDITEXT); + potm = ExAllocatePoolWithTag(PagedPool, Size, GDITAG_TEXT); if (!potm) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -4159,7 +4159,7 @@ GreGetGlyphIndicesW( RtlCopyMemory( pgi, Buffer, cwc*sizeof(WORD)); ErrorRet: - if (Buffer) ExFreePoolWithTag(Buffer, TAG_GDITEXT); + if (Buffer) ExFreePoolWithTag(Buffer, GDITAG_TEXT); return cwc; } @@ -4210,7 +4210,7 @@ NtGdiGetGlyphIndicesW( FontGDI = ObjToGDI(TextObj->Font, FONT); TEXTOBJ_UnlockText(TextObj); - Buffer = ExAllocatePoolWithTag(PagedPool, cwc*sizeof(WORD), TAG_GDITEXT); + Buffer = ExAllocatePoolWithTag(PagedPool, cwc*sizeof(WORD), GDITAG_TEXT); if (!Buffer) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -4221,7 +4221,7 @@ NtGdiGetGlyphIndicesW( else { Size = IntGetOutlineTextMetrics(FontGDI, 0, NULL); - potm = ExAllocatePoolWithTag(PagedPool, Size, TAG_GDITEXT); + potm = ExAllocatePoolWithTag(PagedPool, Size, GDITAG_TEXT); if (!potm) { Status = ERROR_NOT_ENOUGH_MEMORY; @@ -4282,7 +4282,7 @@ NtGdiGetGlyphIndicesW( _SEH2_END; ErrorRet: - ExFreePoolWithTag(Buffer, TAG_GDITEXT); + ExFreePoolWithTag(Buffer, GDITAG_TEXT); if (NT_SUCCESS(Status)) return cwc; EngSetLastError(Status); return GDI_ERROR; diff --git a/subsystems/win32/win32k/objects/icm.c b/subsystems/win32/win32k/objects/icm.c index a3effb060b7..104cefa99a7 100644 --- a/subsystems/win32/win32k/objects/icm.c +++ b/subsystems/win32/win32k/objects/icm.c @@ -146,7 +146,7 @@ NtGdiGetDeviceGammaRamp(HDC hDC, return FALSE; } - SafeRamp = ExAllocatePoolWithTag(PagedPool, sizeof(GAMMARAMP), TAG_GDIICM); + SafeRamp = ExAllocatePoolWithTag(PagedPool, sizeof(GAMMARAMP), GDITAG_ICM); if (!SafeRamp) { DC_UnlockDc(dc); @@ -174,7 +174,7 @@ NtGdiGetDeviceGammaRamp(HDC hDC, _SEH2_END; DC_UnlockDc(dc); - ExFreePoolWithTag(SafeRamp, TAG_GDIICM); + ExFreePoolWithTag(SafeRamp, GDITAG_ICM); if (!NT_SUCCESS(Status)) { @@ -204,16 +204,16 @@ NtGdiSetColorSpace(IN HDC hdc, if (pdcattr->hColorSpace == hColorSpace) { DC_UnlockDc(pDC); - return TRUE; + return TRUE; } - + pCS = COLORSPACEOBJ_LockCS(hColorSpace); if (!pCS) { EngSetLastError(ERROR_INVALID_HANDLE); return FALSE; } - + if (pDC->dclevel.pColorSpace) { GDIOBJ_ShareUnlockObjByPtr((POBJ) pDC->dclevel.pColorSpace); @@ -345,7 +345,7 @@ IntSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp, BOOL Test) // This way we have a record of the change in memory. if (!pGDev->pvGammaRamp && !(pGDev->flFlags & PDEV_GAMMARAMP_TABLE)) { // If the above is true and we have nothing allocated, create it. - pGDev->pvGammaRamp = ExAllocatePoolWithTag(PagedPool, sizeof(GAMMARAMP), TAG_GDIICM); + pGDev->pvGammaRamp = ExAllocatePoolWithTag(PagedPool, sizeof(GAMMARAMP), GDITAG_ICM); pGDev->flFlags |= PDEV_GAMMARAMP_TABLE; } if (pGDev->pvGammaRamp) @@ -377,7 +377,7 @@ NtGdiSetDeviceGammaRamp(HDC hDC, return FALSE; } - SafeRamp = ExAllocatePoolWithTag(PagedPool, sizeof(GAMMARAMP), TAG_GDIICM); + SafeRamp = ExAllocatePoolWithTag(PagedPool, sizeof(GAMMARAMP), GDITAG_ICM); if (!SafeRamp) { DC_UnlockDc(dc); @@ -402,14 +402,14 @@ NtGdiSetDeviceGammaRamp(HDC hDC, if (!NT_SUCCESS(Status)) { DC_UnlockDc(dc); - ExFreePoolWithTag(SafeRamp, TAG_GDIICM); + ExFreePoolWithTag(SafeRamp, GDITAG_ICM); SetLastNtError(Status); return FALSE; } Ret = IntSetDeviceGammaRamp((HDEV)dc->ppdev, SafeRamp, TRUE); DC_UnlockDc(dc); - ExFreePoolWithTag(SafeRamp, TAG_GDIICM); + ExFreePoolWithTag(SafeRamp, GDITAG_ICM); return Ret; } diff --git a/subsystems/win32/win32k/objects/line.c b/subsystems/win32/win32k/objects/line.c index 79445d7c680..1894a63bfae 100644 --- a/subsystems/win32/win32k/objects/line.c +++ b/subsystems/win32/win32k/objects/line.c @@ -262,7 +262,7 @@ IntGdiPolyline(DC *dc, if (!(pbrLine->flAttrs & GDIBRUSH_IS_NULL)) { - Points = EngAllocMem(0, Count * sizeof(POINT), TAG_COORD); + Points = EngAllocMem(0, Count * sizeof(POINT), GDITAG_TEMP); if (Points != NULL) { psurf = dc->dclevel.pSurface; diff --git a/subsystems/win32/win32k/objects/metafile.c b/subsystems/win32/win32k/objects/metafile.c index 6ef6d716e5e..4cf931fa4d0 100644 --- a/subsystems/win32/win32k/objects/metafile.c +++ b/subsystems/win32/win32k/objects/metafile.c @@ -28,213 +28,29 @@ NtGdiConvertMetafileRect(IN HDC hDC, } /* - * @unimplemented + * @implemented */ HDC APIENTRY NtGdiCreateMetafileDC(IN HDC hdc) { - - UNIMPLEMENTED; - return NULL; - - -#if 0 - PDC Dc; + PDC pDc; HDC ret = NULL; - DWORD length = 0; - HDC tempHDC; - DWORD MemSize; - DWORD dwDesiredAccess; - tempHDC = hDCRef; - if (hDCRef == NULL) + if (hdc) { - /* FIXME ?? - * Shall we create hdc NtGdiHdcCompatible hdc ?? - */ - UNICODE_STRING DriverName; - RtlInitUnicodeString(&DriverName, L"DISPLAY"); - //IntGdiCreateDC(&DriverName, NULL, NULL, NULL, FALSE); - tempHDC = NtGdiOpenDCW( &DriverName, - NULL, - NULL, - 0, // DCW 0 and ICW 1. - NULL, - (PVOID) NULL, - (PVOID) NULL ); + pDc = DC_LockDc(hdc); + if (pDc) + { // Not sure this is right for getting the HDEV handle, maybe Timo could help or just if'ed it out. + ret = IntGdiCreateDisplayDC(pDc->ppdev->BaseObject.hHmgr, DC_TYPE_INFO, TRUE); + DC_UnlockDc(pDc); } - - GDIOBJ_SetOwnership(GdiHandleTable, tempHDC, PsGetCurrentProcess()); - DC_SetOwnership(tempHDC, PsGetCurrentProcess()); - - Dc = DC_LockDc(tempHDC); - if (Dc == NULL) - { - if (hDCRef == NULL) - { - NtGdiDeleteObjectApp(tempHDC); } - EngSetLastError(ERROR_INVALID_HANDLE); - return NULL; - } - - if(Description) - { - length = wcslen(Description); - length += wcslen(Description + length + 1); - length += 3; - length *= 2; - } - - MemSize = sizeof(ENHMETAHEADER) + (length + 3) / 4 * 4; - - if (!(Dc->emh = EngAllocMem(FL_ZERO_MEMORY, MemSize, 0))) - { - DC_UnlockDc(Dc); - if (hDCRef == NULL) - { - NtGdiDeleteObjectApp(tempHDC); - } - EngSetLastError(ERROR_INVALID_HANDLE); - return NULL; - } - - Dc->emh->iType = EMR_HEADER; - Dc->emh->nSize = MemSize; - - Dc->emh->rclBounds.left = Dc->emh->rclBounds.top = 0; - Dc->emh->rclBounds.right = Dc->emh->rclBounds.bottom = -1; - - if(Rect) - { - Dc->emh->rclFrame.left = Rect->left; - Dc->emh->rclFrame.top = Rect->top; - Dc->emh->rclFrame.right = Rect->right; - Dc->emh->rclFrame.bottom = Rect->bottom; - } else { - /* Set this to {0,0 - -1,-1} and update it at the end */ - Dc->emh->rclFrame.left = Dc->emh->rclFrame.top = 0; - Dc->emh->rclFrame.right = Dc->emh->rclFrame.bottom = -1; + ret = UserGetDesktopDC(DC_TYPE_INFO, TRUE, FALSE); } - - Dc->emh->dSignature = ENHMETA_SIGNATURE; - Dc->emh->nVersion = 0x10000; - Dc->emh->nBytes = Dc->emh->nSize; - Dc->emh->nRecords = 1; - Dc->emh->nHandles = 1; - - Dc->emh->sReserved = 0; /* According to docs, this is reserved and must be 0 */ - Dc->emh->nDescription = length / 2; - - Dc->emh->offDescription = length ? sizeof(ENHMETAHEADER) : 0; - - Dc->emh->nPalEntries = 0; /* I guess this should start at 0 */ - - /* Size in pixels */ - Dc->emh->szlDevice.cx = NtGdiGetDeviceCaps(tempHDC, HORZRES); - Dc->emh->szlDevice.cy = NtGdiGetDeviceCaps(tempHDC, VERTRES); - - /* Size in millimeters */ - Dc->emh->szlMillimeters.cx = NtGdiGetDeviceCaps(tempHDC, HORZSIZE); - Dc->emh->szlMillimeters.cy = NtGdiGetDeviceCaps(tempHDC, VERTSIZE); - - /* Size in micrometers */ - Dc->emh->szlMicrometers.cx = Dc->emh->szlMillimeters.cx * 1000; - Dc->emh->szlMicrometers.cy = Dc->emh->szlMillimeters.cy * 1000; - - if(Description) - { - memcpy((char *)Dc->emh + sizeof(ENHMETAHEADER), Description, length); - } - - ret = tempHDC; - if (File) - { - OBJECT_ATTRIBUTES ObjectAttributes; - IO_STATUS_BLOCK IoStatusBlock; - IO_STATUS_BLOCK Iosb; - UNICODE_STRING NtPathU; - NTSTATUS Status; - ULONG FileAttributes = (FILE_ATTRIBUTE_VALID_FLAGS & ~FILE_ATTRIBUTE_DIRECTORY); - - DPRINT1("Trying Create EnhMetaFile\n"); - - /* disk based metafile */ - dwDesiredAccess = GENERIC_WRITE | GENERIC_READ | SYNCHRONIZE | FILE_READ_ATTRIBUTES; - - if (!RtlDosPathNameToNtPathName_U (File, &NtPathU, NULL, NULL)) - { - DC_UnlockDc(Dc); - if (hDCRef == NULL) - { - NtGdiDeleteObjectApp(tempHDC); - } - DPRINT1("Can not Create EnhMetaFile\n"); - EngSetLastError(ERROR_PATH_NOT_FOUND); - return NULL; - } - - InitializeObjectAttributes(&ObjectAttributes, &NtPathU, 0, NULL, NULL); - - Status = NtCreateFile (&Dc->hFile, dwDesiredAccess, &ObjectAttributes, &IoStatusBlock, - NULL, FileAttributes, 0, FILE_OVERWRITE_IF, FILE_NON_DIRECTORY_FILE, - NULL, 0); - - RtlFreeHeap(RtlGetProcessHeap(), 0, NtPathU.Buffer); - - if (!NT_SUCCESS(Status)) - { - Dc->hFile = NULL; - DC_UnlockDc(Dc); - if (hDCRef == NULL) - { - NtGdiDeleteObjectApp(tempHDC); - } - DPRINT1("Create EnhMetaFile fail\n"); - EngSetLastError(ERROR_INVALID_HANDLE); - return NULL; - } - - EngSetLastError(IoStatusBlock.Information == FILE_OVERWRITTEN ? ERROR_ALREADY_EXISTS : 0); - - Status = NtWriteFile(Dc->hFile, NULL, NULL, NULL, &Iosb, (PVOID)&Dc->emh, Dc->emh->nSize, NULL, NULL); - if (Status == STATUS_PENDING) - { - Status = NtWaitForSingleObject(Dc->hFile,FALSE,NULL); - if (NT_SUCCESS(Status)) - { - Status = Iosb.Status; - } - } - - if (NT_SUCCESS(Status)) - { - ret = tempHDC; - DC_UnlockDc(Dc); - } - else - { - Dc->hFile = NULL; - DPRINT1("Write to EnhMetaFile fail\n"); - EngSetLastError(ERROR_CAN_NOT_COMPLETE); - ret = NULL; - DC_UnlockDc(Dc); - if (hDCRef == NULL) - { - NtGdiDeleteObjectApp(tempHDC); - } - } - } - else - { - DC_UnlockDc(Dc); - } - return ret; -#endif } /* diff --git a/subsystems/win32/win32k/objects/path.c b/subsystems/win32/win32k/objects/path.c index f96580a0ae2..8a9010ced68 100644 --- a/subsystems/win32/win32k/objects/path.c +++ b/subsystems/win32/win32k/objects/path.c @@ -2051,7 +2051,7 @@ PATH_ExtTextOut(PDC dc, INT x, INT y, UINT flags, const RECTL *lprc, sinEsc = 0; } - IntGdiGetDCOrg(dc, &org); + org = dc->ptlDCOrig; for (idx = 0; idx < count; idx++) { diff --git a/subsystems/win32/win32k/objects/pen.c b/subsystems/win32/win32k/objects/pen.c index 953fdff6eec..ef6944762b4 100644 --- a/subsystems/win32/win32k/objects/pen.c +++ b/subsystems/win32/win32k/objects/pen.c @@ -228,10 +228,10 @@ PEN_GetObject(PBRUSH pbrushPen, INT cbCount, PLOGPEN pBuffer) if (cbCount < cbRetCount) return 0; - if ( (pbrushPen->ulPenStyle & PS_STYLE_MASK) == PS_NULL && + if ( (pbrushPen->ulPenStyle & PS_STYLE_MASK) == PS_NULL && cbCount == sizeof(EXTLOGPEN)) { - pExtLogPen = (PEXTLOGPEN)pBuffer; + pExtLogPen = (PEXTLOGPEN)pBuffer; pExtLogPen->elpPenStyle = pbrushPen->ulPenStyle; pExtLogPen->elpWidth = 0; pExtLogPen->elpBrushStyle = pbrushPen->ulStyle; @@ -331,7 +331,7 @@ NtGdiExtCreatePen( if (dwStyleCount > 0) { - pSafeStyle = ExAllocatePoolWithTag(NonPagedPool, dwStyleCount * sizeof(DWORD), TAG_PENSTYLES); + pSafeStyle = ExAllocatePoolWithTag(NonPagedPool, dwStyleCount * sizeof(DWORD), GDITAG_PENSTYLE); if (!pSafeStyle) { SetLastNtError(ERROR_NOT_ENOUGH_MEMORY); @@ -352,7 +352,7 @@ NtGdiExtCreatePen( if(!NT_SUCCESS(Status)) { SetLastNtError(Status); - ExFreePoolWithTag(pSafeStyle, TAG_PENSTYLES); + ExFreePoolWithTag(pSafeStyle, GDITAG_PENSTYLE); return 0; } } @@ -371,7 +371,7 @@ NtGdiExtCreatePen( if(!NT_SUCCESS(Status)) { SetLastNtError(Status); - if (pSafeStyle) ExFreePoolWithTag(pSafeStyle, TAG_PENSTYLES); + if (pSafeStyle) ExFreePoolWithTag(pSafeStyle, GDITAG_PENSTYLE); return 0; } } @@ -390,7 +390,7 @@ NtGdiExtCreatePen( if (!hPen && pSafeStyle) { - ExFreePoolWithTag(pSafeStyle, TAG_PENSTYLES); + ExFreePoolWithTag(pSafeStyle, GDITAG_PENSTYLE); } return hPen; } diff --git a/subsystems/win32/win32k/objects/print.c b/subsystems/win32/win32k/objects/print.c index b9592e09fc2..f0ab461cbac 100644 --- a/subsystems/win32/win32k/objects/print.c +++ b/subsystems/win32/win32k/objects/print.c @@ -174,7 +174,7 @@ NtGdiExtEscape( return -1; } - SafeInData = ExAllocatePoolWithTag ( PagedPool, InSize, TAG_PRINT ); + SafeInData = ExAllocatePoolWithTag ( PagedPool, InSize, GDITAG_TEMP ); if ( !SafeInData ) { DC_UnlockDc(pDC); @@ -197,7 +197,7 @@ NtGdiExtEscape( if ( !NT_SUCCESS(Status) ) { - ExFreePoolWithTag ( SafeInData, TAG_PRINT ); + ExFreePoolWithTag ( SafeInData, GDITAG_TEMP ); DC_UnlockDc(pDC); SetLastNtError(Status); return -1; @@ -224,13 +224,13 @@ NtGdiExtEscape( goto freeout; } - SafeOutData = ExAllocatePoolWithTag ( PagedPool, OutSize, TAG_PRINT ); + SafeOutData = ExAllocatePoolWithTag ( PagedPool, OutSize, GDITAG_TEMP ); if ( !SafeOutData ) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); freeout: if ( SafeInData ) - ExFreePoolWithTag ( SafeInData, TAG_PRINT ); + ExFreePoolWithTag ( SafeInData, GDITAG_TEMP ); DC_UnlockDc(pDC); return -1; } @@ -241,7 +241,7 @@ freeout: DC_UnlockDc(pDC); if ( SafeInData ) - ExFreePoolWithTag ( SafeInData ,TAG_PRINT ); + ExFreePoolWithTag ( SafeInData ,GDITAG_TEMP ); if ( SafeOutData ) { @@ -258,7 +258,7 @@ freeout: } _SEH2_END; - ExFreePoolWithTag ( SafeOutData, TAG_PRINT ); + ExFreePoolWithTag ( SafeOutData, GDITAG_TEMP ); if ( !NT_SUCCESS(Status) ) { SetLastNtError(Status); diff --git a/subsystems/win32/win32k/objects/region.c b/subsystems/win32/win32k/objects/region.c index ca52b082d2f..c681d4e9f42 100644 --- a/subsystems/win32/win32k/objects/region.c +++ b/subsystems/win32/win32k/objects/region.c @@ -3486,6 +3486,7 @@ NtGdiExtCreateRegion( DWORD dwSize = 0; NTSTATUS Status = STATUS_SUCCESS; MATRIX matrix; + XFORMOBJ xo; DPRINT("NtGdiExtCreateRegion\n"); _SEH2_TRY @@ -3531,13 +3532,14 @@ NtGdiExtCreateRegion( /* Init the XFORMOBJ from the Xform struct */ Status = STATUS_INVALID_PARAMETER; - ret = XFORMOBJ_iSetXform((XFORMOBJ*)&matrix, (XFORML*)Xform); + XFORMOBJ_vInit(&xo, &matrix); + ret = XFORMOBJ_iSetXform(&xo, (XFORML*)Xform); /* Check for error, also no scale and shear allowed */ if (ret != DDI_ERROR && ret != GX_GENERAL) { /* Apply the coordinate transformation on the rects */ - if (XFORMOBJ_bApplyXform((XFORMOBJ*)&matrix, + if (XFORMOBJ_bApplyXform(&xo, XF_LTOL, nCount * 2, RgnData->Buffer, @@ -3637,83 +3639,6 @@ NtGdiFrameRgn( } -/* See wine, msdn, osr and Feng Yuan - Windows Graphics Programming Win32 Gdi And Directdraw - - 1st: http://www.codeproject.com/gdi/cliprgnguide.asp is wrong! - - The intersection of the clip with the meta region is not Rao it's API! - Go back and read 7.2 Clipping pages 418-19: - Rao = API & Vis: - 1) The Rao region is the intersection of the API region and the system region, - named after the Microsoft engineer who initially proposed it. - 2) The Rao region can be calculated from the API region and the system region. - - API: - API region is the intersection of the meta region and the clipping region, - clearly named after the fact that it is controlled by GDI API calls. -*/ -INT APIENTRY -NtGdiGetRandomRgn( - HDC hDC, - HRGN hDest, - INT iCode -) -{ - INT ret = 0; - PDC pDC; - HRGN hSrc = NULL; - POINT org; - - pDC = DC_LockDc(hDC); - if (pDC == NULL) - { - EngSetLastError(ERROR_INVALID_HANDLE); - return -1; - } - - switch (iCode) - { - case CLIPRGN: - hSrc = pDC->rosdc.hClipRgn; -// if (pDC->dclevel.prgnClip) hSrc = ((PROSRGNDATA)pDC->dclevel.prgnClip)->BaseObject.hHmgr; - break; - case METARGN: - if (pDC->dclevel.prgnMeta) hSrc = ((PROSRGNDATA)pDC->dclevel.prgnMeta)->BaseObject.hHmgr; - break; - case APIRGN: - if (pDC->prgnAPI) hSrc = ((PROSRGNDATA)pDC->prgnAPI)->BaseObject.hHmgr; -// else if (pDC->dclevel.prgnClip) hSrc = ((PROSRGNDATA)pDC->dclevel.prgnClip)->BaseObject.hHmgr; - else if (pDC->rosdc.hClipRgn) hSrc = pDC->rosdc.hClipRgn; - else if (pDC->dclevel.prgnMeta) hSrc = ((PROSRGNDATA)pDC->dclevel.prgnMeta)->BaseObject.hHmgr; - break; - case SYSRGN: - if (pDC->prgnVis) hSrc = pDC->prgnVis->BaseObject.hHmgr; - break; - default: - hSrc = 0; - } - if (hSrc) - { - if (NtGdiCombineRgn(hDest, hSrc, 0, RGN_COPY) == ERROR) - { - ret = -1; - } - else - { - ret = 1; - } - } - if (iCode == SYSRGN) - { - IntGdiGetDCOrg(pDC, &org); - NtGdiOffsetRgn(hDest, org.x, org.y ); - } - - DC_UnlockDc(pDC); - - return ret; -} - INT APIENTRY NtGdiGetRgnBox( HRGN hRgn, diff --git a/subsystems/win32/win32k/objects/text.c b/subsystems/win32/win32k/objects/text.c index bc5f45dae6d..6c3fe7a6605 100644 --- a/subsystems/win32/win32k/objects/text.c +++ b/subsystems/win32/win32k/objects/text.c @@ -3,9 +3,9 @@ * LICENSE: GPL - See COPYING in the top level directory * FILE: subsystems/win32/win32k/objects/text.c * PURPOSE: Text/Font - * PROGRAMMER: + * PROGRAMMER: */ - + /** Includes ******************************************************************/ #include @@ -70,7 +70,7 @@ GreGetTextExtentW( DC_UnlockDc(pdc); return Result; -} +} /* @@ -103,10 +103,10 @@ GreGetTextExtentExW( if ( !Count ) { - if ( Fit ) Fit = 0; + if ( Fit ) Fit = 0; return TRUE; } - + pdc = DC_LockDc(hDC); if (NULL == pdc) { @@ -295,7 +295,7 @@ NtGdiGetTextExtentExW( return TRUE; } - String = ExAllocatePoolWithTag(PagedPool, Count * sizeof(WCHAR), TAG_GDITEXT); + String = ExAllocatePoolWithTag(PagedPool, Count * sizeof(WCHAR), GDITAG_TEXT); if (NULL == String) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -304,10 +304,10 @@ NtGdiGetTextExtentExW( if (NULL != UnsafeDx) { - Dx = ExAllocatePoolWithTag(PagedPool, Count * sizeof(INT), TAG_GDITEXT); + Dx = ExAllocatePoolWithTag(PagedPool, Count * sizeof(INT), GDITAG_TEXT); if (NULL == Dx) { - ExFreePoolWithTag(String, TAG_GDITEXT); + ExFreePoolWithTag(String, GDITAG_TEXT); EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); return FALSE; } @@ -322,9 +322,9 @@ NtGdiGetTextExtentExW( { if (NULL != Dx) { - ExFreePoolWithTag(Dx, TAG_GDITEXT); + ExFreePoolWithTag(Dx, GDITAG_TEXT); } - ExFreePoolWithTag(String, TAG_GDITEXT); + ExFreePoolWithTag(String, GDITAG_TEXT); SetLastNtError(Status); return FALSE; } @@ -334,9 +334,9 @@ NtGdiGetTextExtentExW( { if (NULL != Dx) { - ExFreePoolWithTag(Dx, TAG_GDITEXT); + ExFreePoolWithTag(Dx, GDITAG_TEXT); } - ExFreePoolWithTag(String, TAG_GDITEXT); + ExFreePoolWithTag(String, GDITAG_TEXT); EngSetLastError(ERROR_INVALID_HANDLE); return FALSE; } @@ -359,12 +359,12 @@ NtGdiGetTextExtentExW( Result = FALSE; DC_UnlockDc(dc); - ExFreePoolWithTag(String, TAG_GDITEXT); + ExFreePoolWithTag(String, GDITAG_TEXT); if (! Result) { if (NULL != Dx) { - ExFreePoolWithTag(Dx, TAG_GDITEXT); + ExFreePoolWithTag(Dx, GDITAG_TEXT); } return FALSE; } @@ -376,7 +376,7 @@ NtGdiGetTextExtentExW( { if (NULL != Dx) { - ExFreePoolWithTag(Dx, TAG_GDITEXT); + ExFreePoolWithTag(Dx, GDITAG_TEXT); } SetLastNtError(Status); return FALSE; @@ -390,7 +390,7 @@ NtGdiGetTextExtentExW( { if (NULL != Dx) { - ExFreePoolWithTag(Dx, TAG_GDITEXT); + ExFreePoolWithTag(Dx, GDITAG_TEXT); } SetLastNtError(Status); return FALSE; @@ -398,7 +398,7 @@ NtGdiGetTextExtentExW( } if (NULL != Dx) { - ExFreePoolWithTag(Dx,TAG_GDITEXT); + ExFreePoolWithTag(Dx,GDITAG_TEXT); } Status = MmCopyToCaller(UnsafeSize, &Size, sizeof(SIZE)); @@ -506,7 +506,7 @@ NtGdiGetTextFaceW( } else { - ret = fLen; + ret = fLen; } TEXTOBJ_UnlockText(TextObj); diff --git a/subsystems/win32/win32k/objects/xformobj.c b/subsystems/win32/win32k/objects/xformobj.c index 9ba7311ef06..87e1e070a94 100644 --- a/subsystems/win32/win32k/objects/xformobj.c +++ b/subsystems/win32/win32k/objects/xformobj.c @@ -115,7 +115,7 @@ INTERNAL_CALL XFORMOBJ_UpdateAccel( IN XFORMOBJ *pxo) { - PMATRIX pmx = (PMATRIX)pxo; + PMATRIX pmx = XFORMOBJ_pmx(pxo); /* Copy Dx and Dy to FIX format */ pmx->fxDx = FLOATOBJ_GetFix(&pmx->efDx); @@ -155,9 +155,9 @@ ULONG INTERNAL_CALL XFORMOBJ_iSetXform( OUT XFORMOBJ *pxo, - IN XFORML * pxform) + IN const XFORML *pxform) { - PMATRIX pmx = (PMATRIX)pxo; + PMATRIX pmx = XFORMOBJ_pmx(pxo); /* Check parameters */ if (!pxo || !pxform) @@ -195,9 +195,9 @@ XFORMOBJ_iCombine( MATRIX mx; PMATRIX pmx, pmx1, pmx2; - pmx = (PMATRIX)pxo; - pmx1 = (PMATRIX)pxo1; - pmx2 = (PMATRIX)pxo2; + pmx = XFORMOBJ_pmx(pxo); + pmx1 =XFORMOBJ_pmx(pxo1); + pmx2 = XFORMOBJ_pmx(pxo2); /* Do a 3 x 3 matrix multiplication with mx as destinantion */ MulAdd(&mx.efM11, &pmx1->efM11, &pmx2->efM11, &pmx1->efM12, &pmx2->efM21); @@ -226,17 +226,18 @@ XFORMOBJ_iCombineXform( IN BOOL bLeftMultiply) { MATRIX mx; - XFORMOBJ *pxo2 = (XFORMOBJ*)&mx; + XFORMOBJ xo2; - XFORMOBJ_iSetXform(pxo2, pxform); + XFORMOBJ_vInit(&xo2, &mx); + XFORMOBJ_iSetXform(&xo2, pxform); if (bLeftMultiply) { - return XFORMOBJ_iCombine(pxo, pxo2, pxo1); + return XFORMOBJ_iCombine(pxo, &xo2, pxo1); } else { - return XFORMOBJ_iCombine(pxo, pxo1, pxo2); + return XFORMOBJ_iCombine(pxo, pxo1, &xo2); } } @@ -246,15 +247,15 @@ XFORMOBJ_iCombineXform( */ ULONG INTERNAL_CALL -XFORMOBJ_Inverse( +XFORMOBJ_iInverse( OUT XFORMOBJ *pxoDst, IN XFORMOBJ *pxoSrc) { PMATRIX pmxDst, pmxSrc; FLOATOBJ foDet; - pmxDst = (PMATRIX)pxoDst; - pmxSrc = (PMATRIX)pxoSrc; + pmxDst = XFORMOBJ_pmx(pxoDst); + pmxSrc = XFORMOBJ_pmx(pxoSrc); /* det = M11 * M22 - M12 * M21 */ MulSub(&foDet, &pmxSrc->efM11, &pmxSrc->efM22, &pmxSrc->efM12, &pmxSrc->efM21); @@ -296,17 +297,17 @@ XFORMOBJ_bXformFixPoints( FLOATOBJ fo1, fo2; FLONG flAccel; - pmx = (PMATRIX)pxo; - flAccel = pmx->flAccel & (MX_INTEGER|MX_SCALE|MX_IDENTITYSCALE); + pmx = XFORMOBJ_pmx(pxo); + flAccel = pmx->flAccel; - switch (flAccel) + if ((flAccel & (MX_SCALE|MX_IDENTITYSCALE)) == (MX_SCALE|MX_IDENTITYSCALE)) { - case (MX_SCALE | MX_IDENTITYSCALE): - case (MX_SCALE | MX_IDENTITYSCALE | MX_INTEGER): /* Identity transformation, nothing todo */ - break; - - case (MX_IDENTITYSCALE | MX_INTEGER): + } + else if (flAccel & MX_INTEGER) + { + if (flAccel & MX_IDENTITYSCALE) + { /* 1-scale integer transform */ i = cPoints - 1; do @@ -317,9 +318,9 @@ XFORMOBJ_bXformFixPoints( pptOut[i].x = x; } while (--i >= 0); - break; - - case (MX_SCALE | MX_INTEGER): + } + else if (flAccel & MX_SCALE) + { /* Diagonal integer transform */ i = cPoints - 1; do @@ -328,9 +329,9 @@ XFORMOBJ_bXformFixPoints( pptOut[i].y = pptIn[i].y * FLOATOBJ_GetLong(&pmx->efM22); } while (--i >= 0); - break; - - case (MX_INTEGER): + } + else + { /* Full integer transform */ i = cPoints - 1; do @@ -343,9 +344,10 @@ XFORMOBJ_bXformFixPoints( pptOut[i].x = x; } while (--i >= 0); - break; - - case (MX_IDENTITYSCALE): + } + } + else if (flAccel & MX_IDENTITYSCALE) + { /* 1-scale transform */ i = cPoints - 1; do @@ -358,9 +360,9 @@ XFORMOBJ_bXformFixPoints( pptOut[i].y = pptIn[i].y + FLOATOBJ_GetLong(&fo2); } while (--i >= 0); - break; - - case (MX_SCALE): + } + else if (flAccel & MX_SCALE) + { /* Diagonal float transform */ i = cPoints - 1; do @@ -373,9 +375,9 @@ XFORMOBJ_bXformFixPoints( pptOut[i].y = FLOATOBJ_GetLong(&fo2); } while (--i >= 0); - break; - - default: + } + else + { /* Full float transform */ i = cPoints - 1; do @@ -386,7 +388,6 @@ XFORMOBJ_bXformFixPoints( pptOut[i].y = FLOATOBJ_GetLong(&fo2); } while (--i >= 0); - break; } if (!(pmx->flAccel & MX_NOTRANSLATE)) @@ -414,7 +415,7 @@ XFORMOBJ_iGetXform( IN XFORMOBJ *pxo, OUT XFORML *pxform) { - PMATRIX pmx = (PMATRIX)pxo; + PMATRIX pmx = XFORMOBJ_pmx(pxo); /* Check parameters */ if (!pxo || !pxform) @@ -442,7 +443,7 @@ XFORMOBJ_iGetFloatObjXform( IN XFORMOBJ *pxo, OUT FLOATOBJ_XFORM *pxfo) { - PMATRIX pmx = (PMATRIX)pxo; + PMATRIX pmx = XFORMOBJ_pmx(pxo); /* Check parameters */ if (!pxo || !pxfo) @@ -474,6 +475,7 @@ XFORMOBJ_bApplyXform( OUT PVOID pvOut) { MATRIX mx; + XFORMOBJ xoInv; POINTL *pptl; INT i; @@ -486,13 +488,12 @@ XFORMOBJ_bApplyXform( /* Use inverse xform? */ if (iMode == XF_INV_FXTOL || iMode == XF_INV_LTOL) { - ULONG ret; - ret = XFORMOBJ_Inverse((XFORMOBJ*)&mx, pxo); - if (ret == DDI_ERROR) + XFORMOBJ_vInit(&xoInv, &mx); + if (XFORMOBJ_iInverse(&xoInv, pxo) == DDI_ERROR) { return FALSE; } - pxo = (XFORMOBJ*)&mx; + pxo = &xoInv; } /* Convert POINTL to POINTFIX? */ diff --git a/subsystems/win32/win32k/pch.h b/subsystems/win32/win32k/pch.h index 339918377a1..8a39b1dba58 100644 --- a/subsystems/win32/win32k/pch.h +++ b/subsystems/win32/win32k/pch.h @@ -62,12 +62,14 @@ typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; #include #include +/* Undocumented user definitions */ +#include + /* Internal Win32K Header */ #include "include/win32kp.h" /* Undocumented stuff */ typedef DRIVEROBJ *PDRIVEROBJ; -#define WM_SYSTIMER 280 #ifndef M_PI #define M_PI 3.14159265358979323846f #define M_PI_2 1.57079632679489661923 diff --git a/subsystems/win32/win32k/stubs/stubs.c b/subsystems/win32/win32k/stubs/stubs.c index 7685c19ad99..e2dd07daa9a 100644 --- a/subsystems/win32/win32k/stubs/stubs.c +++ b/subsystems/win32/win32k/stubs/stubs.c @@ -3,6 +3,7 @@ */ #include +#undef XFORMOBJ #define UNIMPLEMENTED DbgPrint("(%s:%i) WIN32K: %s UNIMPLEMENTED\n", __FILE__, __LINE__, __FUNCTION__ ) diff --git a/subsystems/win32/win32k/stubs/umpdstubs.c b/subsystems/win32/win32k/stubs/umpdstubs.c index 9ecafb906af..a25f4369769 100644 --- a/subsystems/win32/win32k/stubs/umpdstubs.c +++ b/subsystems/win32/win32k/stubs/umpdstubs.c @@ -1,4 +1,5 @@ #include +#undef XFORMOBJ #define UNIMPLEMENTED DbgPrint("(%s:%i) WIN32K: %s UNIMPLEMENTED\n", __FILE__, __LINE__, __FUNCTION__ ) diff --git a/subsystems/win32/win32k/win32k.spec b/subsystems/win32/win32k/win32k.spec index 265e02b09b7..800a084c1b5 100644 --- a/subsystems/win32/win32k/win32k.spec +++ b/subsystems/win32/win32k/win32k.spec @@ -211,9 +211,9 @@ @ stdcall WNDOBJ_bEnum(ptr long ptr) @ stdcall WNDOBJ_cEnumStart(ptr long long long) @ stdcall WNDOBJ_vSetConsumer(ptr ptr) -@ stdcall XFORMOBJ_bApplyXform(ptr long long ptr ptr) -@ stdcall XFORMOBJ_iGetFloatObjXform(ptr ptr) -@ stdcall XFORMOBJ_iGetXform(ptr ptr) +@ stdcall XFORMOBJ_bApplyXform(ptr long long ptr ptr) EXFORMOBJ_bApplyXform +@ stdcall XFORMOBJ_iGetFloatObjXform(ptr ptr) EXFORMOBJ_iGetFloatObjXform +@ stdcall XFORMOBJ_iGetXform(ptr ptr) EXFORMOBJ_iGetXform @ stdcall XLATEOBJ_cGetPalette(ptr long long ptr) @ stdcall XLATEOBJ_hGetColorTransform(ptr) @ stdcall XLATEOBJ_iXlate(ptr long)