delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/08/16/08:13:49

Date: Wed, 16 Aug 2000 15:16:10 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: r_maj AT poczta DOT onet DOT pl
Message-Id: <2950-Wed16Aug2000151610+0300-eliz@is.elta.co.il>
X-Mailer: Emacs 20.6 (via feedmail 8.2.emacs20_6 I) and Blat ver 1.8.5b
CC: djgpp AT delorie DOT com
In-reply-to: <8ndkeb$lt8$5@info.cyf-kr.edu.pl> (r_maj@poczta.onet.pl)
Subject: Re: calling functions
References: <8ndkeb$lt8$5 AT info DOT cyf-kr DOT edu DOT pl>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: "Rafal Maj" <r_maj AT poczta DOT onet DOT pl>
> Newsgroups: comp.os.msdos.djgpp
> Date: Wed, 16 Aug 2000 10:44:44 +0200
> 
>   long int size = ((long int)(void*)fun_end) - ((long int)(void*)fun);
>   char *ptr = new char[size];
>   memcpy(ptr,(void*)fun,size);
> 
>   void (*function_ptr)() = (void (*)()) ptr;
> 
>   (*function_ptr)();  // <------ CALL of function copy

This is not supposed to work.  You are in protected mode, where code
and data have different protection bits.  In particularly, you are
forbidden from calling code that sits in a data buffer.  This happens
because data and code are accessed using different selectors with
different access rights.

Why would you want to do anything crazy like that, anyway?

The fact that your first program works is pure coincidence, due to the
peculiar memory layout of DJGPP program.  This is too complicated to
explain; if you really want to dig into this, I suggest a good book
about x86 protected-mode programming, or the relevant parts of the
Intel Pentium manuals.

> So, can You send me working example, how to call copy of functions ?
> I know it's possible, because Allegro is using stuf like this.

Copy the code from Allegro more faithfully, and it will work for you
as well.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019