PackageKit: tweak classes used by packagefs to write to user buffers.
when compiled in kernel mode, BMemoryIO::WriteAt() and BBufferDataReader::ReadData() now check the buffer to write to, and eventually call user_memcpy() instead of memcpy().
This commit is contained in:
parent
51051c56d3
commit
8c44fc0f65
|
@ -10,6 +10,10 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
|
||||
#include <arch/user_memory.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
|
@ -63,6 +67,12 @@ BBufferDataReader::ReadData(off_t offset, void* buffer, size_t size)
|
|||
if (size > fSize || offset > (off_t)fSize - (off_t)size)
|
||||
return B_ERROR;
|
||||
|
||||
#if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
|
||||
if (IS_USER_ADDRESS(buffer)) {
|
||||
if (user_memcpy(buffer, (const uint8*)fData + offset, size) != B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
} else
|
||||
#endif
|
||||
memcpy(buffer, (const uint8*)fData + offset, size);
|
||||
return B_OK;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
|
||||
#include <Errors.h>
|
||||
|
||||
#if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
|
||||
#include <arch/user_memory.h>
|
||||
#endif
|
||||
|
||||
|
||||
BDataIO::BDataIO()
|
||||
{
|
||||
|
@ -366,6 +370,12 @@ BMemoryIO::WriteAt(off_t pos, const void* buffer, size_t size)
|
|||
ssize_t sizeWritten = 0;
|
||||
if (pos < (off_t)fBufferSize) {
|
||||
sizeWritten = min_c((off_t)size, (off_t)fBufferSize - pos);
|
||||
#if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
|
||||
if (IS_USER_ADDRESS(fBuffer)) {
|
||||
if (user_memcpy(fBuffer + pos, buffer, sizeWritten) != B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
} else
|
||||
#endif
|
||||
memcpy(fBuffer + pos, buffer, sizeWritten);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue