Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibWeb: Port to Windows #3000

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 14 additions & 4 deletions AK/Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
#include <AK/Checked.h>
#include <AK/Platform.h>
#include <AK/Types.h>
#ifdef AK_OS_WINDOWS
#include <time.h>
#ifndef AK_OS_WINDOWS
# include <sys/time.h>
#else
struct timeval {
long tv_sec;
long tv_usec;
};
#else
# include <sys/time.h>
inline int gettimeofday(struct timeval* tv, struct timezone*)
{
timespec ts = {};
if (timespec_get(&ts, TIME_UTC) != TIME_UTC)
return -1;

tv->tv_sec = (long)ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
return 0;
}
#endif
#include <time.h>

namespace AK {

Expand Down
4 changes: 0 additions & 4 deletions Libraries/LibCore/ResourceImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#include <LibCore/ResourceImplementationFile.h>
#include <LibCore/System.h>

#if defined(AK_OS_WINDOWS)
# include <dirent.h>
#endif

namespace Core {

static OwnPtr<ResourceImplementation> s_the;
Expand Down
4 changes: 0 additions & 4 deletions Libraries/LibCore/ResourceImplementationFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
#include <LibCore/ResourceImplementationFile.h>
#include <LibCore/System.h>

#if defined(AK_OS_WINDOWS)
# include <dirent.h>
#endif

namespace Core {

ResourceImplementationFile::ResourceImplementationFile(String base_directory)
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibCore/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# include <utime.h>
#else
# define O_CLOEXEC O_NOINHERIT
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
using sighandler_t = void (*)(int);
using socklen_t = int;
#endif
Expand Down
8 changes: 8 additions & 0 deletions Libraries/LibCore/SystemWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,12 @@ int getpid()
return GetCurrentProcessId();
}

u64 physical_memory_bytes()
{
MEMORYSTATUSEX ms = {};
ms.dwLength = sizeof ms;
GlobalMemoryStatusEx(&ms);
return ms.ullTotalPhys;
}

}
5 changes: 0 additions & 5 deletions Libraries/LibFileSystem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ endif()

serenity_lib(LibFileSystem filesystem)
target_link_libraries(LibFileSystem PRIVATE LibCoreMinimal)

if (WIN32)
find_path(DIRENT_INCLUDE_DIR dirent.h REQUIRED)
target_include_directories(LibFileSystem PRIVATE ${DIRENT_INCLUDE_DIR})
endif()
2 changes: 1 addition & 1 deletion Libraries/LibFileSystem/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#elif defined(AK_OS_LINUX)
# include <linux/fs.h>
#elif defined(AK_OS_WINDOWS)
# include <dirent.h>
# include <windows.h>
#endif

// On Linux distros that use glibc `basename` is defined as a macro that expands to `__xpg_basename`, so we undefine it
Expand Down
30 changes: 12 additions & 18 deletions Libraries/LibWeb/HTML/MessagePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,11 @@ WebIDL::ExceptionOr<void> MessagePort::transfer_steps(HTML::TransferDataHolder&
m_remote_port->m_has_been_shipped = true;

// 2. Set dataHolder.[[RemotePort]] to remotePort.
if constexpr (IsSame<IPC::Transport, IPC::TransportSocket>) {
auto fd = MUST(m_transport->release_underlying_transport_for_transfer());
m_transport = {};
data_holder.fds.append(IPC::File::adopt_fd(fd));
data_holder.data.append(IPC_FILE_TAG);
} else {
VERIFY(false && "Don't know how to transfer IPC::Transport type");
}
// TODO: Mach IPC
auto fd = MUST(m_transport->release_underlying_transport_for_transfer());
m_transport = {};
data_holder.fds.append(IPC::File::adopt_fd(fd));
data_holder.data.append(IPC_FILE_TAG);
}

// 4. Otherwise, set dataHolder.[[RemotePort]] to null.
Expand All @@ -128,16 +125,13 @@ WebIDL::ExceptionOr<void> MessagePort::transfer_receiving_steps(HTML::TransferDa
// (This will disentangle dataHolder.[[RemotePort]] from the original port that was transferred.)
auto fd_tag = data_holder.data.take_first();
if (fd_tag == IPC_FILE_TAG) {
if constexpr (IsSame<IPC::Transport, IPC::TransportSocket>) {
auto fd = data_holder.fds.take_first();
m_transport = IPC::Transport(MUST(Core::LocalSocket::adopt_fd(fd.take_fd())));

m_transport->set_up_read_hook([strong_this = GC::make_root(this)]() {
strong_this->read_from_transport();
});
} else {
VERIFY(false && "Don't know how to receive IPC::Transport type");
}
// TODO: Mach IPC
auto fd = data_holder.fds.take_first();
m_transport = IPC::Transport(MUST(Core::LocalSocket::adopt_fd(fd.take_fd())));

m_transport->set_up_read_hook([strong_this = GC::make_root(this)]() {
strong_this->read_from_transport();
});
} else if (fd_tag != 0) {
dbgln("Unexpected byte {:x} in MessagePort transfer data", fd_tag);
VERIFY_NOT_REACHED();
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/HTML/WorkerAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ void WorkerAgent::initialize(JS::Realm& realm)

auto worker_socket = MUST(Core::LocalSocket::adopt_fd(worker_socket_file.take_fd()));
MUST(worker_socket->set_blocking(true));
static_assert(IsSame<IPC::Transport, IPC::TransportSocket>, "Handle other IPC::Transport types here");

// TODO: Mach IPC
auto transport = IPC::Transport(move(worker_socket));

m_worker_ipc = make_ref_counted<WebWorkerClient>(move(transport));
Expand Down
Loading