[comp.bugs.sys5] Venix-86 sbrk

wendt@arizona.edu (Alan Lee Wendt) (05/21/88)

Problem:    sbrk wraps the break, returning a low number.

Symptom:    Segmentation violations.  On my system attempts to
            backtrace the problem in the debugger crash the system.

System:     80286 Venix V Rev 2.2, but examine other Sys V
	    in case it's generic.

Reproduce:  Set the break to 65022 with a series of sbrk calls.
	    Then do sbrk(526).  My system will set the new break
	    to 12.

Fix:        I added a jump on no-carry (jnb) around some code that
	    sets the errno to ENOMEM and returns -1.  If the addition
	    to get the new break wraps, it will set the carry and
	    fall into the error case.
	    You'll need to disassemble brk.o in /lib/libc.  The
	    routine brk is also in brk.o but is not shown here
	    because it doesn't need changes.

	    Apologies for the hard constants.

Fixer:      Alan Wendt


	.globl	_end
	.comm	_errno,2
	.data
	.even
_loc:	.word	_end

	.text

	.globl	_sbrk
_sbrk:	push	bp
	mov	bp,sp
	mov	bx,#17
	mov	ax,*4(bp)
	add	ax,_loc
	jnb	_try			*new
	mov	_errno,*12		*new
	mov	ax,*-1			*new
	j	_out1			*new
_try:					*new
	int	241
	jcxz	_ok1
	mov	_errno,cx
	j	_out1
_ok1:	mov	bx,_loc
	mov	ax,bx
	add	bx,*4(bp)
	mov	_loc,bx
_out1:	pop	bp
	ret