brk.c 832 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <unistd.h>
  7. #include <sys/syscall.h>
  8. #include <errno.h>
  9. #include "sysdep.h"
  10. libc_hidden_proto(brk)
  11. extern void * __curbrk;
  12. extern int __init_brk (void);
  13. libc_hidden_proto(__init_brk)
  14. int brk(void * end_data_seg)
  15. {
  16. if (__init_brk () == 0) {
  17. /*
  18. * Notice that we don't need to save/restore the GOT
  19. * register since that is not call clobbered by the syscall.
  20. */
  21. asm ("move.d %1,$r10\n\t"
  22. "movu.w " STR(__NR_brk) ",$r9\n\t"
  23. "break 13\n\t"
  24. "move.d $r10, %0"
  25. : "=r" (__curbrk)
  26. : "g" (end_data_seg)
  27. : "r9", "r10");
  28. if (__curbrk == end_data_seg)
  29. return 0;
  30. __set_errno(ENOMEM);
  31. }
  32. return -1;
  33. }
  34. libc_hidden_def(brk)