-
Notifications
You must be signed in to change notification settings - Fork 121
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
GetCurrentProcessToken
missing
#436
Comments
Unfortunately these are inlined functions that use code instead of a DLL import. Maybe we could represent them with attributes: Header version: FORCEINLINE
HANDLE
GetCurrentProcessToken (
VOID
)
{
return (HANDLE)(LONG_PTR) -4;
} Metadata version: [return: DoNotRelease]
[return: UseConstant(-4)]
public static extern HANDLE GetCurrentProcessToken(); |
Yeah, something like that might be a good idea. I don't know how pervasive this kind of inline code is, but it would be helpful to document somehow so that a projection doesn't omit these APIs. |
Got asked about this today too. The proposed attributes above look great. Some additional examples: FORCEINLINE
HANDLE
GetCurrentProcessToken (
VOID
)
{
return (HANDLE)(LONG_PTR) -4;
}
FORCEINLINE
HANDLE
GetCurrentThreadToken (
VOID
)
{
return (HANDLE)(LONG_PTR) -5;
}
FORCEINLINE
HANDLE
GetCurrentThreadEffectiveToken (
VOID
)
{
return (HANDLE)(LONG_PTR) -6;
} |
There are more challenging ones, such as FORCEINLINE
BOOLEAN
IsBthLEUuidMatch(
_In_ BTH_LE_UUID uuid1,
_In_ BTH_LE_UUID uuid2
)
{
BTH_LE_UUID tempLongUuid = {0};
tempLongUuid.IsShortUuid = FALSE;
tempLongUuid.Value.LongUuid = BTH_LE_ATT_BLUETOOTH_BASE_GUID;
if (uuid1.IsShortUuid && uuid2.IsShortUuid) {
return (uuid1.Value.ShortUuid == uuid2.Value.ShortUuid);
} else if (!uuid1.IsShortUuid && !uuid2.IsShortUuid) {
return (0 == memcmp(&uuid1.Value.LongUuid, &uuid2.Value.LongUuid, sizeof(GUID)));
} else if (uuid1.IsShortUuid) {
tempLongUuid.Value.LongUuid.Data1 += uuid1.Value.ShortUuid;
return (0 == memcmp(&tempLongUuid, &uuid2.Value.LongUuid, sizeof(GUID)));
} else if (uuid2.IsShortUuid) {
tempLongUuid.Value.LongUuid.Data1 += uuid2.Value.ShortUuid;
return (0 == memcmp(&uuid1.Value.LongUuid, &tempLongUuid.Value.LongUuid, sizeof(GUID)));
}
return FALSE;
}
#ifdef __cplusplus
}
#endif FORCEINLINE
VOID
InitializeThreadpoolEnvironment(
_Out_ PTP_CALLBACK_ENVIRON pcbe
)
{
TpInitializeCallbackEnviron(pcbe);
} |
Please no. 😑 |
These are awful. It's a shame the API was written in this way, but we are where we are. I think it might be simplest for the metadata to simply flag these with some kind of "inline" attribute, and then projections like ours will have to implement them manually in code. But having them in the metadata is important, since otherwise I don't even know that they exist. |
Is the conclusion here to do nothing? Or should we do something about the inlines that return constants? I don't see us doing anything about the more complex inlines. |
Yes, I'd leave this for now. |
Ideally I'd prefer that we do something here, even if it's relatively lightweight. After all, these are very much part of the Windows API. It's an unfortunate situation that they are implemented in such a way as to be uncallable without a C compiler being involved, but from a user's perspective, there's no obvious way to even tell from the docs that they are implemented as inline macros (nor should they care). For simple constants, which are presumably the majority, we could easily support them with an attribute. For more complex ones like |
We introduced the Should we also apply it to inline functions that return constants? The suggestion above was |
Sure, if we use the same |
I think I need to provide a DllImport attribute for the manual definition to show up in the winmd. Should I add some placeholder DLL name so parsers aren't broken? Below is what I have showing up in the winmd even though this inline function isn't actually exported from kernel32.dll. I just manually added the attribute so it was emitted.
|
If you put the |
How about this?
|
It doesn't look awfully elegant to have a Why are the constants strings and not ints? |
If you wanted to query all The |
I'm not a fan of any of this. Feels like a slippery slope situation--why are we doing work for these inline functions and not the billion others? |
What do you mean? Also you were supportive of this earlier. What changed? |
Since my enthusiasic reply in 2021, we've gotten beat up over other inline functions/macros like
These are all virtually part of the Windows API surface too. Right? RIGHT? 🙃 So when evaluating the changes here, I also think of those functions and macros. And I don't think we're going to be able to apply the solution proposed here to those. So now I'm wondering if projection authors really want to add support for yet another attribute given the limited applicability/scope. Would they be better off implementing what they feel their respective community needs/wants manually? I'm not opposed to try it out though. Metadata is nimble and we're still in pre-release. One question about the proposed implementation (#436 (comment)): Should implementers assume |
I'm fine experimenting with these few.
No the type should be deduced from the context ( |
also
GetCurrentThreadToken
andGetCurrentThreadEffectiveToken
.See:
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocesstoken
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentthreadeffectivetoken
The text was updated successfully, but these errors were encountered: