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

AddInterfacesToAdapter pAdapter not a pointer #736

Closed
marler8997 opened this issue Nov 9, 2021 · 1 comment
Closed

AddInterfacesToAdapter pAdapter not a pointer #736

marler8997 opened this issue Nov 9, 2021 · 1 comment
Assignees
Labels
broken api An API is inaccurate and could lead to runtime failure bug Something isn't working

Comments

@marler8997
Copy link
Contributor

The first parameter pAdapter in the function AddInterfacesToAdapter has NativeArrayInfo but it's not defined as a pointer.

HRESULT AddInterfacesToAdapter([In][NativeArrayInfo(CountParamIndex = 1)] INetCfgComponent pAdapter, [In] uint dwNumInterfaces);

Also note that it's a pointer in the native interface:
https://docs.microsoft.com/en-us/previous-versions/windows/hardware/network/ff547809(v=vs.85)

HRESULT AddInterfacesToAdapter(
  [in] INetCfgComponent *pAdapter,
  [in] DWORD            dwNumInterfaces
);

This was found in my projection because I have a function GetChildType that runs on every parameter type with NativeArrayInfo. All other parameter types that use it are some sort of pointer type.

https://github.com/marlersoft/win32jsongen/blob/16f9bb264b1534dbd90e376ffcb2a5d8bf422039/Generator/TypeRef.cs#L23

      private TypeRef GetChildType(TypeRefDecoder decoder)
        {
            if (this is TypeRef.PointerTo pointerTo)
            {
                return pointerTo.ChildType;
            }

            if (object.ReferenceEquals(this, Primitive.IntPtr))
            {
                return Primitive.Void;
            }

            if (this is TypeRef.User userType)
            {
                if (userType.Info.Fqn == "Windows.Win32.Foundation.PSTR")
                {
                    return TypeRef.Primitive.Byte;
                }

                if (userType.Info.Fqn == "Windows.Win32.Foundation.PWSTR")
                {
                    return TypeRef.Primitive.Char;
                }

                // This is the type of a parameter for PxeProviderSetAttribute that changes dynamically depending on another
                // parameter, so we'll just default to representing it as a Byte array.
                if (userType.Info.Fqn == "Windows.Win32.WindowsDeploymentServices.PxeProviderSetAttribute_pParameterBufferFlags")
                {
                    return TypeRef.Primitive.Byte;
                }

                // I think this is an array of bytes based on https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getpath
                // aj: A pointer to an array of bytes that receives the vertex types.
                if (userType.Info.Fqn == "Windows.Win32.Gdi.GetPath_aj")
                {
                    return TypeRef.Primitive.Byte;
                }

                if (userType.Info.Fqn == "Windows.Win32.Security.PSID")
                {
                    return decoder.GetTypeFromNamespaceAndNameInThisModule("Windows.Win32.Security", "SID");
                }
            }

            throw Violation.Data();
        }
@sotteson1
Copy link
Contributor

sotteson1 commented Nov 9, 2021

This took me a few minutes to figure out what was going on! The SAL is incorrect for pAdapter. It's not an array, it's meant to be a single adapter, which is what the metadata is doing. The count is referring to how many "new interfaces" (whatever that means) are to be added to the single adapter. I looked at the implementation to make sure this is the case. The fix would be to get rid of the "[NativeArrayInfo(CountParamIndex = 1)]" attribute. If it were an actual array, the C declaration would be INetCfgComponent **pAdapter.

@mikebattista mikebattista added broken api An API is inaccurate and could lead to runtime failure bug Something isn't working labels Nov 9, 2021
@mikebattista mikebattista self-assigned this Jan 11, 2022
@mikebattista mikebattista removed their assignment Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken api An API is inaccurate and could lead to runtime failure bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants