| 185 | } |
| 186 | |
| 187 | void test_real() { |
| 188 | // the soft AND hard limit are lowered to 256 KiB: the soft limit cannot be raised, the real mlock refuses most of 10 MiB (a process with CAP_IPC_LOCK is not limited: then all locks) |
| 189 | const int rc = in_child([] { |
| 190 | struct rlimit lo { 256 * 1024, 256 * 1024 }; |
| 191 | if (setrlimit(RLIMIT_MEMLOCK, &lo) != 0) return 90; |
| 192 | uint8_t* a = map_pages(2 * MiB, 5); |
| 193 | uint8_t* b = map_pages(8 * MiB, 6); |
| 194 | const uint64_t sa = sum(a, 2 * MiB), sb = sum(b, 8 * MiB); |
| 195 | auto parts = two_parts(a, 2 * MiB, b, 8 * MiB); |
| 196 | const LockEnv e = read_lock_env(10 * MiB); |
| 197 | LockOutcome o = lock_parts(parts, e); // must return, whatever the kernel says |
| 198 | const bool privileged = o.locked == o.want; |
| 199 | if (!privileged && o.locked > 256 * 1024 + 4096) return 91; |
| 200 | if (!privileged && lock_line(parts, o).empty()) return 92; |
| 201 | if (sum(a, 2 * MiB) != sa || sum(b, 8 * MiB) != sb) return 93; |
| 202 | return 0; |
| 203 | }); |
| 204 | CHECK(rc == 0); |
| 205 | } |
| 206 | |
| 207 | void test_raise() { |
| 208 | // soft 128 KiB, hard 64 MiB, need 10 MiB: the soft limit is raised (privileged or not) and the whole lock succeeds |
no test coverage detected