sys_info_freebsd.cc 956 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) 2011 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/system/sys_info.h"
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <sys/sysctl.h>
  8. #include "base/notreached.h"
  9. namespace base {
  10. int64_t SysInfo::AmountOfPhysicalMemoryImpl() {
  11. int pages, page_size;
  12. size_t size = sizeof(pages);
  13. sysctlbyname("vm.stats.vm.v_page_count", &pages, &size, NULL, 0);
  14. sysctlbyname("vm.stats.vm.v_page_size", &page_size, &size, NULL, 0);
  15. if (pages == -1 || page_size == -1) {
  16. NOTREACHED();
  17. return 0;
  18. }
  19. return static_cast<int64_t>(pages) * page_size;
  20. }
  21. // static
  22. uint64_t SysInfo::MaxSharedMemorySize() {
  23. size_t limit;
  24. size_t size = sizeof(limit);
  25. if (sysctlbyname("kern.ipc.shmmax", &limit, &size, NULL, 0) < 0) {
  26. NOTREACHED();
  27. return 0;
  28. }
  29. return static_cast<uint64_t>(limit);
  30. }
  31. } // namespace base