Bug 1564900 - [OS.File] Fix size of statvfs::f_frsize;r=Yoric

Make Firefox not assume type of member statvfs::f_frsize from sys head, which may vary

Differential Revision: https://phabricator.services.mozilla.com/D38306

--HG--
extra : moz-landing-system : lando
This commit is contained in:
M. Sirringhaus 2019-07-18 08:55:43 +00:00
parent ac079371c1
commit ab47597a2c
2 changed files with 22 additions and 1 deletions

View File

@ -11,6 +11,14 @@
#include "prsystem.h"
// Short macro to get the size of a member of a
// given struct at compile time.
// t is the type of struct, m the name of the
// member:
// DOM_SIZEOF_MEMBER(struct mystruct, myint)
// will give you the size of the type of myint.
#define DOM_SIZEOF_MEMBER(t, m) sizeof(((t*)0)->m)
#if defined(XP_UNIX)
# include "unistd.h"
# include "dirent.h"
@ -602,6 +610,9 @@ static const dom::ConstantSpec gLibcProperties[] = {
{"OSFILE_SIZEOF_STATVFS", JS::Int32Value(sizeof(struct statvfs))},
// We have no guarantee how big "f_frsize" is, so we have to calculate that.
{"OSFILE_SIZEOF_STATVFS_F_FRSIZE",
JS::Int32Value(DOM_SIZEOF_MEMBER(struct statvfs, f_frsize))},
{"OSFILE_OFFSETOF_STATVFS_F_FRSIZE",
JS::Int32Value(offsetof(struct statvfs, f_frsize))},
{"OSFILE_OFFSETOF_STATVFS_F_BAVAIL",

View File

@ -257,6 +257,16 @@
Type.fsblkcnt_t = Type.uintn_t(Const.OSFILE_SIZEOF_FSBLKCNT_T).withName(
"fsblkcnt_t"
);
// There is no guarantee of the size or order of members in sys-header structs
// It mostly is "unsigned long", but can be "unsigned int" as well.
// So it has its own "type".
// NOTE: This is still only partially correct, as signedness is also not guaranteed,
// so assuming an unsigned int might still be wrong here.
// But unsigned seems to have worked all those years, even though its signed
// on various platforms.
Type.statvfs_f_frsize = Type.uintn_t(
Const.OSFILE_SIZEOF_STATVFS_F_FRSIZE
).withName("statvfs_f_rsize");
// Structure |statvfs|
// Use an hollow structure
@ -269,7 +279,7 @@
statvfs.add_field_at(
Const.OSFILE_OFFSETOF_STATVFS_F_FRSIZE,
"f_frsize",
Type.unsigned_long.implementation
Type.statvfs_f_frsize.implementation
);
statvfs.add_field_at(
Const.OSFILE_OFFSETOF_STATVFS_F_BAVAIL,