Skip to content

Added compiling target Android support #982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ objects = \
kernel-shared/uuid-tree.o \
kernel-shared/volumes.o \
kernel-shared/zoned.o \
pthread/btrfs_pthread.o \
common/array.o \
common/cpu-utils.o \
common/device-scan.o \
Expand Down Expand Up @@ -292,7 +293,7 @@ tune_objects = tune/main.o tune/seeding.o tune/change-uuid.o tune/change-metadat
all_objects = $(objects) $(cmds_objects) $(libbtrfs_objects) $(convert_objects) \
$(mkfs_objects) $(image_objects) $(tune_objects) $(libbtrfsutil_objects)

tags_files = $(addsuffix /*.[ch], . check cmds common convert crypto image include mkfs tune \
tags_files = $(addsuffix /*.[ch], . check cmds common convert crypto image include mkfs pthread tune \
kernel-lib kernel-shared kernel-shared/uapi \
libbtrfs libbtrfsutil libbtrfsutil/python tests)

Expand Down Expand Up @@ -928,6 +929,7 @@ clean: $(CLEANDIRS)
libbtrfs/*.o libbtrfs/.deps/*.o.d \
libbtrfsutil/*.o libbtrfsutil/.deps/*.o.d \
mkfs/*.o mkfs/.deps/*.o.d \
pthread/*.o pthread/.deps/*.o.d \
tune/*.o tune/.deps/*.o.d
$(Q)$(RM) -fd -- .deps */.deps */*/.deps
@echo "Cleaning test targets"
Expand Down
2 changes: 1 addition & 1 deletion cmds/rescue-chunk-recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <errno.h>
#include <stddef.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion cmds/scrub.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <poll.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <ctype.h>
#include <signal.h>
#include <stdarg.h>
Expand Down
2 changes: 1 addition & 1 deletion cmds/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <getopt.h>
#include <limits.h>
#include <errno.h>
Expand Down
2 changes: 1 addition & 1 deletion common/task-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include <sys/timerfd.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
Expand Down
2 changes: 1 addition & 1 deletion common/task-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "kerncompat.h"
#include <time.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"

struct periodic_info {
int timer_fd;
Expand Down
2 changes: 1 addition & 1 deletion convert/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <stdbool.h>
#include <errno.h>
#include <limits.h>
Expand Down
2 changes: 1 addition & 1 deletion convert/source-ext2.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <sys/stat.h>
#include <linux/limits.h>
#include <errno.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion convert/source-fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "kerncompat.h"
#include <sys/types.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include "kernel-shared/uapi/btrfs_tree.h"
#include "convert/common.h"

Expand Down
2 changes: 1 addition & 1 deletion image/image-create.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <zlib.h>
#include "kernel-lib/list.h"
#include "kernel-lib/rbtree.h"
Expand Down
2 changes: 1 addition & 1 deletion image/image-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <zlib.h>
#include "kernel-lib/list.h"
#include "kernel-lib/rbtree.h"
Expand Down
2 changes: 1 addition & 1 deletion image/metadump.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define __BTRFS_IMAGE_METADUMP_H__

#include "kerncompat.h"
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include "kernel-lib/list.h"
#include "kernel-lib/sizes.h"
#include "kernel-shared/ctree.h"
Expand Down
2 changes: 1 addition & 1 deletion mkfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include <pthread.h>
#include "pthread/btrfs_pthread.h"
#include <uuid/uuid.h>
#include <blkid/blkid.h>
#include "kernel-lib/list.h"
Expand Down
40 changes: 40 additions & 0 deletions pthread/btrfs_pthread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "include/config.h"

#ifdef __ANDROID__

/* Workaround for `pthread_cancel()` in Android, using `pthread_kill()` instead,
* as Android NDK does not support `pthread_cancel()`.
*/

#include <string.h>
#include <signal.h>
#include "btrfs_pthread.h"

int pthread_setcanceltype(int type, int *oldtype) { return 0; }
int pthread_setcancelstate(int state, int *oldstate) { return 0; }
int pthread_cancel(pthread_t thread_id) {
int status;
if ((status = btrfs_set_thread_exit_handler()) == 0) {
status = pthread_kill(thread_id, SIGUSR1);
}
return status;
}

void btrfs_thread_exit_handler(int sig) {
pthread_exit(0);
}

int btrfs_set_thread_exit_handler() {
int rc;
struct sigaction actions;

memset(&actions, 0, sizeof(actions));
sigemptyset(&actions.sa_mask);
actions.sa_flags = 0;
actions.sa_handler = btrfs_thread_exit_handler;

rc = sigaction(SIGUSR1, &actions, NULL);
return rc;
}

#endif
24 changes: 24 additions & 0 deletions pthread/btrfs_pthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "include/config.h"

#include <pthread.h>

#ifdef __ANDROID__

/* Adding missing `pthread` related definitions in Android.
*/

#define PTHREAD_CANCELED ((void *) -1)

#define PTHREAD_CANCEL_DEFERRED 0
#define PTHREAD_CANCEL_ASYNCHRONOUS 0
#define PTHREAD_CANCEL_ENABLE 0
#define PTHREAD_CANCEL_DISABLE 0

int pthread_setcanceltype(int type, int *oldtype);
int pthread_setcancelstate(int state, int *oldstate);
int pthread_cancel(pthread_t thread_id);

int btrfs_set_thread_exit_handler();
void btrfs_thread_exit_handler(int sig);

#endif
8 changes: 8 additions & 0 deletions pthread/pthread.sym
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PTHREAD_0.1 {
global:
pthread_setcanceltype; /* used */
pthread_setcancelstate; /* used */
pthread_cancel; /* used */
local:
*;
};
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this needed? The file is not used anywhere.

Copy link
Author

Choose a reason for hiding this comment

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

It's for debugging pthread