Article View: es.comp.os.linux.programacion
Article #7378Re: about simple checkpointing
From: Pascal Bourguignon
Date: Tue, 04 Mar 2003 23:53
Date: Tue, 04 Mar 2003 23:53
114 lines
4833 bytes
4833 bytes
"karim bernardet" <bernardet.karim@wanadoo.fr> writes:
> > > data_start=(long)&_etext;
> >
> > I may be wrong, but I believe the 'text' is the code of the program,
> > not the data. Memory for the code of the program is usually read-only
> > (because self modifying programs are bad and because it allows sharing
> > the program text between several processes, not to speak of the shared
> > libraries).
> >
> > What about &__data_start or &data_start? (you'd need to rename your
> > local variable).
>
> thanks for your answer !
> according to the book I have, the text zone goes from 0 to _etext, the data
> from _etext to _data and the bss from _data to _end ...
>
> Karim
Right. etext is the end of the text.
The problem is that there is a zone between &_etext and &data_start
that is marked read-only. You can memcpy from _etext to brk() but you
cannot memset the same range. You must first discover the zone that
are write protected and unprotect them.
(I've tried mprotect but this does not seem to work for this range).
...
i=632
i=633
i=634
i=635
ii=1193
[pascal@thalassa tests]$ ls -l data.dat
-rwx------ 1 pascal regular 9740 Mar 5 00:23 data.dat*
[pascal@thalassa tests]$
[pascal@thalassa tests]$ ./checkpointing 1
Recover ...
Restoring Data Section
data start=134517084
data size=9728
HEAP END=134526812
Problem to read data segment nb=-1
read: Bad address
[pascal@thalassa tests]$ gdb ./checkpointing
GNU gdb 20010316
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-suse-linux"...
(gdb) set arg 1
(gdb) break 169
Breakpoint 1 at 0x8048cd2: file checkpointing.c, line 169.
(gdb) run
Starting program: /local/users/pascal/tmp/tests/./checkpointing 1
Recover ...
Restoring Data Section
data start=134517084
data size=9728
HEAP END=134526812
Breakpoint 1, restore_data () at checkpointing.c:169
169 if ((nb=read(f,data_start,data_size))<data_size)
(gdb) x data_start
0x804915c: 0x00000000
(gdb) print data_size
$2 = 9728
(gdb) shell ls -l data.dat
-rwx------ 1 pascal regular 9740 Mar 5 00:23 data.dat
(gdb) next
171 fprintf(stderr,"Problem to read data segment nb=%ld\n",nb);
(gdb) print nb
$3 = -1
(gdb) print errno
$5 = 14
(gdb) print perror("ici")
ici: Bad address
$6 = 17
(gdb) print &_etext
$8 = (<variable (not text or data), no debug info> *) 0x804915c ""
(gdb) x data_start
0x804915c: 0x00000000
(gdb) x sbrk(0)
0x804b75c: 0x00000000
(gdb) print sbrk(0) - data_start
$11 = 9728
(gdb) print memset(data_start,0,data_size)
Program received signal SIGSEGV, Segmentation fault.
0x400b8126 in memset () from /lib/libc.so.6
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (memset) will be abandoned.
(gdb) up
#1 <function called from gdb>
(gdb) up
#2 restore_data () at checkpointing.c:171
171 fprintf(stderr,"Problem to read data segment nb=%ld\n",nb);
(gdb) print memcpy(malloc(data_size),data_start,data_size)
$12 = 1073836032
(gdb)
--
__Pascal_Bourguignon__ http://www.informatimago.com/
----------------------------------------------------------------------
There is a fault in reality. Do not adjust your minds. -- Salman Rushdie
Technical Details
Message-ID:
<87bs0q7kpn.fsf@thalassa.informatimago.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!easynet-quince!easynet.net!feed.news.nacamar.de!fu-berlin.de!uni-berlin.de!213.220.35.225!not-for-mailReferences:
<b3j7li$813$1@news-reader11.wanadoo.fr> <87adgicyid.fsf@thalassa.informatimago.com> <b3ljrv$1vn$1@news-reader12.wanadoo.fr>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f86c8,1f98dfe213fdbb12 X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2003-03-04 15:53:34 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!easynet-quince!easynet.net!feed.news.nacamar.de!fu-berlin.de!uni-berlin.de!213.220.35.225!not-for-mail From: Pascal Bourguignon <pjb@informatimago.com> Newsgroups: es.comp.os.linux.programacion Subject: Re: about simple checkpointing Date: 05 Mar 2003 00:53:08 +0100 Organization: informatimago.com Lines: 114 Sender: pascal@thalassa.informatimago.com Message-ID: <87bs0q7kpn.fsf@thalassa.informatimago.com> References: <b3j7li$813$1@news-reader11.wanadoo.fr> <87adgicyid.fsf@thalassa.informatimago.com> <b3ljrv$1vn$1@news-reader12.wanadoo.fr> NNTP-Posting-Host: 213.220.35.225 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: fu-berlin.de 1046822012 62460187 213.220.35.225 (16 [41911]) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50