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

Compilation fixes and memory corruption prevention #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Subsentient
Copy link

So this is rolled into one commit, I tried to keep the working tree as clean as possible.

The following is done here:

  • MIT-licensed missing files added to repository from 16.2 SDK package
  • Fixed compile error for Linux driver due to missing stddef.h.
  • Various cleanups of strncpy() usage that could occasionally cause corruption -- strncpy() is terrible, just terrible.

NOTE: Apparently CMake build of the kernel module is still fouled up, looking at the CMakeLists.txt it looks like you're missing the .ko target. So, in the meantime, the Makefile stuff works.

Thanks!

… build, and fix a pile of incorrect strncpy() usage that expects it to behave saner than it actually does.
@Subsentient
Copy link
Author

Should mention that this also fixes a few GCC warnings.

@Subsentient
Copy link
Author

Symlinks are fixed, and I should add that this code is tested as working and makes it possible to build the Linux driver from this repository. :^)

@paulh-aja
Copy link
Contributor

@Subsentient Would you mind splitting your change for the memory corruption into a separate PR so our engineering team can review the proposed changes in isolation from the other changes suggested here? Thanks.

Regarding the missing driver build files, I just pushed a branch I'd been working on this week which addresses this.

With regards to building the kernel module with CMake, that work hadn't been finished yet but is something we do want to provide. I just hadn't gotten to adding the build target for it to the CMakeLists, and testing the resultant module. As it currently exists the ajadriver/CMakeLists.txt was only configured to allow running the cmake --install command, for deployment of the source code to a CMake install directory.

@paulh-aja
Copy link
Contributor

paulh-aja commented Mar 11, 2022

After investigating actually building the kernel module via CMake, it is not as straightforward as it may seem. Kernel module builds use the Kbuild system. Trying to adapt the building of kernel modules to CMake effectively entails calling make as a shell command from CMake, but keeping the existing Kbuild Makefile stuff.

This was all new to me as I'm not the author of the existing AJA NTV2 kernel module, and am learning these details for the first time here.

I found this very basic example which demonstrates this: https://gitlab.com/christophacham/cmake-kernel-module

@Subsentient
Copy link
Author

Sorry for the delay, busy with work for my employer. I can try that if absolutely necessary, but other than the added missing files, I think it should take the engineering team all of 5 minutes to read these commits. As a result, I'm requesting that you merge this anyways. Thanks!

@@ -990,7 +990,7 @@ bool CNTV2DriverInterface::BitstreamStatus (NTV2ULWordVector & outRegValues)
void CNTV2DriverInterface::FinishOpen (void)
{
// HACK! FinishOpen needs frame geometry to determine frame buffer size and number.
NTV2FrameGeometry fg;
NTV2FrameGeometry fg{};

Choose a reason for hiding this comment

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

This initializer won't work if the library is built without C++11 compiler support.

Copy link
Author

Choose a reason for hiding this comment

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

That's true, but I thought new versions of NTV2 were C++11+ only?

Choose a reason for hiding this comment

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

Believe me, we'd love to pull that trigger, but we have a surprising number of customers that are stuck with older hardware and operating systems yet still need to use our newer hardware. In SDK 16.0, we changed to assume (by default) C++11 support, but the library can be built without it (by commenting out the lines defining the NTV2_USE_CPLUSPLUS11 and AJA_USE_CPLUSPLUS11 macros).

Copy link
Contributor

@paulh-aja paulh-aja Apr 29, 2022

Choose a reason for hiding this comment

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

Because of the reason Mr. Bill mentioned, in my own code I have preferred initializing NTV2 enum types to either their equivalent zero-value, or their UNKNOWN or INVALID value, ex:

NTV2FrameGeometry fg = NTV2_FG_1920x1080; // default 0-value for NTV2FrameGeometry
NTV2VideoFormat vf = NTV2_FORMAT_UNKNOWN; // default 0-value for NTV2VideoFormat
NTV2PixelFormat pf = NTV2_FBF_FIRST; // default 0-value for NTV2FrameBufferFormat/NTV2PixelFormat

Copy link
Author

Choose a reason for hiding this comment

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

@mrbillaja Ahh, okay, I understand. That is unfortunate but understandable. In that case you can either do that or for other structs with less well-defined default values, it's often a safe bet to just do struct MyStruct Name = { 0 }; since 0 is also acceptable as an initializer for pointers and floats (though implicitly converted), and the compiler will zero out the rest as long as something is initialized explicitly.

@@ -175,8 +175,10 @@ bool CNTV2Card::LoadDynamicDevice (const NTV2DeviceID inDeviceID)
currentBitfileVersion = 0xff; // ignores bitfile version
}

if (!currentDesignID)
{DDFAIL("Current design ID is zero for " << oldDevName); return false;}

Choose a reason for hiding this comment

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

We need to log failures here.

@@ -244,8 +244,12 @@ NTV2NubPkt * BuildNubBasePacket (NTV2NubProtocolVersion protocolVersion,
pPkt->hdr.dataLength = dataSize;

char *p (reinterpret_cast<char*>(pPkt->data)); // Work around ISO C++ forbids zero-size array
ULWord len (ULWord(::strlen(queryRespStr)) + 1);

Choose a reason for hiding this comment

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

This code module is disappearing in 16.3.

@@ -283,7 +283,7 @@ void ConvertLinetoRGB(UByte * ycbcrBuffer,
bool fUseSDMatrix,
bool fUseSMPTERange)
{
YCbCrAlphaPixel ycbcrPixel;
YCbCrAlphaPixel ycbcrPixel{};

Choose a reason for hiding this comment

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

Willl this initializer work if the library is built without C++11 compiler support?

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.

4 participants