Skip to content

[BUG] gettid() optimization  #2024

Closed
Closed
@vvb2060

Description

@vvb2060

Description

#include <stdio.h>
#include <unistd.h>
#include <syscall.h>
#include <sys/wait.h>

int main(int argc, char *argv[]) {
    printf("p getpid()=%d gettid()=%d\n", getpid(), gettid());
    int pid = fork();
    if (pid == 0) {
        printf("getpid()=%d gettid()=%d NR_getpid=%ld NR_gettid=%ld\n", getpid(), gettid(),
               syscall(__NR_getpid), syscall(__NR_gettid));
    } else if (pid > 0) {
        waitpid(pid, nullptr, 0);
    }
    return 0;
}

release build and exec

p getpid()=22023 gettid()=22023
getpid()=22024 gettid()=22023 NR_getpid=22024 NR_gettid=22024

decompile

__int64 sub_888()
{
  unsigned int v0; // w20
  unsigned int v1; // w19
  int v2; // w0
  unsigned int v3; // w20
  __int64 v4; // x21
  __int64 v5; // x0

  v0 = getpid();
  v1 = gettid();
  printf("p getpid()=%d gettid()=%d\n", v0, v1);
  v2 = fork();
  if ( v2 )
  {
    if ( v2 >= 1 )
      waitpid(v2, 0LL, 0);
  }
  else
  {
    v3 = getpid();
    v4 = syscall(172LL);
    v5 = syscall(178LL);
    printf("getpid()=%d gettid()=%d NR_getpid=%ld NR_gettid=%ld\n", v3, v1, v4, v5);
  }
  return 0LL;
}

Affected versions

r27

Canary version

No response

Host OS

Windows

Host OS version

Windows10

Affected ABIs

arm64-v8a

Build system

ndk-build

Other build system

No response

minSdkVersion

23

Device API level

34

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions