Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11120 > unrolled thread

Function Interposition for C++ Operator new

Started byAbhi <meetabhi31@gmail.com>
First post2011-10-27 13:40 -0700
Last post2011-10-28 09:46 -0700
Articles 10 — 6 participants

Back to article view | Back to comp.lang.c++


Contents

  Function Interposition for C++ Operator new Abhi <meetabhi31@gmail.com> - 2011-10-27 13:40 -0700
    Re: Function Interposition for C++ Operator new Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2011-10-27 14:35 -0700
    Re: Function Interposition for C++ Operator new Ian Collins <ian-news@hotmail.com> - 2011-10-28 13:31 +1300
      Re: Function Interposition for C++ Operator new Abhi <meetabhi31@gmail.com> - 2011-10-27 22:31 -0700
        Re: Function Interposition for C++ Operator new Ian Collins <ian-news@hotmail.com> - 2011-10-28 19:37 +1300
          Re: Function Interposition for C++ Operator new Marc <marc.glisse@gmail.com> - 2011-10-28 07:33 +0000
            Re: Function Interposition for C++ Operator new 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-28 04:19 -0700
              Re: Function Interposition for C++ Operator new 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-28 06:51 -0700
                Re: Function Interposition for C++ Operator new "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-10-28 16:53 +0200
            Re: Function Interposition for C++ Operator new Abhi <meetabhi31@gmail.com> - 2011-10-28 09:46 -0700

#11120 — Function Interposition for C++ Operator new

FromAbhi <meetabhi31@gmail.com>
Date2011-10-27 13:40 -0700
SubjectFunction Interposition for C++ Operator new
Message-ID<0b17afaa-7349-43d9-848b-cadcfae18888@m5g2000prg.googlegroups.com>
Recently only I was introduced to this very nice concept of Function
Interposition in C. I tried googling it a bit further for C++, but
could not find much info.
Could someone please help me in applying the interposition concept to
replace the calls for new and delete with my own calls.

Thanks.

[toc] | [next] | [standalone]


#11122

FromAnand Hariharan <mailto.anand.hariharan@gmail.com>
Date2011-10-27 14:35 -0700
Message-ID<7dd92f7f-5fa9-428e-bb96-6961be40a252@t38g2000prg.googlegroups.com>
In reply to#11120
On Oct 27, 3:40 pm, Abhi <meetabh...@gmail.com> wrote:
> Recently only I was introduced to this very nice concept of Function
> Interposition in C. I tried googling it a bit further for C++, but
> could not find much info.
> Could someone please help me in applying the interposition concept to
> replace the calls for new and delete with my own calls.
>
> Thanks.

Never heard of "Function Interposition" myself, but "placement new" is
probably what you are looking for.

- Anand

[toc] | [prev] | [next] | [standalone]


#11123

FromIan Collins <ian-news@hotmail.com>
Date2011-10-28 13:31 +1300
Message-ID<9gubfgFlttU1@mid.individual.net>
In reply to#11120
On 10/28/11 09:40 AM, Abhi wrote:
> Recently only I was introduced to this very nice concept of Function
> Interposition in C. I tried googling it a bit further for C++, but
> could not find much info.
> Could someone please help me in applying the interposition concept to
> replace the calls for new and delete with my own calls.

You don't have to resort to interposing for the new and delete 
operators, just provide your own and the language will do the rest!

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#11124

FromAbhi <meetabhi31@gmail.com>
Date2011-10-27 22:31 -0700
Message-ID<e93b8d2d-8a44-498c-b9c4-557973d43c1e@13g2000prp.googlegroups.com>
In reply to#11123
On Oct 28, 5:31 am, Ian Collins <ian-n...@hotmail.com> wrote:
> On10/28/11 09:40 AM, Abhi wrote:
>
> > Recently only I was introduced to this very nice concept of Function
> > Interposition in C. I tried googling it a bit further for C++, but
> > could not find much info.
> > Could someone please help me in applying the interposition concept to
> > replace the calls for new and delete with my own calls.
>
> You don't have to resort to interposing for the new and delete
> operators, just provide your own and the language will do the rest!
>
> --
> Ian Collins


Yes u r correct, overloading new and delete is one option, but that
would
call for recompiling. Interposition however will let me do the same
without recompiling
Reading this, http://www.jayconrod.com/cgi/view_post.py?23
will provide better understanding of the problem

Thanks
Abhishek

[toc] | [prev] | [next] | [standalone]


#11125

FromIan Collins <ian-news@hotmail.com>
Date2011-10-28 19:37 +1300
Message-ID<9gv0u7F4kmU1@mid.individual.net>
In reply to#11124
On 10/28/11 06:31 PM, Abhi wrote:
> On Oct 28, 5:31 am, Ian Collins<ian-n...@hotmail.com>  wrote:
>> On10/28/11 09:40 AM, Abhi wrote:
>>
>>> Recently only I was introduced to this very nice concept of Function
>>> Interposition in C. I tried googling it a bit further for C++, but
>>> could not find much info.
>>> Could someone please help me in applying the interposition concept to
>>> replace the calls for new and delete with my own calls.
>>
>> You don't have to resort to interposing for the new and delete
>> operators, just provide your own and the language will do the rest!
>
> Yes u r correct, overloading new and delete is one option, but that
> would
> call for recompiling. Interposition however will let me do the same
> without recompiling

You still have to compile something!

> Reading this, http://www.jayconrod.com/cgi/view_post.py?23
> will provide better understanding of the problem

As a long time Unix programmer, I am very familiar with function 
interposition.

The same rules apply to C++, but there in an extra layer of complexity 
in the form of name mangling.  In order to interpose a C++ function, you 
have to know it's mangled name.  That name will be compiler specific.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#11126

FromMarc <marc.glisse@gmail.com>
Date2011-10-28 07:33 +0000
Message-ID<j8dlri$50t$1@news-rocq.inria.fr>
In reply to#11125
Ian Collins  wrote:

> The same rules apply to C++, but there in an extra layer of complexity 
> in the form of name mangling.  In order to interpose a C++ function, you 
> have to know it's mangled name.

Do you? The object that you use to interpose will be compiled by a C++
compiler which will be responsible for mangling, as usual. You do have
to be careful to give the function the exact same signature though.

[toc] | [prev] | [next] | [standalone]


#11127

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-10-28 04:19 -0700
Message-ID<5180695.679.1319800760428.JavaMail.geo-discussion-forums@prmv24>
In reply to#11126
I need to use an instance that has a list of methods to be hooked by my users without accessing my source code and deriving new classes. Can someone give some useful advice about the properties in the class I am desired without using the  a function pointer in the old C language?   

[toc] | [prev] | [next] | [standalone]


#11131

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-10-28 06:51 -0700
Message-ID<32543630.2684.1319809875005.JavaMail.geo-discussion-forums@prog16>
In reply to#11127
Bill Gates do know C well in Win 95-98. But I am thinking is the system written in C or C++.

[toc] | [prev] | [next] | [standalone]


#11133

From"Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl>
Date2011-10-28 16:53 +0200
Message-ID<j8eflc$6k3$1@news.albasani.net>
In reply to#11131
"88888 Dihedral"  wrote in message 
news:32543630.2684.1319809875005.JavaMail.geo-discussion-forums@prog16...
>
>Bill Gates do know C well in Win 95-98. But I am thinking is the system 
>written in C or C++.

Is that a question or an observation? Cogito ergo sum?
What is the relation with the subject "Function Interposition for C++ 
Operator new"? 

[toc] | [prev] | [next] | [standalone]


#11135

FromAbhi <meetabhi31@gmail.com>
Date2011-10-28 09:46 -0700
Message-ID<38e2ef2d-5110-44c9-be12-187db4fd11bb@p20g2000prm.googlegroups.com>
In reply to#11126
On Oct 28, 12:33 pm, Marc <marc.gli...@gmail.com> wrote:
> Ian Collins  wrote:
> > The same rules apply to C++, but there in an extra layer of complexity
> > in the form of name mangling.  In order to interpose a C++ function, you
> > have to know it's mangled name.
>
> Do you? The object that you use to interpose will be compiled by a C++
> compiler which will be responsible for mangling, as usual. You do have
> to be careful to give the function the exact same signature though.

Thanks Ian and Mark for your help.
I successfully interposed my implementation of new :)
As suggested correctly, the same rules apply to C++ as well. So what
all i did was -
1. Created a new .cc file and defined my operator new. Compiled this
into a shared object (g++ -ldl -fPIC -shared FakeNew.cc -o
libfakenew.so)
2. set LD_PRELOAD to point to this shared library
3. Executed my old program (no recompiling)
4. All the calls to new now calls my implementation

I was not blocked by name mangling as such, and even if it does play
some role, then we have utilities like nm and c++filt to help us.

Abhishek

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web