Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix vm::try_alloc regression #10857

Merged
merged 3 commits into from Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp
Expand Up @@ -95,16 +95,16 @@ error_code console_getc()
return CELL_OK;
}

void console_putc(char ch)
void console_putc(ppu_thread& ppu, char ch)
{
sysPrxForUser.trace("console_putc(ch=0x%x)", ch);
sys_tty_write(0, vm::var<char>(ch), 1, vm::var<u32>{});
sys_tty_write(ppu, 0, vm::var<char>(ch), 1, vm::var<u32>{});
}

error_code console_write(vm::ptr<char> data, u32 len)
error_code console_write(ppu_thread& ppu, vm::ptr<char> data, u32 len)
{
sysPrxForUser.trace("console_write(data=*0x%x, len=%d)", data, len);
sys_tty_write(0, data, len, vm::var<u32>{});
sys_tty_write(ppu, 0, data, len, vm::var<u32>{});
return CELL_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/sys_libc_.cpp
Expand Up @@ -416,7 +416,7 @@ error_code _sys_printf(ppu_thread& ppu, vm::cptr<char> fmt, ppu_va_args_t va_arg

const auto buf = vm::make_str(ps3_fmt(ppu, fmt, va_args.count));

sys_tty_write(0, buf, buf.get_count() - 1, vm::var<u32>{});
sys_tty_write(ppu, 0, buf, buf.get_count() - 1, vm::var<u32>{});

return CELL_OK;
}
Expand Down
12 changes: 6 additions & 6 deletions rpcs3/Emu/Cell/lv2/sys_fs.cpp
Expand Up @@ -727,21 +727,19 @@ error_code sys_fs_close(ppu_thread& ppu, u32 fd)
ppu.state += cpu_flag::wait;
lv2_obj::sleep(ppu);

sys_fs.trace("sys_fs_close(fd=%d)", fd);

const auto file = idm::get<lv2_fs_object, lv2_file>(fd);

if (!file)
{
return CELL_EBADF;
return {CELL_EBADF, fd};
}

{
std::lock_guard lock(file->mp->mutex);

if (!file->file)
{
return CELL_EBADF;
return {CELL_EBADF, fd};
}

if (!(file->mp->flags & (lv2_mp_flag::read_only + lv2_mp_flag::cache)) && file->flags & CELL_FS_O_ACCMODE)
Expand Down Expand Up @@ -772,12 +770,14 @@ error_code sys_fs_close(ppu_thread& ppu, u32 fd)

if (!ret || ret.ret == CELL_EBADF)
{
return CELL_EBADF;
return {CELL_EBADF, fd};
}

sys_fs.warning("sys_fs_close(fd=%u): path='%s'", fd, file->name.data());

if (file->lock == 1)
{
return CELL_EBUSY;
return {CELL_EBUSY, fd};
}

return CELL_OK;
Expand Down
17 changes: 16 additions & 1 deletion rpcs3/Emu/Cell/lv2/sys_tty.cpp
@@ -1,5 +1,7 @@
#include "stdafx.h"
#include "Emu/system_config.h"
#include "Emu/Cell/PPUThread.h"
#include "Emu/Cell/timers.hpp"

#include "sys_tty.h"

Expand Down Expand Up @@ -86,7 +88,7 @@ error_code sys_tty_read(s32 ch, vm::ptr<char> buf, u32 len, vm::ptr<u32> preadle
return CELL_OK;
}

error_code sys_tty_write(s32 ch, vm::cptr<char> buf, u32 len, vm::ptr<u32> pwritelen)
error_code sys_tty_write(ppu_thread& ppu, s32 ch, vm::cptr<char> buf, u32 len, vm::ptr<u32> pwritelen)
{
sys_tty.notice("sys_tty_write(ch=%d, buf=*0x%x, len=%d, pwritelen=*0x%x)", ch, buf, len, pwritelen);

Expand All @@ -102,6 +104,19 @@ error_code sys_tty_write(s32 ch, vm::cptr<char> buf, u32 len, vm::ptr<u32> pwrit
}
}

if (msg.find("abort"sv) != umax || msg.find("error"sv) != umax || [&]()
{
static atomic_t<u64> last_write = 0;

// Dump thread about every period which TTY was not being touched for about half a second
const u64 current = get_system_time();
return current - last_write.exchange(current) >= 500'000;
}())
{
std::string dump_useful_thread_info();
ppu_log.notice("\n%s", dump_useful_thread_info());
}

// Hack: write to tty even on CEX mode, but disable all error checks
if (ch < 0 || ch > 15)
{
Expand Down
4 changes: 3 additions & 1 deletion rpcs3/Emu/Cell/lv2/sys_tty.h
Expand Up @@ -25,6 +25,8 @@ enum
SYS_TTYP_USER13 = 15,
};

class ppu_thread;

// SysCalls
error_code sys_tty_read(s32 ch, vm::ptr<char> buf, u32 len, vm::ptr<u32> preadlen);
error_code sys_tty_write(s32 ch, vm::cptr<char> buf, u32 len, vm::ptr<u32> pwritelen);
error_code sys_tty_write(ppu_thread& ppu, s32 ch, vm::cptr<char> buf, u32 len, vm::ptr<u32> pwritelen);
4 changes: 2 additions & 2 deletions rpcs3/Emu/Memory/vm.cpp
Expand Up @@ -1083,11 +1083,11 @@ namespace vm
flags |= page_executable;
}

if ((flags & page_size_mask) == page_size_64k)
if ((bflags & page_size_mask) == page_size_64k)
{
flags |= page_64k_size;
}
else if (!(flags & (page_size_mask & ~page_size_1m)))
else if (!(bflags & (page_size_mask & ~page_size_1m)))
{
flags |= page_1m_size;
}
Expand Down