mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:57:45 +00:00
Kernel: Replace "current" with Thread::current and Process::current
Suggested by Sergey. The currently running Thread and Process are now Thread::current and Process::current respectively. :^)
This commit is contained in:
parent
4f4af24b9d
commit
48f7c28a5c
37 changed files with 257 additions and 252 deletions
|
@ -395,7 +395,7 @@ void E1000NetworkAdapter::send_raw(const u8* data, size_t length)
|
|||
sti();
|
||||
break;
|
||||
}
|
||||
current->wait_on(m_wait_queue);
|
||||
Thread::current->wait_on(m_wait_queue);
|
||||
}
|
||||
#ifdef E1000_DEBUG
|
||||
kprintf("E1000: Sent packet, status is now %b!\n", descriptor.status);
|
||||
|
|
|
@ -68,7 +68,7 @@ IPv4Socket::IPv4Socket(int type, int protocol)
|
|||
: Socket(AF_INET, type, protocol)
|
||||
{
|
||||
#ifdef IPV4_SOCKET_DEBUG
|
||||
kprintf("%s(%u) IPv4Socket{%p} created with type=%u, protocol=%d\n", current->process().name().characters(), current->pid(), this, type, protocol);
|
||||
kprintf("%s(%u) IPv4Socket{%p} created with type=%u, protocol=%d\n", Process::current->name().characters(), Process::current->pid(), this, type, protocol);
|
||||
#endif
|
||||
m_buffer_mode = type == SOCK_STREAM ? BufferMode::Bytes : BufferMode::Packets;
|
||||
if (m_buffer_mode == BufferMode::Bytes) {
|
||||
|
@ -111,9 +111,9 @@ KResult IPv4Socket::bind(const sockaddr* user_address, socklen_t address_size)
|
|||
return KResult(-EINVAL);
|
||||
|
||||
auto requested_local_port = ntohs(address.sin_port);
|
||||
if (!current->process().is_superuser()) {
|
||||
if (!Process::current->is_superuser()) {
|
||||
if (requested_local_port < 1024) {
|
||||
dbg() << current->process() << " (uid " << current->process().uid() << ") attempted to bind " << class_name() << " to port " << requested_local_port;
|
||||
dbg() << Process::current << " (uid " << Process::current->uid() << ") attempted to bind " << class_name() << " to port " << requested_local_port;
|
||||
return KResult(-EACCES);
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
|
|||
|
||||
int nsent = protocol_send(data, data_length);
|
||||
if (nsent > 0)
|
||||
current->did_ipv4_socket_write(nsent);
|
||||
Thread::current->did_ipv4_socket_write(nsent);
|
||||
return nsent;
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ ssize_t IPv4Socket::receive_byte_buffered(FileDescription& description, void* bu
|
|||
if (!description.is_blocking())
|
||||
return -EAGAIN;
|
||||
|
||||
auto res = current->block<Thread::ReadBlocker>(description);
|
||||
auto res = Thread::current->block<Thread::ReadBlocker>(description);
|
||||
|
||||
LOCKER(lock());
|
||||
if (!m_can_read) {
|
||||
|
@ -259,7 +259,7 @@ ssize_t IPv4Socket::receive_byte_buffered(FileDescription& description, void* bu
|
|||
ASSERT(!m_receive_buffer.is_empty());
|
||||
int nreceived = m_receive_buffer.read((u8*)buffer, buffer_length);
|
||||
if (nreceived > 0)
|
||||
current->did_ipv4_socket_read((size_t)nreceived);
|
||||
Thread::current->did_ipv4_socket_read((size_t)nreceived);
|
||||
|
||||
m_can_read = !m_receive_buffer.is_empty();
|
||||
return nreceived;
|
||||
|
@ -293,7 +293,7 @@ ssize_t IPv4Socket::receive_packet_buffered(FileDescription& description, void*
|
|||
return 0;
|
||||
}
|
||||
|
||||
auto res = current->block<Thread::ReadBlocker>(description);
|
||||
auto res = Thread::current->block<Thread::ReadBlocker>(description);
|
||||
|
||||
LOCKER(lock());
|
||||
if (!m_can_read) {
|
||||
|
@ -351,7 +351,7 @@ ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t
|
|||
nreceived = receive_packet_buffered(description, buffer, buffer_length, flags, addr, addr_length);
|
||||
|
||||
if (nreceived > 0)
|
||||
current->did_ipv4_socket_read(nreceived);
|
||||
Thread::current->did_ipv4_socket_read(nreceived);
|
||||
return nreceived;
|
||||
}
|
||||
|
||||
|
@ -463,7 +463,7 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, unsigned arg)
|
|||
{
|
||||
REQUIRE_PROMISE(inet);
|
||||
auto* ifr = (ifreq*)arg;
|
||||
if (!current->process().validate_read_typed(ifr))
|
||||
if (!Process::current->validate_read_typed(ifr))
|
||||
return -EFAULT;
|
||||
|
||||
char namebuf[IFNAMSIZ + 1];
|
||||
|
@ -475,7 +475,7 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, unsigned arg)
|
|||
|
||||
switch (request) {
|
||||
case SIOCSIFADDR:
|
||||
if (!current->process().is_superuser())
|
||||
if (!Process::current->is_superuser())
|
||||
return -EPERM;
|
||||
if (ifr->ifr_addr.sa_family != AF_INET)
|
||||
return -EAFNOSUPPORT;
|
||||
|
@ -483,14 +483,14 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, unsigned arg)
|
|||
return 0;
|
||||
|
||||
case SIOCGIFADDR:
|
||||
if (!current->process().validate_write_typed(ifr))
|
||||
if (!Process::current->validate_write_typed(ifr))
|
||||
return -EFAULT;
|
||||
ifr->ifr_addr.sa_family = AF_INET;
|
||||
((sockaddr_in&)ifr->ifr_addr).sin_addr.s_addr = adapter->ipv4_address().to_u32();
|
||||
return 0;
|
||||
|
||||
case SIOCGIFHWADDR:
|
||||
if (!current->process().validate_write_typed(ifr))
|
||||
if (!Process::current->validate_write_typed(ifr))
|
||||
return -EFAULT;
|
||||
ifr->ifr_hwaddr.sa_family = AF_INET;
|
||||
{
|
||||
|
|
|
@ -63,12 +63,12 @@ LocalSocket::LocalSocket(int type)
|
|||
LOCKER(all_sockets().lock());
|
||||
all_sockets().resource().append(this);
|
||||
|
||||
m_prebind_uid = current->process().uid();
|
||||
m_prebind_gid = current->process().gid();
|
||||
m_prebind_uid = Process::current->uid();
|
||||
m_prebind_gid = Process::current->gid();
|
||||
m_prebind_mode = 0666;
|
||||
|
||||
#ifdef DEBUG_LOCAL_SOCKET
|
||||
kprintf("%s(%u) LocalSocket{%p} created with type=%u\n", current->process().name().characters(), current->pid(), this, type);
|
||||
kprintf("%s(%u) LocalSocket{%p} created with type=%u\n", Process::current->name().characters(), Process::current->pid(), this, type);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -105,12 +105,12 @@ KResult LocalSocket::bind(const sockaddr* user_address, socklen_t address_size)
|
|||
auto path = String(address.sun_path, strnlen(address.sun_path, sizeof(address.sun_path)));
|
||||
|
||||
#ifdef DEBUG_LOCAL_SOCKET
|
||||
kprintf("%s(%u) LocalSocket{%p} bind(%s)\n", current->process().name().characters(), current->pid(), this, safe_address);
|
||||
kprintf("%s(%u) LocalSocket{%p} bind(%s)\n", Process::current->name().characters(), Process::current->pid(), this, safe_address);
|
||||
#endif
|
||||
|
||||
mode_t mode = S_IFSOCK | (m_prebind_mode & 04777);
|
||||
UidAndGid owner { m_prebind_uid, m_prebind_gid };
|
||||
auto result = VFS::the().open(path, O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, current->process().current_directory(), owner);
|
||||
auto result = VFS::the().open(path, O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current->current_directory(), owner);
|
||||
if (result.is_error()) {
|
||||
if (result.error() == -EEXIST)
|
||||
return KResult(-EADDRINUSE);
|
||||
|
@ -145,10 +145,10 @@ KResult LocalSocket::connect(FileDescription& description, const sockaddr* addre
|
|||
memcpy(safe_address, local_address.sun_path, sizeof(local_address.sun_path));
|
||||
|
||||
#ifdef DEBUG_LOCAL_SOCKET
|
||||
kprintf("%s(%u) LocalSocket{%p} connect(%s)\n", current->process().name().characters(), current->pid(), this, safe_address);
|
||||
kprintf("%s(%u) LocalSocket{%p} connect(%s)\n", Process::current->name().characters(), Process::current->pid(), this, safe_address);
|
||||
#endif
|
||||
|
||||
auto description_or_error = VFS::the().open(safe_address, O_RDWR, 0, current->process().current_directory());
|
||||
auto description_or_error = VFS::the().open(safe_address, O_RDWR, 0, Process::current->current_directory());
|
||||
if (description_or_error.is_error())
|
||||
return KResult(-ECONNREFUSED);
|
||||
|
||||
|
@ -175,13 +175,13 @@ KResult LocalSocket::connect(FileDescription& description, const sockaddr* addre
|
|||
return KSuccess;
|
||||
}
|
||||
|
||||
if (current->block<Thread::ConnectBlocker>(description) != Thread::BlockResult::WokeNormally) {
|
||||
if (Thread::current->block<Thread::ConnectBlocker>(description) != Thread::BlockResult::WokeNormally) {
|
||||
m_connect_side_role = Role::None;
|
||||
return KResult(-EINTR);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOCAL_SOCKET
|
||||
kprintf("%s(%u) LocalSocket{%p} connect(%s) status is %s\n", current->process().name().characters(), current->pid(), this, safe_address, to_string(setup_state()));
|
||||
kprintf("%s(%u) LocalSocket{%p} connect(%s) status is %s\n", Process::current->name().characters(), Process::current->pid(), this, safe_address, to_string(setup_state()));
|
||||
#endif
|
||||
|
||||
if (!is_connected()) {
|
||||
|
@ -265,7 +265,7 @@ ssize_t LocalSocket::sendto(FileDescription& description, const void* data, size
|
|||
return -EPIPE;
|
||||
ssize_t nwritten = send_buffer_for(description).write((const u8*)data, data_size);
|
||||
if (nwritten > 0)
|
||||
current->did_unix_socket_write(nwritten);
|
||||
Thread::current->did_unix_socket_write(nwritten);
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t
|
|||
return -EAGAIN;
|
||||
}
|
||||
} else if (!can_read(description)) {
|
||||
auto result = current->block<Thread::ReadBlocker>(description);
|
||||
auto result = Thread::current->block<Thread::ReadBlocker>(description);
|
||||
if (result != Thread::BlockResult::WokeNormally)
|
||||
return -EINTR;
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t
|
|||
ASSERT(!buffer_for_me.is_empty());
|
||||
int nread = buffer_for_me.read((u8*)buffer, buffer_size);
|
||||
if (nread > 0)
|
||||
current->did_unix_socket_read(nread);
|
||||
Thread::current->did_unix_socket_read(nread);
|
||||
return nread;
|
||||
}
|
||||
|
||||
|
@ -389,7 +389,7 @@ KResult LocalSocket::chown(uid_t uid, gid_t gid)
|
|||
if (m_file)
|
||||
return m_file->chown(uid, gid);
|
||||
|
||||
if (!current->process().is_superuser() && (current->process().euid() != uid || !current->process().in_group(gid)))
|
||||
if (!Process::current->is_superuser() && (Process::current->euid() != uid || !Process::current->in_group(gid)))
|
||||
return KResult(-EPERM);
|
||||
|
||||
m_prebind_uid = uid;
|
||||
|
|
|
@ -109,7 +109,7 @@ void NetworkTask_main()
|
|||
for (;;) {
|
||||
size_t packet_size = dequeue_packet(buffer, buffer_size);
|
||||
if (!packet_size) {
|
||||
current->wait_on(packet_wait_queue);
|
||||
Thread::current->wait_on(packet_wait_queue);
|
||||
continue;
|
||||
}
|
||||
if (packet_size < sizeof(EthernetFrameHeader)) {
|
||||
|
|
|
@ -137,7 +137,7 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source)
|
|||
request.set_sender_protocol_address(adapter->ipv4_address());
|
||||
adapter->send({ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, request);
|
||||
|
||||
(void)current->block_until("Routing (ARP)", [next_hop_ip] {
|
||||
(void)Thread::current->block_until("Routing (ARP)", [next_hop_ip] {
|
||||
return arp_table().resource().get(next_hop_ip).has_value();
|
||||
});
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ Socket::Socket(int domain, int type, int protocol)
|
|||
, m_type(type)
|
||||
, m_protocol(protocol)
|
||||
{
|
||||
auto& process = current->process();
|
||||
auto& process = *Process::current;
|
||||
m_origin = { process.pid(), process.uid(), process.gid() };
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ Socket::~Socket()
|
|||
void Socket::set_setup_state(SetupState new_setup_state)
|
||||
{
|
||||
#ifdef SOCKET_DEBUG
|
||||
kprintf("%s(%u) Socket{%p} setup state moving from %s to %s\n", current->process().name().characters(), current->pid(), this, to_string(m_setup_state), to_string(new_setup_state));
|
||||
kprintf("%s(%u) Socket{%p} setup state moving from %s to %s\n", Process::current->name().characters(), Process::current->pid(), this, to_string(m_setup_state), to_string(new_setup_state));
|
||||
#endif
|
||||
|
||||
m_setup_state = new_setup_state;
|
||||
|
@ -77,11 +77,11 @@ RefPtr<Socket> Socket::accept()
|
|||
if (m_pending.is_empty())
|
||||
return nullptr;
|
||||
#ifdef SOCKET_DEBUG
|
||||
kprintf("%s(%u) Socket{%p} de-queueing connection\n", current->process().name().characters(), current->pid(), this);
|
||||
kprintf("%s(%u) Socket{%p} de-queueing connection\n", Process::current->name().characters(), Process::current->pid(), this);
|
||||
#endif
|
||||
auto client = m_pending.take_first();
|
||||
ASSERT(!client->is_connected());
|
||||
auto& process = current->process();
|
||||
auto& process = *Process::current;
|
||||
client->m_acceptor = { process.pid(), process.uid(), process.gid() };
|
||||
client->m_connected = true;
|
||||
client->m_role = Role::Accepted;
|
||||
|
@ -91,7 +91,7 @@ RefPtr<Socket> Socket::accept()
|
|||
KResult Socket::queue_connection_from(NonnullRefPtr<Socket> peer)
|
||||
{
|
||||
#ifdef SOCKET_DEBUG
|
||||
kprintf("%s(%u) Socket{%p} queueing connection\n", current->process().name().characters(), current->pid(), this);
|
||||
kprintf("%s(%u) Socket{%p} queueing connection\n", Process::current->name().characters(), Process::current->pid(), this);
|
||||
#endif
|
||||
LOCKER(m_lock);
|
||||
if (m_pending.size() >= m_backlog)
|
||||
|
|
|
@ -49,7 +49,7 @@ void TCPSocket::set_state(State new_state)
|
|||
{
|
||||
#ifdef TCP_SOCKET_DEBUG
|
||||
kprintf("%s(%u) TCPSocket{%p} state moving from %s to %s\n",
|
||||
current->process().name().characters(), current->pid(), this,
|
||||
Process::current->name().characters(), Process::current->pid(), this,
|
||||
to_string(m_state), to_string(new_state));
|
||||
#endif
|
||||
|
||||
|
@ -385,7 +385,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
|
|||
m_direction = Direction::Outgoing;
|
||||
|
||||
if (should_block == ShouldBlock::Yes) {
|
||||
if (current->block<Thread::ConnectBlocker>(description) != Thread::BlockResult::WokeNormally)
|
||||
if (Thread::current->block<Thread::ConnectBlocker>(description) != Thread::BlockResult::WokeNormally)
|
||||
return KResult(-EINTR);
|
||||
ASSERT(setup_state() == SetupState::Completed);
|
||||
if (has_error()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue