delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/10/21:45:27

From: Michele Manzato <aragorn AT dei DOT unipd DOT it>
Newsgroups: comp.os.msdos.djgpp
Subject: Creating and using a protected stack area: how?
Date: Fri, 10 Apr 1998 13:25:02 +0200
Organization: BBS - Universita' di Padova - Italia
Lines: 52
Message-ID: <Pine.GSO.3.93.980410130622.5959A-100000@ogni9>
NNTP-Posting-Host: ogni9.dei.unipd.it
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I am writing a multithreading library for DJGPP, so I have to manage stack
switches from a thread to another thread. Obviously the stacks are private
to the thread and are allocated via malloc(). Stack switching works
very vell... as long as I use DS as SS.

Now I want to have a protected stack for every thread, so I want to set up
a selector for the thread's private stack. This is the code I wrote, I
hope it is self explaining: 

	// stack base is stack_base (long *)
	// stack length is _stackLength (int)
	// stack pointer is stack_pointer (long *)

	unsigned long	baseaddr;
	short		sel;
        int		r;
	unsigned short	SS;
	unsigned long	ESP;
                        
        r = __dpmi_get_segment_base_address(_my_ds(), &baseaddr);
        baseaddr +=  (unsigned long) (stack_base);
        sel = __dpmi_create_alias_descriptor(_my_ds());
        r = __dpmi_set_segment_base_address(sel, baseaddr);
        r = __dpmi_set_segment_limit(sel, _stackLength);
        
        SS = sel;
	ESP = (long *) ((long) stack_pointer - (long) 
                             (stack_base));
        
then when I have to switch the stack I simply copy SS to %ss and ESP to
%esp (with an assembly procedure). No way! Debugging the program I can
see that the stack is OK (it contains what it must) and the program
runs correctly until it finds a 'retf' instruction. Then it returns... to
nowhere, the debugger only shows rubbish. Please note that without using
the new SS:ESP it works fine. I suspect that changing SS influences CS
as well, or at least it influences the way 'retf' works... but I don't
know how.

Can anybody help me? Any suggestion will be greatly appreciated.

	Ciao (bye)

					Michele

-- Michele Manzato -------------------------------------------------------
Home:	via Aldo Moro, 30 - 37066	School:	via dei Savonarola, 176		
	Sommacampagna VR ITALY			PADOVA PD ITALY		
 	Phone no. +45 896 0281			Phone no. +49 871 9777		
e-mail:	aragorn AT resurrection DOT com        WWW:    www.dei.unipd.it/~aragorn
--------------------------------------------------------------------------	

- Raw text -


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