mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
Userland: Fix 64-bit portability issues
This commit is contained in:
parent
fdbe66a7b4
commit
b613817bca
15 changed files with 59 additions and 30 deletions
|
@ -360,13 +360,13 @@ void ChessWidget::set_piece_set(const StringView& set)
|
||||||
|
|
||||||
Chess::Square ChessWidget::mouse_to_square(GUI::MouseEvent& event) const
|
Chess::Square ChessWidget::mouse_to_square(GUI::MouseEvent& event) const
|
||||||
{
|
{
|
||||||
size_t tile_width = width() / 8;
|
unsigned tile_width = width() / 8;
|
||||||
size_t tile_height = height() / 8;
|
unsigned tile_height = height() / 8;
|
||||||
|
|
||||||
if (side() == Chess::Color::White) {
|
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 {
|
} else {
|
||||||
return { event.y() / tile_height, 7 - (event.x() / tile_width) };
|
return { (unsigned)(event.y() / tile_height), (unsigned)(7 - (event.x() / tile_width)) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,23 +18,40 @@ __BEGIN_DECLS
|
||||||
#define PRIi8 "d"
|
#define PRIi8 "d"
|
||||||
#define PRIi16 "d"
|
#define PRIi16 "d"
|
||||||
#define PRIi32 "d"
|
#define PRIi32 "d"
|
||||||
#define PRIi64 "lld"
|
#ifndef __LP64__
|
||||||
|
# define PRIi64 "lld"
|
||||||
|
#else
|
||||||
|
# define PRIi64 "ld"
|
||||||
|
#endif
|
||||||
#define PRIu8 "u"
|
#define PRIu8 "u"
|
||||||
#define PRIo8 "o"
|
#define PRIo8 "o"
|
||||||
#define PRIo16 "o"
|
#define PRIo16 "o"
|
||||||
#define PRIo32 "o"
|
#define PRIo32 "o"
|
||||||
#define PRIo64 "llo"
|
#ifndef __LP64__
|
||||||
|
# define PRIo64 "llo"
|
||||||
|
#else
|
||||||
|
# define PRIo64 "lo"
|
||||||
|
#endif
|
||||||
#define PRIu16 "u"
|
#define PRIu16 "u"
|
||||||
#define PRIu32 "u"
|
#define PRIu32 "u"
|
||||||
#define PRIu64 "llu"
|
#ifndef __LP64__
|
||||||
|
# define PRIu64 "llu"
|
||||||
|
#else
|
||||||
|
# define PRIu64 "lu"
|
||||||
|
#endif
|
||||||
#define PRIx8 "b"
|
#define PRIx8 "b"
|
||||||
#define PRIX8 "hhX"
|
#define PRIX8 "hhX"
|
||||||
#define PRIx16 "w"
|
#define PRIx16 "w"
|
||||||
#define PRIX16 "hX"
|
#define PRIX16 "hX"
|
||||||
#define PRIx32 "x"
|
#define PRIx32 "x"
|
||||||
#define PRIX32 "X"
|
#define PRIX32 "X"
|
||||||
#define PRIx64 "llx"
|
#ifndef __LP64__
|
||||||
#define PRIX64 "llX"
|
# define PRIx64 "llx"
|
||||||
|
# define PRIX64 "llX"
|
||||||
|
#else
|
||||||
|
# define PRIx64 "lx"
|
||||||
|
# define PRIX64 "lX"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define __PRI64_PREFIX "ll"
|
#define __PRI64_PREFIX "ll"
|
||||||
#define __PRIPTR_PREFIX
|
#define __PRIPTR_PREFIX
|
||||||
|
|
|
@ -259,7 +259,7 @@ void DebugSession::run(DesiredInitialDebugeeState initial_debugee_state, Callbac
|
||||||
Optional<BreakPoint> current_breakpoint;
|
Optional<BreakPoint> current_breakpoint;
|
||||||
|
|
||||||
if (state == State::FreeRun || state == State::Syscall) {
|
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())
|
if (current_breakpoint.has_value())
|
||||||
state = State::FreeRun;
|
state = State::FreeRun;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <LibCore/FileStream.h>
|
#include <LibCore/FileStream.h>
|
||||||
#include <LibCore/MimeData.h>
|
#include <LibCore/MimeData.h>
|
||||||
#include <LibHTTP/HttpRequest.h>
|
#include <LibHTTP/HttpRequest.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.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(escape_html_entities(name));
|
||||||
builder.append("</a></td><td> </td>");
|
builder.append("</a></td><td> </td>");
|
||||||
|
|
||||||
builder.appendf("<td>%10lld</td><td> </td>", st.st_size);
|
builder.appendf("<td>%10" PRIi64 "</td><td> </td>", st.st_size);
|
||||||
builder.append("<td>");
|
builder.append("<td>");
|
||||||
builder.append(Core::DateTime::from_timestamp(st.st_mtime).to_string());
|
builder.append(Core::DateTime::from_timestamp(st.st_mtime).to_string());
|
||||||
builder.append("</td>");
|
builder.append("</td>");
|
||||||
|
|
|
@ -53,7 +53,7 @@ int main()
|
||||||
|
|
||||||
uintptr_t g_processes = *(uintptr_t*)&base[0x1b51c4];
|
uintptr_t g_processes = *(uintptr_t*)&base[0x1b51c4];
|
||||||
printf("base = %p\n", base);
|
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* {
|
auto get_ptr = [&](uintptr_t value) -> void* {
|
||||||
value -= 0xc0000000;
|
value -= 0xc0000000;
|
||||||
|
@ -80,7 +80,7 @@ int main()
|
||||||
|
|
||||||
Process* process = (Process*)get_ptr(process_list->head);
|
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()) {
|
if (process->pid == getpid()) {
|
||||||
printf("That's me! Let's become r00t!\n");
|
printf("That's me! Let's become r00t!\n");
|
||||||
|
|
|
@ -88,7 +88,7 @@ int main()
|
||||||
strcpy(shstrtab, ".strtab");
|
strcpy(shstrtab, ".strtab");
|
||||||
|
|
||||||
auto* code = &buffer[8192];
|
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);
|
printf("memcpy(%p, %p, %zu)\n", code, haxcode, haxcode_size);
|
||||||
memcpy(code, (void*)haxcode, haxcode_size);
|
memcpy(code, (void*)haxcode, haxcode_size);
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ int main()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nwritten = write(fd, buffer, sizeof(buffer));
|
auto nwritten = write(fd, buffer, sizeof(buffer));
|
||||||
if (nwritten < 0) {
|
if (nwritten < 0) {
|
||||||
perror("write");
|
perror("write");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -21,18 +21,18 @@ bool verify_block(int fd, int seed, off_t block, AK::ByteBuffer& buffer)
|
||||||
auto offset = block * buffer.size();
|
auto offset = block * buffer.size();
|
||||||
auto rs = lseek(fd, offset, SEEK_SET);
|
auto rs = lseek(fd, offset, SEEK_SET);
|
||||||
if (rs < 0) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
auto rw = read(fd, buffer.data(), buffer.size());
|
auto rw = read(fd, buffer.data(), buffer.size());
|
||||||
if (rw != static_cast<int>(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;
|
return false;
|
||||||
}
|
}
|
||||||
srand((seed + 1) * (block + 1));
|
srand((seed + 1) * (block + 1));
|
||||||
for (size_t i = 0; i < buffer.size(); i++) {
|
for (size_t i = 0; i < buffer.size(); i++) {
|
||||||
if (buffer[i] != rand() % 256) {
|
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;
|
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 offset = block * buffer.size();
|
||||||
auto rs = lseek(fd, offset, SEEK_SET);
|
auto rs = lseek(fd, offset, SEEK_SET);
|
||||||
if (rs < 0) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
srand((seed + 1) * (block + 1));
|
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();
|
buffer[i] = rand();
|
||||||
auto rw = write(fd, buffer.data(), buffer.size());
|
auto rw = write(fd, buffer.data(), buffer.size());
|
||||||
if (rw != static_cast<int>(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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -267,8 +267,14 @@ int main(int argc, char** argv)
|
||||||
return Crash::Failure::UnexpectedError;
|
return Crash::Failure::UnexpectedError;
|
||||||
|
|
||||||
u8* bad_esp = bad_stack + 2048;
|
u8* bad_esp = bad_stack + 2048;
|
||||||
|
#ifndef __LP64__
|
||||||
asm volatile("mov %%eax, %%esp" ::"a"(bad_esp));
|
asm volatile("mov %%eax, %%esp" ::"a"(bad_esp));
|
||||||
asm volatile("pushl $0");
|
asm volatile("pushl $0");
|
||||||
|
#else
|
||||||
|
asm volatile("movq %%rax, %%rsp" ::"a"(bad_esp));
|
||||||
|
asm volatile("pushq $0");
|
||||||
|
#endif
|
||||||
|
|
||||||
return Crash::Failure::DidNotCrash;
|
return Crash::Failure::DidNotCrash;
|
||||||
}).run(run_type);
|
}).run(run_type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
|
@ -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((total_block_count - free_block_count) * block_size).characters());
|
||||||
printf("%10s ", human_readable_size(free_block_count * block_size).characters());
|
printf("%10s ", human_readable_size(free_block_count * block_size).characters());
|
||||||
} else {
|
} else {
|
||||||
printf("%10" PRIu64 " ", total_block_count);
|
printf("%10" PRIu64 " ", (uint64_t)total_block_count);
|
||||||
printf("%10" PRIu64 " ", total_block_count - free_block_count);
|
printf("%10" PRIu64 " ", (uint64_t)(total_block_count - free_block_count));
|
||||||
printf("%10" PRIu64 " ", free_block_count);
|
printf("%10" PRIu64 " ", (uint64_t)free_block_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s", mount_point.characters());
|
printf("%s", mount_point.characters());
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <LibCore/DirIterator.h>
|
#include <LibCore/DirIterator.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/Object.h>
|
#include <LibCore/Object.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -151,7 +152,7 @@ int print_space_usage(const String& path, const DuOption& du_option, int max_dep
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long size = path_stat.st_size;
|
off_t size = path_stat.st_size;
|
||||||
if (du_option.apparent_size) {
|
if (du_option.apparent_size) {
|
||||||
const auto block_size = 512;
|
const auto block_size = 512;
|
||||||
size = path_stat.st_blocks * block_size;
|
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);
|
size = size / block_size + (size % block_size != 0);
|
||||||
|
|
||||||
if (du_option.time_type == DuOption::TimeType::NotUsed)
|
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 {
|
else {
|
||||||
auto time = path_stat.st_mtime;
|
auto time = path_stat.st_mtime;
|
||||||
switch (du_option.time_type) {
|
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();
|
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;
|
return 0;
|
||||||
|
|
|
@ -68,7 +68,7 @@ static NonnullOwnPtr<HashMap<void*, X86::Instruction>> instrument_code()
|
||||||
if (section.name() != ".text")
|
if (section.name() != ".text")
|
||||||
return IterationDecision::Continue;
|
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);
|
X86::Disassembler disassembler(stream);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto offset = stream.offset();
|
auto offset = stream.offset();
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -313,7 +314,7 @@ static bool print_filesystem_object(const String& path, const String& name, cons
|
||||||
if (flag_human_readable) {
|
if (flag_human_readable) {
|
||||||
printf(" %10s ", human_readable_size(st.st_size).characters());
|
printf(" %10s ", human_readable_size(st.st_size).characters());
|
||||||
} else {
|
} else {
|
||||||
printf(" %10lld ", st.st_size);
|
printf(" %10" PRIu64 " ", (uint64_t)st.st_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.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))
|
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
|
||||||
printf(" Device: %u,%u\n", major(st.st_rdev), minor(st.st_rdev));
|
printf(" Device: %u,%u\n", major(st.st_rdev), minor(st.st_rdev));
|
||||||
else
|
else
|
||||||
printf(" Size: %lld\n", st.st_size);
|
printf(" Size: %" PRIi64 "\n", st.st_size);
|
||||||
printf(" Links: %u\n", st.st_nlink);
|
printf(" Links: %u\n", st.st_nlink);
|
||||||
printf(" Blocks: %u\n", st.st_blocks);
|
printf(" Blocks: %u\n", st.st_blocks);
|
||||||
printf(" UID: %u", st.st_uid);
|
printf(" UID: %u", st.st_uid);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/ProcessStatisticsReader.h>
|
#include <LibCore/ProcessStatisticsReader.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -87,7 +88,7 @@ int main()
|
||||||
if (stat(tty.characters(), &st) == 0) {
|
if (stat(tty.characters(), &st) == 0) {
|
||||||
auto idle_time = now - st.st_mtime;
|
auto idle_time = now - st.st_mtime;
|
||||||
if (idle_time >= 0) {
|
if (idle_time >= 0) {
|
||||||
builder.appendf("%llds", idle_time);
|
builder.appendf("%" PRIi64 "s", idle_time);
|
||||||
idle_string = builder.to_string();
|
idle_string = builder.to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue