Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ src/System.Management.Automation/engine/remoting @dantraMSFT @mirichmo @PaulHi
# Area: Side-By-Side
# @mirichmo @charub

# Area: Libpsl-native
src/libpsl-native @dantraMSFT

# Areas: Build
# Must be last
*.config @daxian-dbw @TravisEz13 @adityapatwardhan
Expand Down
1 change: 1 addition & 0 deletions src/libpsl-native/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pal_config.h
4 changes: 4 additions & 0 deletions src/libpsl-native/src/getstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
//! @retval -1 if failed
//!

// DO NOT use in managed code
// use externally defined structs in managed code has proven to be buggy
// (memory corruption issues due to layout difference between platforms)
// see https://github.com/dotnet/corefx/issues/29700#issuecomment-389313075
int32_t GetStat(const char* path, struct stat* buf)
{
assert(path);
Expand Down
28 changes: 25 additions & 3 deletions src/libpsl-native/src/setdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,44 @@

//! @brief SetDate sets the date and time on local computer.
//! You must be super-user to set the time.
//! See comment in setdate.h about the use of private_tm
//!
//! SetDate
//!
//! @retval 0 successfully set date
//! @retval -1 if failure occurred.
//!
int32_t SetDate(struct tm* time)
int32_t SetDate(struct private_tm* time)
{
errno = 0;

// Select locale from environment
setlocale(LC_ALL, "");

struct timeval tv;
int32_t result = GetTimeVal(*time,tv);
if(result != 0)
{
return result;
}

return settimeofday(&tv, NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use settimeofday if we don't use second parameter (timezone)?
Could we use stime? In the case we have to adjust only one parameter time_t.

Second question do this parameter adjustements work correctly for ARM reverse byte order?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are known issues there this isn't working on ARM. @dantraMSFT mentioned this to me.

Feel free to file an issue to switch to stime, although the better fix is probably to include the timezone. This fix is scoped to stop corrupting memory.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the timezone can be a issue too. We should look this in depth. Will push new Issue to discuss better solution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking issue #6962

}

static int32_t GetTimeVal(struct private_tm& time, struct timeval& tv)
{
struct tm nativeTime = 0;
nativeTime.tm_hour = static_cast<int>(time.Hour);
nativeTime.tm_isdst = static_cast<int>(time.IsDst);
nativeTime.tm_mday = static_cast<int>(time.DayOfMonth);
nativeTime.tm_min = static_cast<int>(time.Minutes);
nativeTime.tm_mon = static_cast<int>(time.Month);
nativeTime.tm_sec = static_cast<int>(time.Seconds);
nativeTime.tm_wday = static_cast<int>(time.DayOfWeek);
nativeTime.tm_yday = static_cast<int>(time.DayInYear);
nativeTime.tm_year = static_cast<int>(time.Year);

time_t newTime = mktime(time);
time_t newTime = mktime(&nativeTime);
if (newTime == -1)
{
return -1;
Expand All @@ -39,5 +61,5 @@ int32_t SetDate(struct tm* time)
tv.tv_sec = newTime;
tv.tv_usec = 0;

return settimeofday(&tv, NULL);
return 0;
}
23 changes: 22 additions & 1 deletion src/libpsl-native/src/setdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@

PAL_BEGIN_EXTERNC

int32_t SetDate(struct tm* time);
int32_t SetDate(struct private_tm* time);

static int32_t GetTimeVal(struct private_tm& time, struct timeval& tv);

PAL_END_EXTERNC

// Using a private struct because theuse externally defined structs
// in managed code has proven to be buggy
// (memory corruption issues due to layout difference between platforms)
// see https://github.com/dotnet/corefx/issues/29700#issuecomment-389313075
#pragma pack(push, 4) // exact fit - no padding
struct private_tm
{
int32_t Seconds; /* Seconds (0-60) */
int32_t Minutes; /* Minutes (0-59) */
int32_t Hour; /* Hours (0-23) */
int32_t DayOfMonth;/* Day of the month (1-31) */
int32_t Month; /* Month (0-11) */
int32_t Year; /* Year - 1900 */
int32_t DayOfWeek; /* Day of the week (0-6, Sunday = 0) */
int32_t DayInYear; /* Day in the year (0-365, 1 Jan = 0) */
int32_t IsDst; /* Daylight saving time */
};
#pragma pack(pop) //back to whatever the previous packing mode was