1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +00:00

Userland: Fix 64-bit portability issues

This commit is contained in:
Gunnar Beutner 2021-05-02 00:00:52 +02:00 committed by Andreas Kling
parent fdbe66a7b4
commit b613817bca
15 changed files with 59 additions and 30 deletions

View file

@ -360,13 +360,13 @@ void ChessWidget::set_piece_set(const StringView& set)
Chess::Square ChessWidget::mouse_to_square(GUI::MouseEvent& event) const
{
size_t tile_width = width() / 8;
size_t tile_height = height() / 8;
unsigned tile_width = width() / 8;
unsigned tile_height = height() / 8;
if (side() == Chess::Color::White) {
return { 7 - (event.y() / tile_height), event.x() / tile_width };
return { (unsigned)(7 - (event.y() / tile_height)), (unsigned)(event.x() / tile_width) };
} else {
return { event.y() / tile_height, 7 - (event.x() / tile_width) };
return { (unsigned)(event.y() / tile_height), (unsigned)(7 - (event.x() / tile_width)) };
}
}

View file

@ -18,23 +18,40 @@ __BEGIN_DECLS
#define PRIi8 "d"
#define PRIi16 "d"
#define PRIi32 "d"
#ifndef __LP64__
# define PRIi64 "lld"
#else
# define PRIi64 "ld"
#endif
#define PRIu8 "u"
#define PRIo8 "o"
#define PRIo16 "o"
#define PRIo32 "o"
#ifndef __LP64__
# define PRIo64 "llo"
#else
# define PRIo64 "lo"
#endif
#define PRIu16 "u"
#define PRIu32 "u"
#ifndef __LP64__
# define PRIu64 "llu"
#else
# define PRIu64 "lu"
#endif
#define PRIx8 "b"
#define PRIX8 "hhX"
#define PRIx16 "w"
#define PRIX16 "hX"
#define PRIx32 "x"
#define PRIX32 "X"
#ifndef __LP64__
# define PRIx64 "llx"
# define PRIX64 "llX"
#else
# define PRIx64 "lx"
# define PRIX64 "lX"
#endif
#define __PRI64_PREFIX "ll"
#define __PRIPTR_PREFIX

View file

@ -259,7 +259,7 @@ void DebugSession::run(DesiredInitialDebugeeState initial_debugee_state, Callbac
Optional<BreakPoint> current_breakpoint;
if (state == State::FreeRun || state == State::Syscall) {
current_breakpoint = m_breakpoints.get((void*)((u32)regs.eip - 1));
current_breakpoint = m_breakpoints.get((void*)((uintptr_t)regs.eip - 1));
if (current_breakpoint.has_value())
state = State::FreeRun;
} else {

View file

@ -17,6 +17,7 @@
#include <LibCore/FileStream.h>
#include <LibCore/MimeData.h>
#include <LibHTTP/HttpRequest.h>
#include <inttypes.h>
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
@ -220,7 +221,7 @@ void Client::handle_directory_listing(const String& requested_path, const String
builder.append(escape_html_entities(name));
builder.append("</a></td><td>&nbsp;</td>");
builder.appendf("<td>%10lld</td><td>&nbsp;</td>", st.st_size);
builder.appendf("<td>%10" PRIi64 "</td><td>&nbsp;</td>", st.st_size);
builder.append("<td>");
builder.append(Core::DateTime::from_timestamp(st.st_mtime).to_string());
builder.append("</td>");

View file

@ -53,7 +53,7 @@ int main()
uintptr_t g_processes = *(uintptr_t*)&base[0x1b51c4];
printf("base = %p\n", base);
printf("g_processes = %#08x\n", g_processes);
printf("g_processes = %p\n", (void*)g_processes);
auto get_ptr = [&](uintptr_t value) -> void* {
value -= 0xc0000000;
@ -80,7 +80,7 @@ int main()
Process* process = (Process*)get_ptr(process_list->head);
printf("{%p} PID: %d, UID: %d, next: %#08x\n", process, process->pid, process->uid, process->next);
printf("{%p} PID: %d, UID: %d, next: %p\n", process, process->pid, process->uid, (void*)process->next);
if (process->pid == getpid()) {
printf("That's me! Let's become r00t!\n");

View file

@ -88,7 +88,7 @@ int main()
strcpy(shstrtab, ".strtab");
auto* code = &buffer[8192];
size_t haxcode_size = (u32)haxcode_end - (u32)haxcode;
size_t haxcode_size = (uintptr_t)haxcode_end - (uintptr_t)haxcode;
printf("memcpy(%p, %p, %zu)\n", code, haxcode, haxcode_size);
memcpy(code, (void*)haxcode, haxcode_size);
@ -100,7 +100,7 @@ int main()
return 1;
}
int nwritten = write(fd, buffer, sizeof(buffer));
auto nwritten = write(fd, buffer, sizeof(buffer));
if (nwritten < 0) {
perror("write");
return 1;

View file

@ -21,18 +21,18 @@ bool verify_block(int fd, int seed, off_t block, AK::ByteBuffer& buffer)
auto offset = block * buffer.size();
auto rs = lseek(fd, offset, SEEK_SET);
if (rs < 0) {
fprintf(stderr, "Couldn't seek to block %lld (offset %lld) while verifying: %s\n", block, offset, strerror(errno));
fprintf(stderr, "Couldn't seek to block %" PRIi64 " (offset %" PRIi64 ") while verifying: %s\n", block, offset, strerror(errno));
return false;
}
auto rw = read(fd, buffer.data(), buffer.size());
if (rw != static_cast<int>(buffer.size())) {
fprintf(stderr, "Failure to read block %lld: %s\n", block, strerror(errno));
fprintf(stderr, "Failure to read block %" PRIi64 ": %s\n", block, strerror(errno));
return false;
}
srand((seed + 1) * (block + 1));
for (size_t i = 0; i < buffer.size(); i++) {
if (buffer[i] != rand() % 256) {
fprintf(stderr, "Discrepancy detected at block %lld offset %zd\n", block, i);
fprintf(stderr, "Discrepancy detected at block %" PRIi64 " offset %zd\n", block, i);
return false;
}
}
@ -44,7 +44,7 @@ bool write_block(int fd, int seed, off_t block, AK::ByteBuffer& buffer)
auto offset = block * buffer.size();
auto rs = lseek(fd, offset, SEEK_SET);
if (rs < 0) {
fprintf(stderr, "Couldn't seek to block %lld (offset %lld) while verifying: %s\n", block, offset, strerror(errno));
fprintf(stderr, "Couldn't seek to block %" PRIi64 " (offset %" PRIi64 ") while verifying: %s\n", block, offset, strerror(errno));
return false;
}
srand((seed + 1) * (block + 1));
@ -52,7 +52,7 @@ bool write_block(int fd, int seed, off_t block, AK::ByteBuffer& buffer)
buffer[i] = rand();
auto rw = write(fd, buffer.data(), buffer.size());
if (rw != static_cast<int>(buffer.size())) {
fprintf(stderr, "Failure to write block %lld: %s\n", block, strerror(errno));
fprintf(stderr, "Failure to write block %" PRIi64 ": %s\n", block, strerror(errno));
return false;
}
return true;

View file

@ -267,8 +267,14 @@ int main(int argc, char** argv)
return Crash::Failure::UnexpectedError;
u8* bad_esp = bad_stack + 2048;
#ifndef __LP64__
asm volatile("mov %%eax, %%esp" ::"a"(bad_esp));
asm volatile("pushl $0");
#else
asm volatile("movq %%rax, %%rsp" ::"a"(bad_esp));
asm volatile("pushq $0");
#endif
return Crash::Failure::DidNotCrash;
}).run(run_type);
}

View file

@ -7,6 +7,7 @@
#include <AK/String.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DateTime.h>
#include <inttypes.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>

View file

@ -71,9 +71,9 @@ int main(int argc, char** argv)
printf("%10s ", human_readable_size((total_block_count - free_block_count) * block_size).characters());
printf("%10s ", human_readable_size(free_block_count * block_size).characters());
} else {
printf("%10" PRIu64 " ", total_block_count);
printf("%10" PRIu64 " ", total_block_count - free_block_count);
printf("%10" PRIu64 " ", free_block_count);
printf("%10" PRIu64 " ", (uint64_t)total_block_count);
printf("%10" PRIu64 " ", (uint64_t)(total_block_count - free_block_count));
printf("%10" PRIu64 " ", (uint64_t)free_block_count);
}
printf("%s", mount_point.characters());

View file

@ -13,6 +13,7 @@
#include <LibCore/DirIterator.h>
#include <LibCore/File.h>
#include <LibCore/Object.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
@ -151,7 +152,7 @@ int print_space_usage(const String& path, const DuOption& du_option, int max_dep
return 0;
}
long long size = path_stat.st_size;
off_t size = path_stat.st_size;
if (du_option.apparent_size) {
const auto block_size = 512;
size = path_stat.st_blocks * block_size;
@ -164,7 +165,7 @@ int print_space_usage(const String& path, const DuOption& du_option, int max_dep
size = size / block_size + (size % block_size != 0);
if (du_option.time_type == DuOption::TimeType::NotUsed)
printf("%lld\t%s\n", size, path.characters());
printf("%" PRIi64 "\t%s\n", size, path.characters());
else {
auto time = path_stat.st_mtime;
switch (du_option.time_type) {
@ -178,7 +179,7 @@ int print_space_usage(const String& path, const DuOption& du_option, int max_dep
}
const auto formatted_time = Core::DateTime::from_timestamp(time).to_string();
printf("%lld\t%s\t%s\n", size, formatted_time.characters(), path.characters());
printf("%" PRIi64 "\t%s\t%s\n", size, formatted_time.characters(), path.characters());
}
return 0;

View file

@ -68,7 +68,7 @@ static NonnullOwnPtr<HashMap<void*, X86::Instruction>> instrument_code()
if (section.name() != ".text")
return IterationDecision::Continue;
X86::SimpleInstructionStream stream((const u8*)((u32)lib.file->data() + section.offset()), section.size());
X86::SimpleInstructionStream stream((const u8*)((uintptr_t)lib.file->data() + section.offset()), section.size());
X86::Disassembler disassembler(stream);
for (;;) {
auto offset = stream.offset();

View file

@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <inttypes.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
@ -313,7 +314,7 @@ static bool print_filesystem_object(const String& path, const String& name, cons
if (flag_human_readable) {
printf(" %10s ", human_readable_size(st.st_size).characters());
} else {
printf(" %10lld ", st.st_size);
printf(" %10" PRIu64 " ", (uint64_t)st.st_size);
}
}

View file

@ -9,6 +9,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/DateTime.h>
#include <grp.h>
#include <inttypes.h>
#include <pwd.h>
#include <stdio.h>
#include <sys/stat.h>
@ -28,7 +29,7 @@ static int stat(const char* file, bool should_follow_links)
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
printf(" Device: %u,%u\n", major(st.st_rdev), minor(st.st_rdev));
else
printf(" Size: %lld\n", st.st_size);
printf(" Size: %" PRIi64 "\n", st.st_size);
printf(" Links: %u\n", st.st_nlink);
printf(" Blocks: %u\n", st.st_blocks);
printf(" UID: %u", st.st_uid);

View file

@ -10,6 +10,7 @@
#include <LibCore/DateTime.h>
#include <LibCore/File.h>
#include <LibCore/ProcessStatisticsReader.h>
#include <inttypes.h>
#include <pwd.h>
#include <stdio.h>
#include <sys/stat.h>
@ -87,7 +88,7 @@ int main()
if (stat(tty.characters(), &st) == 0) {
auto idle_time = now - st.st_mtime;
if (idle_time >= 0) {
builder.appendf("%llds", idle_time);
builder.appendf("%" PRIi64 "s", idle_time);
idle_string = builder.to_string();
}
}