Explicitly allocate ResState on the call stack
Previously known as __res_state, res_state, res or even statp, the
ResState struct holds the context of a query in progress.
After a long series of preparatory patches, the thread-local storage
nonsense that's been plaguing this fine codebase for decades is finally
gone. Sayonara! ResState is now explicitly allocated on the stack at the
beginning of each query and passed down as a regular function argument.
To keep this patch reviewable, I threw in two compatibility typedefs for
the legacy names. We'll get rid of them in a separate mechanical patch.
Next steps:
- Give ResState a regular constructor and, crucially, a real destructor
- Move the definition to ResState.h, like it's a real class
- Populate the nameservers immediately on construction
- Switch to safe C++ data structures
Change-Id: I5c0b85da3ad9a55fa41dca6c87e57fe8f50c6abc
diff --git a/resolv_cache_unit_test.cpp b/resolv_cache_unit_test.cpp
index f62f317..1db209f 100644
--- a/resolv_cache_unit_test.cpp
+++ b/resolv_cache_unit_test.cpp
@@ -30,6 +30,7 @@
#include <gtest/gtest.h>
#include "netd_resolv/stats.h"
+#include "res_init.h"
#include "resolv_cache.h"
#include "resolv_private.h"
#include "tests/dns_responder/dns_responder.h"
@@ -64,9 +65,10 @@
};
std::vector<char> makeQuery(int op, const char* qname, int qclass, int qtype) {
- res_state res = res_get_state();
uint8_t buf[MAXPACKET] = {};
- const int len = res_nmkquery(res, op, qname, qclass, qtype, NULL, 0, NULL, buf, sizeof(buf));
+ const int len = res_nmkquery(op, qname, qclass, qtype, /*data=*/nullptr, /*datalen=*/0, buf,
+ sizeof(buf),
+ /*netcontext_flags=*/0);
return std::vector<char>(buf, buf + len);
}