This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

brk(2) trouble


Hi there,

The following is supposed to be the brk(2) implementation in
glibc/NetBSD.  The problem is with dynamically linked programs, where
the program interpreter, the program and the library each get its own
``_end'' symbol.  Now, with libc.so mapped high the program calls
SYS_break like this

 28862 a.out    CALL  break(0x4805a5c4)
 28862 a.out    RET   break -1 errno 12 Cannot allocate memory
 
which naturally fails with ENOMEM.  

How brk(2) is supposed to be implemnted ?  And what's the semantics of
"break" in a dynamically linked program anyway ?

~velco

#include <sysdep.h>
#include <sys/syscall.h>

	.comm	C_SYMBOL_NAME(__curbrk), 4

	.data	
	.globl	C_SYMBOL_NAME (__minbrk)
C_LABEL (__minbrk)
	.long	C_SYMBOL_NAME (_end)
	.size	C_SYMBOL_NAME (__minbrk), 4
	
	.text
ENTRY (__brk)
	movl	4(%esp), %eax
#ifdef	PIC
	call	0f
0:
	popl	%ecx
	addl	$_GLOBAL_OFFSET_TABLE_ + [. - 0b], %ecx
	movl	C_SYMBOL_NAME (__minbrk@GOT) (%ecx), %ecx
	cmpl	%eax, (%ecx)
	jb	1f
	movl	(%ecx), %eax
	movl	%eax, 4(%esp)
1:
	DO_CALL	(break, 1)
	jc	lose
	call	2f
2:
	popl	%ecx
	addl	$_GLOBAL_OFFSET_TABLE_ + [. - 2b], %ecx
	movl	C_SYMBOL_NAME (__curbrk@GOT) (%ecx), %ecx
	movl	%edx, (%ecx)
#else
	movl	4(%esp), %eax
	cmpl	%eax, C_SYMBOL_NAME (__minbrk)
	jb	0f
	movl	C_SYMBOL_NAME (__minbrk), %eax
	movl	%eax, 4(%esp)
0:
	DO_CALL	(break, 1)
	jc	lose
	movl	%ecx, C_SYMBOL_NAME (__curbrk)
#endif
	xorl	%eax, %eax
	ret
lose:
	SYSCALL_PIC_SETUP
	jmp	JUMPTARGET (syscall_error)
PSEUDO_END (__brk)

weak_alias (__brk, brk)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]