Charles,
1.
Your noble British answer (
) doesn't precise that "the
ebx,
ebp and
esp registers should be protected" if and only if their content is modified by the user-coded assembly within that very function. Also, once modified by the user, the
ebx register will not let the user access static data and Oxygen's table of user-declared imported functions until the register state is restored.
So my humble Slavonic assertion (
) would be that Peter's brave German pushad-popad-ing (
) is unnecessary and redundant since neither of these three registers are used and/or modified anywhere in his assembly code. The states of other registers are either protected by Oxygen itself or are simply irrelevant for proper functioning of the language.
2.
(ebx references all static entities)
This reminds me of a couple of other questions I wanted to ask. Here's a typical skeleton listing of a function exported from Peter's sw.dll as seen in
Ida Pro:
0001 public Foo
0002 Foo proc near
0003
0004 push ebx ; Conventional protection of registers
0005 push esi ; - do -
0006 push edi ; - do -
0007 push eax ; What's this for? (see line 0015)
0008
0009 call sub_XXXX ; Oxygen-specific (see line 0022)
0010
0011 push ebp ; Oxygen's sub stack frame prolog
0012 mov ebp, esp ; - do -
XXXX ........................ ; user code
0013 mov esp, ebp ; Oxygen's sub stack frame epilog
0014 pop ebp ; - do -
0015 add esp, 4 ; This effectively discards eax saved on line 0007!
0016 pop edi ; Restore conventionally protected registers
0017 pop esi ; - do -
0018 pop ebx ; - do -
0019 retn N ; N depends on the number and size of sub's actual parameters
0020 Foo endp
0021
0022 sub_XXXX proc near
0023 call $+5 ; Get current EIP value into ebx
0024 pop ebx ; - do -
0025 sub ebx, YYYYY ; Get the address of Oxygen's table of static data and imports into ebx
0026 add ebx, ZZZZZ ; - do -
0027 retn
0028 sub_XXXX endp
Question 0: Why aren't protectable registers preserved within the function stack frame but rather outside of it? Are there any benefits in such a design decision?
Question 1: Why is
eax preserved at all if its value is discarded at least throughout Peter's library (see line 0015)? Are there any cases at all when Oxygen uses this register statically (perhaps for its own purposes)?
Question 2: Why would static data go into the table that's stored in the
.text (i.e. code) section of the binary? This section should be marked READABLE and EXECUTABLE only and should deny writes else the AV software may flag it as suspicious.
3.
Perfect!
Are you going to provide a more BASIC-stylish
param() access to ParamArray too? I realize that your code is perfect for the fastest access to parameters possible. But variadic functions are also very useful in non-time critical scenarios, and that coding style looks too much like good old C or sometimes even C-- (a HLL assembler). I'm thinking about total beginners...