Sponsored Content
Full Discussion: C function call dynamically
Top Forums Programming C function call dynamically Post 302379391 by DreamWarrior on Thursday 10th of December 2009 02:57:07 PM
Old 12-10-2009
Quote:
Originally Posted by Corona688
Only unoptimized. Optimization can cause unpredictable things -- I've seen gcc do weird things like stuff floating-point doubles into SSE registers when calling fprintf.
Odd...how would fprintf know where to pick them up if not from the stack....?

---------- Post updated at 03:57 PM ---------- Previous update was at 03:52 PM ----------

Quote:
Originally Posted by jim mcnamara
Dream Warrior - consider trampolines or indirect function calls found most often in callbacks. I think python uses trampolines to support coroutines. ghostdog would know for sure.

Linux trampoline code is described in great detail in: 'Understanding the Linux Kernel' by Daniel P. Bovet and Marco Cesati.

gcc documentation:
Trampolines - GNU Compiler Collection (GCC) Internals



The lazy man's version -
A trampoline is small code segment, usually a vector, created at run time. It normally lives on the stack, in the stack frame of the 'holding' function.

For mixing pieces of code with incompatible calling conventions, trampolines can convert the caller's convention to the callee's convention. For example, C code that needs to call C++ objects can have a trampoline to change calling conventions.

gcc implements trampolines as nested functions.
I'm unsure how this could be used to dynamically figure out the arguments of another function and populate the call stack and call it.... And the man page you posted is above my head Smilie.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

function call

can I call a function in bash script just as in C++ while do function() done function() thanks, Steffen (3 Replies)
Discussion started by: forever_49ers
3 Replies

2. Programming

Help with a function call

Hi, Can anyone help me figure out the problem I'm having with a function call? I have a header file, which sets an enum: typedef enum {INFO, WARNING, FATAL} Levels; int log_event (Levels, char *fmt, ...); ..then the function is called this way: log_event(INFO, "Message text"); ... (6 Replies)
Discussion started by: Stevhp
6 Replies

3. Shell Programming and Scripting

call function

I have a function check_ok in my abc.sh. which return me 1 or 0 . I want to call this fuction through other shell script. this shell also send two parameter to calling function. Can you please tell me how. I am very new in unix. #!/bin/bash date_equal() { sqlplus -silent... (4 Replies)
Discussion started by: Jamil Qadir
4 Replies

4. Shell Programming and Scripting

help on function call

hello, when i call function inside awk traitement it doesn't work, i don't have error execution but i don't get result and if i call the function outside awk traitement it work well.. there's something special in awk call function?? here is the example : awk -F "," '{ {first=$1; sec=$2;... (3 Replies)
Discussion started by: kamel.seg
3 Replies

5. Shell Programming and Scripting

Function Call

How we can start a process if doesn't exists before? (1 Reply)
Discussion started by: Zaxon
1 Replies

6. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

7. Shell Programming and Scripting

Function call

Hi foiks i am unable to find what is wrong in my code mu functionality is to exit from shell when i give 99 but it is not calling function ext Could you please correct me. read option if ; then ext else echo "out" fi function ext { echo "tested 99 and exit... (12 Replies)
Discussion started by: kojo
12 Replies

8. Shell Programming and Scripting

After exit from function it should not call other function

Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this? iNOUT i AM GIVING TO THE... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

9. Shell Programming and Scripting

How to dynamically name as function in shell?

Hi all, Does anyone know if it possible to append a parameter to a function name? Something like the following: function tnsrec_${SERVICE_NAME} { code.. } Any ideas? (6 Replies)
Discussion started by: jonnyd
6 Replies

10. Homework & Coursework Questions

How to Dynamically Pass Parameter to plsql Function & Capture its Output Value in a Shell Variable?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms: #! /bin/ksh v="ORG_ID" ... (2 Replies)
Discussion started by: sujitdas2104
2 Replies
SIGRETURN(2)						     Linux Programmer's Manual						      SIGRETURN(2)

NAME
sigreturn, rt_sigreturn - return from signal handler and cleanup stack frame SYNOPSIS
int sigreturn(...); DESCRIPTION
If the Linux kernel determines that an unblocked signal is pending for a process, then, at the next transition back to user mode in that process (e.g., upon return from a system call or when the process is rescheduled onto the CPU), it creates a new frame on the user-space stack where it saves various pieces of process context (processor status word, registers, signal mask, and signal stack settings). The kernel also arranges that, during the transition back to user mode, the signal handler is called, and that, upon return from the han- dler, control passes to a piece of user-space code commonly called the "signal trampoline". The signal trampoline code in turn calls sigreturn(). This sigreturn() call undoes everything that was done--changing the process's signal mask, switching signal stacks (see sigaltstack(2))--in order to invoke the signal handler. Using the information that was earlier saved on the user-space stack sigreturn() restores the process's signal mask, switches stacks, and restores the process's context (processor flags and registers, including the stack pointer and instruction pointer), so that the process resumes execution at the point where it was interrupted by the signal. RETURN VALUE
sigreturn() never returns. CONFORMING TO
Many UNIX-type systems have a sigreturn() system call or near equivalent. However, this call is not specified in POSIX, and details of its behavior vary across systems. NOTES
sigreturn() exists only to allow the implementation of signal handlers. It should never be called directly. (Indeed, a simple sigreturn() wrapper in the GNU C library simply returns -1, with errno set to ENOSYS.) Details of the arguments (if any) passed to sigreturn() vary depending on the architecture. (On some architectures, such as x86-64, sigreturn() takes no arguments, since all of the information that it requires is available in the stack frame that was previously created by the kernel on the user-space stack.) Once upon a time, UNIX systems placed the signal trampoline code onto the user stack. Nowadays, pages of the user stack are protected so as to disallow code execution. Thus, on contemporary Linux systems, depending on the architecture, the signal trampoline code lives either in the vdso(7) or in the C library. In the latter case, the C library's sigaction(2) wrapper function informs the kernel of the location of the trampoline code by placing its address in the sa_restorer field of the sigaction structure, and sets the SA_RESTORER flag in the sa_flags field. The saved process context information is placed in a ucontext_t structure (see <sys/ucontext.h>). That structure is visible within the signal handler as the third argument of a handler established via sigaction(2) with the SA_SIGINFO flag. On some other UNIX systems, the operation of the signal trampoline differs a little. In particular, on some systems, upon transitioning back to user mode, the kernel passes control to the trampoline (rather than the signal handler), and the trampoline code calls the signal handler (and then calls sigreturn() once the handler returns). C library/kernel differences The original Linux system call was named sigreturn(). However, with the addition of real-time signals in Linux 2.2, a new system call, rt_sigreturn() was added to support an enlarged sigset_t type. The GNU C library hides these details from us, transparently employing rt_sigreturn() when the kernel provides it. SEE ALSO
kill(2), restart_syscall(2), sigaltstack(2), signal(2), getcontext(3), signal(7), vdso(7) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-09-15 SIGRETURN(2)
All times are GMT -4. The time now is 12:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy