mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:07:34 +00:00
Build: Make Lagom build under macOS (#2341)
Lagom now builds under macOS. Only two minor adjustments were required: * LibCore TCP/UDP code can't use `SOCK_{NONBLOCK,CLOEXEC}` on macOS, use ioctl() and fcntl() instead * LibJS `Heap` code pthread usage ported to MacOS
This commit is contained in:
parent
dd924b730a
commit
c21dc21f36
5 changed files with 51 additions and 1 deletions
|
@ -32,12 +32,22 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#ifndef SOCK_NONBLOCK
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
TCPServer::TCPServer(Object* parent)
|
TCPServer::TCPServer(Object* parent)
|
||||||
: Object(parent)
|
: Object(parent)
|
||||||
{
|
{
|
||||||
|
#ifdef SOCK_NONBLOCK
|
||||||
m_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
m_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
||||||
|
#else
|
||||||
|
m_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
int option = 1;
|
||||||
|
ioctl(m_fd, FIONBIO, &option);
|
||||||
|
fcntl(m_fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
#endif
|
||||||
ASSERT(m_fd >= 0);
|
ASSERT(m_fd >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#ifndef SOCK_NONBLOCK
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
TCPSocket::TCPSocket(int fd, Object* parent)
|
TCPSocket::TCPSocket(int fd, Object* parent)
|
||||||
|
@ -43,7 +47,13 @@ TCPSocket::TCPSocket(int fd, Object* parent)
|
||||||
TCPSocket::TCPSocket(Object* parent)
|
TCPSocket::TCPSocket(Object* parent)
|
||||||
: Socket(Socket::Type::TCP, parent)
|
: Socket(Socket::Type::TCP, parent)
|
||||||
{
|
{
|
||||||
|
#ifdef SOCK_NONBLOCK
|
||||||
int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
|
int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
|
||||||
|
#else
|
||||||
|
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
int option = 1;
|
||||||
|
ioctl(fd, FIONBIO, &option);
|
||||||
|
#endif
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
set_error(errno);
|
set_error(errno);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,12 +31,23 @@
|
||||||
#include <LibCore/UDPSocket.h>
|
#include <LibCore/UDPSocket.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef SOCK_NONBLOCK
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
UDPServer::UDPServer(Object* parent)
|
UDPServer::UDPServer(Object* parent)
|
||||||
: Object(parent)
|
: Object(parent)
|
||||||
{
|
{
|
||||||
|
#ifdef SOCK_NONBLOCK
|
||||||
m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
||||||
|
#else
|
||||||
|
m_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
int option = 1;
|
||||||
|
ioctl(m_fd, FIONBIO, &option);
|
||||||
|
fcntl(m_fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
#endif
|
||||||
ASSERT(m_fd >= 0);
|
ASSERT(m_fd >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#ifndef SOCK_NONBLOCK
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
UDPSocket::UDPSocket(int fd, Object* parent)
|
UDPSocket::UDPSocket(int fd, Object* parent)
|
||||||
|
@ -43,7 +47,14 @@ UDPSocket::UDPSocket(int fd, Object* parent)
|
||||||
UDPSocket::UDPSocket(Object* parent)
|
UDPSocket::UDPSocket(Object* parent)
|
||||||
: Socket(Socket::Type::UDP, parent)
|
: Socket(Socket::Type::UDP, parent)
|
||||||
{
|
{
|
||||||
|
#ifdef SOCK_NONBLOCK
|
||||||
int fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
|
int fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
|
||||||
|
#else
|
||||||
|
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
int option = 1;
|
||||||
|
ioctl(fd, FIONBIO, &option);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
set_error(errno);
|
set_error(errno);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
# include <serenity.h>
|
# include <serenity.h>
|
||||||
#elif __linux__
|
#elif __linux__ or __MACH__
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -157,6 +157,14 @@ void Heap::gather_conservative_roots(HashTable<Cell*>& roots)
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
|
#elif __MACH__
|
||||||
|
stack_base = (FlatPtr)pthread_get_stackaddr_np(pthread_self());
|
||||||
|
pthread_attr_t attr = {};
|
||||||
|
if (int rc = pthread_attr_getstacksize(&attr, &stack_size) != 0) {
|
||||||
|
fprintf(stderr, "pthread_attr_getstacksize: %s\n", strerror(-rc));
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FlatPtr stack_reference = reinterpret_cast<FlatPtr>(&dummy);
|
FlatPtr stack_reference = reinterpret_cast<FlatPtr>(&dummy);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue