Re: exporting global variables from dynamically linked libraries
From: Tauno Voipio (tauno.voipio_at_iki.fi.NOSPAM.invalid)
Date: 08/15/03
- Next message: Tauno Voipio: "Re: no file if_ether.h.."
- Previous message: Pierre Asselin: "Re: newbie here, best c++ gui for linux.."
- In reply to: David Schwartz: "Re: exporting global variables from dynamically linked libraries"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 15 Aug 2003 07:08:41 GMT
"David Schwartz" <davids@webmaster.com> wrote in message
news:bgs23s$6e6$1@nntp.webmaster.com...
>
> "VBDis" <vbdis@aol.com> wrote in message
> news:20030806062302.21428.00001534@mb-m23.aol.com...
>
> > Im Artikel <vitcpm4pr7jt9b@corp.supernews.com>, Boris Bak
> <boris.bak@ni.com>
> > schreibt:
>
> > >The problem I experience is somehow the application has defined its own
> > >copy of those variables.
>
> > This IMO is the defined behaviour of DLLs, at least in Windows. The code
> (CS)
> > is shareable, but the data (DS) are private to the processes.
>
> First of all, this statement is misleading. The code is *NOT* shared
and
> more than the data is. If you don't believe me, modify the code in one
> process that's using the DLL and see if the other process sees the
> modification.
1. The executable pages are not writable to the process having them
executable, unless there is an alias mapping in the hardware (hardware
limitation). You cannot modify the running code. If the code modification
succeeds (with a debugger), you are not seeing the same memory anymore, it's
the COW (copy on write) in action.
2. Although the code is in common memory, it may be mapped to different
linear addresses at each process using it. This is the reason why the shared
libraries have to be position-independent code.
3. If you're after shared memory (like the DLL memory in 16-bit Windows
DLL's, but not in 32-bit DLL's) you need to use different techniques. Google
for Linux shared memory (e.g. <http://fscked.org/writings/SHM/shm.html>).
For a more detailed treatment, see:
W. Richard Stevens, Advanced Programming in the UNIX Environment.
> Both the code and data segments are mapped the same way. They start
out
> as seen in the file and each process' modifications are private.
The data is mapped so that COW creates separate pages per process as soon as
they are written into. This does not normally apply to code.
HTH
Tauno Voipio
tauno voipio @ iki fi
- Next message: Tauno Voipio: "Re: no file if_ether.h.."
- Previous message: Pierre Asselin: "Re: newbie here, best c++ gui for linux.."
- In reply to: David Schwartz: "Re: exporting global variables from dynamically linked libraries"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|