Skip to content

Commit

Permalink
ipc: Convert int types from basictypes.h to the ones from stdint.h
Browse files Browse the repository at this point in the history
Now that the supported toolchain has stdint.h, use the integer types
from this standard header file.

BUG=138542
TEST=ipc_tests
[email protected]
[email protected] # for ui/

Review URL: https://codereview.chromium.org/1322253003

Cr-Commit-Position: refs/heads/master@{#347457}
  • Loading branch information
tfarina authored and Commit bot committed Sep 4, 2015
1 parent 28bf86e commit 10a5c06
Show file tree
Hide file tree
Showing 34 changed files with 181 additions and 147 deletions.
4 changes: 3 additions & 1 deletion ipc/ipc_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "ipc/ipc_channel.h"

#include <stdint.h>

#include <limits>

#include "base/atomic_sequence_num.h"
Expand Down Expand Up @@ -38,7 +40,7 @@ std::string Channel::GenerateUniqueRandomChannelID() {
return base::StringPrintf("%d.%u.%d",
process_id,
g_last_id.GetNext(),
base::RandInt(0, std::numeric_limits<int32>::max()));
base::RandInt(0, std::numeric_limits<int32_t>::max()));
}

} // namespace IPC
3 changes: 2 additions & 1 deletion ipc/ipc_channel_nacl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>

#include <algorithm>
Expand Down Expand Up @@ -358,7 +359,7 @@ bool ChannelNacl::ShouldDispatchInputMessage(Message* msg) {
}

bool ChannelNacl::GetNonBrokeredAttachments(Message* msg) {
uint16 header_fds = msg->header()->num_fds;
uint16_t header_fds = msg->header()->num_fds;
CHECK(header_fds == input_fds_.size());
if (header_fds == 0)
return true; // Nothing to do.
Expand Down
5 changes: 3 additions & 2 deletions ipc/ipc_channel_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
Expand Down Expand Up @@ -440,7 +441,7 @@ bool ChannelPosix::ProcessOutgoingMessages() {

// DCHECK_LE above already checks that
// num_fds < kMaxDescriptorsPerMessage so no danger of overflow.
msg->header()->num_fds = static_cast<uint16>(num_fds);
msg->header()->num_fds = static_cast<uint16_t>(num_fds);
}

if (bytes_written == 1) {
Expand Down Expand Up @@ -812,7 +813,7 @@ bool ChannelPosix::ShouldDispatchInputMessage(Message* msg) {
// This will read from the input_fds_ (READWRITE mode only) and read more
// handles from the FD pipe if necessary.
bool ChannelPosix::GetNonBrokeredAttachments(Message* msg) {
uint16 header_fds = msg->header()->num_fds;
uint16_t header_fds = msg->header()->num_fds;
if (!header_fds)
return true; // Nothing to do.

Expand Down
5 changes: 3 additions & 2 deletions ipc/ipc_channel_posix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ipc/ipc_channel_posix.h"

#include <fcntl.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
Expand All @@ -28,7 +29,7 @@

namespace {

static const uint32 kQuitMessage = 47;
static const uint32_t kQuitMessage = 47;

class IPCChannelPosixTestListener : public IPC::Listener {
public:
Expand All @@ -55,7 +56,7 @@ class IPCChannelPosixTestListener : public IPC::Listener {
return true;
}

void OnChannelConnected(int32 peer_pid) override {
void OnChannelConnected(int32_t peer_pid) override {
status_ = CONNECTED;
if (!quit_only_on_message_) {
QuitRunLoop();
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_channel_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool ChannelProxy::Context::OnMessageReceivedNoFilter(const Message& message) {
}

// Called on the IPC::Channel thread
void ChannelProxy::Context::OnChannelConnected(int32 peer_pid) {
void ChannelProxy::Context::OnChannelConnected(int32_t peer_pid) {
// We cache off the peer_pid so it can be safely accessed from both threads.
peer_pid_ = channel_->GetPeerPID();

Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_channel_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class IPC_EXPORT ChannelProxy : public Endpoint, public base::NonThreadSafe {

// IPC::Listener methods:
bool OnMessageReceived(const Message& message) override;
void OnChannelConnected(int32 peer_pid) override;
void OnChannelConnected(int32_t peer_pid) override;
void OnChannelError() override;

// Like OnMessageReceived but doesn't try the filters.
Expand Down
6 changes: 3 additions & 3 deletions ipc/ipc_channel_proxy_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class MessageCountFilter : public IPC::MessageFilter {
last_filter_event_(NONE),
message_filtering_enabled_(false) {}

MessageCountFilter(uint32 supported_message_class)
MessageCountFilter(uint32_t supported_message_class)
: messages_received_(0),
supported_message_class_(supported_message_class),
is_global_filter_(false),
Expand Down Expand Up @@ -201,7 +201,7 @@ class MessageCountFilter : public IPC::MessageFilter {
}

bool GetSupportedMessageClasses(
std::vector<uint32>* supported_message_classes) const override {
std::vector<uint32_t>* supported_message_classes) const override {
if (is_global_filter_)
return false;
supported_message_classes->push_back(supported_message_class_);
Expand All @@ -219,7 +219,7 @@ class MessageCountFilter : public IPC::MessageFilter {
~MessageCountFilter() override {}

size_t messages_received_;
uint32 supported_message_class_;
uint32_t supported_message_class_;
bool is_global_filter_;

FilterEvent last_filter_event_;
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_channel_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ChannelListenerWithOnConnectedSend : public IPC::TestChannelListener {
ChannelListenerWithOnConnectedSend() {}
~ChannelListenerWithOnConnectedSend() override {}

void OnChannelConnected(int32 peer_pid) override {
void OnChannelConnected(int32_t peer_pid) override {
SendNextMessage();
}
};
Expand Down
13 changes: 7 additions & 6 deletions ipc/ipc_channel_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ipc/ipc_channel_win.h"

#include <stdint.h>
#include <windows.h>

#include "base/auto_reset.h"
Expand Down Expand Up @@ -222,11 +223,11 @@ void ChannelWin::HandleInternalMessage(const Message& msg) {
DCHECK_EQ(msg.type(), static_cast<unsigned>(Channel::HELLO_MESSAGE_TYPE));
// The hello message contains one parameter containing the PID.
base::PickleIterator it(msg);
int32 claimed_pid;
int32_t claimed_pid;
bool failed = !it.ReadInt(&claimed_pid);

if (!failed && validate_client_) {
int32 secret;
int32_t secret;
failed = it.ReadInt(&secret) ? (secret != client_secret_) : true;
}

Expand Down Expand Up @@ -260,8 +261,8 @@ bool ChannelWin::DidEmptyInputBuffers() {
}

// static
const base::string16 ChannelWin::PipeName(
const std::string& channel_id, int32* secret) {
const base::string16 ChannelWin::PipeName(const std::string& channel_id,
int32_t* secret) {
std::string name("\\\\.\\pipe\\chrome.");

// Prevent the shared secret from ending up in the pipe name.
Expand Down Expand Up @@ -356,7 +357,7 @@ bool ChannelWin::CreatePipe(const IPC::ChannelHandle &channel_handle,

// Don't send the secret to the untrusted process, and don't send a secret
// if the value is zero (for IPC backwards compatability).
int32 secret = validate_client_ ? 0 : client_secret_;
int32_t secret = validate_client_ ? 0 : client_secret_;
if (!m->WriteInt(GetCurrentProcessId()) ||
(secret && !m->WriteUInt32(secret))) {
pipe_.Close();
Expand Down Expand Up @@ -469,7 +470,7 @@ bool ChannelWin::ProcessOutgoingMessages(
DCHECK(m->size() <= INT_MAX);
BOOL ok = WriteFile(pipe_.Get(),
m->data(),
static_cast<uint32>(m->size()),
static_cast<uint32_t>(m->size()),
NULL,
&output_state_.context.overlapped);
if (!ok) {
Expand Down
8 changes: 5 additions & 3 deletions ipc/ipc_channel_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "ipc/ipc_channel.h"

#include <stdint.h>

#include <queue>
#include <string>

Expand Down Expand Up @@ -56,7 +58,7 @@ class ChannelWin : public Channel,
bool IsAttachmentBrokerEndpoint() override;

static const base::string16 PipeName(const std::string& channel_id,
int32* secret);
int32_t* secret);
bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode);

bool ProcessConnection();
Expand Down Expand Up @@ -121,13 +123,13 @@ class ChannelWin : public Channel,
bool validate_client_;

// Tracks the lifetime of this object, for debugging purposes.
uint32 debug_flags_;
uint32_t debug_flags_;

// This is a unique per-channel value used to authenticate the client end of
// a connection. If the value is non-zero, the client passes it in the hello
// and the host validates. (We don't send the zero value fto preserve IPC
// compatability with existing clients that don't validate the channel.)
int32 client_secret_;
int32_t client_secret_;

scoped_ptr<base::ThreadChecker> thread_check_;

Expand Down
22 changes: 12 additions & 10 deletions ipc/ipc_fuzzing_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stdint.h>
#include <stdio.h>
#include <string>

#include <sstream>
#include <string>

#include "base/message_loop/message_loop.h"
#include "base/strings/string16.h"
Expand Down Expand Up @@ -38,7 +40,7 @@ namespace {

TEST(IPCMessageIntegrity, ReadBeyondBufferStr) {
// This was BUG 984408.
uint32 v1 = kuint32max - 1;
uint32_t v1 = kuint32max - 1;
int v2 = 666;
IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL);
EXPECT_TRUE(m.WriteInt(v1));
Expand All @@ -51,7 +53,7 @@ TEST(IPCMessageIntegrity, ReadBeyondBufferStr) {

TEST(IPCMessageIntegrity, ReadBeyondBufferStr16) {
// This was BUG 984408.
uint32 v1 = kuint32max - 1;
uint32_t v1 = kuint32max - 1;
int v2 = 777;
IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL);
EXPECT_TRUE(m.WriteInt(v1));
Expand Down Expand Up @@ -101,7 +103,7 @@ TEST(IPCMessageIntegrity, MAYBE_ReadVectorTooLarge1) {
EXPECT_TRUE(m.WriteInt64(1));
EXPECT_TRUE(m.WriteInt64(2));

std::vector<int64> vec;
std::vector<int64_t> vec;
base::PickleIterator iter(m);
EXPECT_FALSE(ReadParam(&m, &iter, &vec));
}
Expand All @@ -115,7 +117,7 @@ TEST(IPCMessageIntegrity, ReadVectorTooLarge2) {
EXPECT_TRUE(m.WriteInt64(1));
EXPECT_TRUE(m.WriteInt64(2));

std::vector<int64> vec;
std::vector<int64_t> vec;
base::PickleIterator iter(m);
EXPECT_FALSE(ReadParam(&m, &iter, &vec));
}
Expand Down Expand Up @@ -170,7 +172,7 @@ class FuzzerServerListener : public SimpleListener {
Cleanup();
}

bool RoundtripAckReply(int routing, uint32 type_id, int reply) {
bool RoundtripAckReply(int routing, uint32_t type_id, int reply) {
IPC::Message* message = new IPC::Message(routing, type_id,
IPC::Message::PRIORITY_NORMAL);
message->WriteInt(reply + 1);
Expand All @@ -185,7 +187,7 @@ class FuzzerServerListener : public SimpleListener {
base::MessageLoop::current()->Quit();
}

void ReplyMsgNotHandled(uint32 type_id) {
void ReplyMsgNotHandled(uint32_t type_id) {
RoundtripAckReply(FUZZER_ROUTING_ID, MsgUnhandled::ID, type_id);
Cleanup();
}
Expand Down Expand Up @@ -213,7 +215,7 @@ class FuzzerClientListener : public SimpleListener {
return true;
}

bool ExpectMessage(int value, uint32 type_id) {
bool ExpectMessage(int value, uint32_t type_id) {
if (!MsgHandlerInternal(type_id))
return false;
int msg_value1 = 0;
Expand All @@ -233,12 +235,12 @@ class FuzzerClientListener : public SimpleListener {
return true;
}

bool ExpectMsgNotHandled(uint32 type_id) {
bool ExpectMsgNotHandled(uint32_t type_id) {
return ExpectMessage(type_id, MsgUnhandled::ID);
}

private:
bool MsgHandlerInternal(uint32 type_id) {
bool MsgHandlerInternal(uint32_t type_id) {
base::MessageLoop::current()->Run();
if (NULL == last_msg_)
return false;
Expand Down
5 changes: 3 additions & 2 deletions ipc/ipc_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#ifndef IPC_IPC_LISTENER_H_
#define IPC_IPC_LISTENER_H_

#include "base/basictypes.h"
#include <stdint.h>

#include "build/build_config.h"
#include "ipc/ipc_export.h"

Expand All @@ -22,7 +23,7 @@ class IPC_EXPORT Listener {

// Called when the channel is connected and we have received the internal
// Hello message from the peer.
virtual void OnChannelConnected(int32 peer_pid) {}
virtual void OnChannelConnected(int32_t peer_pid) {}

// Called when an error is detected that causes the channel to close.
// This method is not called when a channel is closed normally.
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void Logging::OnPostDispatchMessage(const Message& message,
}
}

void Logging::GetMessageText(uint32 type, std::string* name,
void Logging::GetMessageText(uint32_t type, std::string* name,
const Message* message,
std::string* params) {
if (!log_function_map_)
Expand Down
6 changes: 4 additions & 2 deletions ipc/ipc_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef IPC_IPC_LOGGING_H_
#define IPC_IPC_LOGGING_H_

#include <stdint.h>

#include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.

#ifdef IPC_MESSAGE_LOG_ENABLED
Expand All @@ -23,7 +25,7 @@ typedef void (*LogFunction)(std::string* name,
const IPC::Message* msg,
std::string* params);

typedef base::hash_map<uint32, LogFunction > LogFunctionMap;
typedef base::hash_map<uint32_t, LogFunction > LogFunctionMap;

namespace IPC {

Expand Down Expand Up @@ -73,7 +75,7 @@ class IPC_EXPORT Logging {
// Like the *MsgLog functions declared for each message class, except this
// calls the correct one based on the message type automatically. Defined in
// ipc_logging.cc.
static void GetMessageText(uint32 type, std::string* name,
static void GetMessageText(uint32_t type, std::string* name,
const Message* message, std::string* params);

static void set_log_function_map(LogFunctionMap* functions) {
Expand Down
Loading

0 comments on commit 10a5c06

Please sign in to comment.