brk.c 838 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. extern void * __curbrk attribute_hidden;
  11. extern int __init_brk (void) attribute_hidden;
  12. libc_hidden_proto(brk)
  13. int brk(void * end_data_seg)
  14. {
  15. if (__init_brk () == 0) {
  16. /*
  17. * Notice that we don't need to save/restore the GOT
  18. * register since that is not call clobbered by the syscall.
  19. */
  20. __asm__ ("move.d %1,$r10\n\t"
  21. "movu.w " STR(__NR_brk) ",$r9\n\t"
  22. "break 13\n\t"
  23. "move.d $r10, %0"
  24. : "=r" (__curbrk)
  25. : "g" (end_data_seg)
  26. : "r9", "r10");
  27. if (__curbrk == end_data_seg)
  28. return 0;
  29. __set_errno(ENOMEM);
  30. }
  31. return -1;
  32. }
  33. libc_hidden_def(brk)