OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * Non-IRT definition of sbrk for use only in private tests. | 8 * Non-IRT definition of sbrk for use only in private tests. |
9 */ | 9 */ |
10 | 10 |
11 #include <errno.h> | 11 #include <errno.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h" | 14 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h" |
15 | 15 |
16 static void *current_break; | 16 static void *current_break; |
17 | 17 |
18 void *sbrk(intptr_t increment) { | 18 void *sbrk(intptr_t increment) { |
19 void *old_break; | 19 void *old_break; |
20 void *new_break; | 20 void *new_break; |
21 | 21 |
22 if (0 == current_break) | 22 if (0 == current_break) |
23 current_break = NACL_SYSCALL(sysbrk)(0); | 23 current_break = NACL_SYSCALL(brk)(0); |
24 | 24 |
25 old_break = current_break; | 25 old_break = current_break; |
26 new_break = old_break + increment; | 26 new_break = old_break + increment; |
27 | 27 |
28 if (new_break != old_break) { | 28 if (new_break != old_break) { |
29 new_break = NACL_SYSCALL(sysbrk)(new_break); | 29 new_break = NACL_SYSCALL(brk)(new_break); |
30 if (new_break == old_break) { | 30 if (new_break == old_break) { |
31 errno = ENOMEM; | 31 errno = ENOMEM; |
32 return (void *) -1; | 32 return (void *) -1; |
33 } | 33 } |
34 current_break = new_break; | 34 current_break = new_break; |
35 } | 35 } |
36 | 36 |
37 return old_break; | 37 return old_break; |
38 } | 38 } |
OLD | NEW |