Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Unified Diff: util/win/get_function.cc

Issue 1405323003: win: Add and use GET_FUNCTION() and GET_FUNCTION_REQUIRED() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/win/get_function.h ('k') | util/win/get_function_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/win/get_function.cc
diff --git a/snapshot/minidump/minidump_string_reader.cc b/util/win/get_function.cc
similarity index 52%
copy from snapshot/minidump/minidump_string_reader.cc
copy to util/win/get_function.cc
index 6ea36089f60c726e2ec8c7a62e7b00a12ca8b16b..d498d30b77d7ea80a0090904afdd2d9af96c36aa 100644
--- a/snapshot/minidump/minidump_string_reader.cc
+++ b/util/win/get_function.cc
@@ -12,38 +12,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "snapshot/minidump/minidump_string_reader.h"
+#include "util/win/get_function.h"
#include "base/logging.h"
-#include "minidump/minidump_extensions.h"
+#include "base/strings/utf_string_conversions.h"
namespace crashpad {
namespace internal {
-bool ReadMinidumpUTF8String(FileReaderInterface* file_reader,
- RVA rva,
- std::string* string) {
- if (rva == 0) {
- string->clear();
- return true;
+FARPROC GetFunctionInternal(
+ const wchar_t* library, const char* function, bool required) {
+ HMODULE module = LoadLibrary(library);
+ DPCHECK(!required || module) << "LoadLibrary " << base::UTF16ToUTF8(library);
+ if (!module) {
+ return nullptr;
}
- if (!file_reader->SeekSet(rva)) {
- return false;
+ // Strip off any leading :: that may have come from stringifying the
+ // function’s name.
+ if (function[0] == ':' && function[1] == ':' &&
+ function[2] && function[2] != ':') {
+ function += 2;
}
- uint32_t string_size;
- if (!file_reader->ReadExactly(&string_size, sizeof(string_size))) {
- return false;
- }
-
- std::string local_string(string_size, '\0');
- if (!file_reader->ReadExactly(&local_string[0], string_size)) {
- return false;
- }
-
- string->swap(local_string);
- return true;
+ FARPROC proc = GetProcAddress(module, function);
+ DPCHECK(!required || proc) << "GetProcAddress " << function;
+ return proc;
}
} // namespace internal
« no previous file with comments | « util/win/get_function.h ('k') | util/win/get_function_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698