ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
February 2017
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
13 participants
353 discussions
Start a n
N
ew thread
[mjansen] 73746: [GDI32_APITEST] Add tests for font creation. Patch by Katayama Hirofumi MZ. CORE-6621
by mjansen@svn.reactos.org
Author: mjansen Date: Tue Feb 7 11:37:36 2017 New Revision: 73746 URL:
http://svn.reactos.org/svn/reactos?rev=73746&view=rev
Log: [GDI32_APITEST] Add tests for font creation. Patch by Katayama Hirofumi MZ. CORE-6621 Modified: trunk/rostests/apitests/gdi32/CreateFontIndirect.c Modified: trunk/rostests/apitests/gdi32/CreateFontIndirect.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/gdi32/CreateFont…
============================================================================== --- trunk/rostests/apitests/gdi32/CreateFontIndirect.c [iso-8859-1] (original) +++ trunk/rostests/apitests/gdi32/CreateFontIndirect.c [iso-8859-1] Tue Feb 7 11:37:36 2017 @@ -3,11 +3,13 @@ * LICENSE: GPL - See COPYING in the top level directory * PURPOSE: Test for CreateFontIndirect * PROGRAMMERS: Timo Kreuzer + * Katayama Hirofumi MZ */ #include <apitest.h> - #include <wingdi.h> + +#define trace_if(val, msg) do { if (!(val)) trace(msg); } while (0) void Test_CreateFontIndirectA(void) @@ -167,6 +169,588 @@ ok(elfedva.elfEnumLogfontEx.elfFullName[LF_FULLFACESIZE-1] == 0, "\n"); } +static INT CALLBACK +is_truetype_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm, + DWORD type, LPARAM lParam) +{ + if (type != TRUETYPE_FONTTYPE) return 1; + + return 0; +} + +static BOOL is_truetype_font_installed(HDC hDC, const char *name) +{ + if (!EnumFontFamiliesA(hDC, name, is_truetype_font_proc, 0)) + return TRUE; + return FALSE; +} + +static INT CALLBACK +is_charset_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm, + DWORD type, LPARAM lParam) +{ + if (ntm->tmCharSet == (BYTE)lParam) + return 0; + return 1; +} + +static BOOL is_charset_font_installed(HDC hDC, BYTE CharSet) +{ + if (!EnumFontFamiliesA(hDC, NULL, is_charset_font_proc, CharSet)) + return TRUE; + return FALSE; +} + +/* TMPF_FIXED_PITCH is confusing. brain-damaged api */ +#define _TMPF_VAR_PITCH TMPF_FIXED_PITCH + +static INT CALLBACK +is_fixed_charset_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm, + DWORD type, LPARAM lParam) +{ + if (ntm->tmCharSet == (BYTE)lParam && !(ntm->tmPitchAndFamily & _TMPF_VAR_PITCH)) + return 0; + return 1; +} + +static BOOL +is_fixed_charset_font_installed(HDC hDC, BYTE CharSet) +{ + if (!EnumFontFamiliesA(hDC, NULL, is_fixed_charset_font_proc, CharSet)) + return TRUE; + return FALSE; +} + +static void +Test_FontPresence(void) +{ + HDC hDC; + + hDC = CreateCompatibleDC(NULL); + + ok(is_truetype_font_installed(hDC, "Arial"), "'Arial' is not found\n"); + ok(is_truetype_font_installed(hDC, "Courier New"), "'Courier New' is not found\n"); + ok(is_truetype_font_installed(hDC, "Marlett"), "'Marlett' is not found\n"); + ok(is_truetype_font_installed(hDC, "MS Shell Dlg"), "'MS Shell Dlg' is not found\n"); + ok(is_truetype_font_installed(hDC, "Tahoma"), "'Tahoma' is not found\n"); + ok(is_truetype_font_installed(hDC, "Times New Roman"), "'Times New Roman' is not found\n"); + + ok(is_charset_font_installed(hDC, ANSI_CHARSET), "ANSI_CHARSET fonts are not found\n"); + ok(is_charset_font_installed(hDC, SYMBOL_CHARSET), "SYMBOL_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, SHIFTJIS_CHARSET), "SHIFTJIS_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, HANGUL_CHARSET), "HANGUL_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, GB2312_CHARSET), "GB2312_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, CHINESEBIG5_CHARSET), "CHINESEBIG5_CHARSET fonts are not found\n"); + ok(is_charset_font_installed(hDC, OEM_CHARSET), "OEM_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, JOHAB_CHARSET), "JOHAB_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, HEBREW_CHARSET), "HEBREW_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, ARABIC_CHARSET), "ARABIC_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, GREEK_CHARSET), "GREEK_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, TURKISH_CHARSET), "TURKISH_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, VIETNAMESE_CHARSET), "VIETNAMESE_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, THAI_CHARSET), "THAI_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, EASTEUROPE_CHARSET), "EASTEUROPE_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, RUSSIAN_CHARSET), "RUSSIAN_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, MAC_CHARSET), "MAC_CHARSET fonts are not found\n"); + trace_if(is_charset_font_installed(hDC, BALTIC_CHARSET), "BALTIC_CHARSET fonts are not found\n"); + + ok(is_fixed_charset_font_installed(hDC, ANSI_CHARSET), "fixed ANSI_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, SHIFTJIS_CHARSET), "fixed SHIFTJIS_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, HANGUL_CHARSET), "fixed HANGUL_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, GB2312_CHARSET), "fixed GB2312_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, CHINESEBIG5_CHARSET), "fixed CHINESEBIG5_CHARSET fonts are not found\n"); + ok(is_fixed_charset_font_installed(hDC, OEM_CHARSET), "fixed OEM_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, JOHAB_CHARSET), "fixed JOHAB_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, HEBREW_CHARSET), "fixed HEBREW_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, ARABIC_CHARSET), "fixed ARABIC_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, GREEK_CHARSET), "fixed GREEK_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, TURKISH_CHARSET), "fixed TURKISH_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, VIETNAMESE_CHARSET), "fixed VIETNAMESE_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, THAI_CHARSET), "fixed THAI_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, EASTEUROPE_CHARSET), "fixed EASTEUROPE_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, RUSSIAN_CHARSET), "fixed RUSSIAN_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, MAC_CHARSET), "fixed MAC_CHARSET fonts are not found\n"); + trace_if(is_fixed_charset_font_installed(hDC, BALTIC_CHARSET), "fixed BALTIC_CHARSET fonts are not found\n"); + + DeleteDC(hDC); +} + +/* NOTE: TMPF_FIXED_PITCH is confusing and brain-dead. */ +#define _TMPF_VAR_PITCH TMPF_FIXED_PITCH + +typedef enum TRISTATE { + TS_UNKNOWN, + TS_TRUE, + TS_FALSE +} TRISTATE; + +typedef struct FONT_SEL_TEST { + CHAR FaceNameBefore[LF_FACESIZE]; + + BYTE CharSetBefore; + BYTE CharSetAfter; + + TRISTATE BoldBefore; + TRISTATE BoldAfter; + + BYTE ItalicBefore; + TRISTATE ItalicAfter; + + BYTE UnderlineBefore; + TRISTATE UnderlineAfter; + + BYTE StruckOutBefore; + TRISTATE StruckOutAfter; + + TRISTATE FixedPitchBefore; + TRISTATE FixedPitchAfter; +} FONT_SEL_TEST; + +static FONT_SEL_TEST g_Entries[] = +{ + /* Entry #0: default */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + TS_UNKNOWN, TS_FALSE, + TS_UNKNOWN, TS_FALSE, + TS_UNKNOWN, TS_FALSE, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #1: symbol font*/ + { + "", + SYMBOL_CHARSET, SYMBOL_CHARSET + }, + /* Entry #2: non-bold */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_FALSE, TS_FALSE + }, + /* Entry #3: bold */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #4: non-italic (without specifying bold) */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_FALSE + }, + /* Entry #5: italic (without specifying bold) */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + TRUE, TS_TRUE + }, + /* Entry #6: non-underline (without specifying bold) */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_FALSE + }, + /* Entry #7: underline (without specifying bold) */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + TRUE, TS_TRUE + }, + /* Entry #8: struck-out (without specifying bold) */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TRUE, TS_TRUE + }, + /* Entry #9: non-struck-out (without specifying bold) */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_FALSE + }, + /* Entry #10: fixed-pitch (without specifying bold) */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #11: non-fixed-pitch (without specifying bold) */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_FALSE, TS_FALSE + }, + /* Entry #12: fixed-pitch and bold */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_TRUE, TS_TRUE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #13: non-fixed-pitch and bold */ + { + "", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_TRUE, TS_TRUE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_FALSE, TS_FALSE + }, + /* Entry #14: OEM_CHARSET */ + { + "", + OEM_CHARSET, OEM_CHARSET, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #15: OEM_CHARSET and bold */ + { + "", + OEM_CHARSET, OEM_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #16: OEM_CHARSET and fixed-pitch */ + { + "", + OEM_CHARSET, OEM_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #17: CHINESEBIG5_CHARSET (Chinese) */ + { + "", + CHINESEBIG5_CHARSET, CHINESEBIG5_CHARSET, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #18: CHINESEBIG5_CHARSET and bold */ + { + "", + CHINESEBIG5_CHARSET, CHINESEBIG5_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #19: CHINESEBIG5_CHARSET and fixed-pitch */ + { + "", + CHINESEBIG5_CHARSET, CHINESEBIG5_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #20: GB2312_CHARSET (Chinese) */ + { + "", + GB2312_CHARSET, GB2312_CHARSET, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #21: GB2312_CHARSET and bold */ + { + "", + GB2312_CHARSET, GB2312_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #22: GB2312_CHARSET and fixed-pitch */ + { + "", + GB2312_CHARSET, GB2312_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #23: RUSSIAN_CHARSET (Russian) */ + { + "", + RUSSIAN_CHARSET, RUSSIAN_CHARSET, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #24: RUSSIAN_CHARSET and bold */ + { + "", + RUSSIAN_CHARSET, RUSSIAN_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #25: RUSSIAN_CHARSET and italic */ + { + "", + RUSSIAN_CHARSET, RUSSIAN_CHARSET, + TS_UNKNOWN, TS_FALSE, + TRUE, TS_TRUE, + }, + /* Entry #26: RUSSIAN_CHARSET and fixed-pitch */ + { + "", + RUSSIAN_CHARSET, RUSSIAN_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #27: SHIFTJIS_CHARSET (Japanese) */ + { + "", + SHIFTJIS_CHARSET, SHIFTJIS_CHARSET, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #28: SHIFTJIS_CHARSET and bold */ + { + "", + SHIFTJIS_CHARSET, SHIFTJIS_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #29: SHIFTJIS_CHARSET and fixed-pitch */ + { + "", + SHIFTJIS_CHARSET, SHIFTJIS_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #30: HANGUL_CHARSET (Korean) */ + { + "", + HANGUL_CHARSET, HANGUL_CHARSET, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #31: HANGUL_CHARSET and bold */ + { + "", + HANGUL_CHARSET, HANGUL_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #32: HANGUL_CHARSET and fixed-pitch */ + { + "", + HANGUL_CHARSET, HANGUL_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #33: JOHAB_CHARSET (Korean) */ + { + "", + JOHAB_CHARSET, JOHAB_CHARSET, + TS_UNKNOWN, TS_UNKNOWN + }, + /* Entry #34: JOHAB_CHARSET and bold */ + { + "", + JOHAB_CHARSET, JOHAB_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #35: JOHAB_CHARSET and fixed-pitch */ + { + "", + JOHAB_CHARSET, JOHAB_CHARSET, + TS_UNKNOWN, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #36: THAI_CHARSET (Thai) */ + { + "", + THAI_CHARSET, THAI_CHARSET, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #37: THAI_CHARSET and bold */ + { + "", + THAI_CHARSET, THAI_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #38: THAI_CHARSET and fixed-pitch */ + { + "", + THAI_CHARSET, THAI_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #39: GREEK_CHARSET (Greek) */ + { + "", + GREEK_CHARSET, GREEK_CHARSET, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #40: GREEK_CHARSET and bold */ + { + "", + GREEK_CHARSET, GREEK_CHARSET, + TS_TRUE, TS_TRUE + }, + /* Entry #41: GREEK_CHARSET and italic */ + { + "", + GREEK_CHARSET, GREEK_CHARSET, + TS_UNKNOWN, TS_FALSE, + TRUE, TS_TRUE + }, + /* Entry #42: GREEK_CHARSET and fixed-pitch */ + { + "", + GREEK_CHARSET, GREEK_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_TRUE, TS_TRUE + }, + /* Entry #43: "Marlett" */ + { + "Marlett", + DEFAULT_CHARSET, SYMBOL_CHARSET + }, + /* Entry #43: "Arial" */ + { + "Arial", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_UNKNOWN, TS_FALSE + }, + /* Entry #44: "Courier" */ + { + "Courier", + DEFAULT_CHARSET, DEFAULT_CHARSET, + TS_UNKNOWN, TS_FALSE, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + FALSE, TS_UNKNOWN, + TS_UNKNOWN, TS_TRUE + } +}; + +static void +Test_FontSelectionEntry(HDC hDC, UINT nIndex, FONT_SEL_TEST *Entry) +{ + LOGFONTA lf; + HFONT hFont; + HGDIOBJ hFontOld; + TEXTMETRICA tm; + + ZeroMemory(&lf, sizeof(lf)); + + if (Entry->FaceNameBefore[0]) + lstrcpynA(lf.lfFaceName, Entry->FaceNameBefore, _countof(lf.lfFaceName)); + + lf.lfCharSet = Entry->CharSetBefore; + + if (Entry->BoldBefore == TS_TRUE) + lf.lfWeight = FW_BOLD; + else if (Entry->BoldBefore == TS_FALSE) + lf.lfWeight = FW_NORMAL; + else + lf.lfWeight = FW_DONTCARE; + + lf.lfItalic = Entry->ItalicBefore; + lf.lfUnderline = Entry->UnderlineBefore; + lf.lfStrikeOut = Entry->StruckOutBefore; + + if (Entry->FixedPitchBefore == TS_TRUE) + lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; + else if (Entry->FixedPitchBefore == TS_FALSE) + lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; + else + lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; + + hFont = CreateFontIndirectA(&lf); + ok(hFont != NULL, "Entry #%u: hFont failed\n", nIndex); + + hFontOld = SelectObject(hDC, hFont); + { + ok(GetTextMetricsA(hDC, &tm), "Entry #%u: GetTextMetricsA failed\n", nIndex); + + if (Entry->CharSetAfter != DEFAULT_CHARSET) + ok(tm.tmCharSet == Entry->CharSetAfter, "Entry #%u: CharSet mismatched, it was %u\n", nIndex, tm.tmCharSet); + + if (Entry->BoldAfter == TS_TRUE) + ok(tm.tmWeight >= FW_BOLD, "Entry #%u: Weight was non-bold\n", nIndex); + else if (Entry->BoldAfter == TS_FALSE) + ok(tm.tmWeight <= FW_MEDIUM, "Entry #%u: Weight was bold\n", nIndex); + + if (Entry->ItalicAfter == TS_TRUE) + ok(tm.tmItalic, "Entry #%u: Italic was non-italic\n", nIndex); + else if (Entry->ItalicAfter == TS_FALSE) + ok(!tm.tmItalic, "Entry #%u: Italic was italic\n", nIndex); + + if (Entry->UnderlineAfter == TS_TRUE) + ok(tm.tmUnderlined, "Entry #%u: Underlined was FALSE\n", nIndex); + else if (Entry->UnderlineAfter == TS_FALSE) + ok(!tm.tmUnderlined, "Entry #%u: Underlined was TRUE\n", nIndex); + + if (Entry->StruckOutAfter == TS_TRUE) + ok(tm.tmStruckOut, "Entry #%u: Struck-out was FALSE\n", nIndex); + else if (Entry->StruckOutAfter == TS_FALSE) + ok(!tm.tmStruckOut, "Entry #%u: Struck-out was TRUE\n", nIndex); + + if (Entry->FixedPitchAfter == TS_TRUE) + ok(!(tm.tmPitchAndFamily & _TMPF_VAR_PITCH), "Entry #%u: Pitch mismatched, it was non-fixed-pitch\n", nIndex); + else if (Entry->FixedPitchAfter == TS_FALSE) + ok((tm.tmPitchAndFamily & _TMPF_VAR_PITCH), "Entry #%u: Pitch mismatched, it was fixed-pitch\n", nIndex); + } + SelectObject(hDC, hFontOld); + DeleteObject(hFont); +} + +static void +Test_FontSelection(void) +{ + UINT nIndex; + HDC hDC; + + hDC = CreateCompatibleDC(NULL); + for (nIndex = 0; nIndex < _countof(g_Entries); ++nIndex) + { + if (!is_charset_font_installed(hDC, g_Entries[nIndex].CharSetBefore)) + skip("charset not available: 0x%x\n", g_Entries[nIndex].CharSetBefore); + else + Test_FontSelectionEntry(hDC, nIndex, g_Entries + nIndex); + } + DeleteDC(hDC); +} + START_TEST(CreateFontIndirect) { @@ -174,5 +758,7 @@ Test_CreateFontIndirectW(); Test_CreateFontIndirectExA(); Test_CreateFontIndirectExW(); -} - + Test_FontPresence(); + Test_FontSelection(); +} +
7 years, 10 months
1
0
0
0
[mjansen] 73745: [CRT_APITEST] Add additional test for __getmainargs
by mjansen@svn.reactos.org
Author: mjansen Date: Tue Feb 7 10:35:35 2017 New Revision: 73745 URL:
http://svn.reactos.org/svn/reactos?rev=73745&view=rev
Log: [CRT_APITEST] Add additional test for __getmainargs Modified: trunk/rostests/apitests/crt/__getmainargs.c Modified: trunk/rostests/apitests/crt/__getmainargs.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/__getmainarg…
============================================================================== --- trunk/rostests/apitests/crt/__getmainargs.c [iso-8859-1] (original) +++ trunk/rostests/apitests/crt/__getmainargs.c [iso-8859-1] Tue Feb 7 10:35:35 2017 @@ -28,6 +28,7 @@ ok_argsA_imp(const char* input_args, const char* arg1, const char* arg2, const char* arg3) { int argc = 0, mode = 0; + int expect_count = arg3 == NULL ? (arg2 == NULL ? 2 : 3) : 4; char** argv, **env; /* Remove cached argv, setup our input as program argument. */ @@ -37,20 +38,25 @@ /* Process the commandline stored in _acmdln */ __getmainargs(&argc, &argv, &env, 0, &mode); - winetest_ok(argc == 4, "Wrong value for argc, expected: 4, got: %d\n", argc); - if(argc != 4) + winetest_ok(argc == expect_count, "Wrong value for argc, expected: %d, got: %d\n", expect_count, argc); + if(argc != expect_count) return; winetest_ok_str(argv[0], "test.exe"); winetest_ok_str(argv[1], arg1); - winetest_ok_str(argv[2], arg2); - winetest_ok_str(argv[3], arg3); + if (expect_count > 2) + { + winetest_ok_str(argv[2], arg2); + if (expect_count > 3) + winetest_ok_str(argv[3], arg3); + } } void ok_argsW_imp(const wchar_t* input_args, const wchar_t* arg1, const wchar_t* arg2, const wchar_t* arg3) { int argc = 0, mode = 0; + int expect_count = arg3 == NULL ? (arg2 == NULL ? 2 : 3) : 4; wchar_t** argv, **env; /* Remove cached wargv, setup our input as program argument. */ @@ -60,14 +66,18 @@ /* Process the commandline stored in _wcmdln */ __wgetmainargs(&argc, &argv, &env, 0, &mode); - winetest_ok(argc == 4, "Wrong value for argc, expected: 4, got: %d\n", argc); - if(argc != 4) + winetest_ok(argc == expect_count, "Wrong value for argc, expected: %d, got: %d\n", expect_count, argc); + if(argc != expect_count) return; winetest_ok_wstr(argv[0], L"test.exe"); winetest_ok_wstr(argv[1], arg1); - winetest_ok_wstr(argv[2], arg2); - winetest_ok_wstr(argv[3], arg3); + if (expect_count > 2) + { + winetest_ok_wstr(argv[2], arg2); + if (expect_count > 3) + winetest_ok_wstr(argv[3], arg3); + } } START_TEST(__getmainargs) @@ -85,6 +95,7 @@ ok_argsA("test.exe a \"b\\ \"\"\" c\" d", "a", "b\\ \" c", "d"); ok_argsA("test.exe a \"b\\ \"\"\" \"c \"\"\"\" d", "a", "b\\ \" c", "\" d"); ok_argsA("test.exe a b c ", "a", "b", "c"); + ok_argsA("test.exe \"a b c\"", "a b c", NULL, NULL); ok_argsW(L"test.exe \"a b c\" d e", L"a b c", L"d", L"e"); ok_argsW(L"test.exe \"ab\\\"c\" \"\\\\\" d", L"ab\"c", L"\\", L"d"); @@ -99,4 +110,5 @@ ok_argsW(L"test.exe a \"b\\ \"\"\" c\" d", L"a", L"b\\ \" c", L"d"); ok_argsW(L"test.exe a \"b\\ \"\"\" \"c \"\"\"\" d", L"a", L"b\\ \" c", L"\" d"); ok_argsW(L"test.exe a b c ", L"a", L"b", L"c"); + ok_argsW(L"test.exe \"a b c\"", L"a b c", NULL, NULL); }
7 years, 10 months
1
0
0
0
[mjansen] 73744: [WIN32SS] Mute a major spammer in AHK tests.
by mjansen@svn.reactos.org
Author: mjansen Date: Tue Feb 7 10:33:42 2017 New Revision: 73744 URL:
http://svn.reactos.org/svn/reactos?rev=73744&view=rev
Log: [WIN32SS] Mute a major spammer in AHK tests. Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.c Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.…
============================================================================== --- trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] Tue Feb 7 10:33:42 2017 @@ -745,7 +745,12 @@ if (pdc->dctype == DCTYPE_DIRECT) { - UNIMPLEMENTED; + static BOOL g_WarnedOnce = FALSE; + if (!g_WarnedOnce) + { + g_WarnedOnce = TRUE; + UNIMPLEMENTED; + } goto cleanup; }
7 years, 10 months
1
0
0
0
[mjansen] 73743: [BOOTLIB] Additional EfiPrintf conversion like r73736 for MSVC 2013
by mjansen@svn.reactos.org
Author: mjansen Date: Tue Feb 7 10:32:20 2017 New Revision: 73743 URL:
http://svn.reactos.org/svn/reactos?rev=73743&view=rev
Log: [BOOTLIB] Additional EfiPrintf conversion like r73736 for MSVC 2013 Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Tue Feb 7 10:32:20 2017 @@ -507,10 +507,8 @@ } /* We don't support virtual memory yet @TODO */ -#ifdef _MSC_VER // Fuck gcc. - EfiPrintf(L"not yet implemented in " __FUNCTION__ "\r\n"); + EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__); EfiStall(1000000); -#endif return STATUS_NOT_IMPLEMENTED; }
7 years, 10 months
1
0
0
0
[ion] 73742: [BOOTLIB]: Implement MmFwGetMemoryMap when virtual memory is being enabled. [BOOTLIB]: Implement MmPapAllocatePagesInRange when virtual memory is being enabled. What's left now is impl...
by ion@svn.reactos.org
Author: ion Date: Tue Feb 7 04:26:21 2017 New Revision: 73742 URL:
http://svn.reactos.org/svn/reactos?rev=73742&view=rev
Log: [BOOTLIB]: Implement MmFwGetMemoryMap when virtual memory is being enabled. [BOOTLIB]: Implement MmPapAllocatePagesInRange when virtual memory is being enabled. What's left now is implementing extension for the PA allocator when VM is enabled. Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c trunk/reactos/boot/environ/lib/mm/i386/mmx86.c trunk/reactos/boot/environ/lib/mm/pagealloc.c Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/…
============================================================================== --- trunk/reactos/boot/environ/lib/firmware/efi/firmware.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/firmware/efi/firmware.c [iso-8859-1] Tue Feb 7 04:26:21 2017 @@ -1402,6 +1402,7 @@ BL_MEMORY_TYPE MemoryType; PBL_MEMORY_DESCRIPTOR Descriptor; BL_MEMORY_ATTR Attribute; + PVOID LibraryBuffer; /* Initialize EFI memory map attributes */ EfiMemoryMapSize = MapKey = DescriptorSize = DescriptorVersion = 0; @@ -1435,7 +1436,6 @@ if (Status != STATUS_BUFFER_TOO_SMALL) { /* This should've failed because our buffer was too small, nothing else */ - EfiPrintf(L"Got strange EFI status for memory map: %lx\r\n", Status); if (NT_SUCCESS(Status)) { Status = STATUS_UNSUCCESSFUL; @@ -1512,8 +1512,30 @@ } else { - /* We don't support this path yet */ - Status = STATUS_NOT_IMPLEMENTED; + /* Round the map to pages */ + Pages = BYTES_TO_PAGES(EfiMemoryMapSize); + + /* Allocate a large enough buffer */ + Status = MmPapAllocatePagesInRange(&LibraryBuffer, + BlLoaderData, + Pages, + 0, + 0, + 0, + 0); + if (!NT_SUCCESS(Status)) + { + EfiPrintf(L"Failed to allocate mapped VM for EFI map: %lx\r\n", Status); + goto Quickie; + } + + /* Call EFI to get the memory map */ + EfiMemoryMap = LibraryBuffer; + Status = EfiGetMemoryMap(&EfiMemoryMapSize, + LibraryBuffer, + &MapKey, + &DescriptorSize, + &DescriptorVersion); } /* So far so good? */ @@ -1786,6 +1808,12 @@ if (EfiBuffer != 0) { EfiFreePages(Pages, EfiBuffer); + } + + /* Free the library-allocated buffer, if we had one */ + if (LibraryBuffer != 0) + { + MmPapFreePages(LibraryBuffer, BL_MM_INCLUDE_MAPPED_ALLOCATED); } /* On failure, free the memory map if one was passed in */ Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Tue Feb 7 04:26:21 2017 @@ -680,9 +680,10 @@ BL_MEMORY_DESCRIPTOR_LIST FirmwareMdl; PLIST_ENTRY Head, NextEntry; - /* In phase 1 we don't initialize deferred mappings*/ + /* Check which phase this is */ if (Phase == 1) { + /* In phase 1 we don't initialize deferred mappings */ DoDeferred = FALSE; } else @@ -693,6 +694,7 @@ return STATUS_SUCCESS; } + /* We'll do deferred descriptors in phase 2 */ DoDeferred = TRUE; } Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pageal…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] Tue Feb 7 04:26:21 2017 @@ -95,7 +95,7 @@ ULONGLONG LocalEndPage, FoundEndPage, LocalVirtualEndPage; /* Check if any parameters were not passed in correctly */ - if ( !(CurrentList) || !(Request) || (!(NewList) && !(Descriptor))) + if (!(CurrentList) || !(Request) || (!(NewList) && !(Descriptor))) { return STATUS_INVALID_PARAMETER; } @@ -298,8 +298,15 @@ return Status; } - /* Nope, we have to hunt for it elsewhere */ - EfiPrintf(L"TODO\r\n"); + /* Are we failing due to some attributes? */ + if (Request->Flags & BlMemoryValidAllocationAttributeMask) + { + EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__); + EfiStall(1000000); + return STATUS_NOT_IMPLEMENTED; + } + + /* Nope, just fail the entire call */ return Status; } @@ -424,9 +431,15 @@ { NTSTATUS Status; PHYSICAL_ADDRESS BaseAddress; + BL_PA_REQUEST Request; + PBL_MEMORY_DESCRIPTOR_LIST List; + BL_MEMORY_DESCRIPTOR Descriptor; /* Increment nesting depth */ ++MmDescriptorCallTreeCount; + + /* Default list */ + List = &MmMdlMappedAllocated; /* Check for missing parameters or invalid range */ if (!(PhysicalAddress) || @@ -440,11 +453,93 @@ /* What translation mode are we using? */ if (MmTranslationType != BlNone) { - /* We don't support virtual memory yet @TODO */ - EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__); - EfiStall(1000000); - Status = STATUS_NOT_IMPLEMENTED; - goto Exit; + /* Use 1 page alignment if none was requested */ + if (!Alignment) + { + Alignment = 1; + } + + /* Check if we got a range */ + if (Range) + { + /* We don't support virtual memory yet @TODO */ + EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__); + EfiStall(1000000); + Status = STATUS_NOT_IMPLEMENTED; + goto Exit; + } + else + { + Request.BaseRange.Minimum = PapMinimumPhysicalPage; + Request.BaseRange.Maximum = (4 * 1024 * 1024) >> PAGE_SHIFT; + } + + /* Check if a fixed allocation was requested */ + if (Attributes & BlMemoryFixed) + { + /* We don't support virtual memory yet @TODO */ + EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__); + EfiStall(1000000); + Status = STATUS_NOT_IMPLEMENTED; + goto Exit; + } + else + { + /* Check if non-fixed was specifically requested */ + if (Attributes & BlMemoryNonFixed) + { + /* We don't support virtual memory yet @TODO */ + EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__); + EfiStall(1000000); + Status = STATUS_NOT_IMPLEMENTED; + goto Exit; + } + + /* Set the virtual address range */ + Request.VirtualRange.Minimum = 0; + Request.VirtualRange.Maximum = (4 * 1024 * 1024) >> PAGE_SHIFT; + } + + /* Check what type of allocation was requested */ + if (Type) + { + /* Save it */ + Request.Type = Type; + + /* If it was invalid, set the default */ + if (Type & ~(BL_MM_REQUEST_DEFAULT_TYPE | BL_MM_REQUEST_TOP_DOWN_TYPE)) + { + Request.Type = BL_MM_REQUEST_DEFAULT_TYPE; + } + } + else + { + /* Set the default */ + Request.Type = BL_MM_REQUEST_DEFAULT_TYPE; + } + + /* Fill out the request of the request */ + Request.Flags = Attributes; + Request.Alignment = Alignment; + Request.Pages = Pages; + + /* Try to allocate the pages */ + Status = MmPaAllocatePages(List, + &Descriptor, + &MmMdlMappedUnallocated, + &Request, + MemoryType); + if (!NT_SUCCESS(Status)) + { + /* We don't support virtual memory yet @TODO */ + EfiPrintf(L"Need to extend PA allocator\r\n"); + EfiStall(1000000); + Status = STATUS_NOT_IMPLEMENTED; + goto Exit; + } + + /* Return the allocated address */ + *PhysicalAddress = (PVOID)((ULONG_PTR)Descriptor.VirtualPage << PAGE_SHIFT); } else {
7 years, 10 months
1
0
0
0
[ion] 73741: [BOOTLIB]: Finish implementing Mmx86pMapMemoryRegions.
by ion@svn.reactos.org
Author: ion Date: Tue Feb 7 03:34:49 2017 New Revision: 73741 URL:
http://svn.reactos.org/svn/reactos?rev=73741&view=rev
Log: [BOOTLIB]: Finish implementing Mmx86pMapMemoryRegions. Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Tue Feb 7 03:34:49 2017 @@ -677,6 +677,8 @@ ULONGLONG Size; NTSTATUS Status; PVOID VirtualAddress; + BL_MEMORY_DESCRIPTOR_LIST FirmwareMdl; + PLIST_ENTRY Head, NextEntry; /* In phase 1 we don't initialize deferred mappings*/ if (Phase == 1) @@ -756,10 +758,59 @@ /* In phase 1, also do UEFI mappings */ if (Phase != 2) { - EfiPrintf(L"Phase 1 TODO UEFI mappings \r\n"); - } - - return STATUS_NOT_IMPLEMENTED; + /* Get the memory map */ + MmMdInitializeListHead(&FirmwareMdl); + Status = MmFwGetMemoryMap(&FirmwareMdl, BL_MM_FLAG_REQUEST_COALESCING); + if (!NT_SUCCESS(Status)) + { + return Status; + } + + /* Iterate over it */ + Head = FirmwareMdl.First; + NextEntry = Head->Flink; + while (NextEntry != Head) + { + /* Check if this is a UEFI-related descriptor, unless it's the self-map page */ + Descriptor = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, ListEntry); + if (((Descriptor->Type == BlEfiBootMemory) || + (Descriptor->Type == BlEfiRuntimeMemory) || + (Descriptor->Type == BlLoaderMemory)) && + ((Descriptor->BasePage << PAGE_SHIFT) != Mmx86SelfMapBase.QuadPart)) + { + /* Identity-map it */ + PhysicalAddress.QuadPart = Descriptor->BasePage << PAGE_SHIFT; + Status = Mmx86MapInitStructure((PVOID)((ULONG_PTR)Descriptor->BasePage << PAGE_SHIFT), + Descriptor->PageCount << PAGE_SHIFT, + PhysicalAddress); + if (!NT_SUCCESS(Status)) + { + return Status; + } + } + + /* Move to the next descriptor */ + NextEntry = NextEntry->Flink; + } + + /* Reset */ + NextEntry = Head->Flink; + while (NextEntry != Head) + { + /* Get the descriptor */ + Descriptor = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, ListEntry); + + /* Skip to the next entry before we free */ + NextEntry = NextEntry->Flink; + + /* Remove and free it */ + MmMdRemoveDescriptorFromList(&FirmwareMdl, Descriptor); + MmMdFreeDescriptor(Descriptor); + } + } + + /* All library mappings identity mapped now */ + return STATUS_SUCCESS; } NTSTATUS @@ -1114,14 +1165,17 @@ case BlPae: + /* We don't support PAE */ Status = STATUS_NOT_SUPPORTED; break; default: + + /* Invalid architecture type*/ Status = STATUS_INVALID_PARAMETER; break; } + /* Back to caller */ return Status; - -} +}
7 years, 10 months
1
0
0
0
[ion] 73740: [BOOTLIB]: Implement most of Mmx86pMapMemoryRegions. Just missing the UEFI mappings now.
by ion@svn.reactos.org
Author: ion Date: Tue Feb 7 01:52:57 2017 New Revision: 73740 URL:
http://svn.reactos.org/svn/reactos?rev=73740&view=rev
Log: [BOOTLIB]: Implement most of Mmx86pMapMemoryRegions. Just missing the UEFI mappings now. Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Tue Feb 7 01:52:57 2017 @@ -168,39 +168,6 @@ ) { EfiPrintf(L"Supposed to zero shit\r\n"); - return STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS -Mmx86pMapMemoryRegions ( - _In_ ULONG Phase, - _In_ PBL_MEMORY_DATA MemoryData - ) -{ - BOOLEAN DoDeferred; - - /* In phase 1 we don't initialize deferred mappings*/ - if (Phase == 1) - { - DoDeferred = 0; - } - else - { - /* Don't do anything if there's nothing to initialize */ - if (!MmDeferredMappingCount) - { - return STATUS_SUCCESS; - } - - DoDeferred = 1; - } - - if (DoDeferred) - { - EfiPrintf(L"Deferred todo\r\n"); - } - - EfiPrintf(L"Phase 1 TODO\r\n"); return STATUS_NOT_IMPLEMENTED; } @@ -697,6 +664,105 @@ } NTSTATUS +Mmx86pMapMemoryRegions ( + _In_ ULONG Phase, + _In_ PBL_MEMORY_DATA MemoryData + ) +{ + BOOLEAN DoDeferred; + ULONG DescriptorCount; + PBL_MEMORY_DESCRIPTOR Descriptor; + ULONG FinalOffset; + PHYSICAL_ADDRESS PhysicalAddress; + ULONGLONG Size; + NTSTATUS Status; + PVOID VirtualAddress; + + /* In phase 1 we don't initialize deferred mappings*/ + if (Phase == 1) + { + DoDeferred = FALSE; + } + else + { + /* Don't do anything if there's nothing to initialize */ + if (!MmDeferredMappingCount) + { + return STATUS_SUCCESS; + } + + DoDeferred = TRUE; + } + + /* + * Because BL supports cross x86-x64 application launches and a LIST_ENTRY + * is of variable size, care must be taken here to ensure that we see a + * consistent view of descriptors. BL uses some offset magic to figure out + * where the data actually starts, since everything is ULONGLONG past the + * LIST_ENTRY itself + */ + FinalOffset = MemoryData->MdListOffset + MemoryData->DescriptorOffset; + Descriptor = (PBL_MEMORY_DESCRIPTOR)((ULONG_PTR)MemoryData + FinalOffset - + FIELD_OFFSET(BL_MEMORY_DESCRIPTOR, BasePage)); + + /* Scan all of them */ + DescriptorCount = MemoryData->DescriptorCount; + while (DescriptorCount != 0) + { + /* Ignore application data */ + if (Descriptor->Type != BlApplicationData) + { + /* If this is a ramdisk, do it in phase 2 */ + if ((Descriptor->Type == BlLoaderRamDisk) == DoDeferred) + { + /* Get the current physical address and size */ + PhysicalAddress.QuadPart = Descriptor->BasePage << PAGE_SHIFT; + Size = Descriptor->PageCount << PAGE_SHIFT; + + /* Check if it was already mapped */ + if (Descriptor->VirtualPage) + { + /* Use the existing address */ + VirtualAddress = (PVOID)(ULONG_PTR)(Descriptor->VirtualPage << PAGE_SHIFT); + } + else + { + /* Use the physical address */ + VirtualAddress = (PVOID)(ULONG_PTR)PhysicalAddress.QuadPart; + } + + /* Crete the mapping */ + Status = Mmx86MapInitStructure(VirtualAddress, + Size, + PhysicalAddress); + if (!NT_SUCCESS(Status)) + { + return Status; + } + } + + /* Check if we're in phase 1 and deferring RAM disk */ + if ((Phase == 1) && (Descriptor->Type == BlLoaderRamDisk)) + { + MmDeferredMappingCount++; + } + } + + /* Move on to the next descriptor */ + DescriptorCount--; + Descriptor = (PBL_MEMORY_DESCRIPTOR)((ULONG_PTR)Descriptor + MemoryData->DescriptorSize); + } + + /* In phase 1, also do UEFI mappings */ + if (Phase != 2) + { + EfiPrintf(L"Phase 1 TODO UEFI mappings \r\n"); + } + + return STATUS_NOT_IMPLEMENTED; +} + +NTSTATUS Mmx86InitializeMemoryMap ( _In_ ULONG Phase, _In_ PBL_MEMORY_DATA MemoryData @@ -766,8 +832,7 @@ } /* More to do */ - EfiPrintf(L"VM more work\r\n"); - return STATUS_NOT_IMPLEMENTED; + return Mmx86pMapMemoryRegions(Phase, MemoryData); } NTSTATUS
7 years, 10 months
1
0
0
0
[ion] 73739: [BOOTLIB]: Don't use PTE_BASE/PDE_BASE in bootlib. Use MmPteBase and MmPdeBase instead. [BOOTLIB]: Implement MmDefpMapPhysicalAddress, MmDefpTranslateVirtualAddress. Fix definition of ...
by ion@svn.reactos.org
Author: ion Date: Tue Feb 7 01:35:11 2017 New Revision: 73739 URL:
http://svn.reactos.org/svn/reactos?rev=73739&view=rev
Log: [BOOTLIB]: Don't use PTE_BASE/PDE_BASE in bootlib. Use MmPteBase and MmPdeBase instead. [BOOTLIB]: Implement MmDefpMapPhysicalAddress, MmDefpTranslateVirtualAddress. Fix definition of Mmx86MapPhysicalAddress. Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c trunk/reactos/boot/environ/lib/mm/i386/mmx86.c trunk/reactos/boot/environ/lib/mm/mm.c trunk/reactos/boot/environ/lib/mm/pagealloc.c Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/…
============================================================================== --- trunk/reactos/boot/environ/lib/firmware/efi/firmware.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/firmware/efi/firmware.c [iso-8859-1] Tue Feb 7 01:35:11 2017 @@ -1446,7 +1446,6 @@ /* Add 4 more descriptors just in case things changed */ EfiMemoryMapSize += (4 * DescriptorSize); Pages = BYTES_TO_PAGES(EfiMemoryMapSize); - EfiPrintf(L"Memory map size: %lx bytes, %d pages\r\n", EfiMemoryMapSize, Pages); /* Should we use EFI to grab memory? */ if (UseEfiBuffer) Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Tue Feb 7 01:35:11 2017 @@ -10,7 +10,16 @@ #include "bl.h" #include "bcd.h" -#include "../../../../../ntoskrnl/include/internal/i386/mm.h" + +#define PTE_BASE 0xC0000000 + +// +// Specific PDE/PTE macros to be used inside the boot library environment +// +#define MiAddressToPte(x) ((PMMPTE)(((((ULONG)(x)) >> 12) << 2) + (ULONG_PTR)MmPteBase)) +#define MiAddressToPde(x) ((PMMPDE)(((((ULONG)(x)) >> 22) << 2) + (ULONG_PTR)MmPdeBase)) +#define MiAddressToPteOffset(x) ((((ULONG)(x)) << 10) >> 22) +#define MiAddressToPdeOffset(x) (((ULONG)(x)) / (1024 * PAGE_SIZE)) /* DATA VARIABLES ************************************************************/ @@ -81,7 +90,7 @@ typedef NTSTATUS (*PBL_MM_MAP_PHYSICAL_ADDRESS) ( - _In_ PPHYSICAL_ADDRESS PhysicalAddress, + _In_ PHYSICAL_ADDRESS PhysicalAddress, _Out_ PVOID VirtualAddress, _In_ ULONG Size, _In_ ULONG CacheAttributes @@ -111,6 +120,16 @@ /* FUNCTIONS *****************************************************************/ +BOOLEAN +BlMmIsTranslationEnabled ( + VOID + ) +{ + /* Return if paging is on */ + return ((CurrentExecutionContext) && + (CurrentExecutionContext->Mode & BL_CONTEXT_PAGING_ON)); +} + VOID MmArchNullFunction ( VOID @@ -277,14 +296,152 @@ NTSTATUS MmDefpMapPhysicalAddress ( - _In_ PPHYSICAL_ADDRESS PhysicalAddress, - _Out_ PVOID VirtualAddress, + _In_ PHYSICAL_ADDRESS PhysicalAddress, + _In_ PVOID VirtualAddress, _In_ ULONG Size, _In_ ULONG CacheAttributes ) { - EfiPrintf(L"No map\r\n"); - return STATUS_NOT_IMPLEMENTED; + BOOLEAN Enabled; + ULONG i, PageCount, PdeOffset; + ULONGLONG CurrentAddress; + PMMPDE Pde; + PMMPTE Pte; + PMMPTE PageTable; + PHYSICAL_ADDRESS PageTableAddress; + NTSTATUS Status; + + /* Check if paging is on yet */ + Enabled = BlMmIsTranslationEnabled(); + + /* Get the physical address aligned */ + CurrentAddress = (PhysicalAddress.QuadPart >> PAGE_SHIFT) << PAGE_SHIFT; + + /* Get the number of pages and loop through each one */ + PageCount = Size >> PAGE_SHIFT; + for (i = 0; i < PageCount; i++) + { + /* Check if translation already exists for this page */ + if (Mmx86TranslateVirtualAddress(VirtualAddress, NULL, NULL)) + { + /* Ignore it and move to the next one */ + VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE); + CurrentAddress += PAGE_SIZE; + continue; + } + + /* Get the PDE offset */ + PdeOffset = MiAddressToPdeOffset(VirtualAddress); + + /* Check if paging is actually turned on */ + if (Enabled) + { + /* Get the PDE entry using the self-map */ + Pde = MiAddressToPde(VirtualAddress); + } + else + { + /* Get it using our physical mappings */ + Pde = &MmPdpt[PdeOffset]; + PageTable = (PMMPDE)(Pde->u.Hard.PageFrameNumber << PAGE_SHIFT); + } + + /* Check if we don't yet have a PDE */ + if (!Pde->u.Hard.Valid) + { + /* Allocate a page table */ + Status = MmPapAllocatePhysicalPagesInRange(&PageTableAddress, + BlLoaderPageDirectory, + 1, + 0, + 0, + &MmMdlUnmappedAllocated, + 0, + 0); + if (!NT_SUCCESS(Status)) + { + return STATUS_NO_MEMORY; + } + + /* This is our page table */ + PageTable = (PVOID)(ULONG_PTR)PageTableAddress.QuadPart; + + /* Build the PDE for it */ + Pde->u.Hard.PageFrameNumber = PageTableAddress.QuadPart >> PAGE_SHIFT; + Pde->u.Hard.Write = 1; + Pde->u.Hard.CacheDisable = 1; + Pde->u.Hard.WriteThrough = 1; + Pde->u.Hard.Valid = 1; + + /* Check if paging is enabled */ + if (Enabled) + { + /* Then actually, get the page table's virtual address */ + PageTable = (PVOID)PAGE_ROUND_DOWN(MiAddressToPte(VirtualAddress)); + + /* Flush the TLB */ + Mmx86FlushTlb(); + } + + /* Zero out the page table */ + RtlZeroMemory(PageTable, PAGE_SIZE); + + /* Reset caching attributes now */ + Pde->u.Hard.CacheDisable = 0; + Pde->u.Hard.WriteThrough = 0; + + /* Check for paging again */ + if (Enabled) + { + /* Flush the TLB entry for the page table only */ + Mmx86FlushTlbEntry(PageTable); + } + } + + /* Add a reference to this page table */ + MmArchReferencePage[PdeOffset]++; + + /* Check if a physical address was given */ + if (PhysicalAddress.QuadPart != -1) + { + /* Check if paging is turned on */ + if (Enabled) + { + /* Get the PTE using the self-map */ + Pte = MiAddressToPte(VirtualAddress); + } + else + { + /* Get the PTE using physical addressing */ + Pte = &PageTable[MiAddressToPteOffset(VirtualAddress)]; + } + + /* Build a valid PTE for it */ + Pte->u.Hard.PageFrameNumber = CurrentAddress >> PAGE_SHIFT; + Pte->u.Hard.Write = 1; + Pte->u.Hard.Valid = 1; + + /* Check if this is uncached */ + if (CacheAttributes == BlMemoryUncached) + { + /* Set the flags */ + Pte->u.Hard.CacheDisable = 1; + Pte->u.Hard.WriteThrough = 1; + } + else if (CacheAttributes == BlMemoryWriteThrough) + { + /* It's write-through, set the flag */ + Pte->u.Hard.WriteThrough = 1; + } + } + + /* Move to the next physical/virtual address */ + VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE); + CurrentAddress += PAGE_SIZE; + } + + /* All done! */ + return STATUS_SUCCESS; } BOOLEAN @@ -294,8 +451,75 @@ _Out_opt_ PULONG CacheAttributes ) { - EfiPrintf(L"No translate\r\n"); - return FALSE; + PMMPDE Pde; + PMMPTE Pte; + PMMPTE PageTable; + BOOLEAN Enabled; + + /* Is there no page directory yet? */ + if (!MmPdpt) + { + return FALSE; + } + + /* Is paging enabled? */ + Enabled = BlMmIsTranslationEnabled(); + + /* Check if paging is actually turned on */ + if (Enabled) + { + /* Get the PDE entry using the self-map */ + Pde = MiAddressToPde(VirtualAddress); + } + else + { + /* Get it using our physical mappings */ + Pde = &MmPdpt[MiAddressToPdeOffset(VirtualAddress)]; + } + + /* Is the PDE valid? */ + if (!Pde->u.Hard.Valid) + { + return FALSE; + } + + /* Check if paging is turned on */ + if (Enabled) + { + /* Get the PTE using the self-map */ + Pte = MiAddressToPte(VirtualAddress); + } + else + { + /* Get the PTE using physical addressing */ + PageTable = (PMMPTE)(Pde->u.Hard.PageFrameNumber << PAGE_SHIFT); + Pte = &PageTable[MiAddressToPteOffset(VirtualAddress)]; + } + + /* Is the PTE valid? */ + if (!Pte->u.Hard.Valid) + { + return FALSE; + } + + /* Does caller want the physical address? */ + if (PhysicalAddress) + { + /* Return it */ + PhysicalAddress->QuadPart = (Pte->u.Hard.PageFrameNumber << PAGE_SHIFT) + + BYTE_OFFSET(VirtualAddress); + } + + /* Does caller want cache attributes? */ + if (CacheAttributes) + { + /* Not yet -- lie and say it's cached */ + EfiPrintf(L"Cache checking not yet enabled\r\n"); + *CacheAttributes = BlMemoryWriteBack; + } + + /* It exists! */ + return TRUE; } NTSTATUS @@ -321,16 +545,6 @@ EfiStall(1000000); #endif return STATUS_NOT_IMPLEMENTED; -} - -BOOLEAN -BlMmIsTranslationEnabled ( - VOID - ) -{ - /* Return if paging is on */ - return ((CurrentExecutionContext) && - (CurrentExecutionContext->Mode & BL_CONTEXT_PAGING_ON)); } NTSTATUS @@ -419,7 +633,7 @@ /* Aactually do the mapping */ TranslatedAddress.QuadPart = PhysicalAddress; - Status = Mmx86MapPhysicalAddress(&TranslatedAddress, + Status = Mmx86MapPhysicalAddress(TranslatedAddress, VirtualAddress, Size, CacheAttributes); @@ -661,7 +875,7 @@ /* The PDE is the PTE of the PTE base */ MmPdeBase = MiAddressToPte(MmPteBase); - PdeIndex = MiGetPdeOffset(MmPdeBase); + PdeIndex = MiAddressToPdeOffset(MmPdeBase); MmPdpt[PdeIndex].u.Hard.Valid = 1; MmPdpt[PdeIndex].u.Hard.Write = 1; MmPdpt[PdeIndex].u.Hard.PageFrameNumber = (ULONG_PTR)MmPdpt >> PAGE_SHIFT; Modified: trunk/reactos/boot/environ/lib/mm/mm.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/mm.c?r…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/mm.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/mm.c [iso-8859-1] Tue Feb 7 01:35:11 2017 @@ -126,70 +126,6 @@ /* All done here */ return STATUS_SUCCESS; -} - -NTSTATUS -MmSelectMappingAddress ( - _Out_ PVOID* MappingAddress, - _In_ ULONGLONG Size, - _In_ ULONG AllocationAttributes, - _In_ ULONG Flags, - _In_ PHYSICAL_ADDRESS PhysicalAddress - ) -{ - /* Are we in physical mode? */ - if (MmTranslationType == BlNone) - { - /* Just return the physical address as the mapping address */ - *MappingAddress = (PVOID)PhysicalAddress.LowPart; - return STATUS_SUCCESS; - } - - /* We don't support virtual memory yet @TODO */ - EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__); - EfiStall(1000000); - return STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS -MmMapPhysicalAddress ( - _Inout_ PPHYSICAL_ADDRESS PhysicalAddress, - _Out_ PVOID VirtualAddress, - _Inout_ PULONGLONG Size, - _In_ ULONG CacheAttributes - ) -{ - ULONGLONG MappingSize; - - /* Fail if any parameters are missing */ - if (!(PhysicalAddress) || !(VirtualAddress) || !(Size)) - { - return STATUS_INVALID_PARAMETER; - } - - /* Fail if the size is over 32-bits */ - MappingSize = *Size; - if (MappingSize > 0xFFFFFFFF) - { - return STATUS_INVALID_PARAMETER; - } - - /* Nothing to do if we're in physical mode */ - if (MmTranslationType == BlNone) - { - return STATUS_SUCCESS; - } - - /* Can't use virtual memory in real mode */ - if (CurrentExecutionContext->Mode == BlRealMode) - { - return STATUS_UNSUCCESSFUL; - } - - /* We don't support virtual memory yet @TODO */ - EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__); - EfiStall(1000000); - return STATUS_NOT_IMPLEMENTED; } NTSTATUS Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pageal…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] Tue Feb 7 01:35:11 2017 @@ -545,6 +545,7 @@ while (ExistingDescriptors != 0) { /* Remove this region from our free memory MDL */ + //EfiPrintf(L"Handling existing descriptor: %llx %llx\r\n", Descriptor->BasePage, Descriptor->PageCount); Status = MmMdRemoveRegionFromMdlEx(&MmMdlUnmappedUnallocated, BL_MM_REMOVE_PHYSICAL_REGION_FLAG, Descriptor->BasePage, @@ -743,7 +744,7 @@ Flags |= BL_MM_ADD_DESCRIPTOR_NEVER_COALESCE_FLAG; } - /* Check if the entire allocation is being free*/ + /* Check if the entire allocation is being freed */ if (PageCount == Descriptor->PageCount) { /* Remove the descriptor from the allocated list */
7 years, 10 months
1
0
0
0
[ion] 73738: [BOOTLIB]: Implement BlMmIsTranslationEnabled and MmMapPhysicalAddress. MmDefpMapPhysicalAddress is missing at this point.
by ion@svn.reactos.org
Author: ion Date: Mon Feb 6 23:13:47 2017 New Revision: 73738 URL:
http://svn.reactos.org/svn/reactos?rev=73738&view=rev
Log: [BOOTLIB]: Implement BlMmIsTranslationEnabled and MmMapPhysicalAddress. MmDefpMapPhysicalAddress is missing at this point. Modified: trunk/reactos/boot/environ/include/bl.h trunk/reactos/boot/environ/lib/mm/i386/mmx86.c Modified: trunk/reactos/boot/environ/include/bl.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?…
============================================================================== --- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original) +++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Feb 6 23:13:47 2017 @@ -2192,9 +2192,18 @@ /* VIRTUAL MEMORY ROUTINES ***************************************************/ NTSTATUS +MmSelectMappingAddress ( + _Out_ PVOID* MappingAddress, + _In_ ULONGLONG Size, + _In_ ULONG AllocationAttributes, + _In_ ULONG Flags, + _In_ PHYSICAL_ADDRESS PhysicalAddress + ); + +NTSTATUS MmMapPhysicalAddress ( _Inout_ PPHYSICAL_ADDRESS PhysicalAddress, - _Out_ PVOID VirtualAddress, + _Out_ PVOID* VirtualAddress, _Inout_ PULONGLONG Size, _In_ ULONG CacheAttributes ); Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Mon Feb 6 23:13:47 2017 @@ -296,6 +296,152 @@ { EfiPrintf(L"No translate\r\n"); return FALSE; +} + +NTSTATUS +MmSelectMappingAddress ( + _Out_ PVOID* MappingAddress, + _In_ ULONGLONG Size, + _In_ ULONG AllocationAttributes, + _In_ ULONG Flags, + _In_ PHYSICAL_ADDRESS PhysicalAddress + ) +{ + /* Are we in physical mode? */ + if (MmTranslationType == BlNone) + { + /* Just return the physical address as the mapping address */ + *MappingAddress = (PVOID)PhysicalAddress.LowPart; + return STATUS_SUCCESS; + } + + /* We don't support virtual memory yet @TODO */ +#ifdef _MSC_VER // Fuck gcc. + EfiPrintf(L"not yet implemented in " __FUNCTION__ "\r\n"); + EfiStall(1000000); +#endif + return STATUS_NOT_IMPLEMENTED; +} + +BOOLEAN +BlMmIsTranslationEnabled ( + VOID + ) +{ + /* Return if paging is on */ + return ((CurrentExecutionContext) && + (CurrentExecutionContext->Mode & BL_CONTEXT_PAGING_ON)); +} + +NTSTATUS +MmMapPhysicalAddress ( + _Inout_ PPHYSICAL_ADDRESS PhysicalAddressPtr, + _Inout_ PVOID* VirtualAddressPtr, + _Inout_ PULONGLONG SizePtr, + _In_ ULONG CacheAttributes + ) +{ + ULONGLONG Size, TotalSize; + ULONGLONG PhysicalAddress; + PVOID VirtualAddress; + PHYSICAL_ADDRESS TranslatedAddress; + ULONG_PTR CurrentAddress, VirtualAddressEnd; + NTSTATUS Status; + + /* Fail if any parameters are missing */ + if (!(PhysicalAddressPtr) || !(VirtualAddressPtr) || !(SizePtr)) + { + return STATUS_INVALID_PARAMETER; + } + + /* Fail if the size is over 32-bits */ + Size = *SizePtr; + if (Size > 0xFFFFFFFF) + { + return STATUS_INVALID_PARAMETER; + } + + /* Nothing to do if we're in physical mode */ + if (MmTranslationType == BlNone) + { + return STATUS_SUCCESS; + } + + /* Can't use virtual memory in real mode */ + if (CurrentExecutionContext->Mode == BlRealMode) + { + return STATUS_UNSUCCESSFUL; + } + + /* Capture the current virtual and physical addresses */ + VirtualAddress = *VirtualAddressPtr; + PhysicalAddress = PhysicalAddressPtr->QuadPart; + + /* Check if a physical address was requested */ + if (PhysicalAddress != 0xFFFFFFFF) + { + /* Round down the base addresses */ + PhysicalAddress = PAGE_ROUND_DOWN(PhysicalAddress); + VirtualAddress = (PVOID)PAGE_ROUND_DOWN(VirtualAddress); + + /* Round up the size */ + TotalSize = ROUND_TO_PAGES(PhysicalAddressPtr->QuadPart - + PhysicalAddress + + Size); + + /* Loop every virtual page */ + CurrentAddress = (ULONG_PTR)VirtualAddress; + VirtualAddressEnd = CurrentAddress + TotalSize - 1; + while (CurrentAddress < VirtualAddressEnd) + { + /* Get the physical page of this virtual page */ + if (MmArchTranslateVirtualAddress((PVOID)CurrentAddress, + &TranslatedAddress, + &CacheAttributes)) + { + /* Make sure the physical page of the virtual page, matches our page */ + if (TranslatedAddress.QuadPart != + (PhysicalAddress + + (CurrentAddress - (ULONG_PTR)VirtualAddress))) + { + /* There is an existing virtual mapping for a different address */ + EfiPrintf(L"Existing mapping exists: %lx vs %lx\r\n", + TranslatedAddress.QuadPart, + PhysicalAddress + (CurrentAddress - (ULONG_PTR)VirtualAddress)); + return STATUS_INVALID_PARAMETER; + } + } + + /* Try the next one */ + CurrentAddress += PAGE_SIZE; + } + } + + /* Aactually do the mapping */ + TranslatedAddress.QuadPart = PhysicalAddress; + Status = Mmx86MapPhysicalAddress(&TranslatedAddress, + VirtualAddress, + Size, + CacheAttributes); + if (!NT_SUCCESS(Status)) + { + EfiPrintf(L"Failed to map!: %lx\r\n", Status); + return Status; + } + + /* Return aligned/fixed up output parameters */ + PhysicalAddressPtr->QuadPart = PhysicalAddress; + *VirtualAddressPtr = VirtualAddress; + *SizePtr = Size; + + /* Flush the TLB if paging is enabled */ + if (BlMmIsTranslationEnabled()) + { + Mmx86FlushTlb(); + } + + /* All good! */ + return STATUS_SUCCESS; } NTSTATUS
7 years, 10 months
1
0
0
0
[hbelusca] 73737: [USERENV] - Fix some DPRINTs; - Add parameter validation in CreateUserProfileExW; - Return the directory path of the created profile in CreateUserProfileExW, if the user wants it; ...
by hbelusca@svn.reactos.org
Author: hbelusca Date: Mon Feb 6 22:58:20 2017 New Revision: 73737 URL:
http://svn.reactos.org/svn/reactos?rev=73737&view=rev
Log: [USERENV] - Fix some DPRINTs; - Add parameter validation in CreateUserProfileExW; - Return the directory path of the created profile in CreateUserProfileExW, if the user wants it; - Add value type validation for RegQueryValueExW calls; - Use ARRAYSIZE where needed; - Add parameter validation in GetAllUsersProfileDirectoryA, GetDefaultUserProfileDirectoryA; - Correctly return error code in GetAllUsersProfileDirectoryW, GetDefaultUserProfileDirectoryW, GetProfilesDirectoryW and GetUserProfileDirectoryW. Should fix the userenv_apitest:GetProfileDirs tests. Modified: trunk/reactos/dll/win32/userenv/profile.c Modified: trunk/reactos/dll/win32/userenv/profile.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/profile.…
============================================================================== --- trunk/reactos/dll/win32/userenv/profile.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/userenv/profile.c [iso-8859-1] Mon Feb 6 22:58:20 2017 @@ -266,7 +266,7 @@ WCHAR szUserProfileName[MAX_PATH]; WCHAR szBuffer[MAX_PATH]; LPWSTR SidString; - DWORD dwLength; + DWORD dwType, dwLength; DWORD dwDisposition; UINT i; HKEY hKey; @@ -276,9 +276,16 @@ DPRINT("CreateUserProfileExW(%p %S %S %p %lu %d)\n", pSid, lpUserName, lpUserHive, lpProfileDir, dwDirSize, bWin9xUpg); + /* Parameters validation */ + if (!pSid || !lpUserName) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + /* * TODO: - * - Add support for lpUserHive, lpProfileDir. + * - Add support for lpUserHive. * - bWin9xUpg is obsolete. Don't waste your time implementing this. */ @@ -299,10 +306,10 @@ Error = RegQueryValueExW(hKey, L"ProfilesDirectory", NULL, - NULL, + &dwType, (LPBYTE)szRawProfilesPath, &dwLength); - if (Error != ERROR_SUCCESS) + if ((Error != ERROR_SUCCESS) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) { DPRINT1("Error: %lu\n", Error); RegCloseKey(hKey); @@ -320,7 +327,8 @@ return FALSE; } - /* create the profiles directory if it does not yet exist */ + /* Create the profiles directory if it does not exist yet */ + // FIXME: Security! if (!CreateDirectoryW(szProfilesPath, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) @@ -335,10 +343,10 @@ Error = RegQueryValueExW(hKey, L"DefaultUserProfile", NULL, - NULL, + &dwType, (LPBYTE)szBuffer, &dwLength); - if (Error != ERROR_SUCCESS) + if ((Error != ERROR_SUCCESS) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) { DPRINT1("Error: %lu\n", Error); RegCloseKey(hKey); @@ -346,19 +354,17 @@ return FALSE; } - RegCloseKey (hKey); - - wcscpy(szUserProfileName, lpUserName); - - wcscpy(szUserProfilePath, szProfilesPath); - wcscat(szUserProfilePath, L"\\"); - wcscat(szUserProfilePath, szUserProfileName); - - wcscpy(szDefaultUserPath, szProfilesPath); - wcscat(szDefaultUserPath, L"\\"); - wcscat(szDefaultUserPath, szBuffer); + RegCloseKey(hKey); + + StringCbCopyW(szUserProfileName, sizeof(szUserProfileName), lpUserName); /* Create user profile directory */ + + StringCbCopyW(szUserProfilePath, sizeof(szUserProfilePath), szProfilesPath); + StringCbCatW(szUserProfilePath, sizeof(szUserProfilePath), L"\\"); + StringCbCatW(szUserProfilePath, sizeof(szUserProfilePath), szUserProfileName); + + // FIXME: Security! if (!CreateDirectoryW(szUserProfilePath, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) @@ -371,10 +377,11 @@ { swprintf(szUserProfileName, L"%s.%03u", lpUserName, i); - wcscpy(szUserProfilePath, szProfilesPath); - wcscat(szUserProfilePath, L"\\"); - wcscat(szUserProfilePath, szUserProfileName); - + StringCbCopyW(szUserProfilePath, sizeof(szUserProfilePath), szProfilesPath); + StringCbCatW(szUserProfilePath, sizeof(szUserProfilePath), L"\\"); + StringCbCatW(szUserProfilePath, sizeof(szUserProfilePath), szUserProfileName); + + // FIXME: Security! if (CreateDirectoryW(szUserProfilePath, NULL)) break; @@ -387,6 +394,12 @@ } /* Copy default user directory */ + + StringCbCopyW(szDefaultUserPath, sizeof(szDefaultUserPath), szProfilesPath); + StringCbCatW(szDefaultUserPath, sizeof(szDefaultUserPath), L"\\"); + StringCbCatW(szDefaultUserPath, sizeof(szDefaultUserPath), szBuffer); + + // FIXME: Security! if (!CopyDirectory(szUserProfilePath, szDefaultUserPath)) { DPRINT1("Error: %lu\n", GetLastError()); @@ -401,9 +414,9 @@ return FALSE; } - wcscpy(szBuffer, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"); - wcscat(szBuffer, SidString); + StringCbCopyW(szBuffer, sizeof(szBuffer), + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"); + StringCbCatW(szBuffer, sizeof(szBuffer), SidString); /* Create user profile key */ Error = RegCreateKeyExW(HKEY_LOCAL_MACHINE, @@ -423,9 +436,9 @@ } /* Create non-expanded user profile path */ - wcscpy(szBuffer, szRawProfilesPath); - wcscat(szBuffer, L"\\"); - wcscat(szBuffer, szUserProfileName); + StringCbCopyW(szBuffer, sizeof(szBuffer), szRawProfilesPath); + StringCbCatW(szBuffer, sizeof(szBuffer), L"\\"); + StringCbCatW(szBuffer, sizeof(szBuffer), szUserProfileName); /* Set 'ProfileImagePath' value (non-expanded) */ Error = RegSetValueExW(hKey, @@ -459,9 +472,11 @@ RegCloseKey(hKey); - /* Create user hive name */ - wcscpy(szBuffer, szUserProfilePath); - wcscat(szBuffer, L"\\ntuser.dat"); + /* Create user hive file */ + + /* Use the default hive file name */ + StringCbCopyW(szBuffer, sizeof(szBuffer), szUserProfilePath); + StringCbCatW(szBuffer, sizeof(szBuffer), L"\\ntuser.dat"); /* Acquire restore privilege */ if (!AcquireRemoveRestorePrivilege(TRUE)) @@ -472,7 +487,7 @@ goto done; } - /* Create new user hive */ + /* Load the user hive */ Error = RegLoadKeyW(HKEY_USERS, SidString, szBuffer); @@ -497,6 +512,13 @@ RegUnLoadKeyW(HKEY_USERS, SidString); AcquireRemoveRestorePrivilege(FALSE); + /* + * If the caller wants to retrieve the user profile path, + * give it now. 'dwDirSize' is the number of characters. + */ + if (lpProfileDir && dwDirSize) + StringCchCopyW(lpProfileDir, dwDirSize, szUserProfilePath); + done: LocalFree((HLOCAL)SidString); SetLastError((DWORD)Error); @@ -516,6 +538,12 @@ LPWSTR lpBuffer; BOOL bResult; + if (!lpcchSize) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + lpBuffer = GlobalAlloc(GMEM_FIXED, *lpcchSize * sizeof(WCHAR)); if (lpBuffer == NULL) @@ -523,273 +551,7 @@ bResult = GetAllUsersProfileDirectoryW(lpBuffer, lpcchSize); - if (bResult) - { - WideCharToMultiByte(CP_ACP, - 0, - lpBuffer, - -1, - lpProfileDir, - *lpcchSize, - NULL, - NULL); - } - - GlobalFree(lpBuffer); - - return bResult; -} - - -BOOL -WINAPI -GetAllUsersProfileDirectoryW( - _Out_opt_ LPWSTR lpProfileDir, - _Inout_ LPDWORD lpcchSize) -{ - WCHAR szProfilePath[MAX_PATH]; - WCHAR szBuffer[MAX_PATH]; - DWORD dwLength; - HKEY hKey; - LONG Error; - - if (!lpcchSize) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", - 0, - KEY_QUERY_VALUE, - &hKey); - if (Error != ERROR_SUCCESS) - { - DPRINT1("Error: %lu\n", Error); - SetLastError((DWORD)Error); - return FALSE; - } - - /* Get profiles path */ - dwLength = sizeof(szBuffer); - Error = RegQueryValueExW(hKey, - L"ProfilesDirectory", - NULL, - NULL, - (LPBYTE)szBuffer, - &dwLength); - if (Error != ERROR_SUCCESS) - { - DPRINT1("Error: %lu\n", Error); - RegCloseKey(hKey); - SetLastError((DWORD)Error); - return FALSE; - } - - /* Expand it */ - if (!ExpandEnvironmentStringsW(szBuffer, - szProfilePath, - MAX_PATH)) - { - DPRINT1("Error: %lu\n", GetLastError()); - RegCloseKey (hKey); - return FALSE; - } - - /* Get 'AllUsersProfile' name */ - dwLength = sizeof(szBuffer); - Error = RegQueryValueExW(hKey, - L"AllUsersProfile", - NULL, - NULL, - (LPBYTE)szBuffer, - &dwLength); - if (Error != ERROR_SUCCESS) - { - DPRINT1("Error: %lu\n", Error); - RegCloseKey(hKey); - SetLastError((DWORD)Error); - return FALSE; - } - - RegCloseKey (hKey); - - wcscat(szProfilePath, L"\\"); - wcscat(szProfilePath, szBuffer); - - dwLength = wcslen(szProfilePath) + 1; - if (lpProfileDir != NULL) - { - if (*lpcchSize < dwLength) - { - *lpcchSize = dwLength; - SetLastError(ERROR_INSUFFICIENT_BUFFER); - return FALSE; - } - - wcscpy(lpProfileDir, szProfilePath); - } - - *lpcchSize = dwLength; - - return TRUE; -} - - -BOOL -WINAPI -GetDefaultUserProfileDirectoryA( - _Out_opt_ LPSTR lpProfileDir, - _Inout_ LPDWORD lpcchSize) -{ - LPWSTR lpBuffer; - BOOL bResult; - - lpBuffer = GlobalAlloc(GMEM_FIXED, - *lpcchSize * sizeof(WCHAR)); - if (lpBuffer == NULL) - return FALSE; - - bResult = GetDefaultUserProfileDirectoryW(lpBuffer, - lpcchSize); - if (bResult) - { - WideCharToMultiByte(CP_ACP, - 0, - lpBuffer, - -1, - lpProfileDir, - *lpcchSize, - NULL, - NULL); - } - - GlobalFree(lpBuffer); - - return bResult; -} - - -BOOL -WINAPI -GetDefaultUserProfileDirectoryW( - _Out_opt_ LPWSTR lpProfileDir, - _Inout_ LPDWORD lpcchSize) -{ - WCHAR szProfilePath[MAX_PATH]; - WCHAR szBuffer[MAX_PATH]; - DWORD dwLength; - HKEY hKey; - LONG Error; - - if (!lpcchSize) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", - 0, - KEY_QUERY_VALUE, - &hKey); - if (Error != ERROR_SUCCESS) - { - DPRINT1("Error: %lu\n", Error); - SetLastError((DWORD)Error); - return FALSE; - } - - /* Get profiles path */ - dwLength = sizeof(szBuffer); - Error = RegQueryValueExW(hKey, - L"ProfilesDirectory", - NULL, - NULL, - (LPBYTE)szBuffer, - &dwLength); - if (Error != ERROR_SUCCESS) - { - DPRINT1("Error: %lu\n", Error); - RegCloseKey(hKey); - SetLastError((DWORD)Error); - return FALSE; - } - - /* Expand it */ - if (!ExpandEnvironmentStringsW(szBuffer, - szProfilePath, - MAX_PATH)) - { - DPRINT1("Error: %lu\n", GetLastError()); - RegCloseKey(hKey); - return FALSE; - } - - /* Get 'DefaultUserProfile' name */ - dwLength = sizeof(szBuffer); - Error = RegQueryValueExW(hKey, - L"DefaultUserProfile", - NULL, - NULL, - (LPBYTE)szBuffer, - &dwLength); - if (Error != ERROR_SUCCESS) - { - DPRINT1("Error: %lu\n", Error); - RegCloseKey(hKey); - SetLastError((DWORD)Error); - return FALSE; - } - - RegCloseKey(hKey); - - wcscat(szProfilePath, L"\\"); - wcscat(szProfilePath, szBuffer); - - dwLength = wcslen(szProfilePath) + 1; - if (lpProfileDir != NULL) - { - if (*lpcchSize < dwLength) - { - *lpcchSize = dwLength; - SetLastError(ERROR_INSUFFICIENT_BUFFER); - return FALSE; - } - - wcscpy(lpProfileDir, szProfilePath); - } - - *lpcchSize = dwLength; - - return TRUE; -} - - -BOOL -WINAPI -GetProfilesDirectoryA( - _Out_ LPSTR lpProfileDir, // _Out_opt_ - _Inout_ LPDWORD lpcchSize) -{ - LPWSTR lpBuffer; - BOOL bResult; - - if (!lpProfileDir || !lpcchSize) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - lpBuffer = GlobalAlloc(GMEM_FIXED, - *lpcchSize * sizeof(WCHAR)); - if (lpBuffer == NULL) - return FALSE; - - bResult = GetProfilesDirectoryW(lpBuffer, - lpcchSize); - if (bResult) + if (bResult && lpProfileDir) { bResult = WideCharToMultiByte(CP_ACP, 0, @@ -809,16 +571,15 @@ BOOL WINAPI -GetProfilesDirectoryW( - _Out_ LPWSTR lpProfilesDir, // _Out_opt_ +GetAllUsersProfileDirectoryW( + _Out_opt_ LPWSTR lpProfileDir, _Inout_ LPDWORD lpcchSize) { - WCHAR szProfilesPath[MAX_PATH]; + WCHAR szProfilePath[MAX_PATH]; WCHAR szBuffer[MAX_PATH]; - DWORD dwLength; + DWORD dwType, dwLength; HKEY hKey; LONG Error; - BOOL bRet = FALSE; if (!lpcchSize) { @@ -843,10 +604,276 @@ Error = RegQueryValueExW(hKey, L"ProfilesDirectory", NULL, - NULL, + &dwType, (LPBYTE)szBuffer, &dwLength); + if ((Error != ERROR_SUCCESS) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) + { + DPRINT1("Error: %lu\n", Error); + RegCloseKey(hKey); + SetLastError((DWORD)Error); + return FALSE; + } + + /* Expand it */ + if (!ExpandEnvironmentStringsW(szBuffer, + szProfilePath, + ARRAYSIZE(szProfilePath))) + { + DPRINT1("Error: %lu\n", GetLastError()); + RegCloseKey(hKey); + return FALSE; + } + + /* Get 'AllUsersProfile' name */ + dwLength = sizeof(szBuffer); + Error = RegQueryValueExW(hKey, + L"AllUsersProfile", + NULL, + &dwType, + (LPBYTE)szBuffer, + &dwLength); + if ((Error != ERROR_SUCCESS) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) + { + DPRINT1("Error: %lu\n", Error); + RegCloseKey(hKey); + SetLastError((DWORD)Error); + return FALSE; + } + + RegCloseKey(hKey); + + StringCbCatW(szProfilePath, sizeof(szProfilePath), L"\\"); + StringCbCatW(szProfilePath, sizeof(szProfilePath), szBuffer); + + dwLength = wcslen(szProfilePath) + 1; + if (lpProfileDir && (*lpcchSize >= dwLength)) + { + StringCchCopyW(lpProfileDir, *lpcchSize, szProfilePath); + *lpcchSize = dwLength; + return TRUE; + } + else // if (!lpProfileDir || (*lpcchSize < dwLength)) + { + *lpcchSize = dwLength; + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } +} + + +BOOL +WINAPI +GetDefaultUserProfileDirectoryA( + _Out_opt_ LPSTR lpProfileDir, + _Inout_ LPDWORD lpcchSize) +{ + LPWSTR lpBuffer; + BOOL bResult; + + if (!lpcchSize) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + lpBuffer = GlobalAlloc(GMEM_FIXED, + *lpcchSize * sizeof(WCHAR)); + if (lpBuffer == NULL) + return FALSE; + + bResult = GetDefaultUserProfileDirectoryW(lpBuffer, + lpcchSize); + if (bResult && lpProfileDir) + { + bResult = WideCharToMultiByte(CP_ACP, + 0, + lpBuffer, + -1, + lpProfileDir, + *lpcchSize, + NULL, + NULL); + } + + GlobalFree(lpBuffer); + + return bResult; +} + + +BOOL +WINAPI +GetDefaultUserProfileDirectoryW( + _Out_opt_ LPWSTR lpProfileDir, + _Inout_ LPDWORD lpcchSize) +{ + WCHAR szProfilePath[MAX_PATH]; + WCHAR szBuffer[MAX_PATH]; + DWORD dwType, dwLength; + HKEY hKey; + LONG Error; + + if (!lpcchSize) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", + 0, + KEY_QUERY_VALUE, + &hKey); if (Error != ERROR_SUCCESS) + { + DPRINT1("Error: %lu\n", Error); + SetLastError((DWORD)Error); + return FALSE; + } + + /* Get profiles path */ + dwLength = sizeof(szBuffer); + Error = RegQueryValueExW(hKey, + L"ProfilesDirectory", + NULL, + &dwType, + (LPBYTE)szBuffer, + &dwLength); + if ((Error != ERROR_SUCCESS) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) + { + DPRINT1("Error: %lu\n", Error); + RegCloseKey(hKey); + SetLastError((DWORD)Error); + return FALSE; + } + + /* Expand it */ + if (!ExpandEnvironmentStringsW(szBuffer, + szProfilePath, + ARRAYSIZE(szProfilePath))) + { + DPRINT1("Error: %lu\n", GetLastError()); + RegCloseKey(hKey); + return FALSE; + } + + /* Get 'DefaultUserProfile' name */ + dwLength = sizeof(szBuffer); + Error = RegQueryValueExW(hKey, + L"DefaultUserProfile", + NULL, + &dwType, + (LPBYTE)szBuffer, + &dwLength); + if ((Error != ERROR_SUCCESS) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) + { + DPRINT1("Error: %lu\n", Error); + RegCloseKey(hKey); + SetLastError((DWORD)Error); + return FALSE; + } + + RegCloseKey(hKey); + + StringCbCatW(szProfilePath, sizeof(szProfilePath), L"\\"); + StringCbCatW(szProfilePath, sizeof(szProfilePath), szBuffer); + + dwLength = wcslen(szProfilePath) + 1; + if (lpProfileDir && (*lpcchSize >= dwLength)) + { + StringCchCopyW(lpProfileDir, *lpcchSize, szProfilePath); + *lpcchSize = dwLength; + return TRUE; + } + else // if (!lpProfileDir || (*lpcchSize < dwLength)) + { + *lpcchSize = dwLength; + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } +} + + +BOOL +WINAPI +GetProfilesDirectoryA( + _Out_ LPSTR lpProfileDir, // _Out_opt_ + _Inout_ LPDWORD lpcchSize) +{ + LPWSTR lpBuffer; + BOOL bResult; + + if (!lpcchSize) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + lpBuffer = GlobalAlloc(GMEM_FIXED, + *lpcchSize * sizeof(WCHAR)); + if (lpBuffer == NULL) + return FALSE; + + bResult = GetProfilesDirectoryW(lpBuffer, + lpcchSize); + if (bResult && lpProfileDir) + { + bResult = WideCharToMultiByte(CP_ACP, + 0, + lpBuffer, + -1, + lpProfileDir, + *lpcchSize, + NULL, + NULL); + } + + GlobalFree(lpBuffer); + + return bResult; +} + + +BOOL +WINAPI +GetProfilesDirectoryW( + _Out_ LPWSTR lpProfilesDir, // _Out_opt_ + _Inout_ LPDWORD lpcchSize) +{ + WCHAR szProfilesPath[MAX_PATH]; + WCHAR szBuffer[MAX_PATH]; + DWORD dwType, dwLength; + HKEY hKey; + LONG Error; + + if (!lpcchSize) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", + 0, + KEY_QUERY_VALUE, + &hKey); + if (Error != ERROR_SUCCESS) + { + DPRINT1("Error: %lu\n", Error); + SetLastError((DWORD)Error); + return FALSE; + } + + /* Get profiles path */ + dwLength = sizeof(szBuffer); + Error = RegQueryValueExW(hKey, + L"ProfilesDirectory", + NULL, + &dwType, + (LPBYTE)szBuffer, + &dwLength); + if ((Error != ERROR_SUCCESS) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) { DPRINT1("Error: %lu\n", Error); RegCloseKey(hKey); @@ -866,26 +893,18 @@ } dwLength = wcslen(szProfilesPath) + 1; - if (lpProfilesDir != NULL) - { - if (*lpcchSize < dwLength) - { - SetLastError(ERROR_INSUFFICIENT_BUFFER); - } - else - { - wcscpy(lpProfilesDir, szProfilesPath); - bRet = TRUE; - } - } - else - { + if (lpProfilesDir && (*lpcchSize >= dwLength)) + { + StringCchCopyW(lpProfilesDir, *lpcchSize, szProfilesPath); + *lpcchSize = dwLength; + return TRUE; + } + else // if (!lpProfilesDir || (*lpcchSize < dwLength)) + { + *lpcchSize = dwLength; SetLastError(ERROR_INSUFFICIENT_BUFFER); - } - - *lpcchSize = dwLength; - - return bRet; + return FALSE; + } } @@ -899,9 +918,9 @@ LPWSTR lpBuffer; BOOL bResult; - if (!lpProfileDir || !lpcchSize) - { - SetLastError( ERROR_INVALID_PARAMETER ); + if (!lpcchSize) + { + SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } @@ -913,16 +932,16 @@ bResult = GetUserProfileDirectoryW(hToken, lpBuffer, lpcchSize); - if (bResult) - { - WideCharToMultiByte(CP_ACP, - 0, - lpBuffer, - -1, - lpProfileDir, - *lpcchSize, - NULL, - NULL); + if (bResult && lpProfileDir) + { + bResult = WideCharToMultiByte(CP_ACP, + 0, + lpBuffer, + -1, + lpProfileDir, + *lpcchSize, + NULL, + NULL); } GlobalFree(lpBuffer); @@ -942,7 +961,7 @@ WCHAR szKeyName[MAX_PATH]; WCHAR szRawImagePath[MAX_PATH]; WCHAR szImagePath[MAX_PATH]; - DWORD dwLength; + DWORD dwType, dwLength; HKEY hKey; LONG Error; @@ -958,19 +977,18 @@ return FALSE; } - if (!GetUserSidStringFromToken(hToken, - &SidString)) - { - DPRINT1("GetUserSidFromToken() failed\n"); + /* Get the user SID string */ + if (!GetUserSidStringFromToken(hToken, &SidString)) + { + DPRINT1("GetUserSidStringFromToken() failed\n"); return FALSE; } DPRINT("SidString: '%wZ'\n", &SidString); - wcscpy(szKeyName, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"); - wcscat(szKeyName, - SidString.Buffer); + StringCbCopyW(szKeyName, sizeof(szKeyName), + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"); + StringCbCatW(szKeyName, sizeof(szKeyName), SidString.Buffer); RtlFreeUnicodeString(&SidString); @@ -992,10 +1010,10 @@ Error = RegQueryValueExW(hKey, L"ProfileImagePath", NULL, - NULL, + &dwType, (LPBYTE)szRawImagePath, &dwLength); - if (Error != ERROR_SUCCESS) + if ((Error != ERROR_SUCCESS) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) { DPRINT1("Error: %lu\n", Error); RegCloseKey(hKey); @@ -1018,18 +1036,19 @@ DPRINT("ImagePath: '%S'\n", szImagePath); - dwLength = wcslen (szImagePath) + 1; - if (*lpcchSize < dwLength) + dwLength = wcslen(szImagePath) + 1; + if (lpProfileDir && (*lpcchSize >= dwLength)) + { + StringCchCopyW(lpProfileDir, *lpcchSize, szImagePath); + *lpcchSize = dwLength; + return TRUE; + } + else // if (!lpProfileDir || (*lpcchSize < dwLength)) { *lpcchSize = dwLength; SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } - - *lpcchSize = dwLength; - wcscpy(lpProfileDir, szImagePath); - - return TRUE; } @@ -1042,10 +1061,10 @@ DPRINT("CheckForLoadedProfile() called\n"); - if (!GetUserSidStringFromToken(hToken, - &SidString)) - { - DPRINT1("GetUserSidFromToken() failed\n"); + /* Get the user SID string */ + if (!GetUserSidStringFromToken(hToken, &SidString)) + { + DPRINT1("GetUserSidStringFromToken() failed\n"); return FALSE; } @@ -1217,7 +1236,8 @@ if (lpProfileInfo->lpProfilePath) { - wcscpy(szUserHivePath, lpProfileInfo->lpProfilePath); + /* Use the caller's specified roaming user profile path */ + StringCbCopyW(szUserHivePath, sizeof(szUserHivePath), lpProfileInfo->lpProfilePath); } else { @@ -1230,9 +1250,9 @@ } /* Create user hive name */ - wcscat(szUserHivePath, L"\\"); - wcscat(szUserHivePath, lpProfileInfo->lpUserName); - wcscat(szUserHivePath, L"\\ntuser.dat"); + StringCbCatW(szUserHivePath, sizeof(szUserHivePath), L"\\"); + StringCbCatW(szUserHivePath, sizeof(szUserHivePath), lpProfileInfo->lpUserName); + StringCbCatW(szUserHivePath, sizeof(szUserHivePath), L"\\ntuser.dat"); DPRINT("szUserHivePath: %S\n", szUserHivePath); /* Create user profile directory if needed */ @@ -1311,11 +1331,11 @@ } } - /* Get user SID string */ + /* Get the user SID string */ ret = GetUserSidStringFromToken(hToken, &SidString); if (!ret) { - DPRINT1("GetUserSidFromToken() failed\n"); + DPRINT1("GetUserSidStringFromToken() failed\n"); goto cleanup; } ret = FALSE; @@ -1390,10 +1410,10 @@ RegCloseKey(hProfile); - if (!GetUserSidStringFromToken(hToken, - &SidString)) - { - DPRINT1("GetUserSidFromToken() failed\n"); + /* Get the user SID string */ + if (!GetUserSidStringFromToken(hToken, &SidString)) + { + DPRINT1("GetUserSidStringFromToken() failed\n"); return FALSE; }
7 years, 10 months
1
0
0
0
← Newer
1
...
24
25
26
27
28
29
30
...
36
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Results per page:
10
25
50
100
200