Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


'new' mess

AlbertAlbert Member - All Emails Posts: 442

We have a 3P static kernel library (no sources) where they have denied a global 'new' and 'delete'.
Our driver code is in C++ and we have had to define 'new' and 'delete' as well. We cant use theirs as they have other propitiatory memory management/tracking logic inside their new/del.

How does one go about on how to fix such scenarios?

Comments

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,605

    I don't know what you mean by "they have denied a global 'new' and 'delete'." It's very easy to define your own operator new and delete that calls ExAllocatePoolWithTag. Until VS2015, Microsoft provided a very adequate implementation in <stdunk.h>, but they decided that was too dangerous for us poor programmers to handle. You can copy their implementation into your driver.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • AlbertAlbert Member - All Emails Posts: 442

    God almighty what a typo, I meant they have 'defined' not 'denied. So what I wrote was:

    We have a 3P static kernel library (no sources) where they have defnied a global 'new' and 'delete'.
    Our driver code is in C++ and we have had to define 'new' and 'delete' as well. We cant use theirs as they have other propitiatory memory management/tracking logic inside their new/del.

    How does one go about on how to fix such scenarios?

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,519
    1 Move all of your code to a namespace, scope your global new/delete to that namespace.
    2 if you have a class hierarchy, add the operators to the base class
    3 add the operators to each class (you could get fancy, or lazy depending on your POV, by creating a macro to do define them to make your life simpler in the short run as a part of the experiment)
    d
  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 259

    @Doron_Holan said:
    3 add the operators to each class

    I always define new/delete for each class. That way it is much easier to debug since instances of each class allocated with it's own tag.

  • AlbertAlbert Member - All Emails Posts: 442

    @Doron_Holan said:
    1 Move all of your code to a namespace, scope your global new/delete to that namespace.
    2 if you have a class hierarchy, add the operators to the base class
    3 add the operators to each class (you could get fancy, or lazy depending on your POV, by creating a macro to do define them to make your life simpler in the short run as a part of the experiment)

    @Doron_Holan #2 and #3 are already done, but #1 will break a lot of our code as then we have to move everything inside namespaced. Simple int x = new (int) wont work any more.

    @Sergey_Pisarev said:

    @Doron_Holan said:
    3 add the operators to each class

    I always define new/delete for each class. That way it is much easier to debug since instances of each class allocated with it's own tag.

    @Sergey_Pisarev If you can also pass in the tag as part of new

  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 259

    @Sergey_Pisarev If you can also pass in the tag as part of new

    sure.
    it won't look as pretty though :)

  • MBond2MBond2 Member Posts: 184

    I seldom use C++, but I believe the changes would be limited to 1 line per compilation unit unless you need to mix calls to allocators within a single class. Even if you had to adjust each call, find / replace can do that for you expiditiously

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Internals & Software Drivers 30 Nov 2020 LIVE ONLINE
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Developing Minifilters Early 2021 LIVE ONLINE