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
Родитель ac079371c1
Коммит ab47597a2c
2 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -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",

Просмотреть файл

@ -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,