Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIN32SS][LPK] Add BiDi support to menus and window captions #738

Merged
merged 12 commits into from Aug 23, 2018

Conversation

peterooch
Copy link
Contributor

@peterooch peterooch commented Aug 10, 2018

Purpose

Added callback function that redirects calls to GreExtTextOutW that didn't went through lpk BiDi processing, calls that are from the kernel.

Completely solves JIRA issue CORE-6910

Compiles and runs, until a menu is loaded...
Issue linger with last letter being corrupted
Now everything is being drawn properly
/* Draw via lpk */
if (!(fuOptions & (ETO_IGNORELANGUAGE | ETO_GLYPH_INDEX)))
{
if(DrawUsingLPK(hDC, XStart, YStart, fuOptions, lprc, String, Count, &bLPKResult))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space between 'if' and '('.


Argument = IntCbAllocateMemory(ArgumentLength);

if(!Argument)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space between 'if' and '('.

/* copy rect */
if (lprc)
{
Argument->rect.left = lprc->left;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe Argument->rect = *(LPRECT)lprc;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you


if (!NT_SUCCESS(Status))
{
*bResult = FALSE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space.

{
_SEH2_TRY
{
ProbeForRead(ResultPointer, sizeof(HMODULE), 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From where did HMODULE come?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is based on what is in co_IntClientLoadLibrary, which also a callback that uses string parameters. but will check if can be changed to BOOL

_SEH2_TRY
{
ProbeForRead(ResultPointer, sizeof(HMODULE), 1);
*bResult = *(BOOL*)ResultPointer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use LPBOOL.


Argument = (PLPK_CALLBACK_ARGUMENTS)Arguments;

Argument->lpString = (PWCHAR)((ULONG_PTR)Argument->lpString + (ULONG_PTR)Argument);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mysterious type casting.
what do you wanna do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See co_IntClientLoadLibrary and User32CallClientLoadLibraryFromKernel

Argument->count,
NULL);

return ZwCallbackReturn(&bResult, sizeof(HMODULE), STATUS_SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HMODULE ditto.

[WIN32SS] Changed some castings to make more sense, simplified the rect copy.
[GDI32] Added code in case of lpk.dll loading failed.[LPK] Fixed the propsheet bug in lpk.dll
Keep freetype.c clear from non font related code,
moved function to rtl\text, now only will activated upon window captions and menus.
@peterooch
Copy link
Contributor Author

virtualbox_reactos_10_08_2018_14_38_08

@peterooch peterooch changed the title [WIN32SS][LPK][WIP] Add BiDi support to menus and window captions [WIN32SS][LPK] Add BiDi support to menus and window captions Aug 10, 2018
@HBelusca
Copy link
Contributor

"Grey +" ? What's that?

@peterooch
Copy link
Contributor Author

peterooch commented Aug 10, 2018

"Grey +" ? What's that?

A 7-zip menu thing...

@HBelusca
Copy link
Contributor

Ah ok, so that's what they write instead of "Ctrl-+" etc...

Fixes crash while installing Notepad++

return bResult;

fallback:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the indentation.

return bResult;

fallback:
return GreExtTextOutW(hdc, x, y, flags, lprc, lpString, count, NULL, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce the indentation to 4 spaces.


Argument->lpString = (LPWSTR)((ULONG_PTR)Argument->lpString + (ULONG_PTR)Argument);

bResult = ExtTextOutW(Argument->hdc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future this certainly will have to be generalized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "generalization"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err forget what I've just said. I indeed see in the user32 symbols that there is indeed a special callback for ExtTextOutW (ClientExtTextOutW).
https://www.reactos.org/wiki/Techwiki:Win32k/apfnDispatch

}
else
{
Argument->bRect = FALSE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're leaving rect uninitialized here, which leaks kernel memory contents to user mode.

RtlStringCchCopyNW(Argument->lpString, count + 1, lpString, count);

pStringBuffer -= (ULONG_PTR)Argument;
Argument->lpString = (LPWSTR)(pStringBuffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little cumbersome. Why not set lpString to the correct value in the first place, and use pStringBuffer or some other value as the copy destination, e.g.

Argument->lpString = (LPWSTR)pStringBuffer;
pStringBuffer += (ULONG_PTR)Argument;
RtlStringCchCopyNW(pStringBuffer, ...);

@yagoulas
Copy link
Member

Adding an extra callback is the way to go but morr changes are needed in the kernel mode part because doing a callback can have unpreidctable results. The thread coukd die in user mode and never return to free resources or the window pwnd could be destroyed while in user mode and we could end up with a stale pwnd pointrr this way.

@ThFabba
Copy link
Member

ThFabba commented Aug 15, 2018

Hmm I don't see any such issues looking at the code. Are you able to point to specific instances?
The memory allocation uses IntCbAllocateMemory which gets added to the thread list, so is safe for callouts, and there's no PWND to be seen, only an HDC, which should be safe as well as far as I understand.
Thanks!

Zero rect struct member if not to be used.
Simplify pointer arithmetic (Thanks for the suggestion!)
PVOID ResultPointer;
ULONG ResultLength;
ULONG ArgumentLength;
ULONG_PTR pStringBuffer = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not need to be zero-initialized.

mimicks code from co_IntClientLoadLibrary */
Argument->lpString = (LPWSTR)pStringBuffer;
pStringBuffer += (ULONG_PTR)Argument;
RtlStringCchCopyNW((LPWSTR)pStringBuffer, count + 1, lpString, count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably check the return from this.

Added documentation to explain the use of the callback function.
Address comments.
@peterooch
Copy link
Contributor Author

Any opinions on should I include the changes that are mentioned in:
https://www.reactos.org/forum/viewtopic.php?f=9&t=17378
or should I keep those for a later PR?

@HBelusca
Copy link
Contributor

Hi! I think that the changes mentioned in the forum should be done in a separate PR.

@HBelusca HBelusca merged commit e7d2bbe into reactos:master Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants