Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
CRuntime_Musl: More fixes for time64
Browse files Browse the repository at this point in the history
The original PR (#3275) missed quite a few spots and conversions,
which led to the build on Alpine Linux failing with Aithmetic Exception
on core.time module constructor.
Links to the two offending commits are included.
For further issues / investigation, search for 'time64' in the git repository.
  • Loading branch information
Geod24 committed Feb 25, 2021
1 parent 3f75cae commit 9537a13
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
30 changes: 27 additions & 3 deletions src/core/sys/linux/sys/socket.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ extern(C):
@nogc:
nothrow:

version (CRuntime_Musl)
{
import core.stdc.config : c_long;
private enum Use_Time64_Values = (time_t.sizeof > c_long.sizeof);
}
else
private enum Use_Time64_Values = false;

static if (Use_Time64_Values)
{
// SO_TIMESTAMP_OLD & friends
// https://www.kernel.org/doc/Documentation/networking/timestamping.txt
enum SO_TIMESTAMP = 29;
enum SO_TIMESTAMPNS = 35;
enum SO_TIMESTAMPING = 37;

}
else
{
enum SO_TIMESTAMP = 63;
enum SO_TIMESTAMPNS = 64;
enum SO_TIMESTAMPING = 65;
}

enum
{
// Protocol families.
Expand Down Expand Up @@ -123,14 +147,14 @@ enum
SO_GET_FILTER = SO_ATTACH_FILTER,

SO_PEERNAME = 28,
SO_TIMESTAMP = 29,
// SO_TIMESTAMP See above
SCM_TIMESTAMP = SO_TIMESTAMP,

SO_PASSSEC = 34,
SO_TIMESTAMPNS = 35,
// SO_TIMESTAMPNS See above
SCM_TIMESTAMPNS = SO_TIMESTAMPNS,
SO_MARK = 36,
SO_TIMESTAMPING = 37,
// SO_TIMESTAMPING See above
SCM_TIMESTAMPING = SO_TIMESTAMPING,
SO_RXQ_OVFL = 40,
SO_WIFI_STATUS = 41,
Expand Down
23 changes: 22 additions & 1 deletion src/core/sys/posix/signal.d
Original file line number Diff line number Diff line change
Expand Up @@ -3427,7 +3427,28 @@ struct timespec
}
*/

version (linux)
version (CRuntime_Musl)
{
// Musl on 32 bits use 64 bits time_t (time64)
// See https://git.musl-libc.org/cgit/musl/commit/?id=9b2921bea1d5017832e1b45d1fd64220047a9802
struct timespec
{
time_t tv_sec;
// 32 bits of padding on 32 bits, or in C:
// int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321);
version (BigEndian)
static if (time_t.sizeof > c_long.sizeof)
int __padding;
c_long tv_nsec;
// Another 32 bits of padding on 32 bits:
// int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321);
version (LittleEndian)
static if (time_t.sizeof > c_long.sizeof)
int __padding;
};

}
else version (linux)
{
struct timespec
{
Expand Down
24 changes: 20 additions & 4 deletions src/core/sys/posix/sys/stat.d
Original file line number Diff line number Diff line change
Expand Up @@ -1745,10 +1745,26 @@ else version (CRuntime_Musl)
blksize_t st_blksize;
blkcnt_t st_blocks;

timespec st_atim;
timespec st_mtim;
timespec st_ctim;
ino_t st_ino;
// Time64 on 32 bits
// See https://git.musl-libc.org/cgit/musl/commit/?id=38143339646a4ccce8afe298c34467767c899f51
static if (time_t.sizeof > c_long.sizeof)
{
private struct old_timespec {
long tv_sec;
long tv_nsec;
}

old_timespec __st_atim32;
old_timespec __st_mtim32;
old_timespec __st_ctim32;
}
else // Probably 64 bits or before v1.2.0
{
timespec st_atim;
timespec st_mtim;
timespec st_ctim;
ino_t st_ino;
}

extern(D) @safe @property inout pure nothrow
{
Expand Down
4 changes: 3 additions & 1 deletion src/core/sys/posix/sys/types.d
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,10 @@ else version (CRuntime_Musl)
alias uint id_t;
version (D_X32)
alias long susseconds_t;
else
else version (CRuntime_Musl_Pre_Time64)
alias c_long suseconds_t;
else
alias long suseconds_t;
}
else version (CRuntime_UClibc)
{
Expand Down

0 comments on commit 9537a13

Please sign in to comment.