blob: 799d2b9117e7393d295b0991d6d06d32764f6b7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/* $OpenBSD: malloc_ulimit1.c,v 1.5 2019/06/12 11:31:36 bluhm Exp $ */
/* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <err.h>
#include <stdlib.h>
#include <stdio.h>
/*
* This code tries to trigger the case present in -current as of April
* 2006) where the allocation of the region itself succeeds, but the
* page dir entry pages fails.
* This in turn trips a "hole in directories" error.
* Having a large (512M) ulimit -m helps a lot in triggering the
* problem. Note that you may need to run this test multiple times to
* see the error.
*/
#define STARTI 1300
#define FACTOR 1024
/* This test takes forever with junking turned on. */
char *malloc_options = "jj";
int
main()
{
struct rlimit lim;
size_t sz;
int i;
void *p;
if (getrlimit(RLIMIT_DATA, &lim) == -1)
err(1, "getrlimit");
sz = lim.rlim_cur / FACTOR;
for (i = STARTI; i >= 0; i--) {
size_t len = (sz-i) * FACTOR;
p = malloc(len);
free(p);
free(malloc(4096));
}
return (0);
}
|