Compare commits

..

No commits in common. "f2eaab6e43a635a3a2bc9f3f26c254570848dcb3" and "b97c1237640ad0692a6dbbefb382ced5fcf3a129" have entirely different histories.

144 changed files with 738 additions and 4754 deletions

View File

@ -7,6 +7,9 @@
.global signal_trampoline
signal_trampoline:
pushl %ebp
movl %esp, %ebp
pusha
movl 40(%esp), %edi
@ -16,22 +19,16 @@ signal_trampoline:
movl %esp, %ebp
andl $-16, %esp
subl $512, %esp
fxsave (%esp)
subl $12, %esp
pushl %edi
call *%eax
addl $16, %esp
fxrstor (%esp)
addl $512, %esp
// restore stack
movl %ebp, %esp
popa
leave
addl $8, %esp
popf
ret

View File

@ -30,14 +30,8 @@ signal_trampoline:
movq %rsp, %rbp
andq $-16, %rsp
subq $512, %rsp
fxsave64 (%rsp)
call *%rax
fxrstor64 (%rsp)
addq $512, %rsp
// restore stack
movq %rbp, %rsp
popq %r15
@ -57,7 +51,6 @@ signal_trampoline:
popq %rax
addq $16, %rsp
popfq
// return over red-zone
ret $128

View File

@ -68,9 +68,7 @@ namespace Kernel
bool has_fd(int fd) const
{
// For some reason having (fd < 0 || ...) makes GCC 15.1.0
// think bitmap access can be out of bounds...
if (static_cast<size_t>(fd) >= events.size())
if (fd < 0 || static_cast<size_t>(fd) >= events.size())
return false;
return bitmap[fd / 32] & (1u << (fd % 32));
}

View File

@ -32,11 +32,11 @@ namespace Kernel
void lock() override
{
const auto tid = Thread::current_tid();
ASSERT(!tid || !Thread::current().has_spinlock());
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
ASSERT(!tid || !Thread::current().has_spinlock());
pid_t expected = -1;
while (!m_locker.compare_exchange(expected, tid))
{
@ -53,6 +53,7 @@ namespace Kernel
bool try_lock() override
{
const auto tid = Thread::current_tid();
ASSERT(!tid || !Thread::current().has_spinlock());
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
@ -101,12 +102,12 @@ namespace Kernel
void lock() override
{
const auto tid = Thread::current_tid();
ASSERT(!tid || !Thread::current().has_spinlock());
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
ASSERT(!tid || !Thread::current().has_spinlock());
bool has_priority = tid ? !Thread::current().is_userspace() : true;
if (has_priority)
m_queue_length++;
@ -126,6 +127,7 @@ namespace Kernel
bool try_lock() override
{
const auto tid = Thread::current_tid();
ASSERT(!tid || !Thread::current().has_spinlock());
if (tid == m_locker)
ASSERT(m_lock_depth > 0);

View File

@ -1,7 +1,6 @@
#pragma once
#include <BAN/Array.h>
#include <BAN/HashSet.h>
#include <kernel/FS/Inode.h>
#include <kernel/FS/VirtualFileSystem.h>
@ -44,8 +43,6 @@ namespace Kernel
void close_all();
void close_cloexec();
BAN::ErrorOr<void> flock(int fd, int op);
BAN::ErrorOr<size_t> read(int fd, BAN::ByteSpan);
BAN::ErrorOr<size_t> write(int fd, BAN::ConstByteSpan);
@ -72,15 +69,6 @@ namespace Kernel
off_t offset { 0 };
int status_flags;
struct flock_t
{
bool locked;
bool shared;
ThreadBlocker thread_blocker;
BAN::HashSet<pid_t> lockers;
};
flock_t flock;
friend class BAN::RefPtr<OpenFileDescription>;
};

View File

@ -112,8 +112,6 @@ namespace Kernel
BAN::ErrorOr<long> sys_symlinkat(const char* path1, int fd, const char* path2);
BAN::ErrorOr<long> sys_flock(int fd, int op);
BAN::ErrorOr<long> sys_pread(int fd, void* buffer, size_t count, off_t offset);
BAN::ErrorOr<long> sys_pwrite(int fd, const void* buffer, size_t count, off_t offset);

View File

@ -179,7 +179,7 @@ namespace Kernel
BAN::Atomic<bool> m_smp_free_lock { false };
SMPMessage* m_smp_free { nullptr };
SMPMessage* m_smp_message_storage { nullptr };
SMPMessage* m_smp_message_storage;
void* m_current_page_table { nullptr };

View File

@ -13,7 +13,7 @@ namespace Kernel
long ret;
asm volatile("int %[irq]"
: "=a"(ret)
: [irq]"i"(static_cast<int>(IRQ_SYSCALL)) // WTF GCC 15
: [irq]"i"(IRQ_SYSCALL)
, "a"(syscall)
, "b"((uintptr_t)arg1)
, "c"((uintptr_t)arg2)

View File

@ -59,6 +59,9 @@ namespace Kernel
public:
BAN::StringView name() const override { return m_name; }
uint32_t height() const override { return m_height; }
uint32_t width() const override { return m_width; }
void clear() override;
protected:
@ -69,6 +72,8 @@ namespace Kernel
bool can_write_impl() const override;
bool has_hungup_impl() const override { return !m_master.valid(); }
BAN::ErrorOr<long> ioctl_impl(int, void*) override;
private:
PseudoTerminalSlave(BAN::String&& name, uint32_t number, mode_t, uid_t, gid_t);
~PseudoTerminalSlave();
@ -78,6 +83,8 @@ namespace Kernel
const uint32_t m_number;
BAN::WeakPtr<PseudoTerminalMaster> m_master;
uint32_t m_width { 0 };
uint32_t m_height { 0 };
friend class PseudoTerminalMaster;
friend class BAN::RefPtr<PseudoTerminalSlave>;

View File

@ -42,6 +42,9 @@ namespace Kernel
public:
static BAN::ErrorOr<BAN::RefPtr<SerialTTY>> create(Serial);
uint32_t width() const override;
uint32_t height() const override;
void clear() override { putchar_impl('\e'); putchar_impl('['); putchar_impl('2'); putchar_impl('J'); }
void update() override;

View File

@ -8,7 +8,6 @@
#include <LibInput/KeyEvent.h>
#include <termios.h>
#include <sys/ioctl.h>
namespace Kernel
{
@ -54,6 +53,9 @@ namespace Kernel
virtual bool is_tty() const override { return true; }
virtual uint32_t height() const = 0;
virtual uint32_t width() const = 0;
virtual dev_t rdev() const final override { return m_rdev; }
virtual void clear() = 0;
@ -78,8 +80,6 @@ namespace Kernel
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) final override;
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) final override;
void update_winsize(unsigned short cols, unsigned short rows);
private:
bool putchar(uint8_t ch);
void do_backspace();
@ -109,8 +109,6 @@ namespace Kernel
};
Buffer m_output;
winsize m_winsize {};
protected:
RecursiveSpinLock m_write_lock;
ThreadBlocker m_write_blocker;

View File

@ -35,7 +35,6 @@ namespace Kernel
: m_palette(palette)
{}
virtual ~TerminalDriver() {}
virtual uint32_t width() const = 0;
virtual uint32_t height() const = 0;

View File

@ -19,6 +19,9 @@ namespace Kernel
BAN::ErrorOr<void> set_font(LibFont::Font&&) override;
uint32_t height() const override { return m_height; }
uint32_t width() const override { return m_width; }
void clear() override;
protected:

View File

@ -103,10 +103,6 @@ namespace Kernel
bool is_userspace() const { return m_is_userspace; }
uint64_t cpu_time_ns() const;
void set_cpu_time_start();
void set_cpu_time_stop();
void set_tls(vaddr_t tls) { m_tls = tls; }
vaddr_t get_tls() const { return m_tls; }
@ -159,10 +155,6 @@ namespace Kernel
SpinLock m_signal_lock;
static_assert(_SIGMAX < 64);
mutable SpinLock m_cpu_time_lock;
uint64_t m_cpu_time_ns { 0 };
uint64_t m_cpu_time_start_ns { UINT64_MAX };
BAN::Atomic<uint32_t> m_spinlock_count { 0 };
BAN::Atomic<uint32_t> m_mutex_count { 0 };

View File

@ -746,8 +746,6 @@ namespace Kernel::ACPI::AML
return {};
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-usage="
static BAN::ErrorOr<void> perform_store(const Node& source, Reference* target, TargetType target_type)
{
dprintln_if(AML_DUMP_FUNCTION_CALLS, "perform_store");
@ -828,7 +826,6 @@ namespace Kernel::ACPI::AML
return {};
}
#pragma GCC diagnostic pop
static BAN::ErrorOr<void> store_into_target(ParseContext& context, const Node& node)
{

View File

@ -176,20 +176,19 @@ namespace Kernel
switch (entry->type)
{
case 0:
MUST(apic->m_processors.emplace_back(Processor {
.processor_id = entry->entry0.acpi_processor_id,
.apic_id = entry->entry0.apic_id,
.flags = static_cast<uint8_t>(entry->entry0.flags & 0x03),
}));
Processor processor;
processor.processor_id = entry->entry0.acpi_processor_id;
processor.apic_id = entry->entry0.apic_id;
processor.flags = entry->entry0.flags & 0x03;
MUST(apic->m_processors.push_back(processor));
break;
case 1:
MUST(apic->m_io_apics.emplace_back(IOAPIC {
.id = entry->entry1.ioapic_id,
.paddr = entry->entry1.ioapic_address,
.vaddr = 0,
.gsi_base = entry->entry1.gsi_base,
.max_redirs = 0,
}));
IOAPIC ioapic;
ioapic.id = entry->entry1.ioapic_id;
ioapic.paddr = entry->entry1.ioapic_address;
ioapic.gsi_base = entry->entry1.gsi_base;
ioapic.max_redirs = 0;
MUST(apic->m_io_apics.push_back(ioapic));
break;
case 2:
apic->m_irq_overrides[entry->entry2.irq_source] = entry->entry2.gsi;

View File

@ -251,8 +251,7 @@ namespace Kernel
));
SpinLockGuard _(s_bound_socket_lock);
if (s_bound_sockets.contains(file.canonical_path))
return BAN::Error::from_errno(EADDRINUSE);
ASSERT(!s_bound_sockets.contains(file.canonical_path));
TRY(s_bound_sockets.emplace(file.canonical_path, TRY(get_weak_ptr())));
m_bound_path = BAN::move(file.canonical_path);

View File

@ -5,7 +5,6 @@
#include <kernel/OpenFileDescriptorSet.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/socket.h>
namespace Kernel
@ -311,17 +310,6 @@ namespace Kernel
TRY(validate_fd(fd));
auto& open_file = m_open_files[fd];
if (auto& flock = open_file.description->flock; Thread::current().has_process() && flock.lockers.contains(Process::current().pid()))
{
flock.lockers.remove(Process::current().pid());
if (flock.lockers.empty())
{
flock.locked = false;
flock.thread_blocker.unblock();
}
}
open_file.inode()->on_close(open_file.status_flags());
open_file.description.clear();
open_file.descriptor_flags = 0;
@ -348,63 +336,6 @@ namespace Kernel
}
}
BAN::ErrorOr<void> OpenFileDescriptorSet::flock(int fd, int op)
{
const auto pid = Process::current().pid();
LockGuard _(m_mutex);
for (;;)
{
TRY(validate_fd(fd));
auto& flock = m_open_files[fd].description->flock;
switch (op & ~LOCK_NB)
{
case LOCK_UN:
flock.lockers.remove(pid);
if (flock.lockers.empty())
{
flock.locked = false;
flock.thread_blocker.unblock();
}
return {};
case LOCK_SH:
if (!flock.locked)
{
TRY(flock.lockers.insert(pid));
flock.locked = true;
flock.shared = true;
return {};
}
if (flock.shared)
{
TRY(flock.lockers.insert(pid));
return {};
}
break;
case LOCK_EX:
if (!flock.locked)
{
TRY(flock.lockers.insert(pid));
flock.locked = true;
flock.shared = false;
return {};
}
if (flock.lockers.contains(pid))
return {};
break;
default:
return BAN::Error::from_errno(EINVAL);
}
if (op & LOCK_NB)
return BAN::Error::from_errno(EWOULDBLOCK);
TRY(Thread::current().block_or_eintr_indefinite(flock.thread_blocker, &m_mutex));
}
}
BAN::ErrorOr<size_t> OpenFileDescriptorSet::read(int fd, BAN::ByteSpan buffer)
{
BAN::RefPtr<Inode> inode;
@ -544,14 +475,33 @@ namespace Kernel
}
LockGuard _(inode->m_mutex);
if (inode->has_hungup())
const auto check_errors =
[&inode, is_nonblock]() -> BAN::ErrorOr<void>
{
if (inode->has_hungup())
{
Thread::current().add_signal(SIGPIPE);
return BAN::Error::from_errno(EPIPE);
}
if (is_nonblock && !inode->can_write())
return BAN::Error::from_errno(EWOULDBLOCK);
return {};
};
TRY(check_errors());
size_t total_sent = 0;
while (total_sent < buffer.size())
{
Thread::current().add_signal(SIGPIPE);
return BAN::Error::from_errno(EPIPE);
TRY(check_errors());
const size_t nsend = TRY(inode->sendto(buffer.slice(total_sent), address, address_len));
if (nsend == 0)
return 0;
total_sent += nsend;
}
if (is_nonblock && !inode->can_write())
return BAN::Error::from_errno(EWOULDBLOCK);
return inode->sendto(buffer, address, address_len);
return total_sent;
}
BAN::ErrorOr<VirtualFileSystem::File> OpenFileDescriptorSet::file_of(int fd) const

View File

@ -514,6 +514,10 @@ namespace Kernel
if (fd == AT_FDCWD)
return TRY(m_working_directory.clone());
const auto status_flags = TRY(m_open_file_descriptors.status_flags_of(fd));
if (!(status_flags & O_RDONLY) && !(status_flags & O_SEARCH))
return BAN::Error::from_errno(EBADF);
return TRY(m_open_file_descriptors.file_of(fd));
}
@ -806,10 +810,13 @@ namespace Kernel
return exited_pid;
}
if (Thread::current().is_interrupted_by_signal())
return BAN::Error::from_errno(EINTR);
if (options & WNOHANG)
return 0;
TRY(Thread::current().block_or_eintr_indefinite(m_child_exit_blocker, &m_process_lock));
m_child_exit_blocker.block_indefinite(&m_process_lock);
}
}
@ -819,18 +826,12 @@ namespace Kernel
return 0;
const uint64_t wake_time_ms = SystemTimer::get().ms_since_boot() + (seconds * 1000);
while (!Thread::current().is_interrupted_by_signal())
{
const uint64_t current_ms = SystemTimer::get().ms_since_boot();
if (current_ms >= wake_time_ms)
break;
SystemTimer::get().sleep_ms(wake_time_ms - current_ms);
}
SystemTimer::get().sleep_ms(seconds * 1000);
const uint64_t current_ms = SystemTimer::get().ms_since_boot();
if (current_ms < wake_time_ms)
return BAN::Math::div_round_up<long>(wake_time_ms - current_ms, 1000);
return 0;
}
@ -1214,16 +1215,6 @@ namespace Kernel
return 0;
}
BAN::ErrorOr<long> Process::sys_flock(int fd, int op)
{
auto maybe_error = m_open_file_descriptors.flock(fd, op);
if (maybe_error.is_error() && maybe_error.error().get_error_code() == ENOMEM)
return BAN::Error::from_errno(ENOLCK);
if (maybe_error.is_error())
return maybe_error.error();
return 0;
}
BAN::ErrorOr<long> Process::sys_pread(int fd, void* buffer, size_t count, off_t offset)
{
auto inode = TRY(m_open_file_descriptors.inode_of(fd));
@ -2093,28 +2084,26 @@ namespace Kernel
return 0;
}
BAN::ErrorOr<long> Process::sys_mmap(const sys_mmap_t* user_args)
BAN::ErrorOr<long> Process::sys_mmap(const sys_mmap_t* args)
{
sys_mmap_t args;
{
LockGuard _(m_process_lock);
TRY(validate_pointer_access(user_args, sizeof(sys_mmap_t), false));
args = *user_args;
TRY(validate_pointer_access(args, sizeof(sys_mmap_t), true));
}
if (args.prot != PROT_NONE && (args.prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)))
if (args->prot != PROT_NONE && (args->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)))
return BAN::Error::from_errno(EINVAL);
if (!(args.flags & MAP_PRIVATE) == !(args.flags & MAP_SHARED))
if (!(args->flags & MAP_PRIVATE) == !(args->flags & MAP_SHARED))
return BAN::Error::from_errno(EINVAL);
auto region_type = (args.flags & MAP_PRIVATE) ? MemoryRegion::Type::PRIVATE : MemoryRegion::Type::SHARED;
auto region_type = (args->flags & MAP_PRIVATE) ? MemoryRegion::Type::PRIVATE : MemoryRegion::Type::SHARED;
PageTable::flags_t page_flags = 0;
if (args.prot & PROT_READ)
if (args->prot & PROT_READ)
page_flags |= PageTable::Flags::Present;
if (args.prot & PROT_WRITE)
if (args->prot & PROT_WRITE)
page_flags |= PageTable::Flags::ReadWrite | PageTable::Flags::Present;
if (args.prot & PROT_EXEC)
if (args->prot & PROT_EXEC)
page_flags |= PageTable::Flags::Execute | PageTable::Flags::Present;
if (page_flags == 0)
@ -2123,21 +2112,21 @@ namespace Kernel
page_flags |= PageTable::Flags::UserSupervisor;
AddressRange address_range { .start = 0x400000, .end = USERSPACE_END };
if (args.flags & MAP_FIXED)
if (args->flags & MAP_FIXED)
{
vaddr_t base_addr = reinterpret_cast<vaddr_t>(args.addr);
vaddr_t base_addr = reinterpret_cast<vaddr_t>(args->addr);
address_range.start = BAN::Math::div_round_up<vaddr_t>(base_addr, PAGE_SIZE) * PAGE_SIZE;
address_range.end = BAN::Math::div_round_up<vaddr_t>(base_addr + args.len, PAGE_SIZE) * PAGE_SIZE;
address_range.end = BAN::Math::div_round_up<vaddr_t>(base_addr + args->len, PAGE_SIZE) * PAGE_SIZE;
}
if (args.flags & MAP_ANONYMOUS)
if (args->flags & MAP_ANONYMOUS)
{
if (args.off != 0)
if (args->off != 0)
return BAN::Error::from_errno(EINVAL);
auto region = TRY(MemoryBackedRegion::create(
page_table(),
args.len,
args->len,
address_range,
region_type, page_flags
));
@ -2149,13 +2138,13 @@ namespace Kernel
LockGuard _(m_process_lock);
auto inode = TRY(m_open_file_descriptors.inode_of(args.fildes));
auto inode = TRY(m_open_file_descriptors.inode_of(args->fildes));
const auto status_flags = TRY(m_open_file_descriptors.status_flags_of(args.fildes));
const auto status_flags = TRY(m_open_file_descriptors.status_flags_of(args->fildes));
if (!(status_flags & O_RDONLY))
return BAN::Error::from_errno(EACCES);
if (region_type == MemoryRegion::Type::SHARED)
if ((args.prot & PROT_WRITE) && !(status_flags & O_WRONLY))
if ((args->prot & PROT_WRITE) && !(status_flags & O_WRONLY))
return BAN::Error::from_errno(EACCES);
BAN::UniqPtr<MemoryRegion> memory_region;
@ -2164,7 +2153,7 @@ namespace Kernel
memory_region = TRY(FileBackedRegion::create(
inode,
page_table(),
args.off, args.len,
args->off, args->len,
address_range,
region_type, page_flags
));
@ -2173,7 +2162,7 @@ namespace Kernel
{
memory_region = TRY(static_cast<Device&>(*inode).mmap_region(
page_table(),
args.off, args.len,
args->off, args->len,
address_range,
region_type, page_flags
));
@ -2379,8 +2368,10 @@ namespace Kernel
BAN::ErrorOr<long> Process::sys_clock_gettime(clockid_t clock_id, timespec* tp)
{
LockGuard _(m_process_lock);
TRY(validate_pointer_access(tp, sizeof(timespec), true));
{
LockGuard _(m_process_lock);
TRY(validate_pointer_access(tp, sizeof(timespec), true));
}
switch (clock_id)
{
@ -2390,31 +2381,10 @@ namespace Kernel
case CLOCK_REALTIME:
*tp = SystemTimer::get().real_time();
break;
case CLOCK_PROCESS_CPUTIME_ID:
{
uint64_t cpu_time_ns { 0 };
for (auto* thread : m_threads)
cpu_time_ns += thread->cpu_time_ns();
*tp = {
.tv_sec = static_cast<time_t>(cpu_time_ns / 1'000'000'000),
.tv_nsec = static_cast<long>(cpu_time_ns % 1'000'000'000),
};
break;
}
case CLOCK_THREAD_CPUTIME_ID:
{
const auto cpu_time_ns = Thread::current().cpu_time_ns();
*tp = {
.tv_sec = static_cast<time_t>(cpu_time_ns / 1'000'000'000),
.tv_nsec = static_cast<long>(cpu_time_ns % 1'000'000'000),
};
break;
}
default:
dwarnln("TODO: clock_gettime({})", clock_id);
return BAN::Error::from_errno(ENOTSUP);
}
return 0;
}

View File

@ -382,9 +382,6 @@ namespace Kernel
}
}
if (!scheduler().is_idle())
Thread::current().set_cpu_time_stop();
#if ARCH(x86_64)
asm volatile(
"movq %%rsp, %%rcx;"
@ -394,7 +391,7 @@ namespace Kernel
// NOTE: This is offset by 2 pointers since interrupt without PL change
// does not push SP and SS. This allows accessing "whole" interrupt stack.
:: [load_sp]"r"(Processor::current_stack_top() - 2 * sizeof(uintptr_t)),
[yield]"i"(static_cast<int>(IRQ_YIELD)) // WTF GCC 15
[yield]"i"(IRQ_YIELD)
: "memory", "rcx"
);
#elif ARCH(i686)
@ -406,7 +403,7 @@ namespace Kernel
// NOTE: This is offset by 2 pointers since interrupt without PL change
// does not push SP and SS. This allows accessing "whole" interrupt stack.
:: [load_sp]"r"(Processor::current_stack_top() - 2 * sizeof(uintptr_t)),
[yield]"i"(static_cast<int>(IRQ_YIELD)) // WTF GCC 15
[yield]"i"(IRQ_YIELD)
: "memory", "ecx"
);
#else
@ -415,9 +412,6 @@ namespace Kernel
processor_info.m_start_ns = SystemTimer::get().ns_since_boot();
if (!scheduler().is_idle())
Thread::current().set_cpu_time_start();
Processor::set_interrupt_state(state);
}

View File

@ -275,10 +275,7 @@ namespace Kernel
page_table.load();
if (thread->state() == Thread::State::NotStarted)
{
thread->m_state = Thread::State::Executing;
thread->set_cpu_time_start();
}
Processor::gdt().set_tss_stack(thread->kernel_stack_top());
Processor::load_tls();
@ -461,14 +458,9 @@ namespace Kernel
else
{
const uint64_t duration_ns = current_ns - m_last_load_balance_ns;
const uint64_t max_thread_load_x1000 = 1000 * most_loaded_thread.node->time_used_ns / duration_ns;
if (max_thread_load_x1000 == 0)
s_processor_infos[Processor::current_id().as_u32()].max_load_threads = 0;
else
{
const uint64_t max_load_thread_count = ((2000 / max_thread_load_x1000) + 1) / 2;
s_processor_infos[Processor::current_id().as_u32()].max_load_threads = max_load_thread_count;
}
const uint64_t max_thread_load_x1000 = 1000 * m_most_loaded_threads.front().node->time_used_ns / duration_ns;
const uint64_t max_load_thread_count = ((2000 / max_thread_load_x1000) + 1) / 2;
s_processor_infos[Processor::current_id().as_u32()].max_load_threads = max_load_thread_count;
}
}

View File

@ -38,8 +38,6 @@ namespace Kernel
#undef O
};
static bool is_restartable_syscall(int syscall);
extern "C" long cpp_syscall_handler(int syscall, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, InterruptStack* interrupt_stack)
{
ASSERT(GDT::is_user_segment(interrupt_stack->cs));
@ -95,7 +93,7 @@ namespace Kernel
auto& current_thread = Thread::current();
if (current_thread.can_add_signal_to_execute())
if (current_thread.handle_signal())
if (ret.is_error() && ret.error().get_error_code() == EINTR && is_restartable_syscall(syscall))
if (ret.is_error() && ret.error().get_error_code() == EINTR)
ret = BAN::Error::from_errno(ERESTART);
Processor::set_interrupt_state(InterruptState::Disabled);
@ -107,26 +105,4 @@ namespace Kernel
return ret.value();
}
bool is_restartable_syscall(int syscall)
{
// https://www.man7.org/linux/man-pages/man7/signal.7.html
// Interruption of system calls and library functions by signal handlers
switch (syscall)
{
case SYS_READ:
case SYS_WRITE:
case SYS_IOCTL:
case SYS_OPENAT:
case SYS_WAIT:
case SYS_ACCEPT:
case SYS_CONNECT:
case SYS_RECVFROM:
case SYS_SENDTO:
case SYS_FLOCK:
return true;
default:
return false;
}
}
}

View File

@ -204,4 +204,20 @@ namespace Kernel
return master->m_buffer_size < master->m_buffer->size();
}
BAN::ErrorOr<long> PseudoTerminalSlave::ioctl_impl(int request, void* argument)
{
switch (request)
{
case TIOCSWINSZ:
{
const auto* winsize = static_cast<struct winsize*>(argument);
m_width = winsize->ws_col;
m_height = winsize->ws_row;
return 0;
}
}
return TTY::ioctl_impl(request, argument);
}
}

View File

@ -181,9 +181,7 @@ namespace Kernel
}, 0600, 0, 0)
, m_name(MUST(BAN::String::formatted("ttyS{}", s_next_tty_number++)))
, m_serial(serial)
{
update_winsize(m_serial.width(), m_serial.height());
}
{}
BAN::ErrorOr<BAN::RefPtr<SerialTTY>> SerialTTY::create(Serial serial)
{
@ -256,6 +254,16 @@ namespace Kernel
handle_input_byte(*ptr++);
}
uint32_t SerialTTY::width() const
{
return m_serial.width();
}
uint32_t SerialTTY::height() const
{
return m_serial.height();
}
bool SerialTTY::putchar_impl(uint8_t ch)
{
m_serial.putchar(ch);

View File

@ -184,13 +184,6 @@ namespace Kernel
return {};
}
void TTY::update_winsize(unsigned short cols, unsigned short rows)
{
m_winsize.ws_col = cols;
m_winsize.ws_row = rows;
(void)Process::kill(-m_foreground_pgrp, SIGWINCH);
}
BAN::ErrorOr<long> TTY::ioctl_impl(int request, void* argument)
{
switch (request)
@ -205,14 +198,8 @@ namespace Kernel
case TIOCGWINSZ:
{
auto* winsize = static_cast<struct winsize*>(argument);
*winsize = m_winsize;
return 0;
}
case TIOCSWINSZ:
{
const auto* winsize = static_cast<const struct winsize*>(argument);
m_winsize = *winsize;
(void)Process::kill(-m_foreground_pgrp, SIGWINCH);
winsize->ws_col = width();
winsize->ws_row = height();
return 0;
}
}

View File

@ -53,7 +53,6 @@ namespace Kernel
{
m_width = m_terminal_driver->width();
m_height = m_terminal_driver->height();
update_winsize(m_width, m_height);
m_buffer = new Cell[m_width * m_height];
ASSERT(m_buffer);
@ -72,38 +71,34 @@ namespace Kernel
if (!m_terminal_driver->has_font())
return BAN::Error::from_errno(EINVAL);
SpinLockGuard _(m_write_lock);
TRY(m_terminal_driver->set_font(BAN::move(font)));
uint32_t new_width = m_terminal_driver->width();
uint32_t new_height = m_terminal_driver->height();
if (m_width != new_width || m_height != new_height)
{
SpinLockGuard _(m_write_lock);
Cell* new_buffer = new Cell[new_width * new_height];
ASSERT(new_buffer);
TRY(m_terminal_driver->set_font(BAN::move(font)));
for (uint32_t i = 0; i < new_width * m_height; i++)
new_buffer[i] = { .foreground = m_foreground, .background = m_background, .codepoint = ' ' };
uint32_t new_width = m_terminal_driver->width();
uint32_t new_height = m_terminal_driver->height();
for (uint32_t y = 0; y < BAN::Math::min<uint32_t>(m_height, new_height); y++)
for (uint32_t x = 0; x < BAN::Math::min<uint32_t>(m_width, new_width); x++)
new_buffer[y * new_width + x] = m_buffer[y * m_width + x];
if (m_width != new_width || m_height != new_height)
{
Cell* new_buffer = new Cell[new_width * new_height];
ASSERT(new_buffer);
for (uint32_t i = 0; i < new_width * m_height; i++)
new_buffer[i] = { .foreground = m_foreground, .background = m_background, .codepoint = ' ' };
for (uint32_t y = 0; y < BAN::Math::min<uint32_t>(m_height, new_height); y++)
for (uint32_t x = 0; x < BAN::Math::min<uint32_t>(m_width, new_width); x++)
new_buffer[y * new_width + x] = m_buffer[y * m_width + x];
delete[] m_buffer;
m_buffer = new_buffer;
m_width = new_width;
m_height = new_height;
}
for (uint32_t y = 0; y < m_height; y++)
for (uint32_t x = 0; x < m_width; x++)
render_from_buffer(x, y);
delete[] m_buffer;
m_buffer = new_buffer;
m_width = new_width;
m_height = new_height;
}
update_winsize(m_width, m_height);
for (uint32_t y = 0; y < m_height; y++)
for (uint32_t x = 0; x < m_width; x++)
render_from_buffer(x, y);
return {};
}
@ -119,10 +114,10 @@ namespace Kernel
m_state = State::Normal;
}
void VirtualTTY::handle_ansi_csi_color(uint8_t value)
void VirtualTTY::handle_ansi_csi_color(uint8_t ch)
{
ASSERT(m_write_lock.current_processor_has_lock());
switch (value)
switch (ch)
{
case 0:
m_foreground = m_palette[15];
@ -130,37 +125,23 @@ namespace Kernel
m_colors_inverted = false;
break;
// TODO: bold
case 1: break;
case 22: break;
case 7: m_colors_inverted = true; break;
case 27: m_colors_inverted = false; break;
case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37:
m_foreground = m_palette[value - 30];
break;
case 39:
m_foreground = m_palette[15];
m_foreground = m_palette[ch - 30];
break;
case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47:
m_background = m_palette[value - 40];
break;
case 49:
m_background = m_palette[0];
m_background = m_palette[ch - 40];
break;
case 90: case 91: case 92: case 93: case 94: case 95: case 96: case 97:
m_foreground = m_palette[value - 90 + 8];
m_foreground = m_palette[ch - 90 + 8];
break;
case 100: case 101: case 102: case 103: case 104: case 105: case 106: case 107:
m_background = m_palette[value - 100 + 8];
break;
default:
dprintln_if(DEBUG_VTTY, "unhandled ANSI SGR {}", value);
m_background = m_palette[ch - 100 + 8];
break;
}
}
@ -408,7 +389,7 @@ namespace Kernel
return;
}
reset_ansi();
dprintln_if(DEBUG_VTTY, "Invalid ANSI CSI ?");
dprintln_if(DEBUG_VTTY, "invalid ANSI CSI ?");
return;
case 'h':
case 'l':
@ -418,15 +399,16 @@ namespace Kernel
return reset_ansi();
}
reset_ansi();
dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character {}", static_cast<char>(ch));
dprintln_if(DEBUG_VTTY, "invalid ANSI CSI character {}", static_cast<char>(ch));
return;
case 'n':
if (m_ansi_state.nums[0] == 6)
{
BAN::Formatter::print(
[this](char ch) { handle_input_byte(ch); },
"\e[{};{}R", m_row + 1, m_column + 1
);
char buffer[2 + 10 + 1 + 10 + 1];
size_t len = 0;
BAN::Formatter::print([&](char ch) { buffer[len++] = ch; }, "\e[{};{}R", m_row + 1, m_column + 1);
for (size_t i = 0; i < len; i++)
handle_input_byte(buffer[i]);
return reset_ansi();
};
reset_ansi();

View File

@ -37,36 +37,18 @@ namespace Kernel
static pid_t s_next_tid = 1;
alignas(16) static uint8_t s_default_sse_storage[512];
static BAN::Atomic<bool> s_default_sse_storage_initialized = false;
static bool s_default_sse_storage_initialized = false;
static void initialize_default_sse_storage()
{
static BAN::Atomic<bool> is_initializing { false };
bool expected { false };
if (!is_initializing.compare_exchange(expected, true))
{
while (!s_default_sse_storage_initialized)
__builtin_ia32_pause();
asm volatile("" ::: "memory");
return;
}
const uint32_t mxcsr = 0x1F80;
asm volatile(
"finit;"
"ldmxcsr %[mxcsr];"
#if ARCH(x86_64)
"fxsave64 %[storage];"
#elif ARCH(i686)
"fxsave %[storage];"
#else
#error
#endif
: [storage]"=m"(s_default_sse_storage)
: [mxcsr]"m"(mxcsr)
);
s_default_sse_storage_initialized = true;
}
BAN::ErrorOr<Thread*> Thread::create_kernel(entry_t entry, void* data, Process* process)
@ -144,7 +126,10 @@ namespace Kernel
: m_tid(tid), m_process(process)
{
if (!s_default_sse_storage_initialized)
{
initialize_default_sse_storage();
s_default_sse_storage_initialized = true;
}
memcpy(m_sse_storage, s_default_sse_storage, sizeof(m_sse_storage));
}
@ -181,29 +166,6 @@ namespace Kernel
}
}
uint64_t Thread::cpu_time_ns() const
{
SpinLockGuard _(m_cpu_time_lock);
if (m_cpu_time_start_ns == UINT64_MAX)
return m_cpu_time_ns;
return m_cpu_time_ns + (SystemTimer::get().ns_since_boot() - m_cpu_time_start_ns);
}
void Thread::set_cpu_time_start()
{
SpinLockGuard _(m_cpu_time_lock);
ASSERT(m_cpu_time_start_ns == UINT64_MAX);
m_cpu_time_start_ns = SystemTimer::get().ns_since_boot();
}
void Thread::set_cpu_time_stop()
{
SpinLockGuard _(m_cpu_time_lock);
ASSERT(m_cpu_time_start_ns != UINT64_MAX);
m_cpu_time_ns += SystemTimer::get().ns_since_boot() - m_cpu_time_start_ns;
m_cpu_time_start_ns = UINT64_MAX;
}
BAN::ErrorOr<Thread*> Thread::pthread_create(entry_t entry, void* arg)
{
auto* thread = TRY(create_userspace(m_process, m_process->page_table()));
@ -523,7 +485,6 @@ namespace Kernel
interrupt_stack.sp -= 128; // skip possible red-zone
#endif
write_to_stack(interrupt_stack.sp, interrupt_stack.ip);
write_to_stack(interrupt_stack.sp, interrupt_stack.flags);
write_to_stack(interrupt_stack.sp, signal);
write_to_stack(interrupt_stack.sp, signal_handler);
interrupt_stack.ip = (uintptr_t)signal_trampoline;
@ -677,24 +638,12 @@ namespace Kernel
void Thread::save_sse()
{
#if ARCH(x86_64)
asm volatile("fxsave64 %0" :: "m"(m_sse_storage));
#elif ARCH(i686)
asm volatile("fxsave %0" :: "m"(m_sse_storage));
#else
#error
#endif
}
void Thread::load_sse()
{
#if ARCH(x86_64)
asm volatile("fxrstor64 %0" :: "m"(m_sse_storage));
#elif ARCH(i686)
asm volatile("fxrstor %0" :: "m"(m_sse_storage));
#else
#error
#endif
}
}

View File

@ -1,27 +0,0 @@
#!/bin/bash ../install.sh
NAME='SDL2'
VERSION='2.30.11'
DOWNLOAD_URL="https://github.com/libsdl-org/SDL/archive/refs/tags/release-$VERSION.tar.gz#cc6136dd964854e8846c679703322f3e2a341d27a06a53f8b3f642c26f1b0cfd"
TAR_CONTENT="SDL-release-$VERSION"
DEPENDENCIES=('mesa')
configure() {
$BANAN_CMAKE \
--toolchain="$CMAKE_TOOLCHAIN_FILE" \
--fresh -GNinja -S . -B build \
-DCMAKE_INSTALL_PREFIX='/usr' \
-DCMAKE_BUILD_TYPE=Release \
-DBANAN_OS=true \
-DUNIX=true \
-DSDL_LIBSAMPLERATE=OFF \
-DSDL_PTHREADS_SEM=OFF
}
build() {
$BANAN_CMAKE --build build --config Release || exit 1
}
install() {
$BANAN_CMAKE --install build || exit 1
}

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +0,0 @@
#!/bin/bash ../install.sh
NAME='bash'
VERSION='5.2.37'
DOWNLOAD_URL="https://ftp.gnu.org/gnu/bash/bash-$VERSION.tar.gz#9599b22ecd1d5787ad7d3b7bf0c59f312b3396d1e281175dd1f8a4014da621ff"
DEPENDENCIES=('ncurses')
CONFIGURE_OPTIONS=(
'--disable-nls'
'--without-bash-malloc'
'--with-curses'
'bash_cv_unusable_rtsigs=no'
'bash_cv_signal_vintage=posix'
'CFLAGS=-std=c17'
'CFLAGS_FOR_BUILD=-std=c17'
)
post_install() {
if [ ! -L $BANAN_SYSROOT/usr/bin/sh ]; then
ln -s bash $BANAN_SYSROOT/usr/bin/sh
fi
}

View File

@ -1,12 +0,0 @@
diff -ruN bash-5.2.37/support/config.sub bash-5.2.37-banan_os/support/config.sub
--- bash-5.2.37/support/config.sub 2022-01-11 21:38:29.000000000 +0200
+++ bash-5.2.37-banan_os/support/config.sub 2024-12-07 05:43:54.697086738 +0200
@@ -1754,7 +1754,7 @@
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | banan_os* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)

View File

@ -1,19 +0,0 @@
diff -ruN bash-5.2.37/parse.y bash-5.2.37-banan_os/parse.y
--- bash-5.2.37/parse.y 2024-09-24 00:24:01.000000000 +0300
+++ bash-5.2.37-banan_os/parse.y 2024-12-07 06:49:40.322734826 +0200
@@ -2640,6 +2640,7 @@
parser_state |= PST_ENDALIAS;
/* We need to do this to make sure last_shell_getc_is_singlebyte returns
true, since we are returning a single-byte space. */
+#if defined (HANDLE_MULTIBYTE)
if (shell_input_line_index == shell_input_line_len && last_shell_getc_is_singlebyte == 0)
{
#if 0
@@ -2653,6 +2654,7 @@
shell_input_line_property[shell_input_line_index - 1] = 1;
#endif
}
+#endif /* HANDLE_MULTIBYTE */
return ' '; /* END_ALIAS */
}
#endif

View File

@ -1,12 +0,0 @@
diff -ruN bash-5.2.37/examples/loadables/Makefile.in bash-5.2.37-banan_os/examples/loadables/Makefile.in
--- bash-5.2.37/examples/loadables/Makefile.in 2022-08-19 23:33:30.000000000 +0300
+++ bash-5.2.37-banan_os/examples/loadables/Makefile.in 2025-01-26 02:43:36.121801845 +0200
@@ -104,7 +104,7 @@
ALLPROG = print truefalse sleep finfo logname basename dirname fdflags \
tty pathchk tee head mkdir rmdir mkfifo mktemp printenv id whoami \
uname sync push ln unlink realpath strftime mypid setpgid seq rm \
- accept csv dsv cut stat getconf
+ accept csv dsv stat
OTHERPROG = necho hello cat pushd asort
all: $(SHOBJ_STATUS)

View File

@ -1,10 +1,9 @@
#!/bin/bash ../install.sh
NAME='binutils'
VERSION='2.44'
DOWNLOAD_URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.gz#0cdd76777a0dfd3dd3a63f215f030208ddb91c2361d2bcc02acec0f1c16b6a2e"
VERSION='2.39'
DOWNLOAD_URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.gz#d12ea6f239f1ffe3533ea11ad6e224ffcb89eb5d01bbea589e9158780fa11f10"
DEPENDENCIES=('zlib')
MAKE_INSTALL_TARGETS=('install-strip')
CONFIGURE_OPTIONS=(
"--target=$BANAN_TOOLCHAIN_TRIPLE"
'--with-sysroot=/'
@ -15,3 +14,11 @@ CONFIGURE_OPTIONS=(
'--disable-nls'
'--disable-werror'
)
build() {
# This file is not even used. binutils just requires it to exist
touch "$BANAN_SYSROOT/usr/include/memory.h"
make -j$(nproc) || exit 1
find . -type f -executable -exec strip --strip-unneeded {} + 2>/dev/null
}

View File

@ -0,0 +1 @@
../../../toolchain/binutils-2.39.patch

View File

@ -1 +0,0 @@
../../../toolchain/binutils-2.44.patch

View File

@ -1,10 +0,0 @@
#!/bin/bash ../install.sh
NAME='bochs'
VERSION='3.0'
DOWNLOAD_URL="https://sourceforge.net/projects/bochs/files/bochs/$VERSION/bochs-$VERSION.tar.gz#cb6f542b51f35a2cc9206b2a980db5602b7cd1b7cf2e4ed4f116acd5507781aa"
DEPENDENCIES=('SDL2')
CONFIGURE_OPTIONS=(
'--with-sdl2'
'--enable-x86-64'
)

View File

@ -1,12 +0,0 @@
diff -ruN bochs-2.8/config.sub bochs-2.8-banan_os/config.sub
--- bochs-2.8/config.sub 2024-03-10 08:59:37.000000000 +0200
+++ bochs-2.8-banan_os/config.sub 2024-12-07 05:15:32.948901314 +0200
@@ -1368,7 +1368,7 @@
| powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \
| skyos* | haiku* | rdos* | toppers* | drops* | es* \
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
- | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi*)
+ | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* | banan_os*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
qnx*)

View File

@ -1,38 +0,0 @@
diff -ruN bochs-3.0/bochs.h bochs-3.0-banan_os/bochs.h
--- bochs-3.0/bochs.h 2024-03-10 08:59:37.000000000 +0200
+++ bochs-3.0-banan_os/bochs.h 2025-04-15 20:46:58.442339461 +0300
@@ -91,6 +91,9 @@
#endif
#include <ctype.h>
#include <string.h>
+#if defined(__banan_os__)
+# include <strings.h>
+#endif
#include <fcntl.h>
#include <limits.h>
#ifdef macintosh
diff -ruN bochs-3.0/iodev/serial.cc bochs-3.0-banan_os/iodev/serial.cc
--- bochs-3.0/iodev/serial.cc 2024-03-10 08:59:37.000000000 +0200
+++ bochs-3.0-banan_os/iodev/serial.cc 2025-04-15 20:49:42.493314963 +0300
@@ -37,6 +37,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
+#include <arpa/inet.h>
#define closesocket(s) close(s)
typedef int SOCKET;
#else
diff -ruN bochs-3.0/gui/keymap.cc bochs-3.0-banan_os/gui/keymap.cc
--- bochs-3.0/gui/keymap.cc 2025-02-16 11:15:29.000000000 +0200
+++ bochs-3.0-banan_os/gui/keymap.cc 2025-06-25 19:17:34.077048625 +0300
@@ -30,6 +30,10 @@
#include "gui.h"
#include "keymap.h"
+#ifdef __banan_os__
+# include <libgen.h>
+#endif
+
// Table of bochs "BX_KEY_*" symbols
// the table must be in BX_KEY_* order
const char *bx_key_symbol[BX_KEY_NBKEYS] = {

View File

@ -1,39 +0,0 @@
diff -ruN bochs-2.8/configure bochs-2.8-banan_os/configure
--- bochs-2.8/configure 2024-03-10 08:59:37.000000000 +0200
+++ bochs-2.8-banan_os/configure 2025-06-25 16:18:01.081403116 +0300
@@ -25286,7 +25286,7 @@
elif test "$with_sdl2" = yes; then
SOUNDLOW_OBJS="$SOUNDLOW_OBJS soundsdl.o"
if test "$bx_plugins" = 1; then
- SDL_SOUND_LINK_OPTS="$SDL_SOUND_LINK_OPTS `sdl2-config --libs`"
+ SDL_SOUND_LINK_OPTS="$SDL_SOUND_LINK_OPTS `pkg-config sdl2 --libs`"
fi
soundlow_drivers="$soundlow_drivers sdl"
if test "$soundlow_default" = "dummy"; then
@@ -25294,7 +25294,7 @@
fi
printf "%s\n" "#define BX_HAVE_SOUND_SDL 1" >>confdefs.h
- SDL2_VERSION=`sdl2-config --version`
+ SDL2_VERSION=`pkg-config sdl2 --version`
# SDL version >= 2.0.5 supports audio capture
sdl2_audio_capture=0
@@ -25967,14 +25967,14 @@
SPECIFIC_GUI_OBJS="$SPECIFIC_GUI_OBJS \$(GUI_OBJS_SDL2)"
# GUI_*FLAGS are added to the compilation of every bochs file, not just
# the files in gui/*.cc.
- SDL2_CFLAGS=`sdl2-config --cflags`
+ SDL2_CFLAGS=`pkg-config sdl2 --cflags`
GUI_CFLAGS="$GUI_CFLAGS $SDL2_CFLAGS"
GUI_CXXFLAGS="$GUI_CXXFLAGS $SDL2_CFLAGS"
- GUI_LINK_OPTS_SDL2="`sdl2-config --libs`"
+ GUI_LINK_OPTS_SDL2="`pkg-config sdl2 --libs`"
GUI_LINK_OPTS="$GUI_LINK_OPTS \$(GUI_LINK_OPTS_SDL2)"
# The plugin version uses multi-threading support in Bochs core
if test "$bx_plugins" = 1; then
- NONPLUGIN_GUI_LINK_OPTS="`sdl2-config --libs`"
+ NONPLUGIN_GUI_LINK_OPTS="`pkg-config sdl2 --libs`"
fi
# The enhanced X debugger depends on GTK2
if test "$gui_debugger" = 1 -a "$DEFAULT_GUI" != win32; then

View File

@ -18,7 +18,9 @@ CONFIGURE_OPTIONS=(
'--without-ca-path'
)
post_install() {
install() {
make install DESTDIR="$BANAN_SYSROOT" || exit 1
# remove libtool file
rm -f $BANAN_SYSROOT/usr/lib/libcurl.la
}

View File

@ -1,5 +0,0 @@
#!/bin/bash ../install.sh
NAME='expat'
VERSION='2.7.1'
DOWNLOAD_URL="https://github.com/libexpat/libexpat/releases/download/R_2_7_1/expat-$VERSION.tar.gz#0cce2e6e69b327fc607b8ff264f4b66bdf71ead55a87ffd5f3143f535f15cfa2"

View File

@ -1,12 +0,0 @@
diff -ruN expat-2.7.1/conftools/config.sub expat-2.7.1-banan_os/conftools/config.sub
--- expat-2.7.1/conftools/config.sub 2022-07-27 15:26:54.000000000 +0300
+++ expat-2.7.1-banan_os/conftools/config.sub 2025-06-17 11:51:49.876848002 +0300
@@ -1775,7 +1775,7 @@
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | banan_os* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)

View File

@ -1,19 +1,29 @@
#!/bin/bash ../install.sh
NAME='gcc'
VERSION='15.1.0'
DOWNLOAD_URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.gz#51b9919ea69c980d7a381db95d4be27edf73b21254eb13d752a08003b4d013b1"
VERSION='12.2.0'
DOWNLOAD_URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.gz#ac6b317eb4d25444d87cf29c0d141dedc1323a1833ec9995211b13e1a851261c"
DEPENDENCIES=('binutils' 'gmp' 'mpfr' 'mpc')
MAKE_BUILD_TARGETS=('all-gcc' 'all-target-libgcc' 'all-target-libstdc++-v3')
MAKE_INSTALL_TARGETS=('install-strip-gcc' 'install-strip-target-libgcc' 'install-strip-target-libstdc++-v3')
CONFIGURE_OPTIONS=(
"--target=$BANAN_TOOLCHAIN_TRIPLE"
'--with-sysroot=/'
"--with-build-sysroot=$BANAN_SYSROOT"
'--enable-initfini-array'
'--enable-threads=posix'
'--enable-shared'
'--enable-lto'
'--disable-nls'
'--enable-languages=c,c++'
)
build() {
make -j$(nproc) all-gcc || exit 1
make -j$(nproc) all-target-libgcc || exit 1
make -j$(nproc) all-target-libstdc++-v3 || exit 1
find . -type f -executable -exec strip --strip-unneeded {} + 2>/dev/null
}
install() {
make install-gcc DESTDIR="$BANAN_SYSROOT" || exit 1
make install-target-libgcc DESTDIR="$BANAN_SYSROOT" || exit 1
make install-target-libstdc++-v3 DESTDIR="$BANAN_SYSROOT" || exit 1
}

View File

@ -0,0 +1 @@
../../../toolchain/gcc-12.2.0.patch

View File

@ -1 +0,0 @@
../../../toolchain/gcc-15.1.0.patch

View File

@ -1,21 +0,0 @@
#!/bin/bash ../install.sh
NAME='glu'
VERSION='9.0.3'
DOWNLOAD_URL="https://archive.mesa3d.org/glu/glu-$VERSION.tar.xz#bd43fe12f374b1192eb15fe20e45ff456b9bc26ab57f0eee919f96ca0f8a330f"
DEPENDENCIES=('mesa')
CONFIGURE_OPTIONS=(
'-Dprefix=/usr'
)
configure() {
meson setup --reconfigure --cross-file "$MESON_CROSS_FILE" "${CONFIGURE_OPTIONS[@]}" build || exit 1
}
build() {
meson compile -C build || exit 1
}
install() {
meson install --destdir="$BANAN_SYSROOT" -C build || exit 1
}

View File

@ -3,6 +3,3 @@
NAME='gmp'
VERSION='6.3.0'
DOWNLOAD_URL="https://ftp.gnu.org/gnu/gmp/gmp-$VERSION.tar.xz#a3c2b80201b89e68616f4ad30bc66aee4927c3ce50e33929ca819d5c43538898"
# configure does not work with (default) c23
export CFLAGS="--std=c17 $CFLAGS"

View File

@ -39,31 +39,15 @@ if [ "$BANAN_ARCH" = "i686" ]; then
export LDFLAGS="-shared-libgcc"
fi
export MESON_CROSS_FILE="$BANAN_PORT_DIR/$BANAN_ARCH-banan_os-meson.txt"
if [ ! -f "$MESON_CROSS_FILE" ] || [ "$MESON_CROSS_FILE" -ot "$BANAN_TOOLCHAIN_DIR/meson-cross-file.in" ]; then
cp "$BANAN_TOOLCHAIN_DIR/meson-cross-file.in" "$MESON_CROSS_FILE"
sed -i "s/ARCH/$BANAN_ARCH/" "$MESON_CROSS_FILE"
sed -i "s/SYSROOT/$BANAN_SYSROOT/" "$MESON_CROSS_FILE"
fi
MAKE_BUILD_TARGETS=('all')
MAKE_INSTALL_TARGETS=('install')
clean() {
find . -mindepth 1 -maxdepth 1 -not -name 'patches' -not -name 'build.sh' -exec rm -rf {} +
}
pre_configure() {
:
}
post_configure() {
:
}
configure() {
pre_configure
configure_options=("--host=$BANAN_ARCH-pc-banan_os" '--prefix=/usr')
configure_options+=("${CONFIGURE_OPTIONS[@]}")
./configure "${configure_options[@]}" || exit 1
@ -72,27 +56,11 @@ configure() {
}
build() {
for target in "${MAKE_BUILD_TARGETS[@]}"; do
make -j$(nproc) $target || exit 1
done
}
pre_install() {
:
}
post_install() {
:
make -j$(nproc) || exit 1
}
install() {
pre_install
for target in "${MAKE_INSTALL_TARGETS[@]}"; do
make $target "DESTDIR=$BANAN_SYSROOT" || exit 1
done
post_install
make install "DESTDIR=$BANAN_SYSROOT" || exit 1
}
source $1

View File

@ -5,7 +5,9 @@ VERSION='9f'
DOWNLOAD_URL="https://www.ijg.org/files/jpegsrc.v9f.tar.gz#04705c110cb2469caa79fb71fba3d7bf834914706e9641a4589485c1f832565b"
TAR_CONTENT="jpeg-$VERSION"
post_install() {
install() {
make install DESTDIR="$BANAN_SYSROOT" || exit 1
# remove libtool files
rm -f $BANAN_SYSROOT/usr/lib/libjpeg.la
}

View File

@ -5,7 +5,9 @@ VERSION='1.6.48'
DOWNLOAD_URL="https://download.sourceforge.net/libpng/libpng-$VERSION.tar.gz#68f3d83a79d81dfcb0a439d62b411aa257bb4973d7c67cd1ff8bdf8d011538cd"
DEPENDENCIES=('zlib')
post_install() {
install() {
make install DESTDIR="$BANAN_SYSROOT" || exit 1
# remove libtool files
rm -f $BANAN_SYSROOT/usr/lib/libpng.la
rm -f $BANAN_SYSROOT/usr/lib/libpng16.la

View File

@ -6,7 +6,9 @@ DOWNLOAD_URL="https://download.osgeo.org/libtiff/tiff-$VERSION.tar.gz#67160e3457
TAR_CONTENT="tiff-$VERSION"
DEPENDENCIES=('zlib' 'zstd' 'libjpeg')
post_install() {
install() {
make install "DESTDIR=$BANAN_SYSROOT" || exit 1
# remove libtool files
rm -f $BANAN_SYSROOT/usr/lib/libtiff.la
rm -f $BANAN_SYSROOT/usr/lib/libtiffxx.la

View File

@ -9,7 +9,9 @@ CONFIGURE_OPTIONS=(
"--with-pnglibdir=$BANAN_SYSROOT/usr/lib"
)
post_install() {
install() {
make install DESTDIR="$BANAN_SYSROOT" || exit 1
# remove libtool files
rm -f $BANAN_SYSROOT/usr/lib/libwebp.la
rm -f $BANAN_SYSROOT/usr/lib/libwebpdemux.la

View File

@ -1,17 +0,0 @@
#!/bin/bash ../install.sh
NAME='lua'
VERSION='5.4.7'
DOWNLOAD_URL="https://www.lua.org/ftp/lua-$VERSION.tar.gz#9fbf5e28ef86c69858f6d3d34eccc32e911c1a28b4120ff3e84aaa70cfbf1e30"
configure() {
make clean
}
build() {
make -j$(nproc) PLAT=posix CC="$CC" LIBS='$(SYSLIBS) $(MYLIBS)' || exit 1
}
install() {
make install PLAT=posix INSTALL_TOP="$BANAN_SYSROOT/usr" || exit 1
}

View File

@ -1,30 +0,0 @@
#!/bin/bash ../install.sh
NAME='mesa'
VERSION='25.0.7'
DOWNLOAD_URL="https://archive.mesa3d.org/mesa-$VERSION.tar.xz#592272df3cf01e85e7db300c449df5061092574d099da275d19e97ef0510f8a6"
DEPENDENCIES=('zlib' 'zstd' 'expat')
CONFIGURE_OPTIONS=(
'-Dprefix=/usr'
'-Dosmesa=true'
'-Dgallium-drivers=softpipe'
'-Dvulkan-drivers=[]'
'-Dplatforms=[]'
'-Dglx=disabled'
'-Dbuildtype=release'
)
configure() {
meson setup --reconfigure --cross-file "$MESON_CROSS_FILE" "${CONFIGURE_OPTIONS[@]}" build || exit 1
}
build() {
meson compile -C build || exit 1
}
install() {
meson install --destdir="$BANAN_SYSROOT" -C build || exit 1
ln -sf osmesa.pc $BANAN_SYSROOT/usr/lib/pkgconfig/opengl.pc
ln -sf libOSMesa.so $BANAN_SYSROOT/usr/lib/libGL.so
}

View File

@ -1,12 +0,0 @@
diff -ruN mesa-25.0.7/src/util/macros.h mesa-25.0.7-banan_os/src/util/macros.h
--- mesa-25.0.7/src/util/macros.h 2025-05-28 18:20:23.000000000 +0300
+++ mesa-25.0.7-banan_os/src/util/macros.h 2025-06-17 13:59:03.341231717 +0300
@@ -25,7 +25,7 @@
#define UTIL_MACROS_H
#include <assert.h>
-#if defined(__HAIKU__) && !defined(__cplusplus)
+#if (defined(__HAIKU__) || defined(__banan_os__)) && !defined(__cplusplus)
#define static_assert _Static_assert
#endif
#include <stddef.h>

View File

@ -1,25 +0,0 @@
diff -ruN mesa-25.0.7/src/util/detect_os.h mesa-25.0.7-banan_os/src/util/detect_os.h
--- mesa-25.0.7/src/util/detect_os.h 2025-05-28 18:20:23.000000000 +0300
+++ mesa-25.0.7-banan_os/src/util/detect_os.h 2025-06-17 14:04:20.625567958 +0300
@@ -76,6 +76,11 @@
#define DETECT_OS_WINDOWS 1
#endif
+#if defined(__banan_os__)
+#define DETECT_OS_BANAN_OS 1
+#define DETECT_OS_POSIX 1
+#endif
+
#if defined(__HAIKU__)
#define DETECT_OS_HAIKU 1
#define DETECT_OS_POSIX 1
@@ -113,6 +118,9 @@
#ifndef DETECT_OS_FREEBSD
#define DETECT_OS_FREEBSD 0
#endif
+#ifndef DETECT_OS_BANAN_OS
+#define DETECT_OS_BANAN_OS 0
+#endif
#ifndef DETECT_OS_HAIKU
#define DETECT_OS_HAIKU 0
#endif

View File

@ -1,34 +0,0 @@
diff -ruN mesa-25.0.7/src/util/os_misc.c mesa-25.0.7-banan_os/src/util/os_misc.c
--- mesa-25.0.7/src/util/os_misc.c 2025-05-28 18:20:23.000000000 +0300
+++ mesa-25.0.7-banan_os/src/util/os_misc.c 2025-06-17 14:14:54.254785327 +0300
@@ -69,6 +69,9 @@
# include <mach/vm_param.h>
# include <mach/vm_statistics.h>
# endif
+#elif DETECT_OS_BANAN_OS
+# include <fcntl.h>
+# include <sys/banan-os.h>
#elif DETECT_OS_HAIKU
# include <kernel/OS.h>
#elif DETECT_OS_WINDOWS
@@ -311,6 +314,20 @@
#endif
return (sysctl(mib, 2, size, &len, NULL, 0) == 0);
+#elif DETECT_OS_BANAN_OS
+ int meminfo_fd = open("/proc/meminfo", O_RDONLY);
+ if (meminfo_fd == -1)
+ return false;
+
+ struct full_meminfo_t meminfo;
+ ssize_t nread = read(meminfo_fd, &meminfo, sizeof(meminfo));
+ close(meminfo_fd);
+
+ if (nread != sizeof(meminfo))
+ return false;
+
+ *size = (meminfo.free_pages + meminfo.used_pages) * meminfo.page_size;
+ return true;
#elif DETECT_OS_HAIKU
system_info info;
status_t ret;

View File

@ -1,14 +0,0 @@
diff -ruN mesa-25.0.7/include/c99_alloca.h mesa-25.0.7-banan_os/include/c99_alloca.h
--- mesa-25.0.7/include/c99_alloca.h 2025-05-28 18:20:23.000000000 +0300
+++ mesa-25.0.7-banan_os/include/c99_alloca.h 2025-06-17 14:29:11.535095878 +0300
@@ -39,6 +39,10 @@
# include <alloca.h>
+#elif defined(__banan_os__)
+
+# define alloca __builtin_alloca
+
#else /* !defined(_MSC_VER) */
# include <stdlib.h>

View File

@ -1,8 +1,8 @@
#!/bin/bash ../install.sh
NAME='mpfr'
VERSION='4.2.2'
DOWNLOAD_URL="https://ftp.gnu.org/gnu/mpfr/mpfr-$VERSION.tar.gz#826cbb24610bd193f36fde172233fb8c009f3f5c2ad99f644d0dea2e16a20e42"
VERSION='4.2.1'
DOWNLOAD_URL="https://ftp.gnu.org/gnu/mpfr/mpfr-$VERSION.tar.gz#116715552bd966c85b417c424db1bbdf639f53836eb361549d1f8d6ded5cb4c6"
DEPENDENCIES=('gmp')
CONFIGURE_OPTIONS=(
"--target=$BANAN_TOOLCHAIN_TRIPLE"

View File

@ -16,7 +16,10 @@ CONFIGURE_OPTIONS=(
'--without-cxx-binding'
)
post_install() {
install() {
make install "DESTDIR=$BANAN_SYSROOT" || exit 1
shellrc="$BANAN_SYSROOT/home/user/.shellrc"
grep -q 'export TERM=' "$shellrc" || echo 'export TERM=ansi' >> "$shellrc"
grep -q 'export NCURSES_NO_UTF8_ACS=' "$shellrc" || echo 'export NCURSES_NO_UTF8_ACS=1' >> "$shellrc"
}

View File

@ -4,8 +4,12 @@ NAME='openssl'
VERSION='3.3.1'
DOWNLOAD_URL="https://github.com/openssl/openssl/releases/download/openssl-$VERSION/openssl-$VERSION.tar.gz#777cd596284c883375a2a7a11bf5d2786fc5413255efab20c50d6ffe6d020b7e"
DEPENDENCIES=('zlib')
MAKE_INSTALL_TARGETS=('install_sw' 'install_ssldirs')
configure() {
./Configure --prefix=/usr --openssldir=/etc/ssl -DOPENSSL_USE_IPV6=0 no-asm no-tests banan_os-generic threads zlib
}
install() {
make install_sw "DESTDIR=$BANAN_SYSROOT" || exit 1
make install_ssldirs "DESTDIR=$BANAN_SYSROOT" || exit 1
}

View File

@ -1,25 +0,0 @@
#!/bin/bash ../install.sh
NAME='sdl12-compat'
VERSION='1.2.68'
DOWNLOAD_URL="https://github.com/libsdl-org/sdl12-compat/archive/refs/tags/release-$VERSION.tar.gz#63c6e4dcc1154299e6f363c872900be7f3dcb3e42b9f8f57e05442ec3d89d02d"
TAR_CONTENT="sdl12-compat-release-$VERSION"
DEPENDENCIES=('SDL2' 'glu')
configure() {
sed -i 's/CMAKE_INSTALL_FULL_DATAROOTDIR/CMAKE_INSTALL_FULL_DATADIR/' CMakeLists.txt
$BANAN_CMAKE \
--toolchain="$CMAKE_TOOLCHAIN_FILE" \
--fresh -GNinja -S . -B build \
-DCMAKE_INSTALL_PREFIX="$BANAN_SYSROOT/usr" \
-DSDL2_INCLUDE_DIR="$BANAN_SYSROOT/usr/include/SDL2"
}
build() {
$BANAN_CMAKE --build build || exit 1
}
install() {
$BANAN_CMAKE --install build || exit 1
}

View File

@ -1,15 +0,0 @@
diff -ruN sdl12-compat-release-1.2.68/src/SDL12_compat.c sdl12-compat-release-1.2.68-banan_os/src/SDL12_compat.c
--- sdl12-compat-release-1.2.68/src/SDL12_compat.c 2023-09-26 20:43:48.000000000 +0300
+++ sdl12-compat-release-1.2.68-banan_os/src/SDL12_compat.c 2025-06-26 03:40:42.751597384 +0300
@@ -1201,7 +1201,11 @@
}
#elif defined(__unix__)
#include <dlfcn.h>
+# if defined(__banan_os__)
+ #define SDL20_LIBNAME "libSDL2.so"
+# else
#define SDL20_LIBNAME "libSDL2-2.0.so.0"
+# endif
#define SDL20_REQUIRED_VER SDL_VERSIONNUM(2,0,7)
static void *Loaded_SDL20 = NULL;
#define LoadSDL20Library() ((Loaded_SDL20 = dlopen(SDL20_LIBNAME, RTLD_LOCAL|RTLD_NOW)) != NULL)

View File

@ -9,9 +9,6 @@ if [ $tcc_arch = 'i686' ]; then
tcc_arch='i386'
fi
MAKE_BUILD_TARGETS=("cross-$tcc_arch $tcc_arch-libtcc1-usegcc=yes")
MAKE_INSTALL_TARGETS=("install-unx")
configure() {
./configure \
--prefix=/usr \
@ -25,6 +22,12 @@ configure() {
--elfinterp=/usr/lib/DynamicLoader.so
}
post_install() {
build() {
touch $BANAN_SYSROOT/usr/include/sys/ucontext.h
make -j$(nproc) cross-$tcc_arch $tcc_arch-libtcc1-usegcc=yes || exit 1
}
install() {
make install-unx DESTDIR=$BANAN_SYSROOT || exit 1
ln -sf $tcc_arch-tcc $BANAN_SYSROOT/usr/bin/tcc
}

View File

@ -1,12 +0,0 @@
diff -ruN tcc-0.9.27/tccrun.c tcc-0.9.27-banan_os/tccrun.c
--- tcc-0.9.27/tccrun.c 2017-12-17 10:27:05.000000000 +0200
+++ tcc-0.9.27-banan_os/tccrun.c 2025-06-28 20:30:00.914206003 +0300
@@ -30,7 +30,7 @@
#ifdef CONFIG_TCC_BACKTRACE
# ifndef _WIN32
# include <signal.h>
-# ifndef __OpenBSD__
+# if !defined(__OpenBSD__) && !defined(__banan_os__)
# include <sys/ucontext.h>
# endif
# else

View File

@ -1,22 +0,0 @@
#!/bin/bash ../install.sh
NAME='tcl'
VERSION='8.6.12'
DOWNLOAD_URL="http://prdownloads.sourceforge.net/tcl/tcl$VERSION-src.tar.gz#26c995dd0f167e48b11961d891ee555f680c175f7173ff8cb829f4ebcde4c1a6"
TAR_CONTENT="tcl$VERSION"
pre_configure() {
pushd unix || exit 1
}
post_configure() {
popd
}
build() {
make -C unix -j$(nproc) all || exit 1
}
install() {
make -C unix install "DESTDIR=$BANAN_SYSROOT" || exit 1
}

View File

@ -1,21 +0,0 @@
diff -ruN tcl8.6.12/unix/tclUnixSock.c tcl8.6.12-banan_os/unix/tclUnixSock.c
--- tcl8.6.12/unix/tclUnixSock.c 2021-10-29 20:08:08.000000000 +0300
+++ tcl8.6.12-banan_os/unix/tclUnixSock.c 2025-06-26 01:23:59.649074073 +0300
@@ -706,6 +706,7 @@
IPv6AddressNeedsNumericRendering(
struct in6_addr addr)
{
+#ifndef __banan_os__
if (IN6_ARE_ADDR_EQUAL(&addr, &in6addr_any)) {
return 1;
}
@@ -721,6 +722,9 @@
return (addr.s6_addr[12] == 0 && addr.s6_addr[13] == 0
&& addr.s6_addr[14] == 0 && addr.s6_addr[15] == 0);
+#else
+ return 0;
+#endif
}
#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
#pragma GCC diagnostic pop

View File

@ -1,19 +0,0 @@
diff -ruN tcl8.6.12/unix/tclUnixCompat.c tcl8.6.12-banan_os/unix/tclUnixCompat.c
--- tcl8.6.12/unix/tclUnixCompat.c 2021-10-29 20:08:08.000000000 +0300
+++ tcl8.6.12-banan_os/unix/tclUnixCompat.c 2025-06-26 01:26:39.033530792 +0300
@@ -702,6 +702,7 @@
len += copied;
p = buf + len;
+#ifndef __banan_os__
/*
* Copy password.
*/
@@ -713,6 +714,7 @@
tgtPtr->gr_passwd = (copied > 0) ? p : NULL;
len += copied;
p = buf + len;
+#endif
/*
* Copy group members.

View File

@ -1,13 +0,0 @@
diff -ruN tcl8.6.12/pkgs/sqlite3.36.0/compat/sqlite3/sqlite3.c tcl8.6.12-banan_os/pkgs/sqlite3.36.0/compat/sqlite3/sqlite3.c
--- tcl8.6.12/pkgs/sqlite3.36.0/compat/sqlite3/sqlite3.c 2021-09-13 01:15:31.000000000 +0300
+++ tcl8.6.12-banan_os/pkgs/sqlite3.36.0/compat/sqlite3/sqlite3.c 2025-06-28 02:27:43.042768624 +0300
@@ -19854,6 +19854,9 @@
#if !defined(alloca) && defined(_WIN32)
# define alloca _alloca
#endif
+#if !defined(alloca) && defined(__banan_os__)
+# include <alloca.h>
+#endif
# define sqlite3StackAllocRaw(D,N) alloca(N)
# define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
# define sqlite3StackFree(D,P)

View File

@ -1,34 +0,0 @@
#!/bin/bash ../install.sh
NAME='tuxracer'
VERSION='0.61'
DOWNLOAD_URL="http://download.sourceforge.net/tuxracer/tuxracer-$VERSION.tar.gz#a311d09080598fe556134d4b9faed7dc0c2ed956ebb10d062e5d4df022f91eff"
DEPENDENCIES=('tcl' 'mesa' 'glu' 'sdl12-compat')
CONFIGURE_OPTIONS=(
'--with-data-dir=/usr/share/tuxracer'
"--with-sdl-prefix=$BANAN_SYSROOT/usr"
'--without-gl-libs'
'--with-tcl-lib-name=tcl8.6'
'--without-x'
)
post_install() {
pushd ..
if [ ! -f "tuxracer-data-$VERSION.tar.gz" ]; then
wget "http://download.sourceforge.net/tuxracer/tuxracer-data-$VERSION.tar.gz" || exit 1
fi
if [ ! -d "tuxracer-data-$VERSION" ]; then
tar xf "tuxracer-data-$VERSION.tar.gz" || exit 1
fi
mkdir -p "$BANAN_SYSROOT/usr/share/tuxracer" || exit 1
cp -r "tuxracer-data-$VERSION"/* "$BANAN_SYSROOT/usr/share/tuxracer/" || exit 1
find "$BANAN_SYSROOT/usr/share/tuxracer" -type f -exec chmod 644 {} +
popd
}
export CFLAGS="-std=c99 -Wno-implicit-int -Wno-incompatible-pointer-types $CFLAGS"
export ac_cv_func_isnan=yes

View File

@ -1,56 +0,0 @@
diff -ruN tuxracer-0.61/src/game_config.c tuxracer-0.61-banan_os/src/game_config.c
--- tuxracer-0.61/src/game_config.c 2001-01-30 22:04:43.000000000 +0200
+++ tuxracer-0.61-banan_os/src/game_config.c 2025-06-26 03:13:06.859798526 +0300
@@ -114,26 +114,26 @@
*/
#define INIT_PARAM( nam, val, typename, commnt ) \
- Params. ## nam ## .loaded = False; \
- Params. ## nam ## .name = #nam; \
- Params. ## nam ## .deflt. ## typename ## _val = val; \
- Params. ## nam ## .comment = commnt;
+ Params.nam.loaded = False; \
+ Params.nam.name = #nam; \
+ Params.nam.deflt.typename ## _val = val; \
+ Params.nam.comment = commnt;
#define INIT_PARAM_STRING( nam, val, commnt ) \
INIT_PARAM( nam, val, string, commnt ); \
- Params. ## nam ## .type = PARAM_STRING;
+ Params.nam.type = PARAM_STRING;
#define INIT_PARAM_CHAR( nam, val, commnt ) \
INIT_PARAM( nam, val, char, commnt ); \
- Params. ## nam ## .type = PARAM_CHAR;
+ Params.nam.type = PARAM_CHAR;
#define INIT_PARAM_INT( nam, val, commnt ) \
INIT_PARAM( nam, val, int, commnt ); \
- Params. ## nam ## .type = PARAM_INT;
+ Params.nam.type = PARAM_INT;
#define INIT_PARAM_BOOL( nam, val, commnt ) \
INIT_PARAM( nam, val, bool, commnt ); \
- Params. ## nam ## .type = PARAM_BOOL;
+ Params.nam.type = PARAM_BOOL;
/*
@@ -310,13 +310,13 @@
*/
#define FN_PARAM( name, typename, type ) \
type getparam_ ## name() { \
- if ( !Params. ## name ## .loaded ) { \
- fetch_param_ ## typename( &( Params. ## name ) ); \
+ if ( !Params.name.loaded ) { \
+ fetch_param_ ## typename( &( Params.name ) ); \
} \
- return Params. ## name ## .val. ## typename ## _val; \
+ return Params.name.val.typename ## _val; \
} \
void setparam_ ## name( type val) { \
- set_param_ ## typename( &( Params. ## name ), val ); }
+ set_param_ ## typename( &( Params.name ), val ); }
#define FN_PARAM_STRING( name ) \
FN_PARAM( name, string, char* )

View File

@ -1,19 +0,0 @@
diff -ruN tuxracer-0.61/src/debug.c tuxracer-0.61-banan_os/src/debug.c
--- tuxracer-0.61/src/debug.c 2001-01-14 00:09:50.000000000 +0200
+++ tuxracer-0.61-banan_os/src/debug.c 2025-06-26 03:18:02.090898960 +0300
@@ -165,6 +165,7 @@
/* Redirect stderr to file; taken from SDL_main.c, which is in the
public domain */
newfp = freopen(BUGREPORT_FILE, "w", stderr);
+#if !defined(__banan_os__)
if ( newfp == NULL ) { /* This happens on NT */
#if !defined(stderr)
stderr = fopen(BUGREPORT_FILE, "w");
@@ -175,6 +176,7 @@
}
#endif
}
+#endif
/* Write bug report header */
fprintf( stderr, "Tux Racer Diagnostic Log\n\n" );

View File

@ -1,12 +0,0 @@
diff -ruN tuxracer-0.61/src/game_config.c tuxracer-0.61-banan_os/src/game_config.c
--- tuxracer-0.61/src/game_config.c 2001-01-30 22:04:43.000000000 +0200
+++ tuxracer-0.61-banan_os/src/game_config.c 2025-06-26 04:03:28.015311092 +0300
@@ -505,7 +505,7 @@
"# decreasing this number, at the cost of lower image quality." );
INIT_PARAM_BOOL(
- fullscreen, True,
+ fullscreen, False,
"# If true then the game will run in full-screen mode." );
INIT_PARAM_INT(

View File

@ -1,15 +0,0 @@
diff -ruN tuxracer-0.61/src/winsys.c tuxracer-0.61-banan_os/src/winsys.c
--- tuxracer-0.61/src/winsys.c 2001-01-14 00:09:51.000000000 +0200
+++ tuxracer-0.61-banan_os/src/winsys.c 2025-06-26 04:05:10.894824478 +0300
@@ -392,6 +392,11 @@
}
break;
+
+ case SDL_QUIT:
+ winsys_exit(0);
+
+ break;
}
SDL_LockAudio();

View File

@ -1,8 +1,9 @@
#!/bin/bash ../install.sh
NAME='vim'
VERSION='9.1.1485'
DOWNLOAD_URL="https://github.com/vim/vim/archive/refs/tags/v$VERSION.tar.gz#89b48e30c9e97bb819ffed752c8a1727b70bed79890bffe9da5f7c2170487dd2"
VERSION='9.0'
DOWNLOAD_URL="ftp://ftp.vim.org/pub/vim/unix/vim-$VERSION.tar.bz2#a6456bc154999d83d0c20d968ac7ba6e7df0d02f3cb6427fb248660bacfb336e"
TAR_CONTENT='vim90'
DEPENDENCIES=('ncurses')
CONFIGURE_OPTIONS=(
'--with-tlib=ncurses'
@ -17,19 +18,9 @@ CONFIGURE_OPTIONS=(
'vim_cv_memmove_handles_overlap=yes'
)
post_configure() {
# vim doesn't do link tests, so it thinks these exists
config_undefines=(
'HAVE_SHM_OPEN'
'HAVE_TIMER_CREATE'
)
install() {
make install "DESTDIR=$BANAN_SYSROOT" || exit 1
for undefine in "${config_undefines[@]}"; do
sed -i "s|^#define $undefine 1$|/\* #undef $undefine \*/|" src/auto/config.h
done
}
post_install() {
shellrc="$BANAN_SYSROOT/home/user/.shellrc"
grep -q 'export EDITOR=' "$shellrc" || echo 'export EDITOR=vim' >> "$shellrc"
}

View File

@ -1,12 +0,0 @@
diff -ruN zlib-1.3.1/configure zlib-1.3.1-banan_os/configure
--- zlib-1.3.1/configure 2024-01-21 04:29:31.000000000 +0200
+++ zlib-1.3.1-banan_os/configure 2025-06-27 23:48:53.039461360 +0300
@@ -236,6 +236,8 @@
*BSD | *bsd* | DragonFly)
LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"}
LDCONFIG="ldconfig -m" ;;
+ *banan_os)
+ LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1"} ;;
CYGWIN* | Cygwin* | cygwin* | *-cygwin* | OS/2*)
EXE='.exe' ;;
MINGW* | mingw* | *-mingw*)

View File

@ -1,7 +1,7 @@
diff -ruN binutils-2.44/bfd/config.bfd binutils-2.44-banan_os/bfd/config.bfd
--- binutils-2.44/bfd/config.bfd 2025-02-02 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/bfd/config.bfd 2025-06-19 11:04:48.871180511 +0300
@@ -612,6 +612,11 @@
diff -ruN binutils-2.39/bfd/config.bfd binutils-2.39-banan_os/bfd/config.bfd
--- binutils-2.39/bfd/config.bfd 2022-07-08 12:46:47.000000000 +0300
+++ binutils-2.39-banan_os/bfd/config.bfd 2024-08-26 15:25:08.612615228 +0300
@@ -602,6 +602,11 @@
targ_defvec=i386_elf32_vec
targ_selvecs=iamcu_elf32_vec
;;
@ -13,7 +13,7 @@ diff -ruN binutils-2.44/bfd/config.bfd binutils-2.44-banan_os/bfd/config.bfd
i[3-7]86-*-dicos*)
targ_defvec=i386_elf32_vec
targ_selvecs=iamcu_elf32_vec
@@ -666,6 +671,11 @@
@@ -656,6 +661,11 @@
targ64_selvecs=x86_64_elf64_vec
;;
#ifdef BFD64
@ -25,21 +25,22 @@ diff -ruN binutils-2.44/bfd/config.bfd binutils-2.44-banan_os/bfd/config.bfd
x86_64-*-cloudabi*)
targ_defvec=x86_64_elf64_cloudabi_vec
want64=true
diff -ruN binutils-2.44/config.sub binutils-2.44-banan_os/config.sub
--- binutils-2.44/config.sub 2025-02-02 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/config.sub 2025-06-19 11:05:16.922967546 +0300
@@ -1976,6 +1976,7 @@
| atheos* \
| auroraux* \
| aux* \
+ | banan_os* \
| beos* \
| bitrig* \
| bme* \
diff -ruN binutils-2.44/gas/configure.tgt binutils-2.44-banan_os/gas/configure.tgt
--- binutils-2.44/gas/configure.tgt 2025-02-02 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/gas/configure.tgt 2025-06-19 11:06:43.781629742 +0300
@@ -225,6 +225,7 @@
diff -ruN binutils-2.39/config.sub binutils-2.39-banan_os/config.sub
--- binutils-2.39/config.sub 2022-07-08 12:46:47.000000000 +0300
+++ binutils-2.39-banan_os/config.sub 2024-08-26 16:01:54.868646232 +0300
@@ -1754,7 +1754,7 @@
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | banan_os* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff -ruN binutils-2.39/gas/configure.tgt binutils-2.39-banan_os/gas/configure.tgt
--- binutils-2.39/gas/configure.tgt 2022-07-08 12:46:47.000000000 +0300
+++ binutils-2.39-banan_os/gas/configure.tgt 2024-08-26 15:29:24.317178187 +0300
@@ -221,6 +221,7 @@
h8300-*-elf) fmt=elf ;;
h8300-*-linux*) fmt=elf em=linux ;;
@ -47,10 +48,10 @@ diff -ruN binutils-2.44/gas/configure.tgt binutils-2.44-banan_os/gas/configure.t
i386-*-beospe*) fmt=coff em=pe ;;
i386-*-beos*) fmt=elf ;;
i386-*-elfiamcu) fmt=elf arch=iamcu ;;
diff -ruN binutils-2.44/ld/configure.tgt binutils-2.44-banan_os/ld/configure.tgt
--- binutils-2.44/ld/configure.tgt 2025-02-02 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/ld/configure.tgt 2025-06-19 11:08:48.725342089 +0300
@@ -367,6 +367,10 @@
diff -ruN binutils-2.39/ld/configure.tgt binutils-2.39-banan_os/ld/configure.tgt
--- binutils-2.39/ld/configure.tgt 2022-07-29 10:37:48.000000000 +0300
+++ binutils-2.39-banan_os/ld/configure.tgt 2024-08-26 15:43:54.040175458 +0300
@@ -352,6 +352,10 @@
i[3-7]86-*-rdos*) targ_emul=elf_i386
targ_extra_emuls=elf_iamcu
;;
@ -61,7 +62,7 @@ diff -ruN binutils-2.44/ld/configure.tgt binutils-2.44-banan_os/ld/configure.tgt
i[3-7]86-*-bsd) targ_emul=i386bsd
targ_extra_ofiles=
;;
@@ -1000,6 +1004,9 @@
@@ -988,6 +992,9 @@
;;
x86_64-*-rdos*) targ_emul=elf64rdos
;;
@ -71,27 +72,27 @@ diff -ruN binutils-2.44/ld/configure.tgt binutils-2.44-banan_os/ld/configure.tgt
x86_64-*-cloudabi*) targ_emul=elf_x86_64_cloudabi
;;
x86_64-*-haiku*) targ_emul=elf_x86_64_haiku
diff -ruN binutils-2.44/ld/emulparams/elf_banan_os.sh binutils-2.44-banan_os/ld/emulparams/elf_banan_os.sh
--- binutils-2.44/ld/emulparams/elf_banan_os.sh 1970-01-01 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/ld/emulparams/elf_banan_os.sh 2025-06-19 11:10:25.877588187 +0300
diff -ruN binutils-2.39/ld/emulparams/elf_banan_os.sh binutils-2.39-banan_os/ld/emulparams/elf_banan_os.sh
--- binutils-2.39/ld/emulparams/elf_banan_os.sh 1970-01-01 02:00:00.000000000 +0200
+++ binutils-2.39-banan_os/ld/emulparams/elf_banan_os.sh 2024-08-26 15:51:32.242246455 +0300
@@ -0,0 +1 @@
+ELF_INTERPRETER_NAME=\"/usr/lib/DynamicLoader.so\"
diff -ruN binutils-2.44/ld/emulparams/elf_i386_banan_os.sh binutils-2.44-banan_os/ld/emulparams/elf_i386_banan_os.sh
--- binutils-2.44/ld/emulparams/elf_i386_banan_os.sh 1970-01-01 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/ld/emulparams/elf_i386_banan_os.sh 2025-06-19 11:10:51.233390738 +0300
diff -ruN binutils-2.39/ld/emulparams/elf_i386_banan_os.sh binutils-2.39-banan_os/ld/emulparams/elf_i386_banan_os.sh
--- binutils-2.39/ld/emulparams/elf_i386_banan_os.sh 1970-01-01 02:00:00.000000000 +0200
+++ binutils-2.39-banan_os/ld/emulparams/elf_i386_banan_os.sh 2024-08-26 15:51:26.431570961 +0300
@@ -0,0 +1,2 @@
+source_sh ${srcdir}/emulparams/elf_i386.sh
+source_sh ${srcdir}/emulparams/elf_banan_os.sh
diff -ruN binutils-2.44/ld/emulparams/elf_x86_64_banan_os.sh binutils-2.44-banan_os/ld/emulparams/elf_x86_64_banan_os.sh
--- binutils-2.44/ld/emulparams/elf_x86_64_banan_os.sh 1970-01-01 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/ld/emulparams/elf_x86_64_banan_os.sh 2025-06-19 11:11:11.664231452 +0300
diff -ruN binutils-2.39/ld/emulparams/elf_x86_64_banan_os.sh binutils-2.39-banan_os/ld/emulparams/elf_x86_64_banan_os.sh
--- binutils-2.39/ld/emulparams/elf_x86_64_banan_os.sh 1970-01-01 02:00:00.000000000 +0200
+++ binutils-2.39-banan_os/ld/emulparams/elf_x86_64_banan_os.sh 2024-08-26 15:51:21.591003274 +0300
@@ -0,0 +1,2 @@
+source_sh ${srcdir}/emulparams/elf_x86_64.sh
+source_sh ${srcdir}/emulparams/elf_banan_os.sh
diff -ruN binutils-2.44/ld/Makefile.am binutils-2.44-banan_os/ld/Makefile.am
--- binutils-2.44/ld/Makefile.am 2025-02-02 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/ld/Makefile.am 2025-06-19 11:12:13.666857368 +0300
@@ -277,6 +277,7 @@
diff -ruN binutils-2.39/ld/Makefile.am binutils-2.39-banan_os/ld/Makefile.am
--- binutils-2.39/ld/Makefile.am 2022-07-08 12:46:48.000000000 +0300
+++ binutils-2.39-banan_os/ld/Makefile.am 2024-08-26 15:46:27.818947949 +0300
@@ -275,6 +275,7 @@
eelf32xtensa.c \
eelf32z80.c \
eelf_i386.c \
@ -99,7 +100,7 @@ diff -ruN binutils-2.44/ld/Makefile.am binutils-2.44-banan_os/ld/Makefile.am
eelf_i386_be.c \
eelf_i386_fbsd.c \
eelf_i386_haiku.c \
@@ -459,6 +460,7 @@
@@ -453,6 +454,7 @@
eelf64tilegx_be.c \
eelf_mipsel_haiku.c \
eelf_x86_64.c \
@ -107,10 +108,10 @@ diff -ruN binutils-2.44/ld/Makefile.am binutils-2.44-banan_os/ld/Makefile.am
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_haiku.c \
diff -ruN binutils-2.44/ld/Makefile.in binutils-2.44-banan_os/ld/Makefile.in
--- binutils-2.44/ld/Makefile.in 2025-02-02 02:00:00.000000000 +0200
+++ binutils-2.44-banan_os/ld/Makefile.in 2025-06-19 11:14:27.198888034 +0300
@@ -788,6 +788,7 @@
diff -ruN binutils-2.39/ld/Makefile.in binutils-2.39-banan_os/ld/Makefile.in
--- binutils-2.39/ld/Makefile.in 2022-08-05 12:56:53.000000000 +0300
+++ binutils-2.39-banan_os/ld/Makefile.in 2024-08-26 15:52:12.046704200 +0300
@@ -772,6 +772,7 @@
eelf32xtensa.c \
eelf32z80.c \
eelf_i386.c \
@ -118,7 +119,7 @@ diff -ruN binutils-2.44/ld/Makefile.in binutils-2.44-banan_os/ld/Makefile.in
eelf_i386_be.c \
eelf_i386_fbsd.c \
eelf_i386_haiku.c \
@@ -969,6 +970,7 @@
@@ -949,6 +950,7 @@
eelf64tilegx_be.c \
eelf_mipsel_haiku.c \
eelf_x86_64.c \
@ -126,7 +127,7 @@ diff -ruN binutils-2.44/ld/Makefile.in binutils-2.44-banan_os/ld/Makefile.in
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_haiku.c \
@@ -1476,6 +1478,7 @@
@@ -1441,6 +1443,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx_be.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386.Po@am__quote@
@ -134,7 +135,7 @@ diff -ruN binutils-2.44/ld/Makefile.in binutils-2.44-banan_os/ld/Makefile.in
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_be.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_haiku.Po@am__quote@
@@ -1486,6 +1489,7 @@
@@ -1451,6 +1454,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_mipsel_haiku.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_s390.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Po@am__quote@

View File

@ -1,11 +1,11 @@
#!/bin/bash
set -e
BINUTILS_VERSION="binutils-2.44"
BINUTILS_VERSION="binutils-2.39"
BINUTILS_TAR="$BINUTILS_VERSION.tar.gz"
BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/$BINUTILS_TAR"
GCC_VERSION="gcc-15.1.0"
GCC_VERSION="gcc-12.2.0"
GCC_TAR="$GCC_VERSION.tar.gz"
GCC_URL="https://ftp.gnu.org/gnu/gcc/$GCC_VERSION/$GCC_TAR"
@ -94,7 +94,7 @@ build_binutils () {
--disable-werror
make $MAKE_JOBS
make install-strip
make install
}
build_gcc () {
@ -131,8 +131,8 @@ build_gcc () {
make $MAKE_JOBS all-gcc
make $MAKE_JOBS all-target-libgcc CFLAGS_FOR_TARGET="$XCFLAGS"
make install-strip-gcc
make install-strip-target-libgcc
make install-gcc
make install-target-libgcc
}
build_libstdcpp () {
@ -143,7 +143,7 @@ build_libstdcpp () {
cd $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build-$BANAN_ARCH
make $MAKE_JOBS all-target-libstdc++-v3
make install-strip-target-libstdc++-v3
make install-target-libstdc++-v3
}
build_grub () {
@ -275,3 +275,5 @@ if (($BUILD_LIBSTDCPP)); then
build_libstdcpp
fi
find "$BANAN_TOOLCHAIN_PREFIX" -type f -executable -exec strip --strip-unneeded {} + 2>/dev/null

189
toolchain/gcc-12.2.0.patch Normal file
View File

@ -0,0 +1,189 @@
diff -ruN gcc-12.2.0/config.sub gcc-12.2.0-banan_os/config.sub
--- gcc-12.2.0/config.sub 2022-08-19 11:09:52.128656687 +0300
+++ gcc-12.2.0-banan_os/config.sub 2024-09-03 23:09:34.347772496 +0300
@@ -1749,7 +1749,7 @@
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | banan_os* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff -ruN gcc-12.2.0/fixincludes/mkfixinc.sh gcc-12.2.0-banan_os/fixincludes/mkfixinc.sh
--- gcc-12.2.0/fixincludes/mkfixinc.sh 2022-08-19 11:09:52.160657095 +0300
+++ gcc-12.2.0-banan_os/fixincludes/mkfixinc.sh 2025-06-03 18:08:13.366965577 +0300
@@ -11,6 +11,7 @@
# Check for special fix rules for particular targets
case $machine in
+ *-*-banan_os* | \
i?86-*-cygwin* | \
i?86-*-mingw32* | \
x86_64-*-mingw32* | \
diff -ruN gcc-12.2.0/gcc/config/banan_os.h gcc-12.2.0-banan_os/gcc/config/banan_os.h
--- gcc-12.2.0/gcc/config/banan_os.h 1970-01-01 02:00:00.000000000 +0200
+++ gcc-12.2.0-banan_os/gcc/config/banan_os.h 2024-09-03 23:09:34.461106020 +0300
@@ -0,0 +1,35 @@
+/* Useful if you wish to make target-specific GCC changes. */
+#undef TARGET_BANAN_OS
+#define TARGET_BANAN_OS 1
+
+/* Default arguments you want when running your
+ *-banan_os-gcc toolchain */
+#undef LIB_SPEC
+#define LIB_SPEC "-lc" /* link against C standard library */
+
+/* Files that are linked before user code.
+ The %s tells GCC to look for these files in the library directory. */
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "%{!shared:crt0.o%s} crti.o%s %{shared|static-pie|!no-pie:crtbeginS.o%s; :crtbegin.o%s}"
+
+/* Files that are linked after user code. */
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "%{shared|static-pie|!no-pie:crtendS.o%s; :crtend.o%s} crtn.o%s"
+
+#undef LINK_SPEC
+#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!shared: %{!static: %{rdynamic:-export-dynamic}}}"
+
+/* We don't have separate math library so don't link it. */
+#undef MATH_LIBRARY
+#define MATH_LIBRARY ""
+
+/* Additional predefined macros. */
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
+ do { \
+ builtin_define ("__banan_os__"); \
+ builtin_define ("__unix__"); \
+ builtin_assert ("system=banan_os"); \
+ builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \
+ } while(0);
diff -ruN gcc-12.2.0/gcc/config.gcc gcc-12.2.0-banan_os/gcc/config.gcc
--- gcc-12.2.0/gcc/config.gcc 2022-08-19 11:09:52.552662114 +0300
+++ gcc-12.2.0-banan_os/gcc/config.gcc 2024-09-03 23:09:34.461106020 +0300
@@ -673,6 +673,13 @@
# Common parts for widely ported systems.
case ${target} in
+*-*-banan_os*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ use_gcc_stdint=provide
+ tmake_file="t-slibgcc"
+ ;;
*-*-darwin*)
tmake_file="t-darwin "
tm_file="${tm_file} darwin.h"
@@ -1870,6 +1876,12 @@
dwarf2=no
fi
;;
+i[34567]86-*-banan_os*)
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h glibc-stdint.h i386/i386elf.h banan_os.h"
+ ;;
+x86_64-*-banan_os*)
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h banan_os.h"
+ ;;
i[34567]86-*-darwin1[89]* | i[34567]86-*-darwin2*)
echo "Error: 32bit target is not supported after Darwin17" 1>&2
;;
diff -ruN gcc-12.2.0/libgcc/config.host gcc-12.2.0-banan_os/libgcc/config.host
--- gcc-12.2.0/libgcc/config.host 2022-08-19 11:09:54.664689148 +0300
+++ gcc-12.2.0-banan_os/libgcc/config.host 2024-09-03 23:09:34.474439376 +0300
@@ -698,6 +698,14 @@
hppa*-*-netbsd*)
tmake_file="$tmake_file pa/t-netbsd"
;;
+i[34567]86-*-banan_os*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic t-slibgcc"
+ ;;
+x86_64-*-banan_os*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic t-slibgcc"
+ ;;
i[34567]86-*-darwin*)
tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi"
tm_file="$tm_file i386/darwin-lib.h"
diff -ruN gcc-12.2.0/libgcc/config/t-slibgcc gcc-12.2.0-banan_os/libgcc/config/t-slibgcc
--- gcc-12.2.0/libgcc/config/t-slibgcc 2022-08-19 11:09:54.724689916 +0300
+++ gcc-12.2.0-banan_os/libgcc/config/t-slibgcc 2024-09-04 23:06:14.275389818 +0300
@@ -26,7 +26,6 @@
SHLIB_OBJS = @shlib_objs@
SHLIB_DIR = @multilib_dir@
SHLIB_SLIBDIR_QUAL = @shlib_slibdir_qual@
-SHLIB_LC = -lc
SHLIB_MAKE_SOLINK = $(LN_S) $(SHLIB_SONAME) $(SHLIB_DIR)/$(SHLIB_SOLINK)
SHLIB_INSTALL_SOLINK = $(LN_S) $(SHLIB_SONAME) \
$(DESTDIR)$(slibdir)$(SHLIB_SLIBDIR_QUAL)/$(SHLIB_SOLINK)
diff -ruN gcc-12.2.0/libstdc++-v3/acinclude.m4 gcc-12.2.0-banan_os/libstdc++-v3/acinclude.m4
--- gcc-12.2.0/libstdc++-v3/acinclude.m4 2022-08-19 11:09:55.380698313 +0300
+++ gcc-12.2.0-banan_os/libstdc++-v3/acinclude.m4 2024-09-03 23:09:34.477772715 +0300
@@ -1380,7 +1380,7 @@
ac_has_nanosleep=yes
ac_has_sched_yield=yes
;;
- openbsd*)
+ openbsd*|banan_os*)
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes
ac_has_nanosleep=yes
diff -ruN gcc-12.2.0/libstdc++-v3/configure gcc-12.2.0-banan_os/libstdc++-v3/configure
--- gcc-12.2.0/libstdc++-v3/configure 2022-08-19 11:09:55.416698774 +0300
+++ gcc-12.2.0-banan_os/libstdc++-v3/configure 2024-09-03 23:09:34.487772732 +0300
@@ -11904,6 +11904,11 @@
lt_cv_dlopen_self=yes
;;
+ banan_os*)
+ lt_cv_dlopen="dlopen"
+ lt_cv_dlopen_libs=
+ ;;
+
mingw* | pw32* | cegcc*)
lt_cv_dlopen="LoadLibrary"
lt_cv_dlopen_libs=
@@ -15603,8 +15608,8 @@
glibcxx_compiler_shared_flag="-D_GLIBCXX_SHARED"
else
- glibcxx_lt_pic_flag=
- glibcxx_compiler_pic_flag=
+ glibcxx_lt_pic_flag="-prefer-pic"
+ glibcxx_compiler_pic_flag="$lt_prog_compiler_pic_CXX"
glibcxx_compiler_shared_flag=
fi
@@ -20575,7 +20580,7 @@
ac_has_nanosleep=yes
ac_has_sched_yield=yes
;;
- openbsd*)
+ openbsd*|banan_os*)
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes
ac_has_nanosleep=yes
@@ -29245,7 +29250,7 @@
# This is a freestanding configuration; there is nothing to do here.
;;
- avr*-*-*)
+ avr*-*-* | *banan_os* )
$as_echo "#define HAVE_ACOSF 1" >>confdefs.h
$as_echo "#define HAVE_ASINF 1" >>confdefs.h
diff -ruN gcc-12.2.0/libstdc++-v3/crossconfig.m4 gcc-12.2.0-banan_os/libstdc++-v3/crossconfig.m4
--- gcc-12.2.0/libstdc++-v3/crossconfig.m4 2022-08-19 11:09:55.420698825 +0300
+++ gcc-12.2.0-banan_os/libstdc++-v3/crossconfig.m4 2024-09-03 23:09:34.531106138 +0300
@@ -9,7 +9,7 @@
# This is a freestanding configuration; there is nothing to do here.
;;
- avr*-*-*)
+ avr*-*-* | *banan_os* )
AC_DEFINE(HAVE_ACOSF)
AC_DEFINE(HAVE_ASINF)
AC_DEFINE(HAVE_ATAN2F)

View File

@ -1,219 +0,0 @@
diff -ruN gcc-15.1.0/config.sub gcc-15.1.0-banan_os/config.sub
--- gcc-15.1.0/config.sub 2025-04-25 11:17:59.000000000 +0300
+++ gcc-15.1.0-banan_os/config.sub 2025-06-19 11:29:44.368548733 +0300
@@ -1749,7 +1749,7 @@
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | banan_os* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff -ruN gcc-15.1.0/fixincludes/mkfixinc.sh gcc-15.1.0-banan_os/fixincludes/mkfixinc.sh
--- gcc-15.1.0/fixincludes/mkfixinc.sh 2025-04-25 11:17:59.000000000 +0300
+++ gcc-15.1.0-banan_os/fixincludes/mkfixinc.sh 2025-06-19 11:30:13.427343038 +0300
@@ -11,6 +11,7 @@
# Check for special fix rules for particular targets
case $machine in
+ *-*-banan_os* | \
i?86-*-cygwin* | \
*-mingw32* | \
powerpc-*-eabisim* | \
diff -ruN gcc-15.1.0/gcc/config/banan_os.h gcc-15.1.0-banan_os/gcc/config/banan_os.h
--- gcc-15.1.0/gcc/config/banan_os.h 1970-01-01 02:00:00.000000000 +0200
+++ gcc-15.1.0-banan_os/gcc/config/banan_os.h 2025-06-19 11:30:53.316059523 +0300
@@ -0,0 +1,35 @@
+/* Useful if you wish to make target-specific GCC changes. */
+#undef TARGET_BANAN_OS
+#define TARGET_BANAN_OS 1
+
+/* Default arguments you want when running your
+ *-banan_os-gcc toolchain */
+#undef LIB_SPEC
+#define LIB_SPEC "-lc" /* link against C standard library */
+
+/* Files that are linked before user code.
+ The %s tells GCC to look for these files in the library directory. */
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "%{!shared:crt0.o%s} crti.o%s %{shared|static-pie|!no-pie:crtbeginS.o%s; :crtbegin.o%s}"
+
+/* Files that are linked after user code. */
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "%{shared|static-pie|!no-pie:crtendS.o%s; :crtend.o%s} crtn.o%s"
+
+#undef LINK_SPEC
+#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!shared: %{!static: %{rdynamic:-export-dynamic}}}"
+
+/* We don't have separate math library so don't link it. */
+#undef MATH_LIBRARY
+#define MATH_LIBRARY ""
+
+/* Additional predefined macros. */
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
+ do { \
+ builtin_define ("__banan_os__"); \
+ builtin_define ("__unix__"); \
+ builtin_assert ("system=banan_os"); \
+ builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \
+ } while(0);
diff -ruN gcc-15.1.0/gcc/config/banan_os.opt gcc-15.1.0-banan_os/gcc/config/banan_os.opt
--- gcc-15.1.0/gcc/config/banan_os.opt 1970-01-01 02:00:00.000000000 +0200
+++ gcc-15.1.0-banan_os/gcc/config/banan_os.opt 2025-06-19 11:31:29.325802503 +0300
@@ -0,0 +1,32 @@
+; banan_os options.
+
+; Copyright (C) 2025 Oskari Alaranta <oskari.alaranta@bananymous.com>
+;
+; This file is part of GCC.
+;
+; GCC is free software; you can redistribute it and/or modify it under
+; the terms of the GNU General Public License as published by the Free
+; Software Foundation; either version 3, or (at your option) any later
+; version.
+;
+; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+; WARRANTY; without even the implied warranty of MERCHANTABILITY or
+; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+; for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with GCC; see the file COPYING3. If not see
+; <http://www.gnu.org/licenses/>.
+
+; See the GCC internals manual (options.texi) for a description of
+; this file's format.
+
+; Please try to keep this file in ASCII collating order.
+
+posix
+Driver
+
+pthread
+Driver
+
+; This comment is to ensure we retain the blank line above.
diff -ruN gcc-15.1.0/gcc/config/banan_os.opt.urls gcc-15.1.0-banan_os/gcc/config/banan_os.opt.urls
--- gcc-15.1.0/gcc/config/banan_os.opt.urls 1970-01-01 02:00:00.000000000 +0200
+++ gcc-15.1.0-banan_os/gcc/config/banan_os.opt.urls 2025-06-19 11:31:29.325802503 +0300
@@ -0,0 +1 @@
+; Not sure what to put here but this works
diff -ruN gcc-15.1.0/gcc/config.gcc gcc-15.1.0-banan_os/gcc/config.gcc
--- gcc-15.1.0/gcc/config.gcc 2025-04-25 11:18:00.000000000 +0300
+++ gcc-15.1.0-banan_os/gcc/config.gcc 2025-06-19 11:32:50.391220522 +0300
@@ -723,6 +723,14 @@
# Common parts for widely ported systems.
case ${target} in
+*-*-banan_os*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ extra_options="${extra_options} banan_os.opt"
+ use_gcc_stdint=provide
+ tmake_file="t-slibgcc"
+ ;;
*-*-darwin*)
tmake_file="t-darwin "
tm_file="${tm_file} darwin.h"
@@ -1972,6 +1980,12 @@
tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h i386/rdos.h i386/rdos64.h"
tmake_file="i386/t-i386elf t-svr4"
;;
+i[34567]86-*-banan_os*)
+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h glibc-stdint.h i386/i386elf.h banan_os.h"
+ ;;
+x86_64-*-banan_os*)
+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h banan_os.h"
+ ;;
i[34567]86-*-dragonfly*)
tm_file="${tm_file} i386/unix.h i386/att.h elfos.h dragonfly.h dragonfly-stdint.h i386/dragonfly.h"
tmake_file="${tmake_file} i386/t-crtstuff"
diff -ruN gcc-15.1.0/libgcc/config/t-slibgcc gcc-15.1.0-banan_os/libgcc/config/t-slibgcc
--- gcc-15.1.0/libgcc/config/t-slibgcc 2025-04-25 11:18:04.000000000 +0300
+++ gcc-15.1.0-banan_os/libgcc/config/t-slibgcc 2025-06-19 11:34:04.674683603 +0300
@@ -26,7 +26,6 @@
SHLIB_OBJS = @shlib_objs@
SHLIB_DIR = @multilib_dir@
SHLIB_SLIBDIR_QUAL = @shlib_slibdir_qual@
-SHLIB_LC = -lc
SHLIB_MAKE_SOLINK = $(LN_S) $(SHLIB_SONAME) $(SHLIB_DIR)/$(SHLIB_SOLINK)
SHLIB_INSTALL_SOLINK = $(LN_S) $(SHLIB_SONAME) \
$(DESTDIR)$(slibdir)$(SHLIB_SLIBDIR_QUAL)/$(SHLIB_SOLINK)
diff -ruN gcc-15.1.0/libgcc/config.host gcc-15.1.0-banan_os/libgcc/config.host
--- gcc-15.1.0/libgcc/config.host 2025-04-25 11:18:04.000000000 +0300
+++ gcc-15.1.0-banan_os/libgcc/config.host 2025-06-19 11:33:42.354845264 +0300
@@ -627,6 +627,14 @@
fixed_point=no
fi
;;
+i[34567]86-*-banan_os*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic t-slibgcc"
+ ;;
+x86_64-*-banan_os*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic t-slibgcc"
+ ;;
bfin*-elf*)
tmake_file="bfin/t-bfin bfin/t-crtlibid bfin/t-crtstuff t-libgcc-pic t-fdpbit"
extra_parts="$extra_parts crtbeginS.o crtendS.o crti.o crtn.o crtlibid.o"
diff -ruN gcc-15.1.0/libstdc++-v3/acinclude.m4 gcc-15.1.0-banan_os/libstdc++-v3/acinclude.m4
--- gcc-15.1.0/libstdc++-v3/acinclude.m4 2025-04-25 11:18:05.000000000 +0300
+++ gcc-15.1.0-banan_os/libstdc++-v3/acinclude.m4 2025-06-19 11:34:58.939289470 +0300
@@ -1792,7 +1792,7 @@
ac_has_nanosleep=yes
ac_has_sched_yield=yes
;;
- freebsd*|netbsd*|dragonfly*|rtems*)
+ freebsd*|netbsd*|dragonfly*|rtems*|banan_os*)
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes
ac_has_nanosleep=yes
diff -ruN gcc-15.1.0/libstdc++-v3/configure gcc-15.1.0-banan_os/libstdc++-v3/configure
--- gcc-15.1.0/libstdc++-v3/configure 2025-04-25 11:18:05.000000000 +0300
+++ gcc-15.1.0-banan_os/libstdc++-v3/configure 2025-06-19 11:37:41.265102481 +0300
@@ -15789,8 +15789,8 @@ if test "$enable_shared" = yes; then
glibcxx_compiler_shared_flag="-D_GLIBCXX_SHARED"
else
- glibcxx_lt_pic_flag=
- glibcxx_compiler_pic_flag=
+ glibcxx_lt_pic_flag="-prefer-pic"
+ glibcxx_compiler_pic_flag="$lt_prog_compiler_pic_CXX"
glibcxx_compiler_shared_flag=
fi
@@ -21377,7 +21377,7 @@
ac_has_nanosleep=yes
ac_has_sched_yield=yes
;;
- freebsd*|netbsd*|dragonfly*|rtems*)
+ freebsd*|netbsd*|dragonfly*|rtems*|banan_os*)
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes
ac_has_nanosleep=yes
@@ -28654,7 +28654,7 @@
# This is a freestanding configuration; there is nothing to do here.
;;
- avr*-*-*)
+ avr*-*-* | *banan_os*)
$as_echo "#define HAVE_ACOSF 1" >>confdefs.h
$as_echo "#define HAVE_ASINF 1" >>confdefs.h
diff -ruN gcc-15.1.0/libstdc++-v3/crossconfig.m4 gcc-15.1.0-banan_os/libstdc++-v3/crossconfig.m4
--- gcc-15.1.0/libstdc++-v3/crossconfig.m4 2025-04-25 11:18:05.000000000 +0300
+++ gcc-15.1.0-banan_os/libstdc++-v3/crossconfig.m4 2025-06-19 11:36:53.954449540 +0300
@@ -9,7 +9,7 @@
# This is a freestanding configuration; there is nothing to do here.
;;
- avr*-*-*)
+ avr*-*-* | *banan_os*)
AC_DEFINE(HAVE_ACOSF)
AC_DEFINE(HAVE_ASINF)
AC_DEFINE(HAVE_ATAN2F)

View File

@ -1,17 +0,0 @@
[host_machine]
system = 'banan_os'
cpu_family = 'ARCH'
cpu = 'ARCH'
endian = 'little'
[binaries]
c = 'ARCH-pc-banan_os-gcc'
cpp = 'ARCH-pc-banan_os-g++'
ar = 'ARCH-pc-banan_os-ar'
ld = 'ARCH-pc-banan_os-ld'
objcopy = 'ARCH-pc-banan_os-objcopy'
strip = 'ARCH-pc-banan_os-strip'
pkgconfig = 'pkg-config'
[properties]
sys_root='SYSROOT'

View File

@ -5,7 +5,6 @@ set(LIBC_SOURCES
ctype.cpp
dirent.cpp
dlfcn.cpp
endian.cpp
environ.cpp
errno.cpp
fcntl.cpp
@ -33,7 +32,6 @@ set(LIBC_SOURCES
strings.cpp
sys/banan-os.cpp
sys/epoll.cpp
sys/file.cpp
sys/ioctl.cpp
sys/mman.cpp
sys/resource.cpp

View File

@ -102,10 +102,3 @@ readdir_do_syscall:
return &dirp->entries[0];
}
void rewinddir(DIR* dirp)
{
dirp->entry_count = 0;
dirp->entry_index = 0;
lseek(dirp->fd, 0, SEEK_SET);
}

View File

@ -1,33 +1,23 @@
#include <BAN/Assert.h>
#include <dlfcn.h>
extern "C" int __dlclose(void*) __attribute__((weak));
int dlclose(void* handle)
int dlclose(void*)
{
if (&__dlclose == nullptr) [[unlikely]]
return -1;
return __dlclose(handle);
ASSERT_NOT_REACHED();
}
extern "C" char* __dlerror() __attribute__((weak));
char* dlerror(void)
{
if (&__dlerror == nullptr) [[unlikely]]
return const_cast<char*>("TODO: dlfcn functions with static linking");
return __dlerror();
ASSERT_NOT_REACHED();
}
extern "C" void* __dlopen(const char*, int) __attribute__((weak));
void* dlopen(const char* file, int mode)
void* dlopen(const char*, int)
{
if (&__dlopen == nullptr) [[unlikely]]
return nullptr;
return __dlopen(file, mode);
ASSERT_NOT_REACHED();
}
extern "C" void* __dlsym(void*, const char*) __attribute__((weak));
void* dlsym(void* __restrict handle, const char* __restrict name)
void* dlsym(void* __restrict, const char* __restrict)
{
if (&__dlsym == nullptr) [[unlikely]]
return nullptr;
return __dlsym(handle, name);
ASSERT_NOT_REACHED();
}

View File

@ -1,31 +0,0 @@
#include <BAN/Endianness.h>
#include <endian.h>
#define BE_TO_H(size) \
uint##size##_t be##size##toh(uint##size##_t x) { return BAN::big_endian_to_host(x); }
BE_TO_H(16)
BE_TO_H(32)
BE_TO_H(64)
#undef BE_TO_H
#define H_TO_BE(size) \
uint##size##_t htobe##size(uint##size##_t x) { return BAN::host_to_big_endian(x); }
H_TO_BE(16)
H_TO_BE(32)
H_TO_BE(64)
#undef H_TO_BE
#define LE_TO_H(size) \
uint##size##_t le##size##toh(uint##size##_t x) { return BAN::little_endian_to_host(x); }
LE_TO_H(16)
LE_TO_H(32)
LE_TO_H(64)
#undef LE_TO_H
#define H_TO_LE(size) \
uint##size##_t htole##size(uint##size##_t x) { return BAN::host_to_little_endian(x); }
H_TO_LE(16)
H_TO_LE(32)
H_TO_LE(64)
#undef H_TO_LE

View File

@ -71,18 +71,18 @@ static int putenv_impl(char* string, bool malloced)
free(environ[i]);
if (malloced)
s_environ_bitmap[byte] |= mask;
s_environ_bitmap[i / 8] |= mask;
else
s_environ_bitmap[byte] &= ~mask;
s_environ_bitmap[i / 8] &= ~mask;
environ[i] = string;
return 0;
}
}
if (s_environ_count % 8 == 0)
if ((s_environ_count + 1) % 8 == 0)
{
const size_t bytes = s_environ_count / 8 + 1;
const size_t bytes = (s_environ_count + 1) / 8;
void* new_bitmap = realloc(s_environ_bitmap, bytes);
if (new_bitmap == nullptr)

View File

@ -1,14 +0,0 @@
#ifndef _ALLOCA_H
#define _ALLOCA_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdio.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define alloca __builtin_alloca
__END_DECLS
#endif

View File

@ -1,41 +0,0 @@
#ifndef _ENDIAN_H
#define _ENDIAN_H 1
// https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/endian.h.html
#include <sys/cdefs.h>
#include <stdint.h>
#define LITTLE_ENDIAN 0
#define BIG_ENDIAN 1
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define BYTE_ORDER BIG_ENDIAN
#endif
__BEGIN_DECLS
uint16_t be16toh(uint16_t);
uint32_t be32toh(uint32_t);
uint64_t be64toh(uint64_t);
uint16_t htobe16(uint16_t);
uint32_t htobe32(uint32_t);
uint64_t htobe64(uint64_t);
uint16_t htole16(uint16_t);
uint32_t htole32(uint32_t);
uint64_t htole64(uint64_t);
uint16_t le16toh(uint16_t);
uint32_t le32toh(uint32_t);
uint64_t le64toh(uint64_t);
__END_DECLS
#endif

View File

@ -99,7 +99,6 @@ void endservent(void);
void freeaddrinfo(struct addrinfo* ai);
const char* gai_strerror(int ecode);
int getaddrinfo(const char* __restrict nodename, const char* __restrict servname, const struct addrinfo* __restrict hints, struct addrinfo** __restrict res);
struct hostent* gethostbyaddr(const void* addr, socklen_t size, int type);
struct hostent* gethostbyname(const char* name);
struct hostent* gethostent(void);
int getnameinfo(const struct sockaddr* __restrict sa, socklen_t salen, char* __restrict node, socklen_t nodelen, char* __restrict service, socklen_t servicelen, int flags);

View File

@ -56,7 +56,6 @@ extern FILE* __stderr;
extern FILE* __stddbg;
#define stddbg __stddbg
int asprintf(char** __restrict ptr, const char* __restrict format, ...);
void clearerr(FILE* stream);
char* ctermid(char* s);
int dprintf(int fildes, const char* __restrict format, ...);
@ -117,7 +116,6 @@ char* tempnam(const char* dir, const char* pfx);
FILE* tmpfile(void);
char* tmpnam(char* s);
int ungetc(int c, FILE* stream);
int vasprintf(char** __restrict ptr, const char* __restrict format, va_list ap);
int vdprintf(int fildes, const char* __restrict format, va_list ap);
int vfprintf(FILE* __restrict stream, const char* __restrict format, va_list ap);
int vfscanf(FILE* __restrict stream, const char* __restrict format, va_list arg);

View File

@ -18,7 +18,7 @@ __BEGIN_DECLS
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
#define RAND_MAX INT_MAX
#define RAND_MAX INT32_MAX
#define MB_CUR_MAX ((size_t)4)

View File

@ -10,10 +10,6 @@ __BEGIN_DECLS
#include <stddef.h>
#include <bits/types/locale_t.h>
// NOTE: A lot of software seems to assume strcasecmp is defined here,
// so let's just include it
#include <strings.h>
void* memccpy(void* __restrict s1, const void* __restrict s2, int c, size_t n);
void* memchr(const void* s, int c, size_t n);
int memcmp(const void* s1, const void* s2, size_t n);

View File

@ -18,11 +18,6 @@ int strcasecmp_l(const char* s1, const char* s2, locale_t locale);
int strncasecmp(const char* s1, const char* s2, size_t n);
int strncasecmp_l(const char* s1, const char* s2, size_t n, locale_t locale);
// deprecated
int bcmp(const void* s1, const void* s2, size_t n);
void bcopy(const void* src, void* dest, size_t n);
void bzero(void* s, size_t n);
__END_DECLS
#endif

View File

@ -1,17 +0,0 @@
#ifndef _SYS_FILE_H
#define _SYS_FILE_H 1
#include <sys/cdefs.h>
__BEGIN_DECLS
#define LOCK_UN 0
#define LOCK_EX 1
#define LOCK_SH 2
#define LOCK_NB 4
int flock(int fd, int op);
__END_DECLS
#endif

View File

@ -41,8 +41,6 @@ struct winsize
{
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel; /* unused by kernel */
unsigned short ws_ypixel; /* unused by kernel */
};
#define TIOCGWINSZ 50
#define TIOCSWINSZ 51

View File

@ -107,7 +107,6 @@ __BEGIN_DECLS
O(SYS_EPOLL_CREATE1, epoll_create1) \
O(SYS_EPOLL_CTL, epoll_ctl) \
O(SYS_EPOLL_PWAIT2, epoll_pwait2) \
O(SYS_FLOCK, flock) \
enum Syscall
{

View File

@ -96,6 +96,12 @@ static bool allocate_pool(size_t pool_index)
node->prev_free = nullptr;
node->next_free = nullptr;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wstringop-overflow"
node->data[-1] = 0;
#pragma GCC diagnostic pop
pool.free_list = node;
return true;
@ -138,14 +144,18 @@ static void shrink_node_if_needed(malloc_pool_t& pool, malloc_node_t* node, size
uint8_t* node_end = (uint8_t*)node->next();
node->size = sizeof(malloc_node_t) + size;
if (auto rem = (node->size + sizeof(malloc_node_t)) % s_malloc_default_align)
node->size += s_malloc_default_align - rem;
auto* next = node->next();
next->allocated = false;
next->size = node_end - (uint8_t*)next;
next->last = node->last;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wstringop-overflow"
next->data[-1] = 0;
#pragma GCC diagnostic pop
node->last = false;
// insert excess node to free list
@ -178,8 +188,6 @@ static void* allocate_from_pool(size_t pool_index, size_t size)
remove_node_from_pool_free_list(pool, node);
shrink_node_if_needed(pool, node, size);
assert(((uintptr_t)node->data & (s_malloc_default_align - 1)) == 0);
return node->data;
}
@ -188,6 +196,29 @@ static void* allocate_from_pool(size_t pool_index, size_t size)
static malloc_node_t* node_from_data_pointer(void* data_pointer)
{
if (((uint8_t*)data_pointer)[-1])
{
malloc_pool_t* pool = nullptr;
for (size_t i = 0; i < s_malloc_pool_count; i++)
{
if (!s_malloc_pools[i].start)
continue;
if (data_pointer < s_malloc_pools[i].start)
continue;
if (data_pointer > s_malloc_pools[i].end())
continue;
pool = &s_malloc_pools[i];
break;
}
assert(pool);
auto* node = (malloc_node_t*)pool->start;
for (; (uint8_t*)node < pool->end(); node = node->next())
if (node->data < data_pointer && data_pointer < node->next())
return node;
assert(false);
}
return (malloc_node_t*)((uint8_t*)data_pointer - sizeof(malloc_node_t));
}
@ -348,53 +379,16 @@ int posix_memalign(void** memptr, size_t alignment, size_t size)
return -1;
}
if (alignment < s_malloc_default_align)
alignment = s_malloc_default_align;
void* unaligned = malloc(size + alignment + sizeof(malloc_node_t));
uint8_t* unaligned = (uint8_t*)malloc(size + alignment);
if (unaligned == nullptr)
return -1;
pthread_mutex_lock(&s_malloc_mutex);
auto* node = node_from_data_pointer(unaligned);
auto& pool = pool_from_node(node);
// NOTE: gcc does not like accessing the node from pointer returned by malloc
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
if (reinterpret_cast<uintptr_t>(unaligned) % alignment)
if (auto rem = (uintptr_t)unaligned % alignment)
{
uintptr_t curr_data_address = reinterpret_cast<uintptr_t>(unaligned);
uintptr_t next_data_address = curr_data_address + sizeof(malloc_node_t);
if (auto rem = next_data_address % alignment)
next_data_address += alignment - rem;
auto* next = node_from_data_pointer(reinterpret_cast<void*>(next_data_address));
next->size = reinterpret_cast<uintptr_t>(node->next()) - reinterpret_cast<uintptr_t>(next);
next->allocated = true;
assert(next->data_size() >= size);
node->size = reinterpret_cast<uintptr_t>(next) - reinterpret_cast<uintptr_t>(node);
node->allocated = false;
// add node to free list
if (pool.free_list)
pool.free_list->prev_free = node;
node->prev_free = nullptr;
node->next_free = pool.free_list;
pool.free_list = node;
node = next;
unaligned += alignment - rem;
unaligned[-1] = 1;
}
#pragma GCC diagnostic pop
shrink_node_if_needed(pool, node, size);
pthread_mutex_unlock(&s_malloc_mutex);
assert(((uintptr_t)node->data & (alignment - 1)) == 0);
*memptr = node->data;
*memptr = unaligned;
return 0;
}

View File

@ -182,77 +182,6 @@ int getnameinfo(const struct sockaddr* __restrict sa, socklen_t salen, char* __r
return 0;
}
struct hostent* gethostbyaddr(const void* addr, socklen_t size, int type)
{
static char* addr_ptrs[2];
static struct hostent hostent;
if (hostent.h_name != nullptr)
free(hostent.h_name);
switch (type)
{
case AF_INET:
{
if (size < static_cast<socklen_t>(sizeof(in_addr)))
return nullptr;
hostent.h_name = static_cast<char*>(malloc(INET_ADDRSTRLEN));
if (hostent.h_name == nullptr)
return nullptr;
const auto* in_addr = static_cast<const ::in_addr*>(addr);
if (!inet_ntop(AF_INET, &in_addr->s_addr, hostent.h_name, INET_ADDRSTRLEN))
return nullptr;
hostent.h_aliases = nullptr;
hostent.h_addrtype = AF_INET;
hostent.h_length = sizeof(::in_addr);
static char in_addr_buffer[sizeof(::in_addr::s_addr)];
memcpy(in_addr_buffer, &in_addr->s_addr, sizeof(::in_addr::s_addr));
addr_ptrs[0] = in_addr_buffer;
addr_ptrs[1] = nullptr;
hostent.h_addr_list = addr_ptrs;
break;
}
case AF_INET6:
{
if (size < static_cast<socklen_t>(sizeof(in6_addr)))
return nullptr;
hostent.h_name = static_cast<char*>(malloc(INET6_ADDRSTRLEN));
if (hostent.h_name == nullptr)
return nullptr;
const auto* in6_addr = static_cast<const ::in6_addr*>(addr);
if (!inet_ntop(AF_INET6, &in6_addr->s6_addr, hostent.h_name, INET6_ADDRSTRLEN))
return nullptr;
hostent.h_aliases = nullptr;
hostent.h_addrtype = AF_INET6;
hostent.h_length = sizeof(::in6_addr::s6_addr);
static char in6_addr_buffer[sizeof(::in6_addr::s6_addr)];
memcpy(in6_addr_buffer, &in6_addr->s6_addr, sizeof(::in6_addr::s6_addr));
addr_ptrs[0] = in6_addr_buffer;
addr_ptrs[1] = nullptr;
hostent.h_addr_list = addr_ptrs;
break;
}
default:
return nullptr;
}
return &hostent;
}
struct hostent* gethostbyname(const char* name)
{
static char name_buffer[HOST_NAME_MAX + 1];

View File

@ -628,24 +628,6 @@ void pthread_testcancel(void)
pthread_exit(PTHREAD_CANCELED);
}
int pthread_getschedparam(pthread_t thread, int* __restrict policy, struct sched_param* __restrict param)
{
(void)thread;
(void)policy;
(void)param;
dwarnln("TODO: pthread_getschedparam");
return ENOTSUP;
}
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param* param)
{
(void)thread;
(void)policy;
(void)param;
dwarnln("TODO: pthread_setschedparam");
return ENOTSUP;
}
int pthread_spin_destroy(pthread_spinlock_t* lock)
{
(void)lock;
@ -666,11 +648,7 @@ int pthread_spin_lock(pthread_spinlock_t* lock)
pthread_t expected = 0;
while (!BAN::atomic_compare_exchange(*lock, expected, tid, BAN::MemoryOrder::memory_order_acquire))
{
__builtin_ia32_pause();
expected = 0;
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show More