brk.c 730 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (C) 2013 Imagination Technologies Ltd.
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <errno.h>
  7. #include <unistd.h>
  8. #include <sys/syscall.h>
  9. libc_hidden_proto(brk)
  10. /* This must be initialized data because commons can't have aliases. */
  11. void * __curbrk attribute_hidden = 0;
  12. int brk (void *addr)
  13. {
  14. void *newbrk;
  15. __asm__ __volatile__ ("MOV D1Re0,%2\n\t"
  16. "MOV D1Ar1,%1\n\t"
  17. "SWITCH #0x440001\n\t"
  18. "MOV %0,D0Re0"
  19. : "=r" (newbrk)
  20. : "r" (addr), "K" (__NR_brk)
  21. : "D0Re0", "D1Re0", "D1Ar1");
  22. __curbrk = newbrk;
  23. if (newbrk < addr)
  24. {
  25. __set_errno (ENOMEM);
  26. return -1;
  27. }
  28. return 0;
  29. }
  30. libc_hidden_def(brk)