[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stack and interrupt question



Hi,

I try to be more specific. This is a schematic version of my main procedure

int main(int argc, char *argv[]) {
                  
    /* Variable and devices initialization code */

    switch(task) {
        case 0;
           task 0();
           task++;
           break;
        case 1:
           task1();
           task++;
           break;
    }

    /* free resources used */
}

osnl_tasks.c file contains task0(), task1() and so on. All the tasks are 
basically the same, and involves the use of functions defined in a 
shared library call libosnlsql.so. One of them is
unsigned char update_maxTemp(netsnmp_variable_list *var) {
    unsigned char undo_val[MAXTEMP_LEN], 
oid_file[(strlen(READ_WRITE_DIR) + strlen(MAXTEMP_FICH) + 1)], *sp;
    int undo_len = MAXTEMP_LEN, fich_len;
   
......  /* initialization code */
         
    if (escribe_fichero_texto(oid_file, sp, &fich_len))  {
        if(sp != NULL) {
            free(sp);
        }
        return 5;
    }
    if(sp != NULL) {
        free(sp);
    }

    return 0;
}

The function escribe_fichero_texto is defined in another shared library 
called libiofile.so. This function writes text files using locks. Using 
this structure of files and libraries the arguments passed to 
escribe_fichero_texto just before call it are different that the 
arguments received inside the function. But if I copy the code of 
update_maxTemp function inside task1 function the arguments passed are 
correct. This makes me think about an stack problem, but now I'm not 
sure of it.
Could you find another explanation for this behavior?

Mikael Starvik wrote:

>The stack expands automatically until the memory is exhausted
>so it never gets full. If you get a corrupt stack it is much 
>more likely that your program has a memory overwrite e.g.
>
>char data[100];
>data[100] = 3;
>
>Maybe you can try to explain your problem with some short
>piece of code that repeats the problem?
>
>/Mikael
>
>-----Original Message-----
>From: owner-dev-etrax@xxxxxxx.com">mailto:owner-dev-etrax@xxxxxxx.com] On Behalf
>Of Daniel Fraile Vergel
>Sent: Thursday, September 09, 2004 3:14 PM
>To: dev-etrax
>Subject: Re: Stack and interrupt question
>
>
>
>Mikael, thank you for your quick answer, but if the stack is expanded 
>automatically,  how can I know when the stack is full? And what is the 
>maximum size for the stack?
>
>Mikael Starvik wrote:
>
>  
>
>>The default stack size in user space is 1 page of memory (8KB) but
>>it is expanded automatically when needed.
>>
>>You can't really use interrupts in user space applications. Instead
>>you must have a kernel driver that puts the application to sleep until
>>the interrupt arrives. The application can then use e.g read() or
>>select() to wait for the driver to wake it up.
>>
>>The easiest example I can think of is arch/cris/drivers/sync_serial.c.
>>In sync_serial_read() you'll find a interruptible_sleep_on which
>>will put the application to sleep until the interrupt occurs if
>>it reads in blocking mode. In tr_interrupt() you'll find the
>>corresponding wake_up_interruptible that will wake it up again.
>>
>>/Mikael
>>
>>-----Original Message-----
>>From: owner-dev-etrax@xxxxxxx.com">mailto:owner-dev-etrax@xxxxxxx.com] On Behalf
>>    
>>
>Of Daniel Fraile Vergel
>  
>
>>Sent: Thursday, September 09, 2004 11:10 AM
>>To: dev-etrax
>>Subject: Stack and interrupt question
>>
>>
>>Hi all,
>>I noticed some strange behavior with functions arguments in my software. I
>>    
>>
>think it could be due to a stack problem.
>  
>
>>What is the default stack size? How do I change this size?. I'm using
>>    
>>
>2.4.22 linux version, and Developer Board 82 Release 1.92 tools.
>  
>
>>At the moment my software interact with external devices polling them. I'm
>>    
>>
>planning to change this, and use interrupts instead of polling.
>  
>
>>Unfortunately I don't know much about interruptions in C using the
>>    
>>
>developer board. I really appreciate if someone could me send some basic
>  
>
>>example code or point me to a good tutorial.
>>
>>Thank you
>>
>> 
>>
>>    
>>
>
>  
>

-- 
Daniel Fraile i Vergel
W-onesys, SL
WDM Optical NEtworks SYStems
c/ Francesc Vila Nave 11, Poligon Industrial Can Magi
08190 Sant Cugat del VallÚs (Barcelona) - SPAIN
Tel. + 34 93 590 11 49
fax  + 34 93 590 11 57
www.w-onesys.com