libroot_debug: Merge guarded heap into libroot_debug.
[haiku.git] / src / system / libroot / os / extended_system_info.cpp
blobff61ae7611ba558883322e4fd551479d3b728c35
1 /*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <extended_system_info.h>
8 #include <extended_system_info_defs.h>
10 #include <syscalls.h>
11 #include <AutoDeleter.h>
13 #include <util/KMessage.h>
16 namespace BPrivate {
19 status_t
20 get_extended_team_info(team_id teamID, uint32 flags, KMessage& info)
22 // initial buffer size
23 size_t bufferSize = 4096;
24 // TODO: Pick it depending on the set flags.
26 while (true) {
27 // allocate the buffer
28 void* buffer = malloc(bufferSize);
29 if (buffer == NULL)
30 return B_NO_MEMORY;
31 MemoryDeleter bufferDeleter(buffer);
33 // get the info
34 size_t sizeNeeded;
35 status_t error = _kern_get_extended_team_info(teamID, flags, buffer,
36 bufferSize, &sizeNeeded);
37 if (error == B_OK) {
38 return info.SetTo((const void*)buffer, sizeNeeded,
39 KMessage::KMESSAGE_CLONE_BUFFER);
40 // TODO: Just transfer our buffer, if it isn't much larger.
43 if (error != B_BUFFER_OVERFLOW)
44 return error;
46 // The buffer was too small. Try again with a larger one.
47 bufferSize = (sizeNeeded + 1023) / 1024 * 1024;
52 } // namespace BPrivate