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

Bug with recovery actions Reboot Message and Run A Program Command #83

Open
WantStuff opened this issue Jul 23, 2019 · 1 comment
Open
Assignees
Labels
Milestone

Comments

@WantStuff
Copy link

Both the Reboot Message and run a program Command properties get corrupted (show random characters).
This appears to be due to incorrect memory/pointer allocation of ServiceFailureActionsInfo ( SERVICE_FAILURE_ACTIONS and SC_ACTION[] ).

@WantStuff
Copy link
Author

WantStuff commented Jul 23, 2019

FYI: I've created my own recovery actions code and have found it works if I use the below code to allocate memory and return a pointer the SC_ACTION list.
Hopefully this will help you identify the issue.

private static SafeMemoryHandle StructureArrayToPtr<SC_ACTION>(IList<SC_ACTION> structureArray)
{
    if (structureArray == null || !structureArray.Any())
        return new SafeMemoryHandle();
    
    var elementSize = Marshal.SizeOf(typeof(SC_ACTION));
    var arrayLength = structureArray.Count;
    
    // Allocate enough unmanaged memory to hold the struct array and collect a pointer to it. 
    var totalArraySize = elementSize * arrayLength;
    var pointerToStruct = new SafeMemoryHandle(Marshal.AllocHGlobal(totalArraySize));
    
    // Populate the allocated memory with each structure.
    for (var i = 0; i < arrayLength; i++)
    {
        var offset = elementSize * i;
        var elementPointer = IntPtr.Add(pointerToStruct, offset);
        Marshal.StructureToPtr(structureArray[i], elementPointer, false);
    }
    
    return pointerToStruct;
}

@dasMulli dasMulli self-assigned this Jul 24, 2019
@dasMulli dasMulli added the bug label Jul 24, 2019
@dasMulli dasMulli added this to the 1.3.0 milestone Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants