2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
7 //! Test application that reproduces bug #4778.
25 size_t size
= rand() % 16384 + 8;
26 if (malloc(size
) == NULL
) {
27 printf("out of memory after having allocated %ld bytes\n", total
);
43 status_t status
= B_ERROR
;
44 uint32 addressSpec
= B_ANY_ADDRESS
;
46 bool readOnly
= false;//(rand() % 256) > 127;
48 // reserve 128 MB of space for the area
49 base
= (void*)0x60000000;
50 status
= _kern_reserve_address_range((addr_t
*)&base
, B_BASE_ADDRESS
,
52 addressSpec
= status
== B_OK
? B_EXACT_ADDRESS
: B_BASE_ADDRESS
;
53 printf("\naddress spec = %lx, base %p (status %s)\n", addressSpec
,
54 base
, strerror(status
));
57 area_id area
= create_area(readOnly
? "read-only memory" : "r/w memory",
58 &base
, addressSpec
, B_PAGE_SIZE
* 4, B_NO_LOCK
,
59 B_READ_AREA
| (readOnly
? 0 : B_WRITE_AREA
));
61 printf("new %s area %ld at %p\n", readOnly
? "read-only" : "r/w",
74 main(int argc
, char** argv
)
76 thread_id eater
= spawn_thread(&memory_eater
, "memory eater",
77 B_NORMAL_PRIORITY
, NULL
);
80 thread_id creator
= spawn_thread(&area_creator
, "area creator",
81 B_NORMAL_PRIORITY
, NULL
);
82 resume_thread(creator
);
84 object_wait_info waitInfos
[2] = {
85 { eater
, B_OBJECT_TYPE_THREAD
, 0 },
86 { creator
, B_OBJECT_TYPE_THREAD
, 0 }
88 ssize_t which
= wait_for_objects(waitInfos
, 2);
89 printf("wait for objects: %ld\n", which
);
91 debugger("Welcome to the land of tomorrow");