Skip to content

Conversation

@jiaxli-QC
Copy link
Contributor

@jiaxli-QC jiaxli-QC commented Dec 9, 2025

Fix compatibility issues for both 64-bit and 32-bit systems.

  1. libminkadaptor: add syscal32.S to support 32-bit system compilation
  2. libminkadaptor: replace 'pc' on 32-bit system with the member 'arm_pc'
  3. listeners: Use container_of macro to complete the address translation
  4. listeners: remove access to non-public fields of glibc
  5. MinkIPC: fix type conversion issues in 32-bit system

// Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

#if defined(__aarch64__)
Copy link
Contributor

@harshaldev27 harshaldev27 Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding these #if defined within the file, use a AARCH64 conditional in the CMake file please.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why on the earth do we need these assembly bits? We have syscall() in libc, we have other standard ways to call into the kernel. Why do we need this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can read this comment to get some insight into the behavior of this assembly code @lumag : https://github.com/qualcomm/minkipc/blob/main/libminkadaptor/src/supplicant.c#L57

The reason this is written in assembly, is to take care of a race condition found in most glibc libraries, whereby when a kill signal for the thread arrives after glibc checks for it, the signal is ignored and the thread gets indefinitely blocked in the kernel. In-effect, there is a possibility of a race between the arrival of the signal and the checking of the signal, this old LWN article digs into it more properly if you're interested: https://lwn.net/Articles/683118/

uint64_t pc_current = (uint64_t)ucontext->uc_mcontext.pc;
uint64_t addr_recv_ioctl = (uint64_t)recv_ioctl;
uint64_t addr_recv = (uint64_t)recv;
uint64_t pc_current = (uint64_t)get_pc_from_ucontext(ucontext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make pc_current, addr_recv_ioctl and addr_recv uintptr_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#include <stddef.h>

#ifndef container_of
#define container_of(ptr, type, member) ({ \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also qlist.h is only for defining the Qlist interfaces and macros, please move it either directly to the .c file using it or find another generic header providing generic helper macros.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offsetof (<stddef. h>/<cstddef>) is a part of the standard library, supported by mainstream compilers such as GCC, Clang, MSVC, ICC, as well as various operating systems/RTOS.
__Builtin_offsetof is only reliable in the ecosystem of GCC/CLang; When ported to MSVC or other compilers, it may be directly unavailable or require macro replacement.
Whereby if the code needs to be ported between different compilers and systems, it is recommended to prioritize using standard offsetof.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright sure, if you want to keep it. However like I said, please move to either .c or a generic header, don't keep this in qlist.h.

QLIST_FOR_ALL(list, node)
{
l_item = (list_item *)node;
l_item = container_of(node, list_item, qn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the typos in the commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

#include <stddef.h>

#ifndef container_of
#define container_of(ptr, type, member) ({ \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, better move it directly to the .c file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recommend defining container_of in a .c file, as it's a generic macro commonly used for list node processing.

my_rsp->buf.st_dev = (uint64_t)buf.st_dev;
#if !defined(__aarch64__)
memcpy(my_rsp->buf.__pad0, buf.__pad0, 4);
my_rsp->buf.__st_ino = (uint32_t)buf.__st_ino;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 305, why delete it? Why not use my_rsp->buf.__st_ino = (uint32_t)buf.st_ino?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable was assigned a value twice.
Please see line 320.

} else {
my_rsp->buf.st_dev = (uint64_t)buf.st_dev;
#if !defined(__aarch64__)
memcpy(my_rsp->buf.__pad0, buf.__pad0, 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of deleting memcpy() I think it's better to set 0 in my_rsp0->buf.__pad0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable was assigned a value twice.
Please see line 319.

my_rsp->buf.st_ctim = (uint32_t)((struct timespec)buf.st_ctim).tv_sec;
my_rsp->buf.st_ctim_nsec = (uint32_t)((struct timespec)buf.st_ctim).tv_nsec;
my_rsp->buf.st_ino = (uint64_t)buf.st_ino;
#if !defined(__aarch64__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why delete this #if section? I think it compiles perfectly and is valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

my_rsp->ret = -1;
} else {
my_rsp->buf.st_dev = (uint64_t)buf.st_dev;
#if !defined(__aarch64__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable was assigned a value twice.
Please see line 375.

my_rsp->buf.st_ctim = (uint32_t)((struct timespec)buf.st_ctim).tv_sec;
my_rsp->buf.st_ctim_nsec = (uint32_t)((struct timespec)buf.st_ctim).tv_nsec;
my_rsp->buf.st_ino = (uint64_t)buf.st_ino;
#if !defined(__aarch64__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor

@harshaldev27 harshaldev27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the commit messages. They should follow the right commit styles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the typo in the commit message? syscall.S.
Also, please use the part before colon ':' to refer to the module.
libminkdaptor: Add 32-bit compilation support via syscall32.S

I would also suggest you use co-pilot for fixing grammatical or other minor mistakes.

Also explain what kind of modifications have you made to the assembly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update

extern int recv(void);
extern int recv_skip(void);

static inline uintptr_t get_pc_from_ucontext(ucontext_t *ucontext) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move these inline functions to supplicant.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel okay about this.

But since this PR addresses a 32-bit system compilation issue, could this modification potentially cause confusion with the content?

Fixed compatible issue for syscal on both arm32 and arm64 system.
The assembly instructions have been modified.

Signed-off-by: Jiaxing Li <jiaxing.li@oss.qualcomm.com>
mcontext_t has no member named pc on 32-bit system.
Unable to access the pc member from mcontext_t on 32-bit system.

Signed-off-by: Jiaxing Li <jiaxing.li@oss.qualcomm.com>
Forcefully converting a QNode pointer to list_item *. Unable to meet
alignment requirements.
Use container_of macro to complete the address translation.

Signed-off-by: Jiaxing Li <jiaxing.li@oss.qualcomm.com>
Directly accessed the non-public internal fields of glibc (__pad0,
__st_ino). On 32-bit ARM, the layout of struct stat and these field
names do not exist.
Only access fields that comply with the POSIX standard to modify
compatibility issue.

Signed-off-by: Jiaxing Li <jiaxing.li@oss.qualcomm.com>
Replace 'uint64_t' type with 'uintptr_t' type.
Use '%zu' to print the size_t variable, as the size_t type length is
different in 32-bit and 64-bit systems.

Signed-off-by: Jiaxing Li <jiaxing.li@oss.qualcomm.com>
@jiaxli-QC jiaxli-QC changed the title Fix compatible issue on 32-bit system Fix compatibility issues for both 64-bit and 32-bit systems. Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants