[OFFTOPIC PROGRAMMING QUESTION]: Modules

Michael Ballbach (ballbach@lorien.ml.org)
Wed, 25 Mar 1998 00:08:58 -0700 (MST)


This question isn't purely kernel related, it's a question on
implementing modules. I apologise in advance for the offtopic nature of
this post.
I'm trying to program an application that will dynamically load
modules, in a similair fashion to how the kernel does it. Now, I've
researched the format of elf objects, and I can get a program to load a
procedure from an elf relocatable, and execute it. The only thing I can
get to execute appropriately however are procedures with no function
calls (except local) and no variables. Now, I can understand why this is,
but my question is, how can I merge the procedure into my already running
code? I've read the kernel and insmod souce, and while it has helped, it's
hard for me to seperate what is kernel specific, and what is important in
all cases. So, if some kernel buff who understands modules could write
down a little about how to merge a procedure from an object into an
already running piece of code, I'd appreciate it.
For instance, I have a program that will load the "hello_world"
procedure from a specified object file, and run it. The program also tells
me all sorts of info on the section headers, and other elf stuff. Now,
this procedure calls printf("Hello World"); (I know, I know) anyway, I
used objdump to disassemble it:

00000000 <hello_world>:
0: 68 00 00 00 00 pushl $0x0
5: e8 fc ff ff ff call 6 <hello_world+6>
a: 83 c4 04 addl $0x4,%esp
d: eb 01 jmp 10 <hello_world+10>
f: 90 nop
10: c3 ret

Is the result. A couple of quetions, if I understand the call
correctly, and it really is trying to call whatever is at the address at
+6, how does that corrolate to printf? Also, where does printf get the
string I passed to it, I'm not pushing any addresses to the stack, granted
I'm not too familiar with linux asm calling conventions, and I'm a novice
in the first place, but I see no way that printf is getting the address of
our string. Also, why the add to the stack pointer?
I've racked my brain for days over this, and I can't seem to find
anything on the internet that has anything to do with what I'm trying to
accomplish, so thanks in advance. :)

--------------------------
Michael A. Ballbach: N0ZTQ
ballbach@lorien.ml.org <--- PGP Key Here. (finger)
mikeb@vr1.com
http://ballbach.lorien.ml.org/

"I don't know how world war three will be fought, but world war four will
be fought with sticks and stones." -- Albert Einstein.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu