brk.c 860 B

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