wok-current rev 21777
linld: fix strdup (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Jul 11 14:43:21 2019 +0200 (2019-07-11) |
parents | a3046db1ef94 |
children | 1865d8875a8e |
files | linld/stuff/src/CRTL.ASM linld/stuff/src/VCPI.ASM |
line diff
1.1 --- a/linld/stuff/src/CRTL.ASM Thu Jul 11 12:50:44 2019 +0200 1.2 +++ b/linld/stuff/src/CRTL.ASM Thu Jul 11 14:43:21 2019 +0200 1.3 @@ -511,28 +511,23 @@ 1.4 ;*************************************************************** 1.5 global @strdup$qpxzc:near 1.6 @strdup$qpxzc: 1.7 - call xchg_heap_top 1.8 - call @strcpy$qpxzct1 1.9 +strdup: ; ax = strdup(bx) 1.10 + mov ax,[_heap_top] 1.11 + xchg ax,bx 1.12 + call @strcpy$qpxzct1 ; bx = strcpy(bx, ax) end +1 1.13 xchg ax,bx 1.14 xchg_heap_top: 1.15 xchg ax,[_heap_top] 1.16 - xchg ax,bx 1.17 ret 1.18 1.19 global @malloc_or_die$qui:near 1.20 proc @malloc_or_die$qui near 1.21 1.22 - xchg ax,cx ; size 1.23 - global malloc_or_die:near ; malloc_or_die(cx) 1.24 + global malloc_or_die:near ; ax = malloc_or_die(ax) 1.25 malloc_or_die: 1.26 - mov ax,[_heap_top] ; return value 1.27 - mov bx,sp 1.28 - add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE 1.29 - sub bx,ax ; can't overflow 1.30 - add ax,cx 1.31 - cmp bx,cx 1.32 mov bx,offset msg_malloc 1.33 - ja xchg_heap_top 1.34 + add ax,[_heap_top] 1.35 + jnc xchg_heap_top 1.36 1.37 endp @malloc_or_die$qui 1.38 1.39 @@ -666,22 +661,22 @@ 1.40 push si 1.41 mov si,bx 1.42 ifdef LARGE_IMAGES 1.43 - movzx ecx,[word ((image_himem si).size) + 2] 1.44 - shr cx,4 ; pages index size = size >> 20 1.45 - add cx,8+4096+8 1.46 + movzx eax,[word ((image_himem si).size) + 2] 1.47 + shr ax,4 ; pages index size = size >> 20 1.48 + add ax,8+4096+8 1.49 call malloc_or_die 1.50 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE; 1.51 add ecx,[(image_himem si).size] 1.52 shr ecx,12 1.53 mov [curdata],ax 1.54 else 1.55 - mov ecx,[(image_himem si).size] 1.56 - dec ecx 1.57 - shr ecx,12 1.58 - inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE; 1.59 - push cx 1.60 - inc cx ; cnt+1 1.61 - shl cx,2 ; bufv => vcpi => vm86 1.62 + mov eax,[(image_himem si).size] 1.63 + dec eax 1.64 + shr eax,12 1.65 + inc ax ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE; 1.66 + push ax 1.67 + inc ax ; cnt+1 1.68 + shl ax,2 ; bufv => vcpi => vm86 1.69 ; our malloc zeroes allocated mem: bufv[cnt]=0; 1.70 ; Allocate pages, storing addrs in addrbuf 1.71 call malloc_or_die 1.72 @@ -1354,13 +1349,16 @@ 1.73 jne @@loop 1.74 inc di 1.75 inc di 1.76 +; ax = strdup(bx) ? 1.77 mov si,di ; progname @es:di 1.78 repne 1.79 scasb 1.80 - mov cx,di 1.81 - sub cx,si ; progname len 1.82 - call malloc_or_die ; keep cx 1.83 - mov di,ax 1.84 + mov ax,di 1.85 + sub ax,si ; progname len 1.86 + push ax 1.87 + call malloc_or_die 1.88 + xchg ax,di 1.89 + pop cx 1.90 push ds 1.91 push es 1.92 pop ds
2.1 --- a/linld/stuff/src/VCPI.ASM Thu Jul 11 12:50:44 2019 +0200 2.2 +++ b/linld/stuff/src/VCPI.ASM Thu Jul 11 14:43:21 2019 +0200 2.3 @@ -141,12 +141,12 @@ 2.4 ;Calculate pagedir/page0 addrs, initialize cr3 and pagedir[0] 2.5 xor eax,eax 2.6 ; heap_top = prepare_vcpi(malloc_or_die(8*1024+4)); 2.7 - mov cx,8*1024+4 2.8 + mov ah,8*1024/256 2.9 extrn malloc_or_die:near 2.10 - call malloc_or_die ;keep cx 2.11 + call malloc_or_die 2.12 2.13 mov edx,cs 2.14 - shl edx,cl ;edx = linear addr of CS 2.15 + shl edx,4 ;edx = linear addr of CS 2.16 mov si,offset gdt_vcpi 2.17 ; Fix up base of some gdt descriptors 2.18 ; Note: 'add [dword xx.base0],edx' actually updates 24 bit quantity!