зеркало из https://github.com/mozilla/gecko-dev.git
Bug 605362, part 1: Allocate page-aligned shmem segments in ShmImage, to match other allocators which more honestly report address space and system mem taken by alloc. r=joe
This commit is contained in:
Родитель
71323d9d0b
Коммит
d1fddc9cfc
|
@ -89,6 +89,7 @@ CPPSRCS += \
|
|||
ProcessChild.cpp \
|
||||
RPCChannel.cpp \
|
||||
ScopedXREEmbed.cpp \
|
||||
SharedMemory.cpp \
|
||||
Shmem.cpp \
|
||||
StringUtil.cpp \
|
||||
SyncChannel.cpp \
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Jones <jones.chris.g@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "mozilla/ipc/SharedMemory.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
/*static*/ size_t
|
||||
SharedMemory::PageAlignedSize(size_t aSize)
|
||||
{
|
||||
size_t pageSize = SystemPageSize();
|
||||
size_t nPagesNeeded = size_t(ceil(double(aSize) / double(pageSize)));
|
||||
return pageSize * nPagesNeeded;
|
||||
}
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace mozilla
|
|
@ -103,6 +103,7 @@ public:
|
|||
|
||||
static void SystemProtect(char* aAddr, size_t aSize, int aRights);
|
||||
static size_t SystemPageSize();
|
||||
static size_t PageAlignedSize(size_t aSize);
|
||||
};
|
||||
|
||||
} // namespace ipc
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "Shmem.h"
|
||||
|
||||
#include "ProtocolUtils.h"
|
||||
|
@ -196,14 +194,6 @@ DestroySegment(SharedMemory* aSegment)
|
|||
aSegment->Release();
|
||||
}
|
||||
|
||||
static size_t
|
||||
PageAlignedSize(size_t aSize)
|
||||
{
|
||||
size_t pageSize = SharedMemory::SystemPageSize();
|
||||
size_t nPagesNeeded = int(ceil(double(aSize) / double(pageSize)));
|
||||
return pageSize * nPagesNeeded;
|
||||
}
|
||||
|
||||
|
||||
#if defined(DEBUG)
|
||||
|
||||
|
@ -401,7 +391,7 @@ Shmem::Alloc(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
|
|||
size_t pageSize = SharedMemory::SystemPageSize();
|
||||
SharedMemory* segment = nsnull;
|
||||
// |2*pageSize| is for the front and back sentinel
|
||||
size_t segmentSize = PageAlignedSize(aNBytes + 2*pageSize);
|
||||
size_t segmentSize = SharedMemory::PageAlignedSize(aNBytes + 2*pageSize);
|
||||
|
||||
if (aType == SharedMemory::TYPE_BASIC)
|
||||
segment = CreateSegment(segmentSize, SharedMemoryBasic::NULLHandle());
|
||||
|
@ -457,7 +447,7 @@ Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
|
|||
SharedMemory* segment = 0;
|
||||
size_t pageSize = SharedMemory::SystemPageSize();
|
||||
// |2*pageSize| is for the front and back sentinels
|
||||
size_t segmentSize = PageAlignedSize(size + 2*pageSize);
|
||||
size_t segmentSize = SharedMemory::PageAlignedSize(size + 2*pageSize);
|
||||
|
||||
if (SharedMemory::TYPE_BASIC == type) {
|
||||
SharedMemoryBasic::Handle handle;
|
||||
|
@ -532,11 +522,11 @@ Shmem::Alloc(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
|
|||
SharedMemory *segment = nsnull;
|
||||
|
||||
if (aType == SharedMemory::TYPE_BASIC)
|
||||
segment = CreateSegment(PageAlignedSize(aNBytes + sizeof(uint32)),
|
||||
segment = CreateSegment(SharedMemory::PageAlignedSize(aNBytes + sizeof(uint32)),
|
||||
SharedMemoryBasic::NULLHandle());
|
||||
#ifdef MOZ_HAVE_SHAREDMEMORYSYSV
|
||||
else if (aType == SharedMemory::TYPE_SYSV)
|
||||
segment = CreateSegment(PageAlignedSize(aNBytes + sizeof(uint32)),
|
||||
segment = CreateSegment(SharedMemory::PageAlignedSize(aNBytes + sizeof(uint32)),
|
||||
SharedMemorySysV::NULLHandle());
|
||||
#endif
|
||||
else
|
||||
|
@ -568,7 +558,7 @@ Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
|
|||
return 0;
|
||||
|
||||
SharedMemory* segment = 0;
|
||||
size_t segmentSize = PageAlignedSize(size + sizeof(size_t));
|
||||
size_t segmentSize = SharedMemory::PageAlignedSize(size + sizeof(size_t));
|
||||
|
||||
if (SharedMemory::TYPE_BASIC == type) {
|
||||
SharedMemoryBasic::Handle handle;
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
|
||||
#ifdef MOZ_HAVE_SHMIMAGE
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
// If XShm isn't available to our client, we'll try XShm once, fail,
|
||||
// set this to false and then never try again.
|
||||
static PRBool gShmAvailable = PR_TRUE;
|
||||
|
@ -76,7 +78,8 @@ nsShmImage::Create(const gfxIntSize& aSize,
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
size_t size = shm->mImage->bytes_per_line * shm->mImage->height;
|
||||
size_t size = SharedMemory::PageAlignedSize(
|
||||
shm->mImage->bytes_per_line * shm->mImage->height);
|
||||
shm->mSegment = new SharedMemorySysV();
|
||||
if (!shm->mSegment->Create(size) || !shm->mSegment->Map(size)) {
|
||||
return nsnull;
|
||||
|
|
|
@ -68,11 +68,11 @@
|
|||
class QRect;
|
||||
class QWidget;
|
||||
|
||||
using mozilla::ipc::SharedMemorySysV;
|
||||
|
||||
class nsShmImage {
|
||||
NS_INLINE_DECL_REFCOUNTING(nsShmImage)
|
||||
|
||||
typedef mozilla::ipc::SharedMemorySysV SharedMemorySysV;
|
||||
|
||||
public:
|
||||
typedef gfxASurface::gfxImageFormat Format;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче