Author: hbelusca
Date: Sun Dec 27 02:01:52 2015
New Revision: 70434
URL: http://svn.reactos.org/svn/reactos?rev=70434&view=rev
Log:
[VFATLIB]
It seems suspicious to directly return the value of fs_close as the NTSTATUS code of the check-disk operation (for FAT32 volumes it happens to return 1 whereas for FAT16 volumes it returns 0).
The documentation of this function says that it "returns a non-zero integer if the file system has been changed since the last fs_open, zero otherwise."
Maybe somebody has a more precise idea on that subject? In the meantime I also add some DPRINTs to attempt to diagnose the conditions where this problem occurs.
Modified:
trunk/reactos/lib/fslib/vfatlib/vfatlib.c
Modified: trunk/reactos/lib/fslib/vfatlib/vfatlib.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fslib/vfatlib/vfatlib.…
==============================================================================
--- trunk/reactos/lib/fslib/vfatlib/vfatlib.c [iso-8859-1] (original)
+++ trunk/reactos/lib/fslib/vfatlib/vfatlib.c [iso-8859-1] Sun Dec 27 02:01:52 2015
@@ -351,6 +351,7 @@
BOOLEAN salvage_files;
ULONG free_clusters;
DOS_FS fs;
+ int ret;
/* Store callback pointer */
ChkdskCallback = Callback;
@@ -372,7 +373,11 @@
if (CheckOnlyIfDirty && !fs_isdirty())
{
/* No need to check FS */
- return fs_close(FALSE);
+ // NOTE: Returning the value of fs_close looks suspicious.
+ // return fs_close(FALSE);
+ ret = fs_close(FALSE);
+ DPRINT1("No need to check FS; fs_close returning %d\n", ret);
+ return STATUS_SUCCESS;
}
read_boot(&fs);
@@ -404,6 +409,8 @@
if (fs_changed())
{
+ DPRINT1("fs_changed is TRUE!\n");
+
if (FixErrors)
{
if (FsCheckFlags & FSCHECK_INTERACTIVE)
@@ -430,7 +437,11 @@
}
/* Close the volume */
- return fs_close(FixErrors) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
+ // NOTE: Returning the value of fs_close looks suspicious.
+ // return fs_close(FixErrors) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
+ res = fs_close(FixErrors);
+ DPRINT1("fs_close returning %d\n", ret);
+ return STATUS_SUCCESS;
}
/* EOF */
Author: hbelusca
Date: Sat Dec 26 21:28:01 2015
New Revision: 70432
URL: http://svn.reactos.org/svn/reactos?rev=70432&view=rev
Log:
[BOOTSECTORS]
- fat.asm: remove trailing whitespace.
- fat32.asm: backport the fixes from fat32.S introduced a long time ago.
- fat32.S/faty.S: use .space 12, 0 instead of the long .byte array (generates the same code, but is better readable).
- isoboot/btrt: whitespace fix only.
Modified:
trunk/reactos/boot/freeldr/bootsect/fat.asm
trunk/reactos/boot/freeldr/bootsect/fat32.S
trunk/reactos/boot/freeldr/bootsect/fat32.asm
trunk/reactos/boot/freeldr/bootsect/faty.S
trunk/reactos/boot/freeldr/bootsect/isoboot.asm
trunk/reactos/boot/freeldr/bootsect/isobtrt.asm
Modified: trunk/reactos/boot/freeldr/bootsect/fat.asm
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/fat.…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/fat.asm [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/fat.asm [iso-8859-1] Sat Dec 26 21:28:01 2015
@@ -133,8 +133,8 @@
xor cx,cx
mov al,[BYTE bp+NumberOfFats] ; Number of fats
mul WORD [BYTE bp+SectorsPerFat] ; Times sectors per fat
- add ax,WORD [BYTE bp+HiddenSectors]
- adc dx,WORD [BYTE bp+HiddenSectors+2] ; Add the number of hidden sectors
+ add ax,WORD [BYTE bp+HiddenSectors]
+ adc dx,WORD [BYTE bp+HiddenSectors+2] ; Add the number of hidden sectors
add ax,WORD [BYTE bp+ReservedSectors] ; Add the number of reserved sectors
adc dx,cx ; Add carry bit
mov WORD [BYTE bp-DataAreaStartLow],ax ; Save the starting sector of the root directory
@@ -225,7 +225,7 @@
Reboot:
; mov si,msgAnyKey ; Press any key message
; call PutChars ; Display it
- xor ax,ax
+ xor ax,ax
int 16h ; Wait for a keypress
int 19h ; Reboot
@@ -270,7 +270,7 @@
; DX:AX has logical sector number to read
; CX has number of sectors to read
ReadSectors:
-
+
; We can't just check if the start sector is
; in the BIOS CHS range. We have to check if
; the start sector + length is in that range.
@@ -314,8 +314,8 @@
; jz PrintDiskError ; Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported
- ; Good, we're here so the computer supports LBA disk access
- ; So finish the extended read
+ ; Good, we're here so the computer supports LBA disk access
+ ; So finish the extended read
mov dl,[BYTE bp+BootDrive] ; Drive number
mov ah,42h ; Int 13h, AH = 42h - Extended Read
int 13h ; Call BIOS
@@ -333,10 +333,10 @@
add bx,byte 20h ; Increment read buffer for next sector
mov es,bx
pop bx
-
+
loop ReadSectorsLBALoop ; Read next sector
- ret
+ ret
; Reads logical sectors into [ES:BX]
@@ -351,7 +351,7 @@
xchg ax,dx
xor dx,dx
div WORD [BYTE bp+SectorsPerTrack]
- xchg ax,cx
+ xchg ax,cx
div WORD [BYTE bp+SectorsPerTrack] ; Divide logical by SectorsPerTrack
inc dx ; Sectors numbering starts at 1 not 0
xchg cx,dx
@@ -385,7 +385,7 @@
; Increment read buffer for next sector
loop ReadSectorsCHSLoop ; Read next sector
- ret
+ ret
msgDiskError db 'Disk error',0dh,0ah,0
Modified: trunk/reactos/boot/freeldr/bootsect/fat32.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/fat3…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/fat32.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/fat32.S [iso-8859-1] Sat Dec 26 21:28:01 2015
@@ -62,9 +62,9 @@
BackupBootSector:
.word 6
Reserved1:
- .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-
+ .space 12, 0
// End FAT32 Inserted Info
+
BootDrive:
.byte 0
Reserved:
@@ -355,8 +355,8 @@
jmp PrintFileNotFound
FindFile:
- mov ax, es // We didn't find it in the previous dir entry
- add ax, 2 // So lets move to the next one
+ mov ax, es // We didn't find it in the previous dir entry
+ add ax, 2 // So lets move to the next one
mov es, ax // And search again
xor di, di
mov si, offset filename
Modified: trunk/reactos/boot/freeldr/bootsect/fat32.asm
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/fat3…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/fat32.asm [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/fat32.asm [iso-8859-1] Sat Dec 26 21:28:01 2015
@@ -108,7 +108,7 @@
; First we have to load our extra boot code at
; sector 14 into memory at [0000:7e00h]
mov eax,0eh
- add eax,DWORD [BYTE bp+HiddenSectors] ; Add the number of hidden sectors
+ add eax,DWORD [BYTE bp+HiddenSectors] ; Add the number of hidden sectors
mov cx,1
xor bx,bx
mov es,bx ; Read sector to [0000:7e00h]
@@ -122,6 +122,7 @@
; EAX has logical sector number to read
; CX has number of sectors to read
ReadSectors:
+ push es
cmp eax,DWORD [BiosCHSDriveSize] ; Check if they are reading a sector outside CHS range
jae ReadSectorsLBA ; Yes - go to the LBA routine
; If at all possible we want to use LBA routines because
@@ -181,6 +182,7 @@
sub cx,[LBASectorsRead]
jnz ReadSectorsLBA ; Read next sector
+ pop es
ret
LBASectorsRead:
@@ -227,7 +229,7 @@
loop ReadSectorsCHSLoop ; Read next sector
- ret
+ ret
@@ -249,7 +251,7 @@
Reboot:
mov si,msgAnyKey ; Press any key message
call PutChars ; Display it
- xor ax,ax
+ xor ax,ax
int 16h ; Wait for a keypress
int 19h ; Reboot
@@ -279,7 +281,7 @@
BootSignature:
dw 0aa55h ; BootSector signature
-
+
; End of bootsector
;
@@ -326,7 +328,7 @@
add ax,2 ; So lets move to the next one
mov es,ax ; And search again
xor di,di
- mov si,filename
+ mov si,filename
mov cx,11
rep cmpsb ; Compare filenames
jz FoundFile ; If same we found it
@@ -340,7 +342,6 @@
jmp StartSearch
FoundFile:
-
; Display "Loading FreeLoader..." message
mov si,msgLoading ; Loading message
call PutChars ; Display it
@@ -437,21 +438,21 @@
LoadFatSector:
push ecx
+
+ mov bx, 9000h ; We will load it to [9000:0000h]
+ mov es, bx
+
; EAX holds logical FAT sector number
; Check if we have already loaded it
cmp eax,DWORD [FatSectorInCache]
je LoadFatSectorAlreadyLoaded
mov DWORD [FatSectorInCache],eax
- mov bx,9000h
- mov es,bx
- xor bx,bx ; We will load it to [9000:0000h]
+ xor bx,bx
mov cx,1
call ReadSectors
LoadFatSectorAlreadyLoaded:
- mov bx,9000h
- mov es,bx
pop ecx
mov eax,DWORD [es:ecx] ; Get FAT entry
and eax,0fffffffh ; Mask off reserved bits
Modified: trunk/reactos/boot/freeldr/bootsect/faty.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/faty…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/faty.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/faty.S [iso-8859-1] Sat Dec 26 21:28:01 2015
@@ -112,7 +112,7 @@
BackupBootSector:
.word 6
Reserved1:
- .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ .space 12, 0
#endif // FAT32
BootDrive:
Modified: trunk/reactos/boot/freeldr/bootsect/isoboot.asm
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/isob…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/isoboot.asm [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/isoboot.asm [iso-8859-1] Sat Dec 26 21:28:01 2015
@@ -14,7 +14,7 @@
; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
; USA; either version 2 of the License, or (at your option) any later
; version; incorporated herein by reference.
-;
+;
; ****************************************************************************
;
; THIS FILE IS A MODIFIED VERSION OF ISOLINUX.ASM
@@ -158,7 +158,7 @@
mov byte [TimeoutCount], 5
.next_second:
mov eax, [BIOS_timer] ; load current tick counter
- add eax, 19 ;
+ add eax, 19 ;
.poll_again:
call pollchar_and_empty
Modified: trunk/reactos/boot/freeldr/bootsect/isobtrt.asm
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/isob…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/isobtrt.asm [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/isobtrt.asm [iso-8859-1] Sat Dec 26 21:28:01 2015
@@ -14,7 +14,7 @@
; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
; USA; either version 2 of the License, or (at your option) any later
; version; incorporated herein by reference.
-;
+;
; ****************************************************************************
;
; THIS FILE IS A MODIFIED VERSION OF ISOLINUX.ASM
Author: hbelusca
Date: Sat Dec 26 20:43:50 2015
New Revision: 70431
URL: http://svn.reactos.org/svn/reactos?rev=70431&view=rev
Log:
[BOOTSECTORS]: Sync the .asm files with their .S counterparts (make easier for diff'ing).
Modified:
trunk/reactos/boot/freeldr/bootsect/fat.S
trunk/reactos/boot/freeldr/bootsect/fat.asm
trunk/reactos/boot/freeldr/bootsect/fat32.S
trunk/reactos/boot/freeldr/bootsect/fat32.asm
trunk/reactos/boot/freeldr/bootsect/isoboot.asm
trunk/reactos/boot/freeldr/bootsect/isobtrt.asm
Modified: trunk/reactos/boot/freeldr/bootsect/fat.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/fat.…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/fat.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/fat.S [iso-8859-1] Sat Dec 26 20:43:50 2015
@@ -29,7 +29,7 @@
// of the PutChars function in the boot sector.
//
// When it locates freeldr.sys on the disk it will
-// load the first sector of the file to 0000:8000
+// load the first sector of the file to 0000:F800
// With the help of this sector we should be able
// to load the entire file off the disk, no matter
// how fragmented it is.
Modified: trunk/reactos/boot/freeldr/bootsect/fat.asm
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/fat.…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/fat.asm [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/fat.asm [iso-8859-1] Sat Dec 26 20:43:50 2015
@@ -29,7 +29,7 @@
; of the PutChars function in the boot sector.
;
; When it locates freeldr.sys on the disk it will
-; load the first sector of the file to 0000:8000
+; load the first sector of the file to 0000:F800
; With the help of this sector we should be able
; to load the entire file off the disk, no matter
; how fragmented it is.
@@ -187,12 +187,12 @@
FoundFreeLoader:
; We found freeldr.sys on the disk
; so we need to load the first 512
- ; bytes of it to 0000:8000
+ ; bytes of it to 0000:F800
; ES:DI has dir entry (ES:DI == 07E0:XXXX)
mov ax,WORD [es:di+1ah] ; Get start cluster
push ax ; Save start cluster
- push WORD 800h ; Put 800h on the stack and load it
- pop es ; Into ES so that we load the cluster at 0000:8000
+ push WORD 0F80h ; FREELDR_BASE / 16 ; Put load segment on the stack and load it
+ pop es ; Into ES so that we load the cluster at 0000:F800
call ReadCluster ; Read the cluster
pop ax ; Restore start cluster of FreeLoader
@@ -204,16 +204,14 @@
; Now AX has start cluster of FreeLoader and we
; have loaded the helper code in the first 512 bytes
- ; of FreeLoader to 0000:8000. Now transfer control
+ ; of FreeLoader to 0000:F800. Now transfer control
; to the helper code. Skip the first three bytes
; because they contain a jump instruction to skip
; over the helper code in the FreeLoader image.
- ;jmp 0000:9003h
- push 0 ; push segment (0x0000)
- mov bx, [0x8000 + 0xA8] ; load the RVA of the EntryPoint into eax
- add bx, 0x8003 ; RVA -> VA and skip 3 bytes (jump to fathelper code)
- push bx ; push offset
- retf ; Transfer control to FreeLoader
+ ;ljmp16 0, FREELDR_BASE + 3
+ db 0EAh
+ dw 0F803h
+ dw 0
@@ -225,8 +223,8 @@
call PutChars ; Display it
Reboot:
- mov si,msgAnyKey ; Press any key message
- call PutChars ; Display it
+ ; mov si,msgAnyKey ; Press any key message
+ ; call PutChars ; Display it
xor ax,ax
int 16h ; Wait for a keypress
int 19h ; Reboot
Modified: trunk/reactos/boot/freeldr/bootsect/fat32.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/fat3…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/fat32.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/fat32.S [iso-8859-1] Sat Dec 26 20:43:50 2015
@@ -400,7 +400,7 @@
cmp eax, HEX(0ffffff8) // Check to see if this is the last cluster in the chain
jae LoadFileDone // If so continue, if not then read the next one
push eax
- xor bx, bx // Load ROSLDR starting at 0000:8000h
+ xor bx, bx // Load ROSLDR starting at 0000:F800h
push es
call ReadCluster
pop es
Modified: trunk/reactos/boot/freeldr/bootsect/fat32.asm
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/fat3…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/fat32.asm [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/fat32.asm [iso-8859-1] Sat Dec 26 20:43:50 2015
@@ -361,14 +361,14 @@
jmp PrintFileSystemError ; If so exit with error
InitializeLoadSegment:
- mov bx,800h
+ mov bx,0F80h ; FREELDR_BASE / 16
mov es,bx
LoadFile:
cmp eax,0ffffff8h ; Check to see if this is the last cluster in the chain
jae LoadFileDone ; If so continue, if not then read the next one
push eax
- xor bx,bx ; Load ROSLDR starting at 0000:8000h
+ xor bx,bx ; Load ROSLDR starting at 0000:F800h
push es
call ReadCluster
pop es
@@ -391,11 +391,11 @@
mov dl,[BYTE bp+BootDrive] ; Load boot drive into DL
mov dh,[BootPartition] ; Load boot partition into DH
- push 0 ; push segment (0x0000)
- mov eax, [0x8000 + 0xA8] ; load the RVA of the EntryPoint into eax
- add eax, 0x8000 ; RVA -> VA
- push ax ; push offset
- retf ; Transfer control to FreeLoader
+ ; Transfer execution to the bootloader
+ ;ljmp16 0, FREELDR_BASE
+ db 0EAh
+ dw 0F800h
+ dw 0
; Returns the FAT entry for a given cluster number
; On entry EAX has cluster number
Modified: trunk/reactos/boot/freeldr/bootsect/isoboot.asm
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/isob…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/isoboot.asm [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/isoboot.asm [iso-8859-1] Sat Dec 26 20:43:50 2015
@@ -360,7 +360,10 @@
call crlf
%endif
- mov bx, 0x8000 ; bx = load address
+; use high segment, as some bios can fail, when offset is too big
+ mov bx, 0x0F80 ; FREELDR_BASE / 16 ; es = load segment
+ mov es, bx
+ xor ebx, ebx ; bx = load offset
mov si, di ; restore file pointer
mov cx, 0xFFFF ; load the whole file
call getfssec ; get the whole file
@@ -373,13 +376,12 @@
mov dl, [DriveNo] ; dl = boot drive
mov dh, 0 ; dh = boot partition
- push 0 ; push segment (0x0000)
- mov eax, [0x8000 + 0xA8] ; load the RVA of the EntryPoint into eax
- add eax, 0x8000 ; RVA -> VA
- push ax ; push offset
- retf ; Transfer control to ROSLDR
-
-
+
+ ; Transfer execution to the bootloader
+ ;ljmp16 0, FREELDR_BASE
+ db 0xEA
+ dw 0xF800
+ dw 0
;
; searchdir:
@@ -944,7 +946,7 @@
startldr_msg: db 'Starting SETUPLDR.SYS', 0
%endif
-nosecsize_msg: db 'No sector size, assume 0800', CR, LF, 0
+; nosecsize_msg: db 'No sector size, assume 0800', CR, LF, 0
spec_err_msg: db 'Load spec failed, trying wing ...', CR, LF, 0
maybe_msg: db 'Found smth at drive = ', 0
alright_msg: db 'might be ok, continuing...', CR, LF, 0
Modified: trunk/reactos/boot/freeldr/bootsect/isobtrt.asm
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/bootsect/isob…
==============================================================================
--- trunk/reactos/boot/freeldr/bootsect/isobtrt.asm [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/bootsect/isobtrt.asm [iso-8859-1] Sat Dec 26 20:43:50 2015
@@ -332,7 +332,10 @@
call crlf
%endif
- mov bx, 0x8000 ; bx = load address
+; use high segment, as some bios can fail, when offset is too big
+ mov bx, 0x0F80 ; FREELDR_BASE / 16 ; es = load segment
+ mov es, bx
+ xor ebx, ebx ; bx = load offset
mov si, di ; restore file pointer
mov cx, 0xFFFF ; load the whole file
call getfssec ; get the whole file
@@ -345,13 +348,12 @@
mov dl, [DriveNo] ; dl = boot drive
mov dh, 0 ; dh = boot partition
- push 0 ; push segment (0x0000)
- mov eax, [0x8000 + 0xA8] ; load the RVA of the EntryPoint into eax
- add eax, 0x8000 ; RVA -> VA
- push ax ; push offset
- retf ; Transfer control to ROSLDR
-
-
+
+ ; Transfer execution to the bootloader
+ ;ljmp16 0, FREELDR_BASE
+ db 0xEA
+ dw 0xF800
+ dw 0
;
; searchdir:
@@ -892,7 +894,7 @@
isolinux_banner db CR, LF, 'Loading IsoBoot...', CR, LF, 0
-copyright_str db ' Copyright (C) 1994-2002 H. Peter Anvin', CR, LF, 0
+copyright_str db ' (C) 1994-2002 H. Peter Anvin', CR, LF, 0
presskey_msg db 'Press any key to boot from CD', 0
dot_msg db '.',0
@@ -910,7 +912,7 @@
startldr_msg: db 'Starting SETUPLDR.SYS', 0
%endif
-nosecsize_msg: db 'Failed to get sector size, assuming 0800', CR, LF, 0
+; nosecsize_msg: db 'Failed to get sector size, assuming 0800', CR, LF, 0
spec_err_msg: db 'Loading spec packet failed, trying to wing it...', CR, LF, 0
maybe_msg: db 'Found something at drive = ', 0
alright_msg: db 'Looks like it might be right, continuing...', CR, LF, 0
Author: tkreuzer
Date: Sat Dec 26 20:34:15 2015
New Revision: 70430
URL: http://svn.reactos.org/svn/reactos?rev=70430&view=rev
Log:
[CRT]
Fix x86 asm implementation of strlen / wcslen.
Modified:
trunk/reactos/lib/sdk/crt/string/i386/tcslen.inc
Modified: trunk/reactos/lib/sdk/crt/string/i386/tcslen.inc
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/i386/tc…
==============================================================================
--- trunk/reactos/lib/sdk/crt/string/i386/tcslen.inc [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/string/i386/tcslen.inc [iso-8859-1] Sat Dec 26 20:34:15 2015
@@ -7,23 +7,34 @@
FUNC _tcslen
FPO 0, 1, 1, 1, 0, FRAME_FPO
+
+ /* Save edi and eflags (according to the x86 ABI, we don't need to do that
+ but since the native function doesn't change the direction flag, we don't
+ either */
push edi
- mov edi, [esp + 8]
+ pushfd
+
+ /* Load the string pointer into edi */
+ mov edi, [esp + 12]
+
+ /* Set eax to 0, since we want to compare with 0 */
xor eax, eax
- test edi, edi
- jz _tcslen_end
+ /* Set ecx to -1 (i.e. 0xFFFFFFFF) */
mov ecx, -1
+
+ /* Clear direction flag */
cld
+ /* Now compare the characters until a 0 is found */
repne _tscas
+ /* Calculate the count (eax = -ecx - 1) */
not ecx
- dec ecx
+ lea eax, [ecx-1]
- mov eax, ecx
-
-_tcslen_end:
+ /* Restore eflags/edi and return the result */
+ popfd
pop edi
ret
ENDFUNC
Author: tkreuzer
Date: Sat Dec 26 20:32:31 2015
New Revision: 70429
URL: http://svn.reactos.org/svn/reactos?rev=70429&view=rev
Log:
[CRT_APITEST]
Add another test for strlen, that tests, whether the direction flag in ELFAGS has been modified. While clearing it is legitimate to do according to the ABI, the native implementation does not change it, so we don't want to do it either.
Modified:
trunk/rostests/apitests/crt/strlen.c
Modified: trunk/rostests/apitests/crt/strlen.c
URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/strlen.c?rev…
==============================================================================
--- trunk/rostests/apitests/crt/strlen.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/crt/strlen.c [iso-8859-1] Sat Dec 26 20:32:31 2015
@@ -23,12 +23,18 @@
}
#endif
+#define EFLAGS_DF 0x400L
+
typedef size_t (*PFN_STRLEN)(const char *);
void
Test_strlen(PFN_STRLEN pstrlen)
{
size_t len;
+#if defined(_M_IX86) || defined(_M_AMD64)
+ volatile uintptr_t eflags;
+ char *teststr = "a\0bcdefghijk";
+#endif
/* basic parameter tests */
StartSeh()
@@ -37,6 +43,21 @@
(void)len;
ok_int((int)pstrlen("test"), 4);
+
+#if defined(_M_IX86) || defined(_M_AMD64)
+ eflags = __readeflags();
+ __writeeflags(eflags | EFLAGS_DF);
+ len = pstrlen(teststr + 4);
+ eflags = __readeflags();
+ ok((eflags & EFLAGS_DF) != 0, "Direction flag in ELFAGS was changed.");
+
+ /* Only test this for the exported versions, intrinsics might do it
+ differently. It's up to us to not do fishy stuff! */
+ if (pstrlen == strlen)
+ {
+ ok(len == 8, "Should not have gone backwards (got len %i)", (int)len);
+ }
+#endif
}
START_TEST(strlen)