Solved

TSR Guru needed

Posted on 1998-11-13
6
187 Views
Last Modified: 2010-04-15
I have writen a TSR for DOS that displays the current files is use. This is done by traversing the DOS Systems File Table the pointer to which can be retrieved by an INT 21,34 call.
When the Hot Key is detected I need to build my own Stack for the TSR's local variables and functions. Otherwise it will use the foreground program's Stack and the results would be very unpredictable. I achive this with the following code.
1. _asm
2. {
3.    mov ss_register, ss
4.    mov sp_register, sp
5.    mov ax, offset my_stack[499]
6.    mov sp, ax
7.    mov ax, ds
8.    mov ss, ax
9. {
in line 3 & 4 i save the SS and SP in to my own variables. and in line 5 & 6 I move the SP to the top of my newly built Stack (my_stack). My doubt hear is that my_stack is a global variable. Hence I am actually creating this Stack in the Data Segment.
* Firstly is their any problems in doing this??

As to the size of the Stack I allocated 500 bytes taking into account the following local variables and one function which I am using in the code that uses this Stack.
    struct table_tag {
                        struct table_tag * table_previous;
                        struct table_tag * table_next;
                        long int _far * table_sft;
                        int table_sft_entries;
                     };
    typedef struct table_tag * TABLE_POINTER;
    TABLE_POINTER current_table, previous_table,          first_table;
    char * save_screen;
    char page_entry[21];
    long int _far * current_sft;
    char _far * table_sft_file;
    char _far * video_position;
    int no_of_elements, no_of_pages, page_tag_element,         general_counter,general2_counter;
    int table_sft_counter, key_press, key_scan,         element_counter;
/* and the function */
PaintPicture()
{
    int general_counter, general2_counter;
    char _far * video_position;
* Is 500 bytes adequet for these variables and one function??

I am using MS C ver 7. When I call the TSR through the Hotkey, the routine pops us and works fine. But when I exit the routine I get a runtime error "Stack Overflow" and the foreground program terminates to the DOS prompt. I cannot run any more programs thereafter. The COMMAND interpertor gives "Program too big" even for the simple MEM program. When I compile without Code Optimization and without Stack Probes, the program simply hangs along with the OS.

What is wrong in what I am doing? and how could I solve this problem?
Any help would be much apreciated.
0
Comment
Question by:ravipal
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
Did you restore the SS and SP to it's original values (in ss_register and sp_register) when the program finishes?
0
 

Author Comment

by:ravipal
Comment Utility
Hi scrapdog,

Yes I did restore the SS and SP, with the following code.

    _asm
    {
        mov ss, ss_register
        mov sp, sp_register
    }

0
 

Author Comment

by:ravipal
Comment Utility
One more thing I fogot to mension. In side my routine I am building a Link List to link all the individual DOS System File Tables into one. For this I use the runtime function "maclloc".

Could their be any problem in using this function in side my TSR routine ??
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Accepted Solution

by:
laeuchli earned 70 total points
Comment Utility
the site :http://www.fys.ruu.nl/~faber/Amain.html has lots of stuff on tsrs. Take a look.

0
 

Author Comment

by:ravipal
Comment Utility
Hi Scrapdog,

I am still waiting for your response...


0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
Beats me...you probably know more than I do about TSRs!!

I was just checking if you restored SS and SP, because I know if you didn't that would cause problems.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now