Commit 67e2a472 authored by topjohnwu's avatar topjohnwu

Fix xxread false negatives

Fix #3710
parent f5c2d724
...@@ -27,6 +27,6 @@ android.injected.testOnly=false ...@@ -27,6 +27,6 @@ android.injected.testOnly=false
kapt.incremental.apt=true kapt.incremental.apt=true
# Magisk # Magisk
magisk.versionCode=21301 magisk.versionCode=21302
magisk.ndkVersion=21d magisk.ndkVersion=21d
magisk.fullNdkVersion=21.3.6528147 magisk.fullNdkVersion=21.3.6528147
#include <sched.h> #include <sched.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <pthread.h> #include <pthread.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -82,11 +80,20 @@ ssize_t xread(int fd, void *buf, size_t count) { ...@@ -82,11 +80,20 @@ ssize_t xread(int fd, void *buf, size_t count) {
// Read exact same size as count // Read exact same size as count
ssize_t xxread(int fd, void *buf, size_t count) { ssize_t xxread(int fd, void *buf, size_t count) {
int ret = read(fd, buf, count); size_t read_sz = 0;
if (count != ret) { int ret = -1;
PLOGE("read (%zu != %d)", count, ret); while (read_sz != count && ret != 0) {
ret = read(fd, buf, count);
if (ret < 0) {
PLOGE("read");
return ret;
}
read_sz += ret;
} }
return ret; if (read_sz != count) {
PLOGE("read (%zu != %zu)", count, read_sz);
}
return read_sz;
} }
int xpipe2(int pipefd[2], int flags) { int xpipe2(int pipefd[2], int flags) {
...@@ -242,7 +249,7 @@ ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags) { ...@@ -242,7 +249,7 @@ ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags) {
return rec; return rec;
} }
int xpthread_create(pthread_t *thread, const pthread_attr_t *attr, int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg) { void *(*start_routine) (void *), void *arg) {
errno = pthread_create(thread, attr, start_routine, arg); errno = pthread_create(thread, attr, start_routine, arg);
if (errno) { if (errno) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment