About <tuple> from msvc stl in driver

Hello everyone!
It is very necessary to use a tuple in the driver, the choice fell on msvc stl, but when connecting the file to the project, an error occurs:
**“_HAS_EXCEPTIONS == 0 is not supported.” **
This is defined in the Windows Kits\10\Include\10.0.19041.0\km\crt\xstddef file
Maybe someone will help me understand why such a condition is there and whether it is possible to somehow use , I really need it!

very necessary to use a tuple

It might be very convenient but it is never very necessary to use a tuple. If it was, then it would have been in the C Language standard.

I really need it

Just program around it. It’ll take you less time than it took you to post this query.

I “need” a lot of things: I need to lose 20 pounds, and I need a month long sea-side vacation on an island in the Caribbean. Doesn’t mean I’m going to get any of those soon. Just gotta embrace life and get on with it.

Peter

2 Likes

Anything that can be done with a tuple can also be done with a custom struct.

As for “why”, the Microsoft compiler implements exceptions by using special locations in process memory that do not exist in the kernel.

1 Like

@Tim_Roberts said:
Anything that can be done with a tuple can also be done with a custom struct.

As for “why”, the Microsoft compiler implements exceptions by using special locations in process memory that do not exist in the kernel.

Could this means that C++ templates in the kernel cannot be used? or in very limited circumstances?

/rolls eyes

1 Like

Could this means that C++ templates in the kernel cannot be used? or in very limited circumstances?

What makes you think that templates and exceptions are related in any way?

1 Like

There do exist versions of STL that do not use exceptions, and those version do work in the kernel. That does mean they aren’t standard-compliant, which brings up trust issues. I would never switch to a custom STL just to get support for tuples, which are easily implemented at structus.

On the other hand, if you look at the source, the Visual C++ version of tuple does not appear to throw any exceptions. If you were really desperate, you could probably isolate it yourself.

1 Like

Templates are a compiler feature, and the MSVC for kernel drivers supports it.
You can simply do a template <typename T1, typename T2> struct Tuple { T1 v1; T2 v2; }; if you really need something that looks like a tuple… althought you don’t need tuples in any way…

You’re writing a driver for an operating system, you’re sort of a “part” of the OS. You’re the one providing feature to the softwares running in usermode (or even other drivers, for that matter). You should be able to write a kernel component/driver without needing any libraries or extensions. So please.

1 Like

You’re writing a driver for an operating system, you’re sort of a “part” of the OS.

This.

And, just to put a finer point on this, you’re not “sort of a part of the OS” – You ARE part of the OS.

In Windows, a driver is an operating system extension created using the interface provided by the I/O Manager. Full stop.

Peter

Thnx guys, osr - the best professional resource!

@Alex_Funky said:
Hello everyone!
It is very necessary to use a tuple in the driver, the choice fell on msvc stl, but when connecting the file to the project, an error occurs:
**“_HAS_EXCEPTIONS == 0 is not supported.” **
This is defined in the Windows Kits\10\Include\10.0.19041.0\km\crt\xstddef file
Maybe someone will help me understand why such a condition is there and whether it is possible to somehow use , I really need it!

In case this is still relevant, try adding $(VC_IncludePath) to the “Include Directories” setting in project properties.

Your first post, and:

a) It’s a necropost… which is not allowed

b) It’s not actually helpful. If you read the thread, you’ll see the issue is that standard C++ exceptions aren’t allowed in kernel-mode… that’s the root of the issue.

Peter

@“Peter_Viscarola_(OSR)” said:
Your first post, and:

a) It’s a necropost… which is not allowed

b) It’s not actually helpful. If you read the thread, you’ll see the issue is that standard C++ exceptions aren’t allowed in kernel-mode… that’s the root of the issue.

Peter

Hello Peter!

Thank you for your explanation! I’m really sorry for breaking the rules, I’m just a newbie here, so I’m not sure I fully catch what means “necropost”…

With regards to the compilation issue itself, I think the root of the issue is not related to the exceptions. Indeed there is a compilation error related to the _HAS_EXCEPTIONS switch (although this is not the only compilation problem for such case). However I think the real problem is lack of includes in the driver project. If you specify valid Include Path, you will be able to compile and use tuple, as well as most of the STL classes, within the driver project. In general I agree STL in kernel-mode (which does not allow C++ exceptions but still handles SEH) is a long discussion and reliability of this approach is probably out of scope for this thread.

I’m not sure I fully catch what means “necropost”

Google is your friend.

I think the root of the issue is not related to the exceptions

I’m sorry, but you are wrong.

You cannot use any C++ feature, from the STL or otherwise, that can raise an exception. This won’t work in kernel-mode. That is the problem. It simply isn’t allowed and does not work.

I am locking this thread now, because the OP’s question was answered, back in February 2021… about a year ago.

Peter