From mint-bounce@lists.fishpool.fi  Sun Nov  6 12:12:08 2005
X-Original-To: fnaumann@mail.boerde.de
Delivered-To: fnaumann@mail.boerde.de
Message-ID: <436DE43C.2010900@obta.uw.edu.pl>
Date: Sun, 06 Nov 2005 12:08:44 +0100
From: Konrad Kokoszkiewicz <draco@obta.uw.edu.pl>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051003)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Miro Kropacek <mikro@hysteria.sk>
Cc: Mint List <mint@fishpool.com>
Subject: Re: [MiNT] strange memory violation
References: <436DD2D2.6090103@hysteria.sk>
In-Reply-To: <436DD2D2.6090103@hysteria.sk>
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit
X-ecartis-version: Ecartis v1.0.0
Sender: mint-bounce@lists.fishpool.fi
Errors-To: mint-bounce@lists.fishpool.fi
X-original-sender: draco@obta.uw.edu.pl
Precedence: bulk
List-help: <mailto:ecartis@lists.fishpool.fi?Subject=help>
List-unsubscribe: <mailto:mint-request@lists.fishpool.fi?Subject=unsubscribe>
List-Id: <mint.lists.fishpool.fi>
X-List-ID: <mint.lists.fishpool.fi>
X-Virus-Scanned: by amavisd-new at relay.boerde.de
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on relay.boerde.de
X-Spam-Status: No, hits=-0.8 tagged_above=-50.5 required=7.0 tests=AWL,
 BAYES_00
X-Spam-Level: 

> after this, Toswin was still active (just desktop.prg was killed, so 
> I've tried it from this)
> memory violation, type: private, PC: 1112c3c, Addr: 1a9a2be, test killed
> 
> after restart, I've tried it from gdb:
> memory violation, type: private, PC: 1c922be, Addr: 1c922be, gdb(!) killed
> memory violation, type: free, PC: 1112c3c, Addr: 18da2be, test killed 
> (yeah, two memory violations at once)
> 
> Could me someone tell, what I'm doing wrong?

You are doing wrong one thing: everything.

You're grabbing an interrupt vector and it points to your program. This is a 
timer interrupt and it occurs asynchronously to task switches, so it occurs even 
when your program does not run (it is waiting for its turn to run). The memory 
that belong to your program is NOT ACCESSIBLE AT THAT TIME. But the timer 
interrupt code tries to access it. So the current process gets bus errors, 
naturally.

First of all, you should never ever make an interrupt vector point to your user 
application. This is unsafe. When the application somehow crashes and exits 
behind your control, its memory becomes invalid, and the next interrupt you had 
grabbed will instantly bring the system down.

Second, you must mark your program Supervisor-protected to avoid bus errors.

Third, MiNT systems will never be stable if such style of programming doesn't 
become exstinct once for good.

KMK


