From 38afe35e66159098bc348314a29fcdc86eccbac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 22 Feb 2004 14:52:59 +0000 Subject: [PATCH] Renamed CHECK_USER_ADDRESS() to IS_USER_ADDRESS() to make its function more clear. Added our license to the updated source files. Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6672 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/arch/ppc/arch_atomic.c | 12 ++-- src/kernel/core/arch/x86/arch_int.c | 11 +++- src/kernel/core/debug.c | 7 ++- src/kernel/core/fs/fd.c | 2 +- src/kernel/core/fs/vfs.cpp | 82 +++++++++++++------------- src/kernel/core/fs/vfs_select.c | 10 ++-- src/kernel/core/image.c | 6 +- src/kernel/core/team.c | 25 ++++---- src/kernel/core/thread.c | 42 +++++++------ src/kernel/core/vm/vm.c | 10 ++-- 10 files changed, 113 insertions(+), 94 deletions(-) diff --git a/src/kernel/core/arch/ppc/arch_atomic.c b/src/kernel/core/arch/ppc/arch_atomic.c index d2148fbeef..9b62202f71 100644 --- a/src/kernel/core/arch/ppc/arch_atomic.c +++ b/src/kernel/core/arch/ppc/arch_atomic.c @@ -104,7 +104,7 @@ _user_atomic_set64(vint64 *value, int64 newValue) { cpu_status status; int64 oldValue; - if (!CHECK_USER_ADDRESS(value) + if (!IS_USER_ADDRESS(value) || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) goto access_violation; @@ -127,7 +127,7 @@ _user_atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst) { cpu_status status; int64 oldValue; - if (!CHECK_USER_ADDRESS(value) + if (!IS_USER_ADDRESS(value) || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) goto access_violation; @@ -151,7 +151,7 @@ _user_atomic_add64(vint64 *value, int64 addValue) { cpu_status status; int64 oldValue; - if (!CHECK_USER_ADDRESS(value) + if (!IS_USER_ADDRESS(value) || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) goto access_violation; @@ -174,7 +174,7 @@ _user_atomic_and64(vint64 *value, int64 andValue) { cpu_status status; int64 oldValue; - if (!CHECK_USER_ADDRESS(value) + if (!IS_USER_ADDRESS(value) || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) goto access_violation; @@ -197,7 +197,7 @@ _user_atomic_or64(vint64 *value, int64 orValue) { cpu_status status; int64 oldValue; - if (!CHECK_USER_ADDRESS(value) + if (!IS_USER_ADDRESS(value) || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) goto access_violation; @@ -219,7 +219,7 @@ _user_atomic_get64(vint64 *value) { cpu_status status; int64 oldValue; - if (!CHECK_USER_ADDRESS(value) + if (!IS_USER_ADDRESS(value) || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) goto access_violation; diff --git a/src/kernel/core/arch/x86/arch_int.c b/src/kernel/core/arch/x86/arch_int.c index 13111475f8..ec18f2e6d4 100755 --- a/src/kernel/core/arch/x86/arch_int.c +++ b/src/kernel/core/arch/x86/arch_int.c @@ -1,3 +1,8 @@ +/* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + /* ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. @@ -192,9 +197,9 @@ i386_handle_trap(struct iframe frame) asm("movl %%cr2, %0" : "=r" (cr2)); - // if the interrupts were disabled, and we are not running the kernel startup - // the page fault was not allowed to happen and we must panic - if (0 == (frame.flags & 0x200) && !kernel_startup) { + if ((frame.flags & 0x200) == 0 && !kernel_startup) { + // if the interrupts were disabled, and we are not running the kernel startup + // the page fault was not allowed to happen and we must panic panic("page fault, but interrupts were disabled. Touching address %p from eip %p\n", (void *)cr2, (void *)frame.eip); } else if (thread != NULL && thread->page_faults_allowed < 1) panic("page fault not allowed at this place. Touching address %p from eip %p\n", (void *)cr2, (void *)frame.eip); diff --git a/src/kernel/core/debug.c b/src/kernel/core/debug.c index bcb7ecb478..4e51a86e85 100644 --- a/src/kernel/core/debug.c +++ b/src/kernel/core/debug.c @@ -1,5 +1,10 @@ /* This file contains the debugger */ +/* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + /* ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. @@ -531,7 +536,7 @@ _user_debug_output(const char *userString) if (!sSerialDebugEnabled) return; - if (!CHECK_USER_ADDRESS(userString) + if (!IS_USER_ADDRESS(userString) || user_strlcpy(string, userString, sizeof(string)) < B_OK) return; diff --git a/src/kernel/core/fs/fd.c b/src/kernel/core/fs/fd.c index 6b096154c2..bb0d604450 100644 --- a/src/kernel/core/fs/fd.c +++ b/src/kernel/core/fs/fd.c @@ -311,7 +311,7 @@ user_read(int fd, off_t pos, void *buffer, size_t length) ssize_t retval; /* This is a user_function, so abort if we have a kernel address */ - if (!CHECK_USER_ADDRESS(buffer)) + if (!IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; descriptor = get_fd(get_current_io_context(false), fd); diff --git a/src/kernel/core/fs/vfs.cpp b/src/kernel/core/fs/vfs.cpp index c06f5c4d3d..aeace1724e 100755 --- a/src/kernel/core/fs/vfs.cpp +++ b/src/kernel/core/fs/vfs.cpp @@ -3947,9 +3947,9 @@ user_mount(const char *upath, const char *udevice, const char *ufs_name, void *a char device[SYS_MAX_PATH_LEN + 1]; int rc; - if (!CHECK_USER_ADDRESS(upath) - || !CHECK_USER_ADDRESS(ufs_name) - || !CHECK_USER_ADDRESS(udevice)) + if (!IS_USER_ADDRESS(upath) + || !IS_USER_ADDRESS(ufs_name) + || !IS_USER_ADDRESS(udevice)) return B_BAD_ADDRESS; rc = user_strlcpy(path, upath, SYS_MAX_PATH_LEN); @@ -3994,7 +3994,7 @@ _user_read_fs_info(dev_t device, struct fs_info *userInfo) if (userInfo == NULL) return B_BAD_VALUE; - if (!CHECK_USER_ADDRESS(userInfo)) + if (!IS_USER_ADDRESS(userInfo)) return B_BAD_ADDRESS; status = fs_read_info(device, &info); @@ -4016,7 +4016,7 @@ _user_write_fs_info(dev_t device, const struct fs_info *userInfo, int mask) if (userInfo == NULL) return B_BAD_VALUE; - if (!CHECK_USER_ADDRESS(userInfo) + if (!IS_USER_ADDRESS(userInfo) || user_memcpy(&info, userInfo, sizeof(struct fs_info)) < B_OK) return B_BAD_ADDRESS; @@ -4037,7 +4037,7 @@ user_open_entry_ref(dev_t device, ino_t inode, const char *userName, int omode) char name[B_FILE_NAME_LENGTH]; int status; - if (!CHECK_USER_ADDRESS(userName)) + if (!IS_USER_ADDRESS(userName)) return B_BAD_ADDRESS; status = user_strlcpy(name, userName, sizeof(name) - 1); @@ -4054,7 +4054,7 @@ user_open(const char *userPath, int omode) char path[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath)) + if (!IS_USER_ADDRESS(userPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4078,7 +4078,7 @@ user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname) char name[B_FILE_NAME_LENGTH]; int status; - if (!CHECK_USER_ADDRESS(uname)) + if (!IS_USER_ADDRESS(uname)) return B_BAD_ADDRESS; status = user_strlcpy(name, uname, sizeof(name)); @@ -4095,7 +4095,7 @@ user_open_dir(const char *userPath) char path[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath)) + if (!IS_USER_ADDRESS(userPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4119,7 +4119,7 @@ user_create_entry_ref(dev_t device, ino_t inode, const char *userName, int openM char name[B_FILE_NAME_LENGTH]; int status; - if (!CHECK_USER_ADDRESS(userName)) + if (!IS_USER_ADDRESS(userName)) return B_BAD_ADDRESS; status = user_strlcpy(name, userName, sizeof(name)); @@ -4136,7 +4136,7 @@ user_create(const char *userPath, int openMode, int perms) char path[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath)) + if (!IS_USER_ADDRESS(userPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4153,7 +4153,7 @@ user_create_dir_entry_ref(dev_t device, ino_t inode, const char *userName, int p char name[B_FILE_NAME_LENGTH]; int status; - if (!CHECK_USER_ADDRESS(userName)) + if (!IS_USER_ADDRESS(userName)) return B_BAD_ADDRESS; status = user_strlcpy(name, userName, sizeof(name)); @@ -4170,7 +4170,7 @@ user_create_dir(const char *userPath, int perms) char path[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath)) + if (!IS_USER_ADDRESS(userPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4187,7 +4187,7 @@ user_remove_dir(const char *userPath) char path[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath)) + if (!IS_USER_ADDRESS(userPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4205,8 +4205,8 @@ user_read_link(const char *userPath, char *userBuffer, size_t bufferSize) char buffer[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath) - || !CHECK_USER_ADDRESS(userBuffer)) + if (!IS_USER_ADDRESS(userPath) + || !IS_USER_ADDRESS(userBuffer)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4235,8 +4235,8 @@ user_write_link(const char *userPath, const char *userToPath) char toPath[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath) - || !CHECK_USER_ADDRESS(userToPath)) + if (!IS_USER_ADDRESS(userPath) + || !IS_USER_ADDRESS(userToPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4262,8 +4262,8 @@ user_create_symlink(const char *userPath, const char *userToPath, int mode) char toPath[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath) - || !CHECK_USER_ADDRESS(userToPath)) + if (!IS_USER_ADDRESS(userPath) + || !IS_USER_ADDRESS(userToPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4289,8 +4289,8 @@ user_create_link(const char *userPath, const char *userToPath) char toPath[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath) - || !CHECK_USER_ADDRESS(userToPath)) + if (!IS_USER_ADDRESS(userPath) + || !IS_USER_ADDRESS(userToPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4315,7 +4315,7 @@ user_unlink(const char *userPath) char path[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath)) + if (!IS_USER_ADDRESS(userPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4333,7 +4333,7 @@ user_rename(const char *userOldPath, const char *userNewPath) char newPath[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userOldPath) || !CHECK_USER_ADDRESS(userNewPath)) + if (!IS_USER_ADDRESS(userOldPath) || !IS_USER_ADDRESS(userNewPath)) return B_BAD_ADDRESS; status = user_strlcpy(oldPath, userOldPath, SYS_MAX_PATH_LEN); @@ -4354,7 +4354,7 @@ user_access(const char *userPath, int mode) char path[SYS_MAX_PATH_LEN + 1]; int status; - if (!CHECK_USER_ADDRESS(userPath)) + if (!IS_USER_ADDRESS(userPath)) return B_BAD_ADDRESS; status = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN); @@ -4372,8 +4372,8 @@ user_read_path_stat(const char *userPath, bool traverseLink, struct stat *userSt struct stat stat; int status; - if (!CHECK_USER_ADDRESS(userPath) - || !CHECK_USER_ADDRESS(userStat) + if (!IS_USER_ADDRESS(userPath) + || !IS_USER_ADDRESS(userStat) || user_strlcpy(path, userPath, SYS_MAX_PATH_LEN) < B_OK) return B_BAD_ADDRESS; @@ -4391,8 +4391,8 @@ user_write_path_stat(const char *userPath, bool traverseLeafLink, const struct s char path[SYS_MAX_PATH_LEN + 1]; struct stat stat; - if (!CHECK_USER_ADDRESS(userStat) - || !CHECK_USER_ADDRESS(userPath) + if (!IS_USER_ADDRESS(userStat) + || !IS_USER_ADDRESS(userPath) || user_strlcpy(path, userPath, SYS_MAX_PATH_LEN) < B_OK || user_memcpy(&stat, userStat, sizeof(struct stat)) < B_OK) return B_BAD_ADDRESS; @@ -4407,7 +4407,7 @@ user_open_attr_dir(int fd, const char *userPath) char pathBuffer[SYS_MAX_PATH_LEN + 1]; if (fd == -1) { - if (!CHECK_USER_ADDRESS(userPath) + if (!IS_USER_ADDRESS(userPath) || user_strlcpy(pathBuffer, userPath, SYS_MAX_PATH_LEN) < B_OK) return B_BAD_ADDRESS; } @@ -4421,7 +4421,7 @@ user_create_attr(int fd, const char *userName, uint32 type, int openMode) { char name[B_FILE_NAME_LENGTH]; - if (!CHECK_USER_ADDRESS(userName) + if (!IS_USER_ADDRESS(userName) || user_strlcpy(name, userName, B_FILE_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; @@ -4434,7 +4434,7 @@ user_open_attr(int fd, const char *userName, int openMode) { char name[B_FILE_NAME_LENGTH]; - if (!CHECK_USER_ADDRESS(userName) + if (!IS_USER_ADDRESS(userName) || user_strlcpy(name, userName, B_FILE_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; @@ -4447,7 +4447,7 @@ user_remove_attr(int fd, const char *userName) { char name[B_FILE_NAME_LENGTH]; - if (!CHECK_USER_ADDRESS(userName) + if (!IS_USER_ADDRESS(userName) || user_strlcpy(name, userName, B_FILE_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; @@ -4461,8 +4461,8 @@ user_rename_attr(int fromFile, const char *userFromName, int toFile, const char char fromName[B_FILE_NAME_LENGTH]; char toName[B_FILE_NAME_LENGTH]; - if (!CHECK_USER_ADDRESS(userFromName) - || !CHECK_USER_ADDRESS(userToName)) + if (!IS_USER_ADDRESS(userFromName) + || !IS_USER_ADDRESS(userToName)) return B_BAD_ADDRESS; if (user_strlcpy(fromName, userFromName, B_FILE_NAME_LENGTH) < B_OK @@ -4485,7 +4485,7 @@ user_create_index(dev_t device, const char *userName, uint32 type, uint32 flags) { char name[B_FILE_NAME_LENGTH]; - if (!CHECK_USER_ADDRESS(userName) + if (!IS_USER_ADDRESS(userName) || user_strlcpy(name, userName, B_FILE_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; @@ -4500,8 +4500,8 @@ user_read_index_stat(dev_t device, const char *userName, struct stat *userStat) struct stat stat; status_t status; - if (!CHECK_USER_ADDRESS(userName) - || !CHECK_USER_ADDRESS(userStat) + if (!IS_USER_ADDRESS(userName) + || !IS_USER_ADDRESS(userStat) || user_strlcpy(name, userName, B_FILE_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; @@ -4520,7 +4520,7 @@ user_remove_index(dev_t device, const char *userName) { char name[B_FILE_NAME_LENGTH]; - if (!CHECK_USER_ADDRESS(userName) + if (!IS_USER_ADDRESS(userName) || user_strlcpy(name, userName, B_FILE_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; @@ -4536,7 +4536,7 @@ user_getcwd(char *userBuffer, size_t size) PRINT(("user_getcwd: buf %p, %ld\n", userBuffer, size)); - if (!CHECK_USER_ADDRESS(userBuffer)) + if (!IS_USER_ADDRESS(userBuffer)) return B_BAD_ADDRESS; if (size > SYS_MAX_PATH_LEN) @@ -4562,7 +4562,7 @@ user_setcwd(int fd, const char *userPath) PRINT(("user_setcwd: path = %p\n", userPath)); if (fd == -1) { - if (!CHECK_USER_ADDRESS(userPath) + if (!IS_USER_ADDRESS(userPath) || user_strlcpy(path, userPath, SYS_MAX_PATH_LEN) < B_OK) return B_BAD_ADDRESS; } diff --git a/src/kernel/core/fs/vfs_select.c b/src/kernel/core/fs/vfs_select.c index e98775e25a..4652ce527f 100644 --- a/src/kernel/core/fs/vfs_select.c +++ b/src/kernel/core/fs/vfs_select.c @@ -315,10 +315,10 @@ user_select(int numfds, fd_set *userReadSet, fd_set *userWriteSet, fd_set *userE if (numfds < 0) return B_BAD_VALUE; - if ((userReadSet != NULL && !CHECK_USER_ADDRESS(userReadSet)) - || (userWriteSet != NULL && !CHECK_USER_ADDRESS(userWriteSet)) - || (userErrorSet != NULL && !CHECK_USER_ADDRESS(userErrorSet)) - || (userSigMask != NULL && !CHECK_USER_ADDRESS(userSigMask))) + if ((userReadSet != NULL && !IS_USER_ADDRESS(userReadSet)) + || (userWriteSet != NULL && !IS_USER_ADDRESS(userWriteSet)) + || (userErrorSet != NULL && !IS_USER_ADDRESS(userErrorSet)) + || (userSigMask != NULL && !IS_USER_ADDRESS(userSigMask))) return B_BAD_ADDRESS; // copy parameters @@ -390,7 +390,7 @@ user_poll(struct pollfd *userfds, int numfds, bigtime_t timeout) if (numfds < 0) return B_BAD_VALUE; - if (userfds == NULL || !CHECK_USER_ADDRESS(userfds)) + if (userfds == NULL || !IS_USER_ADDRESS(userfds)) return B_BAD_ADDRESS; // copy parameters diff --git a/src/kernel/core/image.c b/src/kernel/core/image.c index 07fa2178a2..ed8e4b3da1 100644 --- a/src/kernel/core/image.c +++ b/src/kernel/core/image.c @@ -214,7 +214,7 @@ user_register_image(image_info *userInfo, size_t size) if (size != sizeof(image_info)) return B_BAD_VALUE; - if (!CHECK_USER_ADDRESS(userInfo) + if (!IS_USER_ADDRESS(userInfo) || user_memcpy(&info, userInfo, size) < B_OK) return B_BAD_ADDRESS; @@ -231,7 +231,7 @@ user_get_image_info(image_id id, image_info *userInfo, size_t size) if (size != sizeof(image_info)) return B_BAD_VALUE; - if (!CHECK_USER_ADDRESS(userInfo)) + if (!IS_USER_ADDRESS(userInfo)) return B_BAD_ADDRESS; status = _get_image_info(id, &info, size); @@ -252,7 +252,7 @@ user_get_next_image_info(team_id team, int32 *_cookie, image_info *userInfo, siz if (size != sizeof(image_info)) return B_BAD_VALUE; - if (!CHECK_USER_ADDRESS(userInfo) || !CHECK_USER_ADDRESS(_cookie)) + if (!IS_USER_ADDRESS(userInfo) || !IS_USER_ADDRESS(_cookie)) return B_BAD_ADDRESS; status = _get_next_image_info(team, _cookie, &info, size); diff --git a/src/kernel/core/team.c b/src/kernel/core/team.c index fbb0fab137..336d21d689 100644 --- a/src/kernel/core/team.c +++ b/src/kernel/core/team.c @@ -1,5 +1,10 @@ /* Team functions */ +/* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + /* ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. @@ -838,7 +843,7 @@ user_wait_for_team(team_id id, status_t *_userReturnCode) status_t returnCode; status_t status; - if (!CHECK_USER_ADDRESS(_userReturnCode)) + if (!IS_USER_ADDRESS(_userReturnCode)) return B_BAD_ADDRESS; status = wait_for_team(id, &returnCode); @@ -863,8 +868,8 @@ user_team_create_team(const char *userPath, const char *userName, TRACE(("user_team_create_team: argc = %d\n", argCount)); - if (!CHECK_USER_ADDRESS(userPath) - || !CHECK_USER_ADDRESS(userName)) + if (!IS_USER_ADDRESS(userPath) + || !IS_USER_ADDRESS(userName)) return B_BAD_ADDRESS; rc = user_copy_strings_array(userArgs, argCount, &args); @@ -899,7 +904,7 @@ user_get_team_info(team_id id, team_info *userInfo) status_t status; team_info info; - if (!CHECK_USER_ADDRESS(userInfo)) + if (!IS_USER_ADDRESS(userInfo)) return B_BAD_ADDRESS; status = _get_team_info(id, &info, sizeof(team_info)); @@ -919,8 +924,8 @@ user_get_next_team_info(int32 *userCookie, team_info *userInfo) team_info info; int32 cookie; - if (!CHECK_USER_ADDRESS(userCookie) - || !CHECK_USER_ADDRESS(userInfo) + if (!IS_USER_ADDRESS(userCookie) + || !IS_USER_ADDRESS(userInfo) || user_memcpy(&cookie, userCookie, sizeof(int32)) < B_OK) return B_BAD_ADDRESS; @@ -943,8 +948,8 @@ user_getenv(const char *userName, char **_userValue) char *value; int rc; - if (!CHECK_USER_ADDRESS(userName) - || !CHECK_USER_ADDRESS(_userValue) + if (!IS_USER_ADDRESS(userName) + || !IS_USER_ADDRESS(_userValue) || user_strlcpy(name, userName, SYS_THREAD_STRING_LENGTH_MAX) < B_OK) return B_BAD_ADDRESS; @@ -965,8 +970,8 @@ user_setenv(const char *userName, const char *userValue, int overwrite) char name[SYS_THREAD_STRING_LENGTH_MAX]; char value[SYS_THREAD_STRING_LENGTH_MAX]; - if (!CHECK_USER_ADDRESS(userName) - || !CHECK_USER_ADDRESS(userValue) + if (!IS_USER_ADDRESS(userName) + || !IS_USER_ADDRESS(userValue) || user_strlcpy(name, userName, SYS_THREAD_STRING_LENGTH_MAX) < B_OK || user_strlcpy(value, userValue, SYS_THREAD_STRING_LENGTH_MAX) < B_OK) return B_BAD_ADDRESS; diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index 277a54d286..86926f746d 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -1,5 +1,10 @@ /* Threading routines */ +/* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + /* ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. @@ -1574,8 +1579,8 @@ user_spawn_thread(thread_func entry, const char *userName, int32 priority, void { char name[SYS_MAX_OS_NAME_LEN]; - if (!CHECK_USER_ADDRESS(entry) || entry == NULL - || !CHECK_USER_ADDRESS(userName) + if (!IS_USER_ADDRESS(entry) || entry == NULL + || !IS_USER_ADDRESS(userName) || user_strlcpy(name, userName, SYS_MAX_OS_NAME_LEN) < B_OK) return B_BAD_ADDRESS; @@ -1596,7 +1601,7 @@ user_get_thread_info(thread_id id, thread_info *userInfo) thread_info info; status_t status; - if (!CHECK_USER_ADDRESS(userInfo)) + if (!IS_USER_ADDRESS(userInfo)) return B_BAD_ADDRESS; status = _get_thread_info(id, &info, sizeof(thread_info)); @@ -1615,7 +1620,7 @@ user_get_next_thread_info(team_id team, int32 *userCookie, thread_info *userInfo thread_info info; int32 cookie; - if (!CHECK_USER_ADDRESS(userCookie) || !CHECK_USER_ADDRESS(userInfo) + if (!IS_USER_ADDRESS(userCookie) || !IS_USER_ADDRESS(userInfo) || user_memcpy(&cookie, userCookie, sizeof(int32)) < B_OK) return B_BAD_ADDRESS; @@ -1637,7 +1642,7 @@ user_wait_for_thread(thread_id id, status_t *userReturnCode) status_t returnCode; status_t status; - if (!CHECK_USER_ADDRESS(userReturnCode)) + if (!IS_USER_ADDRESS(userReturnCode)) return B_BAD_ADDRESS; status = wait_for_thread(id, &returnCode); @@ -1659,7 +1664,7 @@ user_has_data(thread_id thread) status_t user_send_data(thread_id thread, int32 code, const void *buffer, size_t bufferSize) { - if (!CHECK_USER_ADDRESS(buffer)) + if (!IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; return send_data(thread, code, buffer, bufferSize); @@ -1673,8 +1678,8 @@ user_receive_data(thread_id *userSender, void *buffer, size_t bufferSize) thread_id sender; status_t code; - if (!CHECK_USER_ADDRESS(userSender) - || !CHECK_USER_ADDRESS(buffer)) + if (!IS_USER_ADDRESS(userSender) + || !IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; code = receive_data(&sender, buffer, bufferSize); @@ -1687,6 +1692,9 @@ user_receive_data(thread_id *userSender, void *buffer, size_t bufferSize) } +// ToDo: the following two functions don't belong here + + int user_getrlimit(int resource, struct rlimit *urlp) { @@ -1696,7 +1704,7 @@ user_getrlimit(int resource, struct rlimit *urlp) if (urlp == NULL) return EINVAL; - if (!CHECK_USER_ADDRESS(urlp)) + if (!IS_USER_ADDRESS(urlp)) return B_BAD_ADDRESS; ret = getrlimit(resource, &rl); @@ -1714,21 +1722,17 @@ user_getrlimit(int resource, struct rlimit *urlp) int -user_setrlimit(int resource, const struct rlimit *urlp) +user_setrlimit(int resource, const struct rlimit *userResourceLimit) { - struct rlimit rl; - int err; + struct rlimit resourceLimit; - if (urlp == NULL) + if (userResourceLimit == NULL) return EINVAL; - if (!CHECK_USER_ADDRESS(urlp)) + if (!IS_USER_ADDRESS(userResourceLimit) + || user_memcpy(&resourceLimit, userResourceLimit, sizeof(struct rlimit)) < B_OK) return B_BAD_ADDRESS; - err = user_memcpy(&rl, urlp, sizeof(struct rlimit)); - if (err < 0) - return err; - - return setrlimit(resource, &rl); + return setrlimit(resource, &resourceLimit); } diff --git a/src/kernel/core/vm/vm.c b/src/kernel/core/vm/vm.c index a4d28935f9..ad9db853d4 100755 --- a/src/kernel/core/vm/vm.c +++ b/src/kernel/core/vm/vm.c @@ -2462,7 +2462,7 @@ _user_get_area_info(area_id area, area_info *userInfo) area_info info; status_t status; - if (!CHECK_USER_ADDRESS(userInfo)) + if (!IS_USER_ADDRESS(userInfo)) return B_BAD_ADDRESS; status = get_area_info(area, &info); @@ -2508,8 +2508,8 @@ _user_clone_area(const char *userName, void **userAddress, uint32 addressSpec, void *address; area_id clonedArea; - if (!CHECK_USER_ADDRESS(userName) - || !CHECK_USER_ADDRESS(userAddress) + if (!IS_USER_ADDRESS(userName) + || !IS_USER_ADDRESS(userAddress) || user_strlcpy(name, userName, sizeof(name)) < B_OK || user_memcpy(&address, userAddress, sizeof(address)) < B_OK) return B_BAD_ADDRESS; @@ -2544,8 +2544,8 @@ _user_create_area(const char *userName, void **userAddress, uint32 addressSpec, if (protection & B_KERNEL_PROTECTION) return B_BAD_VALUE; - if (!CHECK_USER_ADDRESS(userName) - || !CHECK_USER_ADDRESS(userAddress) + if (!IS_USER_ADDRESS(userName) + || !IS_USER_ADDRESS(userAddress) || user_strlcpy(name, userName, sizeof(name)) < B_OK || user_memcpy(&address, userAddress, sizeof(address)) < B_OK) return B_BAD_ADDRESS;