summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/demangle.cpp2
-rw-r--r--src/common/detached_tasks.cpp4
-rw-r--r--src/common/page_table.cpp1
-rw-r--r--src/common/page_table.h1
-rw-r--r--src/common/scratch_buffer.h17
-rw-r--r--src/common/settings.cpp5
-rw-r--r--src/common/socket_types.h17
-rw-r--r--src/common/time_zone.cpp47
8 files changed, 58 insertions, 36 deletions
diff --git a/src/common/demangle.cpp b/src/common/demangle.cpp
index 3310faf86..6e117cb41 100644
--- a/src/common/demangle.cpp
+++ b/src/common/demangle.cpp
@@ -23,7 +23,7 @@ std::string DemangleSymbol(const std::string& mangled) {
SCOPE_EXIT({ std::free(demangled); });
if (is_itanium(mangled)) {
- demangled = llvm::itaniumDemangle(mangled.c_str(), nullptr, nullptr, nullptr);
+ demangled = llvm::itaniumDemangle(mangled.c_str());
}
if (!demangled) {
diff --git a/src/common/detached_tasks.cpp b/src/common/detached_tasks.cpp
index da64848da..f2ed795cc 100644
--- a/src/common/detached_tasks.cpp
+++ b/src/common/detached_tasks.cpp
@@ -30,8 +30,8 @@ DetachedTasks::~DetachedTasks() {
void DetachedTasks::AddTask(std::function<void()> task) {
std::unique_lock lock{instance->mutex};
++instance->count;
- std::thread([task{std::move(task)}]() {
- task();
+ std::thread([task_{std::move(task)}]() {
+ task_();
std::unique_lock thread_lock{instance->mutex};
--instance->count;
std::notify_all_at_thread_exit(instance->cv, std::move(thread_lock));
diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp
index b744b68ce..4b1690269 100644
--- a/src/common/page_table.cpp
+++ b/src/common/page_table.cpp
@@ -66,6 +66,7 @@ void PageTable::Resize(std::size_t address_space_width_in_bits, std::size_t page
<< (address_space_width_in_bits - page_size_in_bits)};
pointers.resize(num_page_table_entries);
backing_addr.resize(num_page_table_entries);
+ blocks.resize(num_page_table_entries);
current_address_space_width_in_bits = address_space_width_in_bits;
page_size = 1ULL << page_size_in_bits;
}
diff --git a/src/common/page_table.h b/src/common/page_table.h
index 1ad3a9f8b..fec8378f3 100644
--- a/src/common/page_table.h
+++ b/src/common/page_table.h
@@ -122,6 +122,7 @@ struct PageTable {
* corresponding attribute element is of type `Memory`.
*/
VirtualBuffer<PageInfo> pointers;
+ VirtualBuffer<u64> blocks;
VirtualBuffer<u64> backing_addr;
diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h
index d5961b020..2a98cda53 100644
--- a/src/common/scratch_buffer.h
+++ b/src/common/scratch_buffer.h
@@ -40,8 +40,21 @@ public:
~ScratchBuffer() = default;
ScratchBuffer(const ScratchBuffer&) = delete;
ScratchBuffer& operator=(const ScratchBuffer&) = delete;
- ScratchBuffer(ScratchBuffer&&) = default;
- ScratchBuffer& operator=(ScratchBuffer&&) = default;
+
+ ScratchBuffer(ScratchBuffer&& other) noexcept {
+ swap(other);
+ other.last_requested_size = 0;
+ other.buffer_capacity = 0;
+ other.buffer.reset();
+ }
+
+ ScratchBuffer& operator=(ScratchBuffer&& other) noexcept {
+ swap(other);
+ other.last_requested_size = 0;
+ other.buffer_capacity = 0;
+ other.buffer.reset();
+ return *this;
+ }
/// This will only grow the buffer's capacity if size is greater than the current capacity.
/// The previously held data will remain intact.
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 6cbbea1b2..d4e55f988 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -26,9 +26,10 @@ std::string GetTimeZoneString() {
std::string location_name;
if (time_zone_index == 0) { // Auto
-#if __cpp_lib_chrono >= 201907L
- const struct std::chrono::tzdb& time_zone_data = std::chrono::get_tzdb();
+#if __cpp_lib_chrono >= 201907L && !defined(MINGW)
+ // Disabled for MinGW -- tzdb always returns Etc/UTC
try {
+ const struct std::chrono::tzdb& time_zone_data = std::chrono::get_tzdb();
const std::chrono::time_zone* current_zone = time_zone_data.current_zone();
std::string_view current_zone_name = current_zone->name();
location_name = current_zone_name;
diff --git a/src/common/socket_types.h b/src/common/socket_types.h
index 0a801a443..63824a5c4 100644
--- a/src/common/socket_types.h
+++ b/src/common/socket_types.h
@@ -3,17 +3,22 @@
#pragma once
+#include <optional>
+#include <string>
+
#include "common/common_types.h"
namespace Network {
/// Address families
enum class Domain : u8 {
- INET, ///< Address family for IPv4
+ Unspecified, ///< Represents 0, used in getaddrinfo hints
+ INET, ///< Address family for IPv4
};
/// Socket types
enum class Type {
+ Unspecified, ///< Represents 0, used in getaddrinfo hints
STREAM,
DGRAM,
RAW,
@@ -22,6 +27,7 @@ enum class Type {
/// Protocol values for sockets
enum class Protocol : u8 {
+ Unspecified, ///< Represents 0, usable in various places
ICMP,
TCP,
UDP,
@@ -48,4 +54,13 @@ constexpr u32 FLAG_MSG_PEEK = 0x2;
constexpr u32 FLAG_MSG_DONTWAIT = 0x80;
constexpr u32 FLAG_O_NONBLOCK = 0x800;
+/// Cross-platform addrinfo structure
+struct AddrInfo {
+ Domain family;
+ Type socket_type;
+ Protocol protocol;
+ SockAddrIn addr;
+ std::optional<std::string> canon_name;
+};
+
} // namespace Network
diff --git a/src/common/time_zone.cpp b/src/common/time_zone.cpp
index d8d7896c6..69e728a9d 100644
--- a/src/common/time_zone.cpp
+++ b/src/common/time_zone.cpp
@@ -4,13 +4,13 @@
#include <chrono>
#include <exception>
#include <iomanip>
+#include <map>
#include <sstream>
#include <stdexcept>
#include <fmt/chrono.h>
#include <fmt/core.h>
#include "common/logging/log.h"
-#include "common/settings.h"
#include "common/time_zone.h"
namespace Common::TimeZone {
@@ -33,32 +33,29 @@ std::string GetDefaultTimeZone() {
return "GMT";
}
-static std::string GetOsTimeZoneOffset() {
- const std::time_t t{std::time(nullptr)};
- const std::tm tm{*std::localtime(&t)};
-
- return fmt::format("{:%z}", tm);
-}
-
-static int ConvertOsTimeZoneOffsetToInt(const std::string& timezone) {
- try {
- return std::stoi(timezone);
- } catch (const std::invalid_argument&) {
- LOG_CRITICAL(Common, "invalid_argument with {}!", timezone);
- return 0;
- } catch (const std::out_of_range&) {
- LOG_CRITICAL(Common, "out_of_range with {}!", timezone);
- return 0;
- }
+// Results are not comparable to seconds since Epoch
+static std::time_t TmSpecToSeconds(const struct std::tm& spec) {
+ const int year = spec.tm_year - 1; // Years up to now
+ const int leap_years = year / 4 - year / 100;
+ std::time_t cumulative = spec.tm_year;
+ cumulative = cumulative * 365 + leap_years + spec.tm_yday; // Years to days
+ cumulative = cumulative * 24 + spec.tm_hour; // Days to hours
+ cumulative = cumulative * 60 + spec.tm_min; // Hours to minutes
+ cumulative = cumulative * 60 + spec.tm_sec; // Minutes to seconds
+ return cumulative;
}
std::chrono::seconds GetCurrentOffsetSeconds() {
- const int offset{ConvertOsTimeZoneOffsetToInt(GetOsTimeZoneOffset())};
+ const std::time_t t{std::time(nullptr)};
+ const std::tm local{*std::localtime(&t)};
+ const std::tm gmt{*std::gmtime(&t)};
- int seconds{(offset / 100) * 60 * 60}; // Convert hour component to seconds
- seconds += (offset % 100) * 60; // Convert minute component to seconds
+ // gmt_seconds is a different offset than time(nullptr)
+ const auto gmt_seconds = TmSpecToSeconds(gmt);
+ const auto local_seconds = TmSpecToSeconds(local);
+ const auto seconds_offset = local_seconds - gmt_seconds;
- return std::chrono::seconds{seconds};
+ return std::chrono::seconds{seconds_offset};
}
// Key is [Hours * 100 + Minutes], multiplied by 100 if DST
@@ -71,11 +68,6 @@ const static std::map<s64, const char*> off_timezones = {
};
std::string FindSystemTimeZone() {
-#if defined(MINGW)
- // MinGW has broken strftime -- https://sourceforge.net/p/mingw-w64/bugs/793/
- // e.g. fmt::format("{:%z}") -- returns "Eastern Daylight Time" when it should be "-0400"
- return timezones[0];
-#else
const s64 seconds = static_cast<s64>(GetCurrentOffsetSeconds().count());
const s64 minutes = seconds / 60;
@@ -97,7 +89,6 @@ std::string FindSystemTimeZone() {
}
}
return fmt::format("Etc/GMT{:s}{:d}", hours > 0 ? "-" : "+", std::abs(hours));
-#endif
}
} // namespace Common::TimeZone