summaryrefslogtreecommitdiffstats
path: root/mojo/system/memory.cc
blob: df658ae5ee3d405aff88f8f244259583f22f81b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/system/memory.h"

#include <limits>

#include "base/logging.h"

namespace mojo {
namespace system {

bool VerifyUserPointer(const void* pointer, size_t count, size_t size_each) {
  DCHECK_GT(size_each, 0u);
  if (count > std::numeric_limits<size_t>::max() / size_each)
    return false;

  // TODO(vtl): If running in kernel mode, do a full verification. For now, just
  // check that it's non-null if |size| is nonzero. (A faster user mode
  // implementation is also possible if this check is skipped.)
  return count == 0 || !!pointer;
}

}  // namespace system
}  // namespace mojo