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

Add support for calling conventions #1999

Merged
merged 7 commits into from Sep 2, 2022
Merged

Add support for calling conventions #1999

merged 7 commits into from Sep 2, 2022

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Sep 1, 2022

Following on #1996 that introduced win32 metadata capturing calling conventions, this update adds support for translating that metadata into Rust bindings. It also corrects a few issues with calculating the stdcall stack size requirements. It now correctly takes into account padding and alignment.

Fixes #1985

@kennykerr
Copy link
Collaborator Author

As expected, the build failed the gnu test of test_calling_convention. I've asked @riverar to now update the gnu and llvm libs and then the build should proceed.

@glandium
Copy link
Contributor

glandium commented Sep 1, 2022

I haven't looked at the symbol names in detail, but this also fixes #1964 (comment)

@glandium
Copy link
Contributor

glandium commented Sep 1, 2022

c0a8db4 has changes that are meant to be in 3f672e7 and vice-versa, it looks like.

@glandium
Copy link
Contributor

glandium commented Sep 1, 2022

Haven't finished looking, but so far, I found that RtmConvertIpv6AddressAndLengthToNetAddress and RtmConvertNetAddressToIpv6AddressAndLength are now cdecl, but aren't in the real rtm.dll.

@riverar
Copy link
Collaborator

riverar commented Sep 1, 2022

Yup can confirm that.

@glandium
Copy link
Contributor

glandium commented Sep 1, 2022

There are a lot more now cdecl that aren't in the real DLLs (probably incomplete list):

__imp__WTSEnableChildSessions
__imp__WTSGetChildSessionId
__imp__WTSIsChildSessionsEnabled
__imp__CreatePrinterIC
__imp__DeletePrinterIC
__imp__ExtDeviceMode
__imp__PlayGdiScriptOnPrinterIC
__imp__RouterFreeBidiResponseContainer
__imp__DoConnectoidsExist
__imp__IsProfilesEnabled
__imp__PerformOperationOverUrlCacheA
__imp__UrlCacheFreeGlobalSpace
__imp__UrlCacheGetGlobalCacheSize
__imp__WerFreeString
__imp__WerStoreClose
__imp__WerStoreGetFirstReportKey
__imp__WerStoreGetNextReportKey
__imp__WerStoreGetReportCount
__imp__WerStoreGetSizeOnDisk
__imp__WerStoreOpen
__imp__WerStorePurge
__imp__WerStoreQueryReportMetadataV1
__imp__WerStoreQueryReportMetadataV2
__imp__WerStoreQueryReportMetadataV3
__imp__WerStoreUploadReport
__imp__PxeProviderFreeInfo
__imp__GetDeviceIDString
__imp__SrpIsTokenService
__imp__AppendPrinterNotifyInfoData
__imp__CallRouterFindFirstPrinterChangeNotification
__imp__GetJobAttributesEx
__imp__ImpersonatePrinterClient
__imp__PartialReplyPrinterChangeNotification
__imp__ProvidorFindClosePrinterChangeNotification
__imp__ProvidorFindFirstPrinterChangeNotification
__imp__ReplyPrinterChangeNotificationEx
__imp__RevertToPrinterSelf
__imp__RouterAllocBidiMem
__imp__RouterAllocBidiResponseContainer
__imp__RouterAllocPrinterNotifyInfo
__imp__RouterFreeBidiMem
__imp__RouterFreePrinterNotifyInfo
__imp__SplIsSessionZero
__imp__SplPromptUIInUsersSession
__imp__SpoolerFindClosePrinterChangeNotification
__imp__SpoolerFindFirstPrinterChangeNotification
__imp__SpoolerFindNextPrinterChangeNotification
__imp__SpoolerFreePrinterNotifyInfo
__imp__SpoolerRefreshPrinterChangeNotification
__imp__CollectionsListAllocateBufferAndSerialize
__imp__CollectionsListCopyAndMarshall
__imp__CollectionsListDeserializeFromBuffer
__imp__CollectionsListGetFillableCount
__imp__CollectionsListGetMarshalledSizeWithoutSerialization
__imp__CollectionsListGetSerializedSize
__imp__CollectionsListMarshall
__imp__CollectionsListSerializeToBuffer
__imp__CollectionsListSortSubscribedActivitiesByConfidence
__imp__CollectionsListUpdateMarshalledPointer
__imp__EvaluateActivityThresholds
__imp__GetPerformanceTime
__imp__InitPropVariantFromCLSIDArray
__imp__InitPropVariantFromFloat
__imp__IsCollectionListSame
__imp__IsGUIDPresentInList
__imp__IsKeyPresentInCollectionList
__imp__IsKeyPresentInPropertyList
__imp__IsSensorSubscribed
__imp__PropKeyFindKeyGetBool
__imp__PropKeyFindKeyGetDouble
__imp__PropKeyFindKeyGetFileTime
__imp__PropKeyFindKeyGetFloat
__imp__PropKeyFindKeyGetGuid
__imp__PropKeyFindKeyGetInt32
__imp__PropKeyFindKeyGetInt64
__imp__PropKeyFindKeyGetNthInt64
__imp__PropKeyFindKeyGetNthUlong
__imp__PropKeyFindKeyGetNthUshort
__imp__PropKeyFindKeyGetPropVariant
__imp__PropKeyFindKeyGetUlong
__imp__PropKeyFindKeyGetUshort
__imp__PropKeyFindKeySetPropVariant
__imp__PropVariantGetInformation
__imp__PropertiesListCopy
__imp__PropertiesListGetFillableCount
__imp__SensorCollectionGetAt
__imp__SerializationBufferAllocate
__imp__SerializationBufferFree
__imp__AcceptSecurityContext@40
__imp__CredMarshalTargetInfo
__imp__CredUnmarshalTargetInfo
__imp__InitializeSecurityContextA@52
__imp__InitializeSecurityContextW@52
__imp__SaslAcceptSecurityContext@40
__imp__SaslInitializeSecurityContextA@52
__imp__SaslInitializeSecurityContextW@52
__imp__LogErrorW
__imp__LogEventW
__imp__RouterAssert
__imp__RouterGetErrorStringA
__imp__RouterGetErrorStringW
__imp__RouterLogDeregisterA
__imp__RouterLogDeregisterW
__imp__RouterLogEventA
__imp__RouterLogEventDataA
__imp__RouterLogEventDataW
__imp__RouterLogEventStringA
__imp__RouterLogEventStringW
__imp__RouterLogEventValistExA
__imp__RouterLogEventValistExW
__imp__RouterLogEventW
__imp__RouterLogRegisterA
__imp__RouterLogRegisterW
__imp__MgmAddGroupMembershipEntry
__imp__MgmDeRegisterMProtocol
__imp__MgmDeleteGroupMembershipEntry
__imp__MgmGetFirstMfeStats
__imp__MgmGetMfeStats
__imp__MgmGetNextMfeStats
__imp__MgmGetProtocolOnInterface
__imp__MgmGroupEnumerationEnd
__imp__MgmGroupEnumerationGetNext
__imp__MgmGroupEnumerationStart
__imp__MgmRegisterMProtocol
__imp__MgmReleaseInterfaceOwnership
__imp__MgmTakeInterfaceOwnership
__imp__RtmConvertIpv6AddressAndLengthToNetAddress
__imp__RtmConvertNetAddressToIpv6AddressAndLength
__imp__I_RpcServerInqAddressChangeFn
__imp__ClusWorkersTerminate
__imp__FreeClusterHealthFaultArray
__imp__InitializeClusterHealthFaultArray
__imp__ResUtilLeftPaxosIsLessThanRight
__imp__ResUtilPaxosComparer
__imp__ResUtilsDeleteKeyTree
__imp__NetAddServiceAccount
__imp__NetEnumerateServiceAccounts
__imp__NetIsServiceAccount
__imp__NetQueryServiceAccount
__imp__NetRemoveServiceAccount
__imp__DestroyIndexedResults
__imp__DestroyResourceIndexer
__imp__WNetSetLastErrorA
__imp__WNetSetLastErrorW
__imp__BackupPerfRegistryToFileW
__imp__RestorePerfRegistryFromFileW
__imp__GetCurrentClockTransactionManager
__imp__GetTransactionManagerId
__imp__KeyCredentialManagerFreeInformation
__imp__GetOwnerModuleFromPidAndInfo
__imp__DnsConnectionDeleteProxyInfo
__imp__DnsConnectionFreeNameList
__imp__DnsConnectionFreeProxyInfoEx
__imp__DnsConnectionFreeProxyList
__imp__DnsConnectionGetNameList
__imp__DnsConnectionGetProxyInfoForHostUrl
__imp__DnsConnectionGetProxyList
__imp__DnsConnectionSetProxyInfo
__imp__DnsConnectionUpdateIfIndexTable
__imp__DnsRecordSetDetach
__imp__DnsValidateName_A
__imp__DnsValidateName_UTF8
__imp__DnsValidateName_W
__imp__DhcpAddServer
__imp__DhcpAuditLogGetParams
__imp__DhcpAuditLogSetParams
__imp__DhcpCreateOptionV5
__imp__DhcpDeleteServer
__imp__DhcpDeleteSuperScopeV4
__imp__DhcpDsCleanup
__imp__DhcpDsInit
__imp__DhcpEnumOptionValuesV5
__imp__DhcpEnumOptionsV5
__imp__DhcpEnumServers
__imp__DhcpGetClassInfo
__imp__DhcpGetMibInfoV6
__imp__DhcpGetOptionInfoV5
__imp__DhcpGetOptionValueV5
__imp__DhcpGetOptionValueV6
__imp__DhcpGetSuperScopeInfoV4
__imp__DhcpGetThreadOptions
__imp__DhcpHlprFindV4DhcpProperty
__imp__DhcpRemoveOptionV5
__imp__DhcpRemoveOptionValueV5
__imp__DhcpServerBackupDatabase
__imp__DhcpServerQueryAttributes
__imp__DhcpServerQueryDnsRegCredentials
__imp__DhcpServerRedoAuthorization
__imp__DhcpServerRestoreDatabase
__imp__DhcpServerSetDnsRegCredentialsV5
__imp__DhcpSetOptionInfoV5
__imp__DhcpSetOptionValueV5
__imp__DhcpSetOptionValuesV5
__imp__DhcpSetSubnetInfoV6
__imp__DhcpSetSuperScopeV4
__imp__DhcpSetThreadOptions
__imp__NetworkIsolationDiagnoseConnectFailureAndGetInfo
__imp__NetworkIsolationEnumAppContainers
__imp__NetworkIsolationFreeAppContainers
__imp__NetworkIsolationGetAppContainerConfig
__imp__NetworkIsolationRegisterForAppContainerChanges
__imp__NetworkIsolationSetAppContainerConfig
__imp__NetworkIsolationSetupAppContainerBinaries
__imp__NetworkIsolationUnregisterForAppContainerChanges
__imp__GetFeatureVariant
__imp__GetFeatureEnabledState
__imp__RecordFeatureError
__imp__RecordFeatureUsage
__imp__SubscribeFeatureStateChangeNotification
__imp__UnsubscribeFeatureStateChangeNotification
__imp__TraceMessageVa

@glandium
Copy link
Contributor

glandium commented Sep 1, 2022

Oh, I just noticed there are some @s in the list I just pasted, those are new inconsistencies:

__imp__AcceptSecurityContext@40 __imp__AcceptSecurityContext@36
__imp__InitializeSecurityContextA@52 __imp__InitializeSecurityContextA@48
__imp__InitializeSecurityContextW@52 __imp__InitializeSecurityContextW@48
__imp__SaslAcceptSecurityContext@40 __imp__SaslAcceptSecurityContext@36
__imp__SaslInitializeSecurityContextA@52 __imp__SaslInitializeSecurityContextA@48
__imp__SaslInitializeSecurityContextW@52 __imp__SaslInitializeSecurityContextW@48

@kennykerr
Copy link
Collaborator Author

Created microsoft/win32metadata#1217 - hopefully @sotteson1 can take a quick look but at a glance I do agree that this metadata is no good as is.

@kennykerr
Copy link
Collaborator Author

kennykerr commented Sep 2, 2022

__imp__AcceptSecurityContext@40 __imp__AcceptSecurityContext@36
__imp__InitializeSecurityContextA@52 __imp__InitializeSecurityContextA@48
__imp__InitializeSecurityContextW@52 __imp__InitializeSecurityContextW@48
__imp__SaslAcceptSecurityContext@40 __imp__SaslAcceptSecurityContext@36
__imp__SaslInitializeSecurityContextA@52 __imp__SaslInitializeSecurityContextA@48
__imp__SaslInitializeSecurityContextW@52 __imp__SaslInitializeSecurityContextW@48

These all looks like win32metadata bugs where the signatures are improperly declared, mixing 32 bit and 64 bit integer types. For example, the win32metadata uses enums like ASC_REQ_FLAGS instead of unsigned 32 bit parameters but the enum's underlying type is an unsigned 64 bit integer. Same for ISC_REQ_FLAGS. This then throws off the stdcall stack size calculation and of course makes these functions uncallable.

I wish the win32metadata could just validate this against the lib files in the SDK using dumpbin.

I'll create a win32metadata issue for this.

@kennykerr
Copy link
Collaborator Author

So we have the following two new win32metadata issues blocking the adoption of calling convention support and publishing accurate import libs:

microsoft/win32metadata#1217
microsoft/win32metadata#1221

I think I'll just disable the calling convention support for now (so that everything appears to use stdcall) rather than backing this all out. That way we can easily validate and re-enable once these bugs have been fixed.

@kennykerr kennykerr merged commit 6b5ab01 into master Sep 2, 2022
@kennykerr kennykerr deleted the calling_conventions branch September 2, 2022 15:02
@glandium
Copy link
Contributor

glandium commented Sep 9, 2022

crates/targets/aarch64_msvc/lib/windows.lib wasn't updated, BTW.

@riverar
Copy link
Collaborator

riverar commented Sep 9, 2022

@glandium Good catch, we'll generate fresh ones tomorrow. We might be regenerating again anyway w/ some big incoming metadata changes.

@kennykerr
Copy link
Collaborator Author

Yes, I'm just waiting for another win32 metadata update since what we have right now is broken anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discrepancy in symbol names between i686*/lib/*windows.* and .lib files in windows SDK
3 participants