Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ jobs:
build_options: "LLVM=1 CROSS_COMPILE=x86_64-unknown-freebsd SYSROOT=~/freebsd-sysroot"
make_sysroot: "./tools/lkl/scripts/freebsd-make-sysroot.sh"
run_qemu: true
- displayTargetName: win64
os: unix
runs_on: ubuntu-24.04
pip_option: --break-system-packages
shell: bash
build_options: "CROSS_COMPILE=x86_64-w64-mingw32-"
make_sysroot: "./tools/lkl/scripts/win64-toolchain.sh"
- displayTargetName: fuzzers
os: unix
runs_on: ubuntu-22.04
Expand Down Expand Up @@ -123,6 +130,15 @@ jobs:
qemu-utils sshpass cloud-image-utils binutils cmake ninja-build liblzma-dev libz-dev \
pkg-config autoconf libtool

- name: Install wine
if: matrix.displayTargetName == 'win64'
run: |
sudo apt install -y wine wine64
echo "WINEDEBUG=-all" >> $GITHUB_ENV
# skip the Mono and Gecko installers, they hang without a display
echo "WINEDLLOVERRIDES=mscoree=;mshtml=" >> $GITHUB_ENV
WINEDEBUG=-all WINEDLLOVERRIDES="mscoree=;mshtml=" wineboot -i

- name: Install patched binutils for Windows
if: runner.os == 'Windows'
run: |
Expand Down
28 changes: 28 additions & 0 deletions arch/lkl/include/uapi/asm/lkl_long.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _ASM_UAPI_LKL_LONG_H
#define _ASM_UAPI_LKL_LONG_H

/*
* lkl_long_t / lkl_ulong_t: pointer-width integer types for the
* LKL cross-world interface (host_ops, syscall dispatch, UAPI structs).
*
* These must be the same size on both sides of the kernel<->host boundary:
* - Kernel side: long = 8 bytes (on Windows the kernel is built with an LP64
* x86_64-pc-cygwin compiler, see tools/lkl/bin/x86_64-w64-mingw32-gcc)
* - Host side (LLP64 MinGW-w64): long = 4 bytes, need long long
* - Host side (LP64 Linux/Cygwin/macOS): long = 8 bytes
*
* The headers_install.py script replaces all 'long' in generated user
* headers with these types to ensure ABI compatibility across data models.
*/
#if defined(_WIN64) && !defined(__LP64__)
/* LLP64: MinGW-w64 x64 user-space */
typedef long long lkl_long_t;
typedef unsigned long long lkl_ulong_t;
#else
/* LP64: kernel side, Linux, Cygwin, macOS, or any ILP32 system */
typedef long lkl_long_t;
typedef unsigned long lkl_ulong_t;
#endif

#endif /* _ASM_UAPI_LKL_LONG_H */
34 changes: 34 additions & 0 deletions arch/lkl/scripts/headers_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def lkl_prefix(self, w):
def install_headers(self):
self.find_headers("arch/lkl/include/uapi/asm/syscalls.h")
self.headers.add("arch/lkl/include/uapi/asm/host_ops.h")
self.headers.add("arch/lkl/include/uapi/asm/lkl_long.h")
self.find_headers("include/uapi/linux/android/binder.h")
self.find_headers("include/uapi/linux/uhid.h")
self.find_headers("include/uapi/linux/mman.h")
Expand Down Expand Up @@ -166,6 +167,37 @@ def find_all_symbols(self):
# needed for i386
self.defines.add("__NR_stime")


def replace_long_types(self, content, h):
"""Replace 'long' and 'unsigned long' with lkl_long_t/lkl_ulong_t
for LLP64 compatibility, preserving 'long long' and 'long double'."""
# Skip lkl_long.h itself
if 'lkl_long.h' in h:
return content
# Step 1: protect 'long long' and 'long double' with placeholders
content = re.sub(r'\blong\s+long\b', '__LKLPH_LONGLONG__', content)
content = re.sub(r'\blong\s+double\b', '__LKLPH_LONGDOUBLE__', content)
# Step 2: replace 'unsigned long [int]' (now safe, no 'long long' present)
content = re.sub(r'\bunsigned\s+long(?:\s+int)?\b', 'lkl_ulong_t', content)
# Step 3: replace remaining 'long [int]'
content = re.sub(r'\blong(?:\s+int)?\b', 'lkl_long_t', content)
# Step 4: restore placeholders
content = content.replace('__LKLPH_LONGLONG__', 'long long')
content = content.replace('__LKLPH_LONGDOUBLE__', 'long double')
# Step 5: add include for lkl_long_t definition if replacements were made
if 'lkl_long_t' in content or 'lkl_ulong_t' in content:
# Insert after the first #ifndef/#define guard or at the top
include_line = '#include <lkl/asm/lkl_long.h>\n'
if include_line not in content:
# Insert after the header guard #define
m = re.search(r'(#ifndef\s+\w+\s*\n#define\s+\w+\s*\n)', content)
if m:
pos = m.end()
content = content[:pos] + '\n' + include_line + '\n' + content[pos:]
else:
content = include_line + content
return content

def update_header(self, h):
# h is a .raw tmp file produced by install_headers(); the final
# destination is h without the .raw suffix.
Expand All @@ -192,6 +224,8 @@ def update_header(self, h):
search_str = r"(\W?union\s+)" + s + r"(\W)"
replace_str = "\\1" + self.lkl_prefix(s) + "\\2"
content = re.sub(search_str, replace_str, content, flags = re.MULTILINE)
# Replace long/unsigned long with lkl_long_t/lkl_ulong_t
content = self.replace_long_types(content, h)
content = content.encode()
existing = None
if os.path.exists(dst) and os.stat(dst).st_size == len(content):
Expand Down
1 change: 1 addition & 0 deletions tools/lkl/bin/x86_64-w64-mingw32-cc
1 change: 1 addition & 0 deletions tools/lkl/bin/x86_64-w64-mingw32-gcc
61 changes: 31 additions & 30 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern "C" {
#undef __unused

#include <lkl/asm/syscalls.h>
#include <lkl/asm/lkl_long.h>

#pragma pop_macro("__unused")

Expand Down Expand Up @@ -67,7 +68,7 @@ static inline int lkl_sys_fstatfs(unsigned int fd, struct lkl_statfs *buf)
static inline int lkl_sys_nanosleep(struct __lkl__kernel_timespec *rqtp,
struct __lkl__kernel_timespec *rmtp)
{
long p[6] = {LKL_CLOCK_MONOTONIC, 0, (long)rqtp, (long)rmtp, 0};
lkl_long_t p[6] = {LKL_CLOCK_MONOTONIC, 0, (lkl_long_t)rqtp, (lkl_long_t)rmtp, 0};

return lkl_syscall(__lkl__NR_clock_nanosleep_time64, p);
}
Expand All @@ -93,7 +94,7 @@ static inline long long lkl_sys_lseek(unsigned int fd, __lkl__kernel_loff_t off,
unsigned int whence)
{
long long res;
long ret = lkl_sys_llseek(fd, off >> 32, off & 0xffffffff, &res, whence);
lkl_long_t ret = lkl_sys_llseek(fd, off >> 32, off & 0xffffffff, &res, whence);

return ret < 0 ? ret : res;
}
Expand All @@ -102,7 +103,7 @@ static inline long long lkl_sys_lseek(unsigned int fd, __lkl__kernel_loff_t off,
static inline void *lkl_sys_mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)
{
return (void *)lkl_sys_mmap_pgoff((long)addr, length, prot, flags, fd,
return (void *)lkl_sys_mmap_pgoff((lkl_long_t)addr, length, prot, flags, fd,
offset >> 12);
}

Expand All @@ -112,15 +113,15 @@ static inline void *lkl_sys_mmap(void *addr, size_t length, int prot, int flags,
/**
* lkl_sys_open - wrapper for lkl_sys_openat
*/
static inline long lkl_sys_open(const char *file, int flags, int mode)
static inline lkl_long_t lkl_sys_open(const char *file, int flags, int mode)
{
return lkl_sys_openat(LKL_AT_FDCWD, file, flags, mode);
}

/**
* lkl_sys_creat - wrapper for lkl_sys_openat
*/
static inline long lkl_sys_creat(const char *file, int mode)
static inline lkl_long_t lkl_sys_creat(const char *file, int mode)
{
return lkl_sys_openat(LKL_AT_FDCWD, file,
LKL_O_CREAT|LKL_O_WRONLY|LKL_O_TRUNC, mode);
Expand All @@ -132,7 +133,7 @@ static inline long lkl_sys_creat(const char *file, int mode)
/**
* lkl_sys_access - wrapper for lkl_sys_faccessat
*/
static inline long lkl_sys_access(const char *file, int mode)
static inline lkl_long_t lkl_sys_access(const char *file, int mode)
{
return lkl_sys_faccessat(LKL_AT_FDCWD, file, mode);
}
Expand All @@ -142,7 +143,7 @@ static inline long lkl_sys_access(const char *file, int mode)
/**
* lkl_sys_chown - wrapper for lkl_sys_fchownat
*/
static inline long lkl_sys_chown(const char *path, lkl_uid_t uid, lkl_gid_t gid)
static inline lkl_long_t lkl_sys_chown(const char *path, lkl_uid_t uid, lkl_gid_t gid)
{
return lkl_sys_fchownat(LKL_AT_FDCWD, path, uid, gid, 0);
}
Expand All @@ -152,7 +153,7 @@ static inline long lkl_sys_chown(const char *path, lkl_uid_t uid, lkl_gid_t gid)
/**
* lkl_sys_chmod - wrapper for lkl_sys_fchmodat
*/
static inline long lkl_sys_chmod(const char *path, mode_t mode)
static inline lkl_long_t lkl_sys_chmod(const char *path, mode_t mode)
{
return lkl_sys_fchmodat(LKL_AT_FDCWD, path, mode);
}
Expand All @@ -162,7 +163,7 @@ static inline long lkl_sys_chmod(const char *path, mode_t mode)
/**
* lkl_sys_link - wrapper for lkl_sys_linkat
*/
static inline long lkl_sys_link(const char *existing, const char *new)
static inline lkl_long_t lkl_sys_link(const char *existing, const char *new)
{
return lkl_sys_linkat(LKL_AT_FDCWD, existing, LKL_AT_FDCWD, new, 0);
}
Expand All @@ -172,7 +173,7 @@ static inline long lkl_sys_link(const char *existing, const char *new)
/**
* lkl_sys_unlink - wrapper for lkl_sys_unlinkat
*/
static inline long lkl_sys_unlink(const char *path)
static inline lkl_long_t lkl_sys_unlink(const char *path)
{
return lkl_sys_unlinkat(LKL_AT_FDCWD, path, 0);
}
Expand All @@ -182,7 +183,7 @@ static inline long lkl_sys_unlink(const char *path)
/**
* lkl_sys_symlink - wrapper for lkl_sys_symlinkat
*/
static inline long lkl_sys_symlink(const char *existing, const char *new)
static inline lkl_long_t lkl_sys_symlink(const char *existing, const char *new)
{
return lkl_sys_symlinkat(existing, LKL_AT_FDCWD, new);
}
Expand All @@ -192,7 +193,7 @@ static inline long lkl_sys_symlink(const char *existing, const char *new)
/**
* lkl_sys_readlink - wrapper for lkl_sys_readlinkat
*/
static inline long lkl_sys_readlink(const char *path, char *buf, size_t bufsize)
static inline lkl_long_t lkl_sys_readlink(const char *path, char *buf, size_t bufsize)
{
return lkl_sys_readlinkat(LKL_AT_FDCWD, path, buf, bufsize);
}
Expand All @@ -202,7 +203,7 @@ static inline long lkl_sys_readlink(const char *path, char *buf, size_t bufsize)
/**
* lkl_sys_rename - wrapper for lkl_sys_renameat
*/
static inline long lkl_sys_rename(const char *old, const char *new)
static inline lkl_long_t lkl_sys_rename(const char *old, const char *new)
{
return lkl_sys_renameat(LKL_AT_FDCWD, old, LKL_AT_FDCWD, new);
}
Expand All @@ -212,7 +213,7 @@ static inline long lkl_sys_rename(const char *old, const char *new)
/**
* lkl_sys_mkdir - wrapper for lkl_sys_mkdirat
*/
static inline long lkl_sys_mkdir(const char *path, mode_t mode)
static inline lkl_long_t lkl_sys_mkdir(const char *path, mode_t mode)
{
return lkl_sys_mkdirat(LKL_AT_FDCWD, path, mode);
}
Expand All @@ -222,7 +223,7 @@ static inline long lkl_sys_mkdir(const char *path, mode_t mode)
/**
* lkl_sys_rmdir - wrapper for lkl_sys_unlinkrat
*/
static inline long lkl_sys_rmdir(const char *path)
static inline lkl_long_t lkl_sys_rmdir(const char *path)
{
return lkl_sys_unlinkat(LKL_AT_FDCWD, path, LKL_AT_REMOVEDIR);
}
Expand All @@ -232,7 +233,7 @@ static inline long lkl_sys_rmdir(const char *path)
/**
* lkl_sys_mknod - wrapper for lkl_sys_mknodat
*/
static inline long lkl_sys_mknod(const char *path, mode_t mode, dev_t dev)
static inline lkl_long_t lkl_sys_mknod(const char *path, mode_t mode, dev_t dev)
{
return lkl_sys_mknodat(LKL_AT_FDCWD, path, mode, dev);
}
Expand All @@ -242,7 +243,7 @@ static inline long lkl_sys_mknod(const char *path, mode_t mode, dev_t dev)
/**
* lkl_sys_pipe - wrapper for lkl_sys_pipe2
*/
static inline long lkl_sys_pipe(int fd[2])
static inline lkl_long_t lkl_sys_pipe(int fd[2])
{
return lkl_sys_pipe2(fd, 0);
}
Expand All @@ -252,7 +253,7 @@ static inline long lkl_sys_pipe(int fd[2])
/**
* lkl_sys_send - wrapper for lkl_sys_sendto
*/
static inline long lkl_sys_send(int fd, void *buf, size_t len, int flags)
static inline lkl_long_t lkl_sys_send(int fd, void *buf, size_t len, int flags)
{
return lkl_sys_sendto(fd, buf, len, flags, 0, 0);
}
Expand All @@ -262,7 +263,7 @@ static inline long lkl_sys_send(int fd, void *buf, size_t len, int flags)
/**
* lkl_sys_recv - wrapper for lkl_sys_recvfrom
*/
static inline long lkl_sys_recv(int fd, void *buf, size_t len, int flags)
static inline lkl_long_t lkl_sys_recv(int fd, void *buf, size_t len, int flags)
{
return lkl_sys_recvfrom(fd, buf, len, flags, 0, 0);
}
Expand All @@ -272,10 +273,10 @@ static inline long lkl_sys_recv(int fd, void *buf, size_t len, int flags)
/**
* lkl_sys_select - wrapper for lkl_sys_pselect
*/
static inline long lkl_sys_select(int n, lkl_fd_set *rfds, lkl_fd_set *wfds,
static inline lkl_long_t lkl_sys_select(int n, lkl_fd_set *rfds, lkl_fd_set *wfds,
lkl_fd_set *efds, struct lkl_timeval *tv)
{
long data[2] = { 0, _LKL_NSIG/8 };
lkl_long_t data[2] = { 0, _LKL_NSIG/8 };
struct __lkl__kernel_timespec ts;

if (tv) {
Expand All @@ -293,7 +294,7 @@ static inline long lkl_sys_select(int n, lkl_fd_set *rfds, lkl_fd_set *wfds,
/**
* lkl_sys_poll - wrapper for lkl_sys_ppoll
*/
static inline long lkl_sys_poll(struct lkl_pollfd *fds, int n, int timeout)
static inline lkl_long_t lkl_sys_poll(struct lkl_pollfd *fds, int n, int timeout)
{
struct __lkl__kernel_timespec ts;

Expand All @@ -311,7 +312,7 @@ static inline long lkl_sys_poll(struct lkl_pollfd *fds, int n, int timeout)
/**
* lkl_sys_epoll_create - wrapper for lkl_sys_epoll_create1
*/
static inline long lkl_sys_epoll_create(int size)
static inline lkl_long_t lkl_sys_epoll_create(int size)
{
return lkl_sys_epoll_create1(0);
}
Expand All @@ -321,7 +322,7 @@ static inline long lkl_sys_epoll_create(int size)
/**
* lkl_sys_epoll_wait - wrapper for lkl_sys_epoll_pwait
*/
static inline long lkl_sys_epoll_wait(int fd, struct lkl_epoll_event *ev,
static inline lkl_long_t lkl_sys_epoll_wait(int fd, struct lkl_epoll_event *ev,
int cnt, int to)
{
return lkl_sys_epoll_pwait(fd, ev, cnt, to, 0, _LKL_NSIG/8);
Expand Down Expand Up @@ -428,7 +429,7 @@ int lkl_get_virtio_blkdev(int disk_id, unsigned int part, uint32_t *pdevid);
* @mnt_str_len - size of mnt_str
* @returns - 0 on success, a negative value on error
*/
long lkl_mount_dev(unsigned int disk_id, unsigned int part, const char *fs_type,
lkl_long_t lkl_mount_dev(unsigned int disk_id, unsigned int part, const char *fs_type,
int flags, const char *opts,
char *mnt_str, unsigned int mnt_str_len);

Expand All @@ -447,7 +448,7 @@ long lkl_mount_dev(unsigned int disk_id, unsigned int part, const char *fs_type,
* @mnt_str_len - size of mnt_str
* @returns - 0 on success, a negative value on error
*/
long lkl_mount_blkdev(unsigned int dev, const char *fs_type, int flags,
lkl_long_t lkl_mount_blkdev(unsigned int dev, const char *fs_type, int flags,
const char *opts, char *mnt_str,
unsigned int mnt_str_len);

Expand All @@ -464,8 +465,8 @@ long lkl_mount_blkdev(unsigned int dev, const char *fs_type, int flags,
* umount can succeed
* @returns - 0 on success, a negative value on error
*/
long lkl_umount_dev(unsigned int disk_id, unsigned int part, int flags,
long timeout_ms);
lkl_long_t lkl_umount_dev(unsigned int disk_id, unsigned int part, int flags,
lkl_long_t timeout_ms);

/**
* lkl_umount_blkdev - umount a block device
Expand All @@ -478,7 +479,7 @@ long lkl_umount_dev(unsigned int disk_id, unsigned int part, int flags,
* umount can succeed
* @returns - 0 on success, a negative value on error
*/
long lkl_umount_blkdev(unsigned int dev, int flags, long timeout_ms);
lkl_long_t lkl_umount_blkdev(unsigned int dev, int flags, lkl_long_t timeout_ms);

/**
* lkl_umount_timeout - umount filesystem with timeout
Expand All @@ -489,7 +490,7 @@ long lkl_umount_blkdev(unsigned int dev, int flags, long timeout_ms);
* umount can succeed
* @returns - 0 on success, a negative value on error
*/
long lkl_umount_timeout(char *path, int flags, long timeout_ms);
lkl_long_t lkl_umount_timeout(char *path, int flags, lkl_long_t timeout_ms);

/**
* lkl_opendir - open a directory
Expand Down
Loading
Loading