8 bit os_f handles
David J. Ruck
druck at freeuk.com
Tue Mar 28 19:13:12 BST 2000
On Tue 28 Mar, Daniel Ellis wrote:
> If anyone tries using code form the library on a machine with a
> perfectly legal filesystem that allocates filehandles above 255 then
> strange things will occur and they won't have the faintest reason
> why. This will cause lack of confidence in the OS and the software.
Exactly. This problem is can lead to the one of the worse insiduous
errors I've come accross. Not all code sequences will fail with
32 bit handles because of the way the compiler keeps variables in
registers. Take this example using the current OSLib:-
os_f f = osfind_openin(osfind_NO_PATH, info.filename, NULL);
osgbpb_read(f, (byte*)&decomp, sizeof(bits));
osfind_close(f);
This compiles to:-
SUB sp,sp,#4
MOV a3,#0
MOV a1,#3
LDR a2,[v1,#0]
BL osfind_openin
MOV v4,a1
MOV a2,sp
MOV a3,#4
BL osgbpb_read
MOV a1,v4
BL &00009C58
|osfind_openin|
ORR a1,a1,#&40 ; ="@" (64)
SWI OS_Find
MOVS pc,lr
|osgbpb_read|
STMFD sp!,{v1}
MOV a4,a3
MOV a3,a2
MOV a2,a1
MOV a1,#4
SWI OS_GBPB
MOV a1,a4
LDMFD sp!,{v1}
MOVS pc,lr
|osfind_close|
MOV a2,a1
MOV a1,#0
SWI OS_Find
MOVS pc,lr
As you can see because OS_Lib returns values in regsiters and those
regsiters are passed directly to the other filing system functions, the 32bit
file handles are maintained.
BUT if mode code is inserted between osfind_openin() and osgbpb_read(), and
the function block is suffienctly complex to cause the os_f handle to be
backed off on to the automatic varibale storage on the stack (or if it were a
global or part of a stucture) it will be stored and retrieved using byte
instructions, therefor truncating it to 8 bits.
So code which happend to work with 32bit handles can be broken by changing
* non releated code in the same function
* compiler optimisation level / debug options / version
Please belive me you dont want to have to track down these types of problems
with your code - you will not have a clue why certain filing system code
works, others dont, and changing the slightest thing can alter it.
Cheers
---Dave
--
______________________________________________________________________
David J. Ruck Phone: 07974 108301 Email: druck at freeuk.com
______________________________________________________________________
More information about the oslib-user
mailing list