Compare commits

...

3 Commits

Author SHA1 Message Date
Bananymous fe94d6cf89 LibC: Implement dummy rename() so vim can save files
vim calls rename when saving a file. This patch adds dummy
implementation that only works for regular files and does a copy instead
of proper rename.
2024-08-05 20:16:05 +03:00
Bananymous 0a7c316ffb Kernel: Fix race condition when blocking threads
If thread was blocked, but had not reached block queue, you might
already get an unblock request which would fail on an assertion.

If blocked thread was load balanced to another processor and unblocked
simultaneously, there was a race condition.
2024-08-05 20:14:13 +03:00
Bananymous e72424e01a Kernel: Implement ANSI CSI M and fix ANSI CSI L
There are not maybe not correct, but work much better than the old ones
2024-08-05 15:53:01 +03:00
3 changed files with 79 additions and 15 deletions

View File

@ -330,11 +330,13 @@ namespace Kernel
{
if (!node->blocked)
return;
m_block_queue.remove_node(node);
if (node != m_current)
m_block_queue.remove_node(node);
if (node->blocker)
node->blocker->remove_blocked_thread(node);
node->blocked = false;
m_run_queue.add_thread_to_back(node);
if (node != m_current)
m_run_queue.add_thread_to_back(node);
}
else
{
@ -467,6 +469,9 @@ namespace Kernel
break;
if (thread_info.node == m_current || thread_info.queue == nullptr)
continue;
// FIXME: allow load balancing with blocked threads, with this algorithm there is a race condition
if (thread_info.node->blocked)
continue;
auto least_loaded_id = find_least_loaded_processor();
if (least_loaded_id == Processor::current_id())

View File

@ -245,19 +245,34 @@ namespace Kernel
case 'L': // Insert Line
if (m_ansi_state.nums[0] == -1)
m_ansi_state.nums[0] = 1;
for (uint32_t y_off = 0; y_off < (uint32_t)m_ansi_state.nums[0]; y_off++)
for (uint32_t row = m_height; row > m_row; row--)
{
const uint32_t src_y = m_row + y_off;
const uint32_t dst_y = src_y + m_ansi_state.nums[0];
if (dst_y < m_height)
{
memcpy(&m_buffer[dst_y * m_width], &m_buffer[src_y * m_width], m_width * sizeof(Cell));
for (uint32_t x = 0; x < m_width; x++)
render_from_buffer(x, dst_y);
}
const uint32_t dst_y = row - 1;
const uint32_t src_y = dst_y - m_ansi_state.nums[0];
memcpy(&m_buffer[dst_y * m_width], &m_buffer[src_y * m_width], m_width * sizeof(Cell));
for (uint32_t x = 0; x < m_width; x++)
putchar_at(' ', x, src_y);
render_from_buffer(x, dst_y);
}
for (uint32_t y_off = 0; y_off < (uint32_t)m_ansi_state.nums[0] && m_row + y_off < m_height; y_off++)
for (uint32_t x = 0; x < m_width; x++)
putchar_at(' ', x, m_row + y_off);
return reset_ansi();
case 'M':
if (m_ansi_state.nums[0] == -1)
m_ansi_state.nums[0] = 1;
if (m_row + m_ansi_state.nums[0] >= m_height)
m_ansi_state.nums[0] = m_height - m_row - 1;
for (uint32_t row = m_row; row < m_height; row++)
{
const uint32_t dst_y = row;
const uint32_t src_y = dst_y + m_ansi_state.nums[0];
memcpy(&m_buffer[dst_y * m_width], &m_buffer[src_y * m_width], m_width * sizeof(Cell));
for (uint32_t x = 0; x < m_width; x++)
render_from_buffer(x, dst_y);
}
for (uint32_t y_off = 0; y_off < (uint32_t)m_ansi_state.nums[0]; y_off++)
for (uint32_t x = 0; x < m_width; x++)
putchar_at(' ', x, m_height - y_off - 1);
return reset_ansi();
case 'S': // Scroll Up
dprintln("Unsupported ANSI CSI character S");

View File

@ -604,11 +604,55 @@ int remove(const char* path)
return unlink(path);
}
// TODO
int rename(const char* old, const char* _new)
{
dwarnln("rename({}, {})", old, _new);
ASSERT_NOT_REACHED();
struct stat st;
if (lstat(old, &st) == -1)
return -1;
if (!S_ISREG(st.st_mode))
{
errno = ENOTSUP;
return -1;
}
if (unlink(_new) == -1 && errno != ENOENT)
return -1;
int old_fd = open(old, O_RDWR);
int new_fd = open(_new, O_RDWR | O_CREAT | O_EXCL, st.st_mode);
if (old_fd == -1 || new_fd == -1)
goto error;
for (;;)
{
char buffer[512];
ssize_t nread = read(old_fd, buffer, sizeof(buffer));
if (nread == -1)
{
unlink(_new);
goto error;
}
if (nread == 0)
break;
if (write(new_fd, buffer, nread) != nread)
{
unlink(_new);
goto error;
}
}
unlink(old);
return 0;
error:
if (old_fd != -1)
close(old_fd);
if (new_fd != -1)
close(new_fd);
return -1;
}
void rewind(FILE* file)