Fixing warnings under GCC4 in preparation to enable -Werror there as well:

* Replaced the use of offsetof() for structs that aren't PODs. Add a
  offset_of_member() macro to util/khash.h because that's what it's used for
  in our cases.
* Change the signature of add_debugger_command()/remove_debugger_command() on
  GCC > 2 to avoid the depricated conversion from string constants to char *.
* Adding some "suggested" parenthesis. I know that not everyone likes that, but
  it pointed out at least one bug that is fixed here as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29113 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2009-02-01 20:48:02 +00:00
parent 47bc666311
commit c33667d400
24 changed files with 112 additions and 79 deletions
+7
View File
@@ -174,9 +174,16 @@ extern void panic(const char *format, ...) _PRINTFLIKE(1, 2);
extern void kernel_debugger(const char *message); extern void kernel_debugger(const char *message);
extern uint64 parse_expression(const char *string); extern uint64 parse_expression(const char *string);
#if __GNUC__ > 2
extern int add_debugger_command(const char *name,
debugger_command_hook hook, const char *help);
extern int remove_debugger_command(const char *name,
debugger_command_hook hook);
#else
extern int add_debugger_command(char *name, debugger_command_hook hook, char *help); extern int add_debugger_command(char *name, debugger_command_hook hook, char *help);
extern int remove_debugger_command(char *name, extern int remove_debugger_command(char *name,
debugger_command_hook hook); debugger_command_hook hook);
#endif
/* Miscellaneous */ /* Miscellaneous */
extern void spin(bigtime_t microseconds); extern void spin(bigtime_t microseconds);
+6
View File
@@ -11,6 +11,12 @@
#include <SupportDefs.h> #include <SupportDefs.h>
// The use of offsetof() on non-PODs is invalid. Since many structs use
// templated members (i.e. DoublyLinkedList) which makes them non-PODs we
// can't use offsetof() anymore. This macro does the same, but requires an
// instance of the object in question.
#define offset_of_member(OBJECT, MEMBER) \
((size_t)((char*)&OBJECT.MEMBER - (char*)&OBJECT))
// can be allocated on the stack // can be allocated on the stack
typedef struct hash_iterator { typedef struct hash_iterator {
@@ -611,7 +611,7 @@ main(int argc, const char *const *argv)
// write the boot code // write the boot code
printf("Writing boot code to \"%s\" (partition offset: %lld bytes, " printf("Writing boot code to \"%s\" (partition offset: %lld bytes, "
"start offset = %d) " "start offset = %lld) "
"...\n", fileName, partitionOffset, startOffset); "...\n", fileName, partitionOffset, startOffset);
write_boot_code_part(fileName, fd, startOffset, bootCodeData, 0, write_boot_code_part(fileName, fd, startOffset, bootCodeData, 0,
+1 -1
View File
@@ -57,7 +57,7 @@ void
UserMessagingMessageSender::SendMessage(const KMessage* message, port_id port, UserMessagingMessageSender::SendMessage(const KMessage* message, port_id port,
int32 token) int32 token)
{ {
if (message != fMessage && fMessage != NULL if ((message != fMessage && fMessage != NULL)
|| fTargetCount == MAX_MESSAGING_TARGET_COUNT) { || fTargetCount == MAX_MESSAGING_TARGET_COUNT) {
FlushMessage(); FlushMessage();
} }
+6 -5
View File
@@ -367,10 +367,10 @@ is_kernel_stack_address(struct thread* thread, addr_t address)
if (thread == NULL) if (thread == NULL)
return IS_KERNEL_ADDRESS(address); return IS_KERNEL_ADDRESS(address);
return address >= thread->kernel_stack_base return (address >= thread->kernel_stack_base
&& address < thread->kernel_stack_top && address < thread->kernel_stack_top)
|| thread->cpu != NULL || (thread->cpu != NULL
&& is_double_fault_stack_address(thread->cpu->cpu_num, address); && is_double_fault_stack_address(thread->cpu->cpu_num, address));
} }
@@ -508,7 +508,8 @@ stack_trace(int argc, char **argv)
threadIndex++; threadIndex++;
} }
if (argc > threadIndex + 1 || argc == 2 && strcmp(argv[1], "--help") == 0) { if (argc > threadIndex + 1
|| (argc == 2 && strcmp(argv[1], "--help") == 0)) {
kprintf(usage, argv[0]); kprintf(usage, argv[0]);
return 0; return 0;
} }
+7 -6
View File
@@ -47,7 +47,6 @@
// system, like out of memory situations - should only panic for debugging. // system, like out of memory situations - should only panic for debugging.
#define FATAL(x) panic x #define FATAL(x) panic x
static const bigtime_t kTransactionIdleTime = 2000000LL; static const bigtime_t kTransactionIdleTime = 2000000LL;
// a transaction is considered idle after 2 seconds of inactivity // a transaction is considered idle after 2 seconds of inactivity
@@ -605,8 +604,8 @@ notify_transaction_listeners(block_cache* cache, cache_transaction* transaction,
while (iterator.HasNext()) { while (iterator.HasNext()) {
cache_listener* listener = iterator.Next(); cache_listener* listener = iterator.Next();
bool remove = isClosing && !is_written_event(listener->events) bool remove = (isClosing && !is_written_event(listener->events))
|| isWritten && is_written_event(listener->events); || (isWritten && is_written_event(listener->events));
if (remove) if (remove)
iterator.Remove(); iterator.Remove();
@@ -804,12 +803,14 @@ block_cache::Init()
if (buffer_cache == NULL) if (buffer_cache == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
hash = hash_init(1024, offsetof(cached_block, next), &cached_block::Compare, cached_block dummyBlock;
&cached_block::Hash); hash = hash_init(1024, offset_of_member(dummyBlock, next),
&cached_block::Compare, &cached_block::Hash);
if (hash == NULL) if (hash == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
transaction_hash = hash_init(16, offsetof(cache_transaction, next), cache_transaction dummyTransaction;
transaction_hash = hash_init(16, offset_of_member(dummyTransaction, next),
&transaction_compare, &::transaction_hash); &transaction_compare, &::transaction_hash);
if (transaction_hash == NULL) if (transaction_hash == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
+3 -3
View File
@@ -242,7 +242,7 @@ FileMap::_Add(file_io_vec* vecs, size_t vecCount, off_t& lastOffset)
if (lastExtent != NULL) { if (lastExtent != NULL) {
if (lastExtent->disk.offset + lastExtent->disk.length if (lastExtent->disk.offset + lastExtent->disk.length
== vecs[i].offset == vecs[i].offset
|| lastExtent->disk.offset == -1 && vecs[i].offset == -1) { || (lastExtent->disk.offset == -1 && vecs[i].offset == -1)) {
lastExtent->disk.length += vecs[i].length; lastExtent->disk.length += vecs[i].length;
offset += vecs[i].length; offset += vecs[i].length;
start--; start--;
@@ -368,8 +368,8 @@ FileMap::SetMode(uint32 mode)
MutexLocker _(fLock); MutexLocker _(fLock);
if (mode == FILE_MAP_CACHE_ALL && fCacheAll if ((mode == FILE_MAP_CACHE_ALL && fCacheAll)
|| mode == FILE_MAP_CACHE_ON_DEMAND && !fCacheAll) || (mode == FILE_MAP_CACHE_ON_DEMAND && !fCacheAll))
return B_OK; return B_OK;
if (mode == FILE_MAP_CACHE_ALL) { if (mode == FILE_MAP_CACHE_ALL) {
+11 -3
View File
@@ -488,8 +488,8 @@ print_debugger_command_usage(const char* commandName)
kprintf_unfiltered("usage: %s ", command->name); kprintf_unfiltered("usage: %s ", command->name);
kputs_unfiltered(command->usage); kputs_unfiltered(command->usage);
} else { } else {
char* args[3] = { NULL, "--help", NULL }; const char* args[3] = { NULL, "--help", NULL };
invoke_debugger_command(command, 2, args); invoke_debugger_command(command, 2, (char**)args);
} }
return true; return true;
@@ -498,16 +498,24 @@ print_debugger_command_usage(const char* commandName)
// #pragma mark - public API // #pragma mark - public API
int int
#if __GNUC__ > 2
add_debugger_command(const char *name, int (*func)(int, char **),
const char *desc)
#else
add_debugger_command(char *name, int (*func)(int, char **), char *desc) add_debugger_command(char *name, int (*func)(int, char **), char *desc)
#endif
{ {
return add_debugger_command_etc(name, func, desc, NULL, 0); return add_debugger_command_etc(name, func, desc, NULL, 0);
} }
int int
#if __GNUC__ > 2
remove_debugger_command(const char * name, int (*func)(int, char **))
#else
remove_debugger_command(char * name, int (*func)(int, char **)) remove_debugger_command(char * name, int (*func)(int, char **))
#endif
{ {
struct debugger_command *cmd = sCommands; struct debugger_command *cmd = sCommands;
struct debugger_command *prev = NULL; struct debugger_command *prev = NULL;
@@ -513,7 +513,7 @@ struct OperationComparator {
off_t offsetA = a->Offset(); off_t offsetA = a->Offset();
off_t offsetB = b->Offset(); off_t offsetB = b->Offset();
return offsetA < offsetB return offsetA < offsetB
|| offsetA == offsetB && a->Length() > b->Length(); || (offsetA == offsetB && a->Length() > b->Length());
} }
}; };
+2 -2
View File
@@ -1746,8 +1746,8 @@ devfs_io(fs_volume *volume, fs_vnode *_vnode, void *_cookie,
bool isWrite = request->IsWrite(); bool isWrite = request->IsWrite();
if (!S_ISCHR(vnode->stream.type) if (!S_ISCHR(vnode->stream.type)
|| ((isWrite && !vnode->stream.u.dev.device->HasWrite() || (((isWrite && !vnode->stream.u.dev.device->HasWrite())
|| !isWrite && !vnode->stream.u.dev.device->HasRead()) || (!isWrite && !vnode->stream.u.dev.device->HasRead()))
&& !vnode->stream.u.dev.device->HasIO()) && !vnode->stream.u.dev.device->HasIO())
|| cookie == NULL) { || cookie == NULL) {
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
@@ -481,7 +481,7 @@ find_driver(dev_t device, ino_t node)
while (true) { while (true) {
driver = (legacy_driver *)hash_next(sDriverHash, &iterator); driver = (legacy_driver *)hash_next(sDriverHash, &iterator);
if (driver == NULL if (driver == NULL
|| driver->device == device && driver->node == node) || (driver->device == device && driver->node == node))
break; break;
} }
@@ -1372,8 +1372,10 @@ legacy_driver_probe(const char* subPath)
extern "C" status_t extern "C" status_t
legacy_driver_init(void) legacy_driver_init(void)
{ {
sDriverHash = hash_init(DRIVER_HASH_SIZE, offsetof(legacy_driver, next), legacy_driver dummyDriver;
&driver_entry_compare, &driver_entry_hash); sDriverHash = hash_init(DRIVER_HASH_SIZE,
offset_of_member(dummyDriver, next), &driver_entry_compare,
&driver_entry_hash);
if (sDriverHash == NULL) if (sDriverHash == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
+5 -5
View File
@@ -2049,9 +2049,9 @@ _user_read_kernel_image_symbols(image_id id, struct Elf32_Sym* symbolTable,
if (_symbolCount == NULL || _stringTableSize == NULL) if (_symbolCount == NULL || _stringTableSize == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!IS_USER_ADDRESS(_symbolCount) || !IS_USER_ADDRESS(_stringTableSize) if (!IS_USER_ADDRESS(_symbolCount) || !IS_USER_ADDRESS(_stringTableSize)
|| _imageDelta != NULL && !IS_USER_ADDRESS(_imageDelta) || (_imageDelta != NULL && !IS_USER_ADDRESS(_imageDelta))
|| symbolTable != NULL && !IS_USER_ADDRESS(symbolTable) || (symbolTable != NULL && !IS_USER_ADDRESS(symbolTable))
|| stringTable != NULL && !IS_USER_ADDRESS(stringTable)) { || (stringTable != NULL && !IS_USER_ADDRESS(stringTable))) {
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
} }
@@ -2120,8 +2120,8 @@ _user_read_kernel_image_symbols(image_id id, struct Elf32_Sym* symbolTable,
if (user_memcpy(_symbolCount, &symbolCount, sizeof(symbolCount)) != B_OK if (user_memcpy(_symbolCount, &symbolCount, sizeof(symbolCount)) != B_OK
|| user_memcpy(_stringTableSize, &stringTableSize, || user_memcpy(_stringTableSize, &stringTableSize,
sizeof(stringTableSize)) != B_OK sizeof(stringTableSize)) != B_OK
|| _imageDelta != NULL && user_memcpy(_imageDelta, &imageDelta, || (_imageDelta != NULL && user_memcpy(_imageDelta, &imageDelta,
sizeof(imageDelta)) != B_OK) { sizeof(imageDelta)) != B_OK)) {
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
} }
+4 -4
View File
@@ -364,7 +364,7 @@ Inode::WriteDataToBuffer(const void *_data, size_t *_length, bool nonBlocking)
while (dataSize > 0) { while (dataSize > 0) {
// Wait until enough space in the buffer is available. // Wait until enough space in the buffer is available.
while (!fActive while (!fActive
|| fBuffer.Writable() < minToWrite && fReaderCount > 0) { || (fBuffer.Writable() < minToWrite && fReaderCount > 0)) {
if (nonBlocking) if (nonBlocking)
return B_WOULD_BLOCK; return B_WOULD_BLOCK;
@@ -639,9 +639,9 @@ Inode::Select(uint8 event, selectsync *sync, int openMode)
// signal right away, if the condition holds already // signal right away, if the condition holds already
if (writer) { if (writer) {
if (event == B_SELECT_WRITE if ((event == B_SELECT_WRITE
&& (fBuffer.Writable() > 0 || fReaderCount == 0) && (fBuffer.Writable() > 0 || fReaderCount == 0))
|| event == B_SELECT_ERROR && fReaderCount == 0) { || (event == B_SELECT_ERROR && fReaderCount == 0)) {
return notify_select_event(sync, event); return notify_select_event(sync, event);
} }
} else { } else {
+6 -6
View File
@@ -119,9 +119,9 @@ copy_address_to_userland(const void* address, socklen_t addressLength,
// copy address size and address back to userland // copy address size and address back to userland
if (user_memcpy(userAddressLength, &addressLength, if (user_memcpy(userAddressLength, &addressLength,
sizeof(socklen_t)) != B_OK sizeof(socklen_t)) != B_OK
|| userAddress != NULL || (userAddress != NULL
&& user_memcpy(userAddress, address, && user_memcpy(userAddress, address,
min_c(addressLength, userAddressBufferSize)) != B_OK) { min_c(addressLength, userAddressBufferSize)) != B_OK)) {
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
} }
@@ -973,10 +973,10 @@ _user_recvmsg(int socket, struct msghdr *userMessage, int flags)
message.msg_name = userAddress; message.msg_name = userAddress;
message.msg_iov = userVecs; message.msg_iov = userVecs;
message.msg_control = userAncillary; message.msg_control = userAncillary;
if (userAddress != NULL && user_memcpy(userAddress, address, if ((userAddress != NULL && user_memcpy(userAddress, address,
message.msg_namelen) != B_OK message.msg_namelen) != B_OK)
|| userAncillary != NULL && user_memcpy(userAncillary, ancillary, || (userAncillary != NULL && user_memcpy(userAncillary, ancillary,
message.msg_controllen) != B_OK message.msg_controllen) != B_OK)
|| user_memcpy(userMessage, &message, sizeof(msghdr)) != B_OK) { || user_memcpy(userMessage, &message, sizeof(msghdr)) != B_OK) {
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
} }
+16 -14
View File
@@ -1852,8 +1852,8 @@ disconnect_mount_or_vnode_fds(struct fs_mount *mount,
if (vnodeToDisconnect != NULL) { if (vnodeToDisconnect != NULL) {
if (vnode == vnodeToDisconnect) if (vnode == vnodeToDisconnect)
disconnect_fd(descriptor); disconnect_fd(descriptor);
} else if (vnode != NULL && vnode->mount == mount } else if ((vnode != NULL && vnode->mount == mount)
|| vnode == NULL && descriptor->u.mount == mount) || (vnode == NULL && descriptor->u.mount == mount))
disconnect_fd(descriptor); disconnect_fd(descriptor);
put_fd(descriptor); put_fd(descriptor);
@@ -4842,15 +4842,17 @@ vfs_setrlimit(int resource, const struct rlimit * rlp)
status_t status_t
vfs_init(kernel_args *args) vfs_init(kernel_args *args)
{ {
sVnodeTable = hash_init(VNODE_HASH_TABLE_SIZE, offsetof(struct vnode, next), struct vnode dummyVnode;
&vnode_compare, &vnode_hash); sVnodeTable = hash_init(VNODE_HASH_TABLE_SIZE,
offset_of_member(dummyVnode, next), &vnode_compare, &vnode_hash);
if (sVnodeTable == NULL) if (sVnodeTable == NULL)
panic("vfs_init: error creating vnode hash table\n"); panic("vfs_init: error creating vnode hash table\n");
list_init_etc(&sUnusedVnodeList, offsetof(struct vnode, unused_link)); list_init_etc(&sUnusedVnodeList, offset_of_member(dummyVnode, unused_link));
sMountsTable = hash_init(MOUNTS_HASH_TABLE_SIZE, offsetof(struct fs_mount, next), struct fs_mount dummyMount;
&mount_compare, &mount_hash); sMountsTable = hash_init(MOUNTS_HASH_TABLE_SIZE,
offset_of_member(dummyMount, next), &mount_compare, &mount_hash);
if (sMountsTable == NULL) if (sMountsTable == NULL)
panic("vfs_init: error creating mounts hash table\n"); panic("vfs_init: error creating mounts hash table\n");
@@ -5752,10 +5754,10 @@ common_fcntl(int fd, int op, uint32 argument, bool kernel)
status = release_advisory_lock(vnode, &flock); status = release_advisory_lock(vnode, &flock);
} else { } else {
// the open mode must match the lock type // the open mode must match the lock type
if ((descriptor->open_mode & O_RWMASK) == O_RDONLY if (((descriptor->open_mode & O_RWMASK) == O_RDONLY
&& flock.l_type == F_WRLCK && flock.l_type == F_WRLCK)
|| (descriptor->open_mode & O_RWMASK) == O_WRONLY || ((descriptor->open_mode & O_RWMASK) == O_WRONLY
&& flock.l_type == F_RDLCK) && flock.l_type == F_RDLCK))
status = B_FILE_ERROR; status = B_FILE_ERROR;
else { else {
status = acquire_advisory_lock(vnode, -1, status = acquire_advisory_lock(vnode, -1,
@@ -6725,7 +6727,7 @@ static dev_t
fs_mount(char* path, const char* device, const char* fsName, uint32 flags, fs_mount(char* path, const char* device, const char* fsName, uint32 flags,
const char* args, bool kernel) const char* args, bool kernel)
{ {
struct fs_mount* mount; struct ::fs_mount* mount;
status_t status = 0; status_t status = 0;
FUNCTION(("fs_mount: entry. path = '%s', fs_name = '%s'\n", path, fsName)); FUNCTION(("fs_mount: entry. path = '%s', fs_name = '%s'\n", path, fsName));
@@ -6840,7 +6842,7 @@ fs_mount(char* path, const char* device, const char* fsName, uint32 flags,
} }
} }
mount = new(std::nothrow) struct ::fs_mount; mount = new(std::nothrow) (struct ::fs_mount);
if (mount == NULL) if (mount == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8390,7 +8392,7 @@ _user_open_parent_dir(int fd, char *userName, size_t nameLength)
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
// open the parent dir // open the parent dir
int parentFD = dir_open(fd, "..", kernel); int parentFD = dir_open(fd, (char*)"..", kernel);
if (parentFD < 0) if (parentFD < 0)
return parentFD; return parentFD;
FDCloser fdCloser(parentFD, kernel); FDCloser fdCloser(parentFD, kernel);
+1 -1
View File
@@ -83,7 +83,7 @@ KernelDaemon::Register(daemon_hook function, void* arg, int frequency)
if (function == NULL || frequency < 1) if (function == NULL || frequency < 1)
return B_BAD_VALUE; return B_BAD_VALUE;
struct daemon* daemon = new(std::nothrow) struct ::daemon; struct ::daemon* daemon = new(std::nothrow) (struct ::daemon);
if (daemon == NULL) if (daemon == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
+2 -2
View File
@@ -2182,8 +2182,8 @@ get_module(const char* path, module_info** _info)
module = (struct module*)hash_lookup(sModulesHash, path); module = (struct module*)hash_lookup(sModulesHash, path);
// if we don't have it cached yet, search for it // if we don't have it cached yet, search for it
if (module == NULL || (module->flags & B_BUILT_IN_MODULE) == 0 if (module == NULL || ((module->flags & B_BUILT_IN_MODULE) == 0
&& module->module_image == NULL) { && module->module_image == NULL)) {
module = search_module(path, &moduleImage); module = search_module(path, &moduleImage);
if (module == NULL) { if (module == NULL) {
FATAL(("module: Search for %s failed.\n", path)); FATAL(("module: Search for %s failed.\n", path));
+6 -1
View File
@@ -26,6 +26,7 @@
#include <util/AutoLock.h> #include <util/AutoLock.h>
#include <util/DoublyLinkedList.h> #include <util/DoublyLinkedList.h>
#include <util/OpenHashTable.h> #include <util/OpenHashTable.h>
#include <util/khash.h>
#include <vm.h> #include <vm.h>
#include <vm_address_space.h> #include <vm_address_space.h>
@@ -597,8 +598,12 @@ object_cache_low_memory(void *_self, uint32 resources, int32 level)
static void static void
object_cache_return_object_wrapper(object_depot *depot, void *object) object_cache_return_object_wrapper(object_depot *depot, void *object)
{ {
// TODO: the offset calculation might be wrong because we hardcode a
// SmallObjectCache instead of a base object_cache. Also this must
// have an unacceptable overhead.
SmallObjectCache dummyCache;
object_cache *cache = (object_cache *)(((uint8 *)depot) object_cache *cache = (object_cache *)(((uint8 *)depot)
- offsetof(object_cache, depot)); - offset_of_member(dummyCache, depot));
object_cache_free(cache, object); object_cache_free(cache, object);
} }
+2 -2
View File
@@ -2724,8 +2724,8 @@ _user_spawn_thread(thread_creation_attributes* userAttributes)
thread_id threadID; thread_id threadID;
if (!IS_USER_ADDRESS(attributes.entry) || attributes.entry == NULL if (!IS_USER_ADDRESS(attributes.entry) || attributes.entry == NULL
|| attributes.stack_address != NULL || (attributes.stack_address != NULL
&& !IS_USER_ADDRESS(attributes.stack_address) && !IS_USER_ADDRESS(attributes.stack_address))
|| (attributes.name != NULL && (!IS_USER_ADDRESS(attributes.name) || (attributes.name != NULL && (!IS_USER_ADDRESS(attributes.name)
|| user_strlcpy(name, attributes.name, B_OS_NAME_LENGTH) < 0))) || user_strlcpy(name, attributes.name, B_OS_NAME_LENGTH) < 0)))
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
+2 -2
View File
@@ -611,7 +611,7 @@ VMAnonymousCache::WriteAsync(off_t offset, const iovec* vecs, size_t count,
} }
// create our callback // create our callback
WriteCallback* callback = (flags & B_VIP_IO_REQUEST != 0) WriteCallback* callback = (flags & B_VIP_IO_REQUEST) != 0
? new(vip_io_alloc) WriteCallback(this, _callback) ? new(vip_io_alloc) WriteCallback(this, _callback)
: new(std::nothrow) WriteCallback(this, _callback); : new(std::nothrow) WriteCallback(this, _callback);
if (callback == NULL) { if (callback == NULL) {
@@ -1211,7 +1211,7 @@ swap_init_post_modules()
close(fd); close(fd);
error = swap_file_add("/var/swap"); error = swap_file_add((char *)"/var/swap");
if (error != B_OK) if (error != B_OK)
dprintf("Failed to add swap file /var/swap: %s\n", strerror(error)); dprintf("Failed to add swap file /var/swap: %s\n", strerror(error));
} }
+11 -11
View File
@@ -418,7 +418,7 @@ AddressSpaceWriteLocker::SetFromArea(team_id team, area_id areaID,
area = (vm_area *)hash_lookup(sAreaHash, &areaID); area = (vm_area *)hash_lookup(sAreaHash, &areaID);
if (area != NULL if (area != NULL
&& (area->address_space->id == team && (area->address_space->id == team
|| allowKernel && team == vm_kernel_address_space_id())) { || (allowKernel && team == vm_kernel_address_space_id()))) {
fSpace = area->address_space; fSpace = area->address_space;
atomic_add(&fSpace->ref_count, 1); atomic_add(&fSpace->ref_count, 1);
} }
@@ -1358,9 +1358,9 @@ set_area_page_protection(vm_area* area, addr_t pageAddress, uint32 protection)
uint32 pageIndex = (pageAddress - area->base) / B_PAGE_SIZE; uint32 pageIndex = (pageAddress - area->base) / B_PAGE_SIZE;
uint8& entry = area->page_protections[pageIndex / 2]; uint8& entry = area->page_protections[pageIndex / 2];
if (pageIndex % 2 == 0) if (pageIndex % 2 == 0)
entry = entry & 0xf0 | protection; entry = (entry & 0xf0) | protection;
else else
entry = entry & 0x0f | (protection << 4); entry = (entry & 0x0f) | (protection << 4);
} }
@@ -2280,9 +2280,9 @@ _vm_map_file(team_id team, const char *name, void **_address, uint32 addressSpec
// The FD must open for reading at any rate. For shared mapping with write // The FD must open for reading at any rate. For shared mapping with write
// access, additionally the FD must be open for writing. // access, additionally the FD must be open for writing.
if ((openMode & O_ACCMODE) == O_WRONLY if ((openMode & O_ACCMODE) == O_WRONLY
|| mapping == REGION_NO_PRIVATE_MAP || (mapping == REGION_NO_PRIVATE_MAP
&& (protection & (B_WRITE_AREA | B_KERNEL_WRITE_AREA)) != 0 && (protection & (B_WRITE_AREA | B_KERNEL_WRITE_AREA)) != 0
&& (openMode & O_ACCMODE) == O_RDONLY) { && (openMode & O_ACCMODE) == O_RDONLY)) {
return EACCES; return EACCES;
} }
@@ -3459,7 +3459,7 @@ dump_caches_recursively(vm_cache* cache, cache_info& info, int level)
if (level == 0) if (level == 0)
kprintf("/%lu", info.page_count); kprintf("/%lu", info.page_count);
if (cache->type == CACHE_TYPE_RAM || level == 0 && info.committed > 0) { if (cache->type == CACHE_TYPE_RAM || (level == 0 && info.committed > 0)) {
kprintf(", committed: %lld", cache->committed_size); kprintf(", committed: %lld", cache->committed_size);
if (level == 0) if (level == 0)
@@ -3704,9 +3704,9 @@ dump_area(int argc, char **argv)
hash_open(sAreaHash, &iter); hash_open(sAreaHash, &iter);
while ((area = (vm_area *)hash_next(sAreaHash, &iter)) != NULL) { while ((area = (vm_area *)hash_next(sAreaHash, &iter)) != NULL) {
if ((area->name != NULL && !strcmp(argv[index], area->name)) if ((area->name != NULL && !strcmp(argv[index], area->name))
|| num != 0 || (num != 0
&& ((addr_t)area->id == num && ((addr_t)area->id == num
|| area->base <= num && area->base + area->size > num)) { || (area->base <= num && area->base + area->size > num)))) {
dump_area_struct(area, mappings); dump_area_struct(area, mappings);
found = true; found = true;
} }
@@ -3736,8 +3736,8 @@ dump_area_list(int argc, char **argv)
hash_open(sAreaHash, &iter); hash_open(sAreaHash, &iter);
while ((area = (vm_area *)hash_next(sAreaHash, &iter)) != NULL) { while ((area = (vm_area *)hash_next(sAreaHash, &iter)) != NULL) {
if (id != 0 && area->address_space->id != id if ((id != 0 && area->address_space->id != id)
|| name != NULL && strstr(area->name, name) == NULL) || (name != NULL && strstr(area->name, name) == NULL))
continue; continue;
kprintf("%p %5lx %p\t%p %4lx\t%4d %s\n", area, area->id, (void *)area->base, kprintf("%p %5lx %p\t%p %4lx\t%4d %s\n", area, area->id, (void *)area->base,
@@ -6347,7 +6347,7 @@ _user_sync_memory(void *_address, size_t size, int flags)
if (writeSync && writeAsync) if (writeSync && writeAsync)
return B_BAD_VALUE; return B_BAD_VALUE;
if (size == 0 || !writeSync && !writeAsync) if (size == 0 || (!writeSync && !writeAsync))
return B_OK; return B_OK;
// iterate through the range and sync all concerned areas // iterate through the range and sync all concerned areas
+2 -1
View File
@@ -389,7 +389,8 @@ status_t
VMCache::Init(uint32 cacheType) VMCache::Init(uint32 cacheType)
{ {
mutex_init(&fLock, "vm_cache"); mutex_init(&fLock, "vm_cache");
list_init_etc(&consumers, offsetof(VMCache, consumer_link)); VMCache dummyCache;
list_init_etc(&consumers, offset_of_member(dummyCache, consumer_link));
areas = NULL; areas = NULL;
fRefCount = 1; fRefCount = 1;
source = NULL; source = NULL;
+4 -4
View File
@@ -1238,11 +1238,11 @@ page_writer(void* /*unused*/)
// until we're low on pages. Also avoid writing temporary pages that // until we're low on pages. Also avoid writing temporary pages that
// are active. // are active.
if (page->wired_count > 0 if (page->wired_count > 0
|| cache->temporary || (cache->temporary
#if ENABLE_SWAP_SUPPORT #if ENABLE_SWAP_SUPPORT
&& (!lowOnPages /*|| page->usage_count > 0*/) && (!lowOnPages /*|| page->usage_count > 0*/)
#endif #endif
) { )) {
continue; continue;
} }
@@ -1444,9 +1444,9 @@ steal_pages(vm_page **pages, size_t count, bool reserve)
InterruptsSpinLocker locker(sPageLock); InterruptsSpinLocker locker(sPageLock);
if (reserve && sReservedPages <= free_page_queue_count() if ((reserve && sReservedPages <= free_page_queue_count())
|| count == 0 || count == 0
|| !reserve && (sInactivePageQueue.count > 0 || ((!reserve && (sInactivePageQueue.count > 0))
|| free_page_queue_count() > sReservedPages)) || free_page_queue_count() > sReservedPages))
return stolen; return stolen;
+1 -1
View File
@@ -564,7 +564,7 @@ common_poll(struct pollfd *fds, nfds_t numFDs, bigtime_t timeout, bool kernel)
int fd = fds[i].fd; int fd = fds[i].fd;
// initialize events masks // initialize events masks
sync->set[i].selected_events = fds[i].events & ~POLLNVAL sync->set[i].selected_events = (fds[i].events & ~POLLNVAL)
| POLLERR | POLLHUP; | POLLERR | POLLHUP;
sync->set[i].events = 0; sync->set[i].events = 0;