]>
Commit | Line | Data |
---|---|---|
f7a9f785 | 1 | /* Copyright (C) 2010-2016 Free Software Foundation, Inc. |
c08fb0d7 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
c08fb0d7 UD |
17 | |
18 | #include <errno.h> | |
19 | #include <sys/resource.h> | |
20 | #include <sys/syscall.h> | |
21 | ||
22 | ||
23 | #ifdef __NR_prlimit64 | |
24 | int | |
25 | prlimit (__pid_t pid, enum __rlimit_resource resource, | |
a784e502 | 26 | const struct rlimit *new_rlimit, struct rlimit *old_rlimit) |
c08fb0d7 UD |
27 | { |
28 | struct rlimit64 new_rlimit64_mem; | |
29 | struct rlimit64 *new_rlimit64 = NULL; | |
30 | struct rlimit64 old_rlimit64_mem; | |
052fa7b3 | 31 | struct rlimit64 *old_rlimit64 = (old_rlimit != NULL |
c08fb0d7 UD |
32 | ? &old_rlimit64_mem : NULL); |
33 | ||
34 | if (new_rlimit != NULL) | |
35 | { | |
36 | if (new_rlimit->rlim_cur == RLIM_INFINITY) | |
37 | new_rlimit64_mem.rlim_cur = RLIM64_INFINITY; | |
38 | else | |
39 | new_rlimit64_mem.rlim_cur = new_rlimit->rlim_cur; | |
40 | if (new_rlimit->rlim_max == RLIM_INFINITY) | |
052fa7b3 | 41 | new_rlimit64_mem.rlim_max = RLIM64_INFINITY; |
c08fb0d7 UD |
42 | else |
43 | new_rlimit64_mem.rlim_max = new_rlimit->rlim_max; | |
44 | new_rlimit64 = &new_rlimit64_mem; | |
45 | } | |
46 | ||
e5dee2c8 L |
47 | int res = INLINE_SYSCALL (prlimit64, 4, pid, resource, new_rlimit64, |
48 | old_rlimit64); | |
c08fb0d7 | 49 | |
e5dee2c8 | 50 | if (res == 0 && old_rlimit != NULL) |
c08fb0d7 UD |
51 | { |
52 | /* The prlimit64 syscall is ill-designed for 32-bit machines. | |
53 | We have to provide a 32-bit variant since otherwise the LFS | |
54 | system would not work. But what shall we do if the syscall | |
55 | succeeds but the old values do not fit into a rlimit | |
56 | structure? We cannot return an error because the operation | |
57 | itself worked. Best is perhaps to return RLIM_INFINITY. */ | |
58 | old_rlimit->rlim_cur = old_rlimit64_mem.rlim_cur; | |
59 | if (old_rlimit->rlim_cur != old_rlimit64_mem.rlim_cur) | |
60 | { | |
052fa7b3 | 61 | if (new_rlimit == NULL) |
2caca60d | 62 | return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); |
c08fb0d7 UD |
63 | old_rlimit->rlim_cur = RLIM_INFINITY; |
64 | } | |
65 | old_rlimit->rlim_max = old_rlimit64_mem.rlim_max; | |
66 | if (old_rlimit->rlim_max != old_rlimit64_mem.rlim_max) | |
67 | { | |
052fa7b3 | 68 | if (new_rlimit == NULL) |
2caca60d | 69 | return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); |
c08fb0d7 UD |
70 | old_rlimit->rlim_max = RLIM_INFINITY; |
71 | } | |
72 | } | |
73 | ||
74 | return res; | |
75 | } | |
76 | #else | |
77 | int | |
78 | prlimit (__pid_t pid, enum __rlimit_resource resource, | |
a784e502 | 79 | const struct rlimit *new_rlimit, struct rlimit *old_rlimit) |
c08fb0d7 | 80 | { |
2caca60d | 81 | return INLINE_SYSCALL_ERROR_RETURN_VALUE (ENOSYS); |
c08fb0d7 UD |
82 | } |
83 | stub_warning (prlimit) | |
84 | #endif |