dart-sdk/runtime/bin/crypto_macos.cc
Alexander Aprelev 94fcf226fc [vm/sigprof] Disable checking of sigprof on mac.
Fixes https://github.com/dart-lang/sdk/issues/41239

Change-Id: I397f70c7d9977bbf8ce33ce649c7d82e02fd26a7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151880
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2020-06-19 18:42:33 +00:00

43 lines
1 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "platform/globals.h"
#if defined(HOST_OS_MACOS)
#include <errno.h> // NOLINT
#include <fcntl.h> // NOLINT
#include "bin/crypto.h"
#include "bin/fdutils.h"
#include "platform/signal_blocker.h"
namespace dart {
namespace bin {
bool Crypto::GetRandomBytes(intptr_t count, uint8_t* buffer) {
intptr_t fd = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_CLOEXEC));
if (fd < 0) {
return false;
}
intptr_t bytes_read = 0;
do {
int res =
TEMP_FAILURE_RETRY(read(fd, buffer + bytes_read, count - bytes_read));
if (res < 0) {
int err = errno;
close(fd);
errno = err;
return false;
}
bytes_read += res;
} while (bytes_read < count);
close(fd);
return true;
}
} // namespace bin
} // namespace dart
#endif // defined(HOST_OS_MACOS)