page_size_posix.cc 635 B

123456789101112131415161718192021222324
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/memory/page_size.h"
  5. #include <unistd.h>
  6. namespace base {
  7. size_t GetPageSize() {
  8. static const size_t pagesize = []() -> size_t {
  9. // For more information see getpagesize(2). Portable applications should use
  10. // sysconf(_SC_PAGESIZE) rather than getpagesize() if it's available.
  11. #if defined(_SC_PAGESIZE)
  12. return static_cast<size_t>(sysconf(_SC_PAGESIZE));
  13. #else
  14. return getpagesize();
  15. #endif
  16. }();
  17. return pagesize;
  18. }
  19. } // namespace base