This commit is contained in:
启星
2025-08-12 14:27:12 +08:00
parent 9d18b353b1
commit 1bd5e77c45
8785 changed files with 978163 additions and 2 deletions

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>aosl.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_armv7</string>
<key>LibraryPath</key>
<string>aosl.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>armv7</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>

View File

@@ -0,0 +1,77 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : May 30th, 2023
* Module: AOSL async result object header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 ~ 2023 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_ARES_H__
#define __AOSL_ARES_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#include <aosl/api/aosl_ref.h>
#include <aosl/api/aosl_poll.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Create an async result object.
* Parameter:
* arg: the parameter attached with the async result object;
* Return value:
* the async result object ref id just created, AOSL_REF_INVALID when failed.
**/
extern __aosl_api__ aosl_ref_t aosl_ares_create (void *arg);
/**
* Complete the specified async result object.
* Parameters:
* ref: the async result object ref id;
* result: a result value which can be retrieved by wait function;
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: successful;
**/
extern __aosl_api__ int aosl_ares_complete (aosl_ref_t ref, intptr_t result);
/**
* Wait the specified async result object to complete.
* Parameters:
* ref: the async result object ref id;
* timeo: maximum waiting time in milliseconds;
* result: variable address for the value which was set by complete function,
* NOTE: the *result only will be set when the return value of wait
* function is AOSL_POLL_ST_SIGNALED and result != NULL, if you
* do not care the complete result, just passing NULL to it;
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: AOSL_POLL_ST_* macros value;
**/
extern __aosl_api__ int aosl_ares_wait (aosl_ref_t ref, intptr_t timeo, intptr_t *result);
/**
* Reset the specified async result object to non signaled state.
* Parameters:
* ref: the async result object ref id
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: successful;
**/
extern __aosl_api__ int aosl_ares_reset (aosl_ref_t ref);
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_ARES_H__ */

View File

@@ -0,0 +1,179 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jul 21st, 2018
* Module: AOSL common definitions header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_DEFS_H__
#define __AOSL_DEFS_H__
#ifdef _MSC_VER
/* C4200: nonstandard extension used: zero sized array */
#pragma warning (disable: 4200)
/* C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax */
#pragma warning (disable: 4576)
#endif
#define aosl_stringify_1(x) #x
#define aosl_stringify(x) aosl_stringify_1(x)
#ifndef __MAKERCORE_ASSEMBLY__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#ifndef __inline__
#define __inline__ __inline
#endif
#endif
#ifndef container_of
#if defined (__GNUC__)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (void *)(ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#else
#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type,member)))
#endif
#endif
#define aosl_rela_addr(type, field) (&((type *)0)->field)
#define aosl_base_addr(ptr, type, field) \
((type *)((uintptr_t)(ptr) - (uintptr_t)(&((type *)0)->field)))
#define aosl_min(x, y) ((x) < (y) ? (x) : (y))
#define aosl_max(x, y) ((x) > (y) ? (x) : (y))
/* I think 64 args is big enough */
#define AOSL_VAR_ARGS_MAX 64
#ifdef BUILD_TARGET_SHARED
#if defined (__GNUC__)
#define __export_in_so__ __attribute__ ((visibility ("default")))
#elif defined (_MSC_VER)
#define __export_in_so__ __declspec (dllexport)
#endif
#else
#define __export_in_so__
#endif
#ifndef __aosl_api__
#if defined (_MSC_VER) && defined (BUILDING_API_IMPL_SOURCE) && defined (BUILD_TARGET_SHARED)
#define __aosl_api__ __declspec (dllexport)
#elif defined (_MSC_VER) && !defined (BUILDING_API_IMPL_SOURCE)
#define __aosl_api__ __declspec (dllimport)
#else
#define __aosl_api__
#endif
#endif
#if defined (BUILDING_API_IMPL_SOURCE) || defined (STATIC_LINKING_AOSL)
#if defined (__GNUC__)
#define __so_api__ __attribute__ ((visibility ("default")))
#elif defined (_MSC_VER)
#define __so_api__ __declspec (dllexport)
#else
#define __so_api__
#endif
#else
#if defined (_MSC_VER)
#define __so_api__ __declspec (dllimport)
#else
#define __so_api__
#endif
#endif
#ifdef __GNUC__
#ifndef __MACH__
#define AOSL_DEFINE_BIN(v, f) \
__asm__ (".section .rodata\n\t" \
".globl "#v"_bin_begin\n\t" \
".hidden "#v"_bin_begin\n\t" \
".align 4\n\t" \
#v"_bin_begin:\n\t" \
".incbin \"" aosl_stringify(MAKERCORE_THIS_FILE_DIR/f)"\"\n\t" \
".globl "#v"_bin_end\n\t" \
".hidden "#v"_bin_end\n\t" \
#v"_bin_end:\n\t" \
".previous\n\t")
#else
#define AOSL_DEFINE_BIN(v, f) \
__asm__ (".section __TEXT,__const\n\t" \
".globl _"#v"_bin_begin\n\t" \
".private_extern _"#v"_bin_begin\n\t" \
".align 4\n\t" \
"_"#v"_bin_begin:\n\t" \
".incbin \"" aosl_stringify (MAKERCORE_THIS_FILE_DIR/f) "\"\n\t" \
".globl _"#v"_bin_end\n\t" \
".private_extern _"#v"_bin_end\n\t" \
"_"#v"_bin_end:\n\t" \
".previous\n\t")
#endif
#define AOSL_DECLARE_BIN(v) extern unsigned char v##_bin_begin, v##_bin_end
#define AOSL_BIN_ADDR(v) ((void *)&v##_bin_begin)
#define AOSL_BIN_SIZE(v) ((size_t)((unsigned char *)&v##_bin_end - (unsigned char *)&v##_bin_begin))
#endif
#ifdef __cplusplus
}
#endif
#else /* __MAKERCORE_ASSEMBLY__ */
#ifdef __GNUC__
#ifndef __MACH__
.macro AOSL_DEFINE_BIN_S v, f
.section .rodata
.globl \v\()_bin_begin
.hidden \v\()_bin_begin
.align 4
\v\()_bin_begin:
.incbin aosl_stringify (MAKERCORE_THIS_FILE_DIR/\f)
.globl \v\()_bin_end
.hidden \v\()_bin_end
\v\()_bin_end:
.previous
.endm
#else
.macro AOSL_DEFINE_BIN_S v, f
.section __TEXT,__const
.globl _\()\v\()_bin_begin
.private_extern _\()\v\()_bin_begin
.align 4
_\()\v\()_bin_begin:
.incbin aosl_stringify (MAKERCORE_THIS_FILE_DIR/\f)
.globl _\()\v\()_bin_end
.private_extern _\()\v\()_bin_end
_\()\v\()_bin_end:
.previous
.endm
#endif
#endif
#endif /* __MAKERCORE_ASSEMBLY__ */
#endif /* __AOSL_DEFS_H__ */

View File

@@ -0,0 +1,91 @@
/*************************************************************
* Author : Lionfore Hao (haolianfu@agora.io)
* Date : Jul 30th, 2020
* Module : AOSL errno definition header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2020 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_ERRNO_H__
#define __AOSL_ERRNO_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined (__linux__) || defined (__MACH__) || defined (_WIN32) || defined (__kliteos__) || defined (__kliteos2__)
#define _AOSL_HAVING_OS_ERRNO
#endif
#if defined (__linux__) || defined (__MACH__) || defined (__kliteos__) || defined (__kliteos2__)
#define _AOSL_USING_OS_ERRNO
#endif
#ifdef _AOSL_USING_OS_ERRNO
#define aosl_errno_ptr() (&errno)
#else
extern __aosl_api__ int *aosl_errno_ptr (void);
#endif
#ifdef _AOSL_HAVING_OS_ERRNO
#include <errno.h>
#define aosl_strerror(err) strerror (err)
#else
/**
* PLEASE BE CAREFUL ENOUGH HERE:
* The macro __kspreadtrum__ is not a compiler toolchain
* predefined macro, and makercore building system will
* define this macro when building Spreadtrum system, so
* you must GUARANTEE define it when not using makercore
* building system.
* Use this style name rather than Kbuild CONFIG_* just
* want to keep consistent with __linux__/__MACH__ etc.
* -- Lionfore Hao Aug 1st, 2020
**/
#if defined (__kspreadtrum__)
#include <DAPS/export/inc/tcpip6/socket_types.h>
#endif
#define errno (*aosl_errno_ptr ())
extern __aosl_api__ char *aosl_strerror (int errnum);
#endif
#define aosl_errno (*aosl_errno_ptr ())
/**
* Check whether a value returned by aosl api is an error code.
* Parameters:
* err: the value returned by one of aosl api;
* Return Value:
* 1: this value is an error code;
* 0: this value is normal, not an error;
*/
extern __aosl_api__ int aosl_is_err (intptr_t err);
/**
* Convert an error code to aosl_errno value.
* Parameters:
* err: the error code value returned by one of aosl api;
* Return Value:
* the corresponding aosl_errno value;
*/
extern __aosl_api__ int aosl_err_to_errno (intptr_t err);
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_ERRNO_H__ */

View File

@@ -0,0 +1,51 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : May 30th, 2023
* Module: AOSL poll functionality definition header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 ~ 2023 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_POLL_H__
#define __AOSL_POLL_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#include <aosl/api/aosl_ref.h>
#ifdef __cplusplus
extern "C" {
#endif
#define AOSL_POLL_ST_NONE 0
#define AOSL_POLL_ST_SIGNALED 1
#define AOSL_POLL_ST_DESTROY 2
/**
* Poll the objects specified in refs, return their states.
* Parameters:
* refs: the object refs array for input, and the signaled refs array for output;
* count: the number of items for input refs array;
* min: the minimum number of signaled refs for triggering waken up.
* NOTE: if any one of the refs encounters error or destroy,
* then wake up immediately regardless min parameter.
* timeo: maximum waiting time in milliseconds;
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: the signaled refs count before timeout;
**/
extern __aosl_api__ ssize_t aosl_poll (aosl_ref_t refs [], size_t count, size_t min, intptr_t timeo);
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_POLL_H__ */

View File

@@ -0,0 +1,331 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Nov 19th, 2018
* Module: AOSL reference object definition file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_REF_H__
#define __AOSL_REF_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _internal_ref_od_ *aosl_ref_t;
#define AOSL_REF_INVALID ((aosl_ref_t)(intptr_t)NULL)
#define aosl_ref_invalid(ref) ((intptr_t)(ref) <= 0)
/**
* The reference object destructor function prototype, which invoked when application
* calling aosl_ref_destroy functions to release resources.
* Parameter:
* arg: the parameter passed in when creating the reference object;
* Return value:
* none.
**/
typedef void (*aosl_ref_dtor_t) (void *arg);
/**
* The reference object creating function prototype, which is used to create a ref object.
* Parameters:
* arg: the parameter attached with the reference object;
* dtor: the ref object destructor function, which will be invoked when
* the ref object is deleted;
* caller_free:
* none-0 guarantee the ref object relatives must be freed in the caller thread
* 0 the ref object relatives could be freed in any thread
* Return value:
* the ref object id, please use aosl_ref_invalid macro to check whether failed.
**/
extern __aosl_api__ aosl_ref_t aosl_ref_create (void *arg, aosl_ref_dtor_t dtor, int caller_free);
/**
* The ref object callback function prototype.
* Parameters:
* arg: the ref object argument which was passed in when creating;
* argc: specify the argv array elements count, the same as the argc
* when invoking aosl_ref_[get|read|write] functions;
* argv: array for passing variable args, the same as the args
* when invoking aosl_task_exec_* functions;
* Return value:
* none.
**/
typedef void (*aosl_ref_func_t) (void *arg, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object, and invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_hold (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_hold_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_hold_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object and read lock it, then invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_read (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_read_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_read_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object and write lock it, then invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_write (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_write_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_write_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object and set it unsafe, then invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_unsafe (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_unsafe_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_unsafe_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object and set it maystall, then invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_maystall (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_maystall_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_maystall_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
typedef void *aosl_refobj_t;
#define AOSL_FREE_ONLY_OBJ ((aosl_refobj_t)(uintptr_t)1)
#define aosl_is_free_only(robj) ((int)((aosl_refobj_t)(robj) == AOSL_FREE_ONLY_OBJ))
/**
* Retrieve the ref object arg.
* Parameter:
* robj: the reference object;
* Return value:
* the ref object arg;
**/
extern __aosl_api__ void *aosl_refobj_arg (aosl_refobj_t robj);
/**
* Get the ref id of the specified ref object.
* Parameter:
* robj: the reference object;
* Return value:
* the ref id.
**/
extern __aosl_api__ aosl_ref_t aosl_refobj_id (aosl_refobj_t robj);
/**
* Make sure read lock the ref object specified by robj, then invoke the specified callback function.
* Parameters:
* robj: the ref object itself;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_refobj_read (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_refobj_read_args (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_refobj_read_argv (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Make sure set the ref object specified by robj unsafe, then invoke the specified callback function.
* Parameters:
* robj: the ref object itself;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_refobj_unsafe (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_refobj_unsafe_args (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_refobj_unsafe_argv (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Make sure set the ref object specified by robj maystall, then invoke the specified callback function.
* Parameters:
* robj: the ref object itself;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_refobj_maystall (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_refobj_maystall_args (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_refobj_maystall_argv (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Detect whether the reference object specified by ref is read locked
* by the calling thread.
* Parameter:
* ref: the reference object id
* Return value:
* 0: not read locked
* none zero: read locked by calling thread
**/
extern __aosl_api__ int aosl_ref_locked (aosl_ref_t ref);
/**
* Set the living scope ref object of the specified ref object.
* Parameters:
* ref: the ref object ref id;
* scope_ref: the living scope ref, the ref object will be destroyed
* when the object specified by scope_ref was destroyed;
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: successful;
**/
extern __aosl_api__ int aosl_ref_set_scope (aosl_ref_t ref, aosl_ref_t scope_ref);
/**
* Destroy the reference object specified by ref.
* Parameters:
* ref: the reference object id
* do_delete: 0 for just marking it destroyed
* non-0 value for deleting it
* Return value:
* 0: success
* <0: failed, and aosl_errno indicates what error occurs
**/
extern __aosl_api__ int aosl_ref_destroy (aosl_ref_t ref, int do_delete);
/**
* The proto for a ref destroy async exec callback function.
* Parameters:
* err: 0 for destroy ref object successfully, <0 for error code;
* argc: the args count passed by exec series functions;
* argv: args vector passed by exec series functions;
* Return value:
* none.
**/
typedef void (*aosl_ref_destroy_exec_f) (int err, uintptr_t argc, uintptr_t argv []);
/**
* Execute the specified function asynchronously in thread pool before destroying
* the reference object specified by ref, this function supports coroutine.
* Parameters:
* ref: the reference object id;
* ares: ares object if you want to wait the execution of function f,
* specify AOSL_REF_INVALID when you do not want to wait;
* f: the target function which will be executed in thread pool
* after destroyed the ref object;
* argc: the args count;
* ...: variable args;
* Return value:
* 0: success
* <0: failed, and aosl_errno indicates what error occurs
* Remarks:
* If ares is AOSL_REF_INVALID and the invoking thread is an mpq thread,
* then this function will support coroutine resume mechanism.
**/
extern __aosl_api__ int aosl_ref_destroy_exec (aosl_ref_t ref, aosl_ref_t ares, aosl_ref_destroy_exec_f f, uintptr_t argc, ...);
/**
* Execute the specified function asynchronously in thread pool before destroying
* the reference object specified by ref, this function supports coroutine.
* Parameters:
* ref: the reference object id;
* ares: ares object if you want to wait the execution of function f,
* specify AOSL_REF_INVALID when you do not want to wait;
* f: the target function which will be executed in thread pool
* after destroyed the ref object;
* argc: the args count;
* args: variable args;
* Return value:
* 0: success
* <0: failed, and aosl_errno indicates what error occurs
* Remarks:
* If ares is AOSL_REF_INVALID and the invoking thread is an mpq thread,
* then this function will support coroutine resume mechanism.
**/
extern __aosl_api__ int aosl_ref_destroy_exec_args (aosl_ref_t ref, aosl_ref_t ares, aosl_ref_destroy_exec_f f, uintptr_t argc, va_list args);
/**
* Execute the specified function asynchronously in thread pool before destroying
* the reference object specified by ref, this function supports coroutine.
* Parameters:
* ref: the reference object id;
* ares: ares object if you want to wait the execution of function f,
* specify AOSL_REF_INVALID when you do not want to wait;
* f: the target function which will be executed in thread pool
* after destroyed the ref object;
* argc: the args count;
* argv: variable args vector;
* Return value:
* 0: success
* <0: failed, and aosl_errno indicates what error occurs
* Remarks:
* If ares is AOSL_REF_INVALID and the invoking thread is an mpq thread,
* then this function will support coroutine resume mechanism.
**/
extern __aosl_api__ int aosl_ref_destroy_exec_argv (aosl_ref_t ref, aosl_ref_t ares, aosl_ref_destroy_exec_f f, uintptr_t argc, uintptr_t argv []);
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_REF_H__ */

View File

@@ -0,0 +1,122 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jul 27th, 2020
* Module: AOSL POSIX definitions header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2020 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_TYPES_H__
#define __AOSL_TYPES_H__
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <inttypes.h>
#if defined (__linux__) || defined (__MACH__) || defined (__kliteos2__) || defined (_WIN32)
#include <sys/types.h>
#if defined (__linux__) || defined (__MACH__)
#include <sys/uio.h>
#endif
#endif
#include <aosl/api/aosl_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#if !defined (__linux__) && !defined (__MACH__)
/**
* Worry about some guy would like to define a macro
* for this type, so confirm that it is not a macro.
* -- Lionfore Hao Nov 5th, 2018
**/
#ifndef __ssize_t_defined
typedef intptr_t ssize_t;
#define __ssize_t_defined
#endif
#endif
/* The AOSL timestamp type */
typedef unsigned long long aosl_ts_t;
/* The proto for a general aosl var args function with argc & argv. */
typedef void (*aosl_argv_f) (uintptr_t argc, uintptr_t argv []);
/* The proto for a general aosl object destructor function. */
typedef aosl_argv_f aosl_obj_dtor_t;
#if !defined (_WIN32) && !defined (__kspreadtrum__)
typedef int aosl_fd_t;
#define AOSL_INVALID_FD ((aosl_fd_t)-1)
static __inline__ int aosl_fd_invalid (aosl_fd_t fd)
{
return (int)(fd < 0);
}
#else
#if defined (_WIN32)
/**
* We MUST include 'winsock2.h' before any occurrence
* of including 'windows.h', the fucking Windows has
* the fucking issue that many definitions would be
* complained redefinition if not so.
* -- Lionfore Hao Sep 25th, 2018
**/
#include <winsock2.h>
#include <windows.h>
typedef HANDLE aosl_fd_t;
#define AOSL_INVALID_FD ((aosl_fd_t)INVALID_HANDLE_VALUE)
#elif defined (__kspreadtrum__)
#include <DAPS/export/inc/tcpip6/socket_types.h>
#include <DAPS/export/inc/tcpip6/socket_api.h>
typedef TCPIP_SOCKET_T aosl_fd_t;
#define AOSL_INVALID_FD ((aosl_fd_t)-1)
#endif
static __inline__ int aosl_fd_invalid (aosl_fd_t fd)
{
return (int)(fd == AOSL_INVALID_FD);
}
#endif
#ifndef _WIN32
typedef aosl_fd_t aosl_sk_t;
#define AOSL_INVALID_SK AOSL_INVALID_FD
#else
typedef SOCKET aosl_sk_t;
#define AOSL_INVALID_SK ((aosl_sk_t)INVALID_SOCKET)
#endif
#if !defined (_WIN32) && !defined (__kspreadtrum__)
typedef struct iovec aosl_miov_t;
#else
typedef struct {
void *iov_base;
size_t iov_len;
} aosl_miov_t;
#endif
#ifndef UIO_MAXIOV
#define UIO_MAXIOV 1024
#endif
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_TYPES_H__ */

View File

@@ -0,0 +1,35 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jul 26th, 2018
* Module: AOSL version definitions.
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 Agora IO
* All rights reserved.
*
************************************************************/
#ifndef __AOSL_VERSION_H__
#define __AOSL_VERSION_H__
#include <aosl/api/aosl_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
extern __aosl_api__ const char *aosl_get_version ();
extern __aosl_api__ const char *aosl_get_git_branch ();
extern __aosl_api__ const char *aosl_get_git_commit ();
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_VERSION_H__ */

View File

@@ -0,0 +1,91 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jun 23rd, 2023
* Module: AOSL async result object for C++ definition file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 ~ 2023 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_ARES_CLASS_H__
#define __AOSL_ARES_CLASS_H__
#include <stdlib.h>
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#include <aosl/api/aosl_ref.h>
#include <aosl/api/aosl_ares.h>
#include <aosl/api/cpp/aosl_ref_class.h>
class aosl_ares_class: public aosl_ref_class {
public:
aosl_ares_class (): aosl_ref_class (aosl_ares_create (this))
{
if (aosl_ref_invalid (ref ()))
abort ();
}
/**
* The destructor of this class is very different with
* base class and other derivatives, destroy the ref
* in the destructor and the destructor is public.
**/
virtual ~aosl_ares_class ()
{
aosl_ref_t refid = ref ();
if (!aosl_ref_invalid (refid))
aosl_ref_destroy (refid, true);
}
/* complete the async result */
int complete (intptr_t result = 0)
{
return aosl_ares_complete (ref (), result);
}
/* wait the async result to be completed */
int wait (intptr_t timeo, intptr_t *result = NULL)
{
return aosl_ares_wait (ref (), timeo, result);
}
/* reset the signaled state */
int reset (void)
{
return aosl_ares_reset (ref ());
}
operator aosl_ref_t () const
{
return ref ();
}
private:
/* we do not allow invoke the destroy function of base class */
int destroy (bool do_delete = true)
{
abort ();
return 0;
}
#if (__cplusplus >= 201103) || (defined (_MSC_VER) && _MSC_VER >= 1800)
private:
aosl_ares_class (const aosl_ares_class &) = delete;
aosl_ares_class (aosl_ares_class &&) = delete;
aosl_ares_class &operator = (const aosl_ares_class &) = delete;
aosl_ares_class &operator = (aosl_ares_class &&) = delete;
#else
private:
aosl_ares_class (const aosl_ares_class &);
aosl_ares_class &operator = (const aosl_ares_class &);
#endif /* C++11 */
};
#endif /* __AOSL_ARES_CLASS_H__ */

View File

@@ -0,0 +1,134 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jun 23rd, 2023
* Module: AOSL poll functionality for C++ definition file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 ~ 2023 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_POLL_CLASS_H__
#define __AOSL_POLL_CLASS_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#include <aosl/api/aosl_ref.h>
#include <aosl/api/aosl_poll.h>
#include <aosl/api/cpp/aosl_ares_class.h>
#if (__cplusplus >= 201103) || (defined (_MSC_VER) && _MSC_VER >= 1800)
#include <memory>
#endif
#include <map>
#include <vector>
class aosl_poll_class {
private:
std::map<aosl_ref_t, const aosl_ares_class *> poll_refs;
std::vector<const aosl_ares_class *> signaled_refs;
public:
void add (const aosl_ares_class &tail)
{
poll_refs [tail.ref ()] = &tail;
}
#if (__cplusplus >= 201103) || (defined (_MSC_VER) && _MSC_VER >= 1800)
template <class T, class ...Targs>
void add (const T &head, const Targs&... rest)
{
poll_refs [head.ref ()] = &head;
add (rest...);
}
/* constructor with variable args */
template <class ...Targs>
aosl_poll_class (Targs&... args)
{
add (args...);
}
#endif /* C++11 */
aosl_poll_class (const aosl_ares_class * const areses [], size_t count)
{
size_t i;
for (i = 0; i < count; i++)
add (*areses [i]);
}
/* poll the constructed async results */
int poll (size_t min, intptr_t timeo)
{
aosl_ref_t local_refs [32];
aosl_ref_t *refs = local_refs;
size_t count = poll_refs.size ();
std::map<aosl_ref_t, const aosl_ares_class *>::iterator it;
int i;
int err;
if (count > sizeof local_refs / sizeof local_refs [0]) {
refs = new aosl_ref_t [count];
if (refs == NULL)
return -1;
}
i = 0;
for (it = poll_refs.begin (); it != poll_refs.end (); it++)
refs [i++] = it->first;
err = aosl_poll (refs, count, min, timeo);
signaled_refs.clear ();
for (i = 0; i < err; i++) {
it = poll_refs.find (refs [i]);
if (it != poll_refs.end ())
signaled_refs.push_back (it->second);
}
if (refs != local_refs)
delete [] refs;
return err;
}
/* total async results count */
size_t total ()
{
return poll_refs.size ();
}
/* signaled async results count */
size_t signaled ()
{
return signaled_refs.size ();
}
/* operator for accessing the signaled async results */
const aosl_ares_class *operator [] (size_t idx)
{
if (idx < signaled_refs.size ())
return signaled_refs [idx];
return NULL;
}
#if (__cplusplus >= 201103) || (defined (_MSC_VER) && _MSC_VER >= 1800)
private:
aosl_poll_class (const aosl_poll_class &) = delete;
aosl_poll_class (aosl_poll_class &&) = delete;
aosl_poll_class &operator = (const aosl_poll_class &) = delete;
aosl_poll_class &operator = (aosl_poll_class &&) = delete;
#else
private:
aosl_poll_class (const aosl_poll_class &);
aosl_poll_class &operator = (const aosl_poll_class &);
#endif
};
#endif /* __AOSL_POLL_CLASS_H__ */

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>aosl</string>
<key>CFBundleIdentifier</key>
<string>io.agora.aosl</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>aosl</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.2.13</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2022 Agora IO. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@@ -0,0 +1,77 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : May 30th, 2023
* Module: AOSL async result object header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 ~ 2023 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_ARES_H__
#define __AOSL_ARES_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#include <aosl/api/aosl_ref.h>
#include <aosl/api/aosl_poll.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Create an async result object.
* Parameter:
* arg: the parameter attached with the async result object;
* Return value:
* the async result object ref id just created, AOSL_REF_INVALID when failed.
**/
extern __aosl_api__ aosl_ref_t aosl_ares_create (void *arg);
/**
* Complete the specified async result object.
* Parameters:
* ref: the async result object ref id;
* result: a result value which can be retrieved by wait function;
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: successful;
**/
extern __aosl_api__ int aosl_ares_complete (aosl_ref_t ref, intptr_t result);
/**
* Wait the specified async result object to complete.
* Parameters:
* ref: the async result object ref id;
* timeo: maximum waiting time in milliseconds;
* result: variable address for the value which was set by complete function,
* NOTE: the *result only will be set when the return value of wait
* function is AOSL_POLL_ST_SIGNALED and result != NULL, if you
* do not care the complete result, just passing NULL to it;
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: AOSL_POLL_ST_* macros value;
**/
extern __aosl_api__ int aosl_ares_wait (aosl_ref_t ref, intptr_t timeo, intptr_t *result);
/**
* Reset the specified async result object to non signaled state.
* Parameters:
* ref: the async result object ref id
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: successful;
**/
extern __aosl_api__ int aosl_ares_reset (aosl_ref_t ref);
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_ARES_H__ */

View File

@@ -0,0 +1,179 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jul 21st, 2018
* Module: AOSL common definitions header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_DEFS_H__
#define __AOSL_DEFS_H__
#ifdef _MSC_VER
/* C4200: nonstandard extension used: zero sized array */
#pragma warning (disable: 4200)
/* C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax */
#pragma warning (disable: 4576)
#endif
#define aosl_stringify_1(x) #x
#define aosl_stringify(x) aosl_stringify_1(x)
#ifndef __MAKERCORE_ASSEMBLY__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#ifndef __inline__
#define __inline__ __inline
#endif
#endif
#ifndef container_of
#if defined (__GNUC__)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (void *)(ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#else
#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type,member)))
#endif
#endif
#define aosl_rela_addr(type, field) (&((type *)0)->field)
#define aosl_base_addr(ptr, type, field) \
((type *)((uintptr_t)(ptr) - (uintptr_t)(&((type *)0)->field)))
#define aosl_min(x, y) ((x) < (y) ? (x) : (y))
#define aosl_max(x, y) ((x) > (y) ? (x) : (y))
/* I think 64 args is big enough */
#define AOSL_VAR_ARGS_MAX 64
#ifdef BUILD_TARGET_SHARED
#if defined (__GNUC__)
#define __export_in_so__ __attribute__ ((visibility ("default")))
#elif defined (_MSC_VER)
#define __export_in_so__ __declspec (dllexport)
#endif
#else
#define __export_in_so__
#endif
#ifndef __aosl_api__
#if defined (_MSC_VER) && defined (BUILDING_API_IMPL_SOURCE) && defined (BUILD_TARGET_SHARED)
#define __aosl_api__ __declspec (dllexport)
#elif defined (_MSC_VER) && !defined (BUILDING_API_IMPL_SOURCE)
#define __aosl_api__ __declspec (dllimport)
#else
#define __aosl_api__
#endif
#endif
#if defined (BUILDING_API_IMPL_SOURCE) || defined (STATIC_LINKING_AOSL)
#if defined (__GNUC__)
#define __so_api__ __attribute__ ((visibility ("default")))
#elif defined (_MSC_VER)
#define __so_api__ __declspec (dllexport)
#else
#define __so_api__
#endif
#else
#if defined (_MSC_VER)
#define __so_api__ __declspec (dllimport)
#else
#define __so_api__
#endif
#endif
#ifdef __GNUC__
#ifndef __MACH__
#define AOSL_DEFINE_BIN(v, f) \
__asm__ (".section .rodata\n\t" \
".globl "#v"_bin_begin\n\t" \
".hidden "#v"_bin_begin\n\t" \
".align 4\n\t" \
#v"_bin_begin:\n\t" \
".incbin \"" aosl_stringify(MAKERCORE_THIS_FILE_DIR/f)"\"\n\t" \
".globl "#v"_bin_end\n\t" \
".hidden "#v"_bin_end\n\t" \
#v"_bin_end:\n\t" \
".previous\n\t")
#else
#define AOSL_DEFINE_BIN(v, f) \
__asm__ (".section __TEXT,__const\n\t" \
".globl _"#v"_bin_begin\n\t" \
".private_extern _"#v"_bin_begin\n\t" \
".align 4\n\t" \
"_"#v"_bin_begin:\n\t" \
".incbin \"" aosl_stringify (MAKERCORE_THIS_FILE_DIR/f) "\"\n\t" \
".globl _"#v"_bin_end\n\t" \
".private_extern _"#v"_bin_end\n\t" \
"_"#v"_bin_end:\n\t" \
".previous\n\t")
#endif
#define AOSL_DECLARE_BIN(v) extern unsigned char v##_bin_begin, v##_bin_end
#define AOSL_BIN_ADDR(v) ((void *)&v##_bin_begin)
#define AOSL_BIN_SIZE(v) ((size_t)((unsigned char *)&v##_bin_end - (unsigned char *)&v##_bin_begin))
#endif
#ifdef __cplusplus
}
#endif
#else /* __MAKERCORE_ASSEMBLY__ */
#ifdef __GNUC__
#ifndef __MACH__
.macro AOSL_DEFINE_BIN_S v, f
.section .rodata
.globl \v\()_bin_begin
.hidden \v\()_bin_begin
.align 4
\v\()_bin_begin:
.incbin aosl_stringify (MAKERCORE_THIS_FILE_DIR/\f)
.globl \v\()_bin_end
.hidden \v\()_bin_end
\v\()_bin_end:
.previous
.endm
#else
.macro AOSL_DEFINE_BIN_S v, f
.section __TEXT,__const
.globl _\()\v\()_bin_begin
.private_extern _\()\v\()_bin_begin
.align 4
_\()\v\()_bin_begin:
.incbin aosl_stringify (MAKERCORE_THIS_FILE_DIR/\f)
.globl _\()\v\()_bin_end
.private_extern _\()\v\()_bin_end
_\()\v\()_bin_end:
.previous
.endm
#endif
#endif
#endif /* __MAKERCORE_ASSEMBLY__ */
#endif /* __AOSL_DEFS_H__ */

View File

@@ -0,0 +1,91 @@
/*************************************************************
* Author : Lionfore Hao (haolianfu@agora.io)
* Date : Jul 30th, 2020
* Module : AOSL errno definition header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2020 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_ERRNO_H__
#define __AOSL_ERRNO_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined (__linux__) || defined (__MACH__) || defined (_WIN32) || defined (__kliteos__) || defined (__kliteos2__)
#define _AOSL_HAVING_OS_ERRNO
#endif
#if defined (__linux__) || defined (__MACH__) || defined (__kliteos__) || defined (__kliteos2__)
#define _AOSL_USING_OS_ERRNO
#endif
#ifdef _AOSL_USING_OS_ERRNO
#define aosl_errno_ptr() (&errno)
#else
extern __aosl_api__ int *aosl_errno_ptr (void);
#endif
#ifdef _AOSL_HAVING_OS_ERRNO
#include <errno.h>
#define aosl_strerror(err) strerror (err)
#else
/**
* PLEASE BE CAREFUL ENOUGH HERE:
* The macro __kspreadtrum__ is not a compiler toolchain
* predefined macro, and makercore building system will
* define this macro when building Spreadtrum system, so
* you must GUARANTEE define it when not using makercore
* building system.
* Use this style name rather than Kbuild CONFIG_* just
* want to keep consistent with __linux__/__MACH__ etc.
* -- Lionfore Hao Aug 1st, 2020
**/
#if defined (__kspreadtrum__)
#include <DAPS/export/inc/tcpip6/socket_types.h>
#endif
#define errno (*aosl_errno_ptr ())
extern __aosl_api__ char *aosl_strerror (int errnum);
#endif
#define aosl_errno (*aosl_errno_ptr ())
/**
* Check whether a value returned by aosl api is an error code.
* Parameters:
* err: the value returned by one of aosl api;
* Return Value:
* 1: this value is an error code;
* 0: this value is normal, not an error;
*/
extern __aosl_api__ int aosl_is_err (intptr_t err);
/**
* Convert an error code to aosl_errno value.
* Parameters:
* err: the error code value returned by one of aosl api;
* Return Value:
* the corresponding aosl_errno value;
*/
extern __aosl_api__ int aosl_err_to_errno (intptr_t err);
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_ERRNO_H__ */

View File

@@ -0,0 +1,51 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : May 30th, 2023
* Module: AOSL poll functionality definition header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 ~ 2023 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_POLL_H__
#define __AOSL_POLL_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#include <aosl/api/aosl_ref.h>
#ifdef __cplusplus
extern "C" {
#endif
#define AOSL_POLL_ST_NONE 0
#define AOSL_POLL_ST_SIGNALED 1
#define AOSL_POLL_ST_DESTROY 2
/**
* Poll the objects specified in refs, return their states.
* Parameters:
* refs: the object refs array for input, and the signaled refs array for output;
* count: the number of items for input refs array;
* min: the minimum number of signaled refs for triggering waken up.
* NOTE: if any one of the refs encounters error or destroy,
* then wake up immediately regardless min parameter.
* timeo: maximum waiting time in milliseconds;
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: the signaled refs count before timeout;
**/
extern __aosl_api__ ssize_t aosl_poll (aosl_ref_t refs [], size_t count, size_t min, intptr_t timeo);
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_POLL_H__ */

View File

@@ -0,0 +1,331 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Nov 19th, 2018
* Module: AOSL reference object definition file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_REF_H__
#define __AOSL_REF_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _internal_ref_od_ *aosl_ref_t;
#define AOSL_REF_INVALID ((aosl_ref_t)(intptr_t)NULL)
#define aosl_ref_invalid(ref) ((intptr_t)(ref) <= 0)
/**
* The reference object destructor function prototype, which invoked when application
* calling aosl_ref_destroy functions to release resources.
* Parameter:
* arg: the parameter passed in when creating the reference object;
* Return value:
* none.
**/
typedef void (*aosl_ref_dtor_t) (void *arg);
/**
* The reference object creating function prototype, which is used to create a ref object.
* Parameters:
* arg: the parameter attached with the reference object;
* dtor: the ref object destructor function, which will be invoked when
* the ref object is deleted;
* caller_free:
* none-0 guarantee the ref object relatives must be freed in the caller thread
* 0 the ref object relatives could be freed in any thread
* Return value:
* the ref object id, please use aosl_ref_invalid macro to check whether failed.
**/
extern __aosl_api__ aosl_ref_t aosl_ref_create (void *arg, aosl_ref_dtor_t dtor, int caller_free);
/**
* The ref object callback function prototype.
* Parameters:
* arg: the ref object argument which was passed in when creating;
* argc: specify the argv array elements count, the same as the argc
* when invoking aosl_ref_[get|read|write] functions;
* argv: array for passing variable args, the same as the args
* when invoking aosl_task_exec_* functions;
* Return value:
* none.
**/
typedef void (*aosl_ref_func_t) (void *arg, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object, and invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_hold (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_hold_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_hold_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object and read lock it, then invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_read (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_read_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_read_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object and write lock it, then invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_write (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_write_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_write_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object and set it unsafe, then invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_unsafe (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_unsafe_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_unsafe_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Hold the ref object and set it maystall, then invoke the specified callback function.
* Parameters:
* ref: the ref object id;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_ref_maystall (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_ref_maystall_args (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_ref_maystall_argv (aosl_ref_t ref, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
typedef void *aosl_refobj_t;
#define AOSL_FREE_ONLY_OBJ ((aosl_refobj_t)(uintptr_t)1)
#define aosl_is_free_only(robj) ((int)((aosl_refobj_t)(robj) == AOSL_FREE_ONLY_OBJ))
/**
* Retrieve the ref object arg.
* Parameter:
* robj: the reference object;
* Return value:
* the ref object arg;
**/
extern __aosl_api__ void *aosl_refobj_arg (aosl_refobj_t robj);
/**
* Get the ref id of the specified ref object.
* Parameter:
* robj: the reference object;
* Return value:
* the ref id.
**/
extern __aosl_api__ aosl_ref_t aosl_refobj_id (aosl_refobj_t robj);
/**
* Make sure read lock the ref object specified by robj, then invoke the specified callback function.
* Parameters:
* robj: the ref object itself;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_refobj_read (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_refobj_read_args (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_refobj_read_argv (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Make sure set the ref object specified by robj unsafe, then invoke the specified callback function.
* Parameters:
* robj: the ref object itself;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_refobj_unsafe (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_refobj_unsafe_args (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_refobj_unsafe_argv (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Make sure set the ref object specified by robj maystall, then invoke the specified callback function.
* Parameters:
* robj: the ref object itself;
* f: the callback function;
* argc: the args count
* ...: variable args
* Return value:
* 0: success
* <0: failure with aosl_errno set
**/
extern __aosl_api__ int aosl_refobj_maystall (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, ...);
extern __aosl_api__ int aosl_refobj_maystall_args (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, va_list args);
extern __aosl_api__ int aosl_refobj_maystall_argv (aosl_refobj_t robj, aosl_ref_func_t f, uintptr_t argc, uintptr_t argv []);
/**
* Detect whether the reference object specified by ref is read locked
* by the calling thread.
* Parameter:
* ref: the reference object id
* Return value:
* 0: not read locked
* none zero: read locked by calling thread
**/
extern __aosl_api__ int aosl_ref_locked (aosl_ref_t ref);
/**
* Set the living scope ref object of the specified ref object.
* Parameters:
* ref: the ref object ref id;
* scope_ref: the living scope ref, the ref object will be destroyed
* when the object specified by scope_ref was destroyed;
* Return value:
* <0: error occured, and aosl_errno indicates which error;
* >=0: successful;
**/
extern __aosl_api__ int aosl_ref_set_scope (aosl_ref_t ref, aosl_ref_t scope_ref);
/**
* Destroy the reference object specified by ref.
* Parameters:
* ref: the reference object id
* do_delete: 0 for just marking it destroyed
* non-0 value for deleting it
* Return value:
* 0: success
* <0: failed, and aosl_errno indicates what error occurs
**/
extern __aosl_api__ int aosl_ref_destroy (aosl_ref_t ref, int do_delete);
/**
* The proto for a ref destroy async exec callback function.
* Parameters:
* err: 0 for destroy ref object successfully, <0 for error code;
* argc: the args count passed by exec series functions;
* argv: args vector passed by exec series functions;
* Return value:
* none.
**/
typedef void (*aosl_ref_destroy_exec_f) (int err, uintptr_t argc, uintptr_t argv []);
/**
* Execute the specified function asynchronously in thread pool before destroying
* the reference object specified by ref, this function supports coroutine.
* Parameters:
* ref: the reference object id;
* ares: ares object if you want to wait the execution of function f,
* specify AOSL_REF_INVALID when you do not want to wait;
* f: the target function which will be executed in thread pool
* after destroyed the ref object;
* argc: the args count;
* ...: variable args;
* Return value:
* 0: success
* <0: failed, and aosl_errno indicates what error occurs
* Remarks:
* If ares is AOSL_REF_INVALID and the invoking thread is an mpq thread,
* then this function will support coroutine resume mechanism.
**/
extern __aosl_api__ int aosl_ref_destroy_exec (aosl_ref_t ref, aosl_ref_t ares, aosl_ref_destroy_exec_f f, uintptr_t argc, ...);
/**
* Execute the specified function asynchronously in thread pool before destroying
* the reference object specified by ref, this function supports coroutine.
* Parameters:
* ref: the reference object id;
* ares: ares object if you want to wait the execution of function f,
* specify AOSL_REF_INVALID when you do not want to wait;
* f: the target function which will be executed in thread pool
* after destroyed the ref object;
* argc: the args count;
* args: variable args;
* Return value:
* 0: success
* <0: failed, and aosl_errno indicates what error occurs
* Remarks:
* If ares is AOSL_REF_INVALID and the invoking thread is an mpq thread,
* then this function will support coroutine resume mechanism.
**/
extern __aosl_api__ int aosl_ref_destroy_exec_args (aosl_ref_t ref, aosl_ref_t ares, aosl_ref_destroy_exec_f f, uintptr_t argc, va_list args);
/**
* Execute the specified function asynchronously in thread pool before destroying
* the reference object specified by ref, this function supports coroutine.
* Parameters:
* ref: the reference object id;
* ares: ares object if you want to wait the execution of function f,
* specify AOSL_REF_INVALID when you do not want to wait;
* f: the target function which will be executed in thread pool
* after destroyed the ref object;
* argc: the args count;
* argv: variable args vector;
* Return value:
* 0: success
* <0: failed, and aosl_errno indicates what error occurs
* Remarks:
* If ares is AOSL_REF_INVALID and the invoking thread is an mpq thread,
* then this function will support coroutine resume mechanism.
**/
extern __aosl_api__ int aosl_ref_destroy_exec_argv (aosl_ref_t ref, aosl_ref_t ares, aosl_ref_destroy_exec_f f, uintptr_t argc, uintptr_t argv []);
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_REF_H__ */

View File

@@ -0,0 +1,122 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jul 27th, 2020
* Module: AOSL POSIX definitions header file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2020 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_TYPES_H__
#define __AOSL_TYPES_H__
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <inttypes.h>
#if defined (__linux__) || defined (__MACH__) || defined (__kliteos2__) || defined (_WIN32)
#include <sys/types.h>
#if defined (__linux__) || defined (__MACH__)
#include <sys/uio.h>
#endif
#endif
#include <aosl/api/aosl_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#if !defined (__linux__) && !defined (__MACH__)
/**
* Worry about some guy would like to define a macro
* for this type, so confirm that it is not a macro.
* -- Lionfore Hao Nov 5th, 2018
**/
#ifndef __ssize_t_defined
typedef intptr_t ssize_t;
#define __ssize_t_defined
#endif
#endif
/* The AOSL timestamp type */
typedef unsigned long long aosl_ts_t;
/* The proto for a general aosl var args function with argc & argv. */
typedef void (*aosl_argv_f) (uintptr_t argc, uintptr_t argv []);
/* The proto for a general aosl object destructor function. */
typedef aosl_argv_f aosl_obj_dtor_t;
#if !defined (_WIN32) && !defined (__kspreadtrum__)
typedef int aosl_fd_t;
#define AOSL_INVALID_FD ((aosl_fd_t)-1)
static __inline__ int aosl_fd_invalid (aosl_fd_t fd)
{
return (int)(fd < 0);
}
#else
#if defined (_WIN32)
/**
* We MUST include 'winsock2.h' before any occurrence
* of including 'windows.h', the fucking Windows has
* the fucking issue that many definitions would be
* complained redefinition if not so.
* -- Lionfore Hao Sep 25th, 2018
**/
#include <winsock2.h>
#include <windows.h>
typedef HANDLE aosl_fd_t;
#define AOSL_INVALID_FD ((aosl_fd_t)INVALID_HANDLE_VALUE)
#elif defined (__kspreadtrum__)
#include <DAPS/export/inc/tcpip6/socket_types.h>
#include <DAPS/export/inc/tcpip6/socket_api.h>
typedef TCPIP_SOCKET_T aosl_fd_t;
#define AOSL_INVALID_FD ((aosl_fd_t)-1)
#endif
static __inline__ int aosl_fd_invalid (aosl_fd_t fd)
{
return (int)(fd == AOSL_INVALID_FD);
}
#endif
#ifndef _WIN32
typedef aosl_fd_t aosl_sk_t;
#define AOSL_INVALID_SK AOSL_INVALID_FD
#else
typedef SOCKET aosl_sk_t;
#define AOSL_INVALID_SK ((aosl_sk_t)INVALID_SOCKET)
#endif
#if !defined (_WIN32) && !defined (__kspreadtrum__)
typedef struct iovec aosl_miov_t;
#else
typedef struct {
void *iov_base;
size_t iov_len;
} aosl_miov_t;
#endif
#ifndef UIO_MAXIOV
#define UIO_MAXIOV 1024
#endif
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_TYPES_H__ */

View File

@@ -0,0 +1,35 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jul 26th, 2018
* Module: AOSL version definitions.
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 Agora IO
* All rights reserved.
*
************************************************************/
#ifndef __AOSL_VERSION_H__
#define __AOSL_VERSION_H__
#include <aosl/api/aosl_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
extern __aosl_api__ const char *aosl_get_version ();
extern __aosl_api__ const char *aosl_get_git_branch ();
extern __aosl_api__ const char *aosl_get_git_commit ();
#ifdef __cplusplus
}
#endif
#endif /* __AOSL_VERSION_H__ */

View File

@@ -0,0 +1,91 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jun 23rd, 2023
* Module: AOSL async result object for C++ definition file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 ~ 2023 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_ARES_CLASS_H__
#define __AOSL_ARES_CLASS_H__
#include <stdlib.h>
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#include <aosl/api/aosl_ref.h>
#include <aosl/api/aosl_ares.h>
#include <aosl/api/cpp/aosl_ref_class.h>
class aosl_ares_class: public aosl_ref_class {
public:
aosl_ares_class (): aosl_ref_class (aosl_ares_create (this))
{
if (aosl_ref_invalid (ref ()))
abort ();
}
/**
* The destructor of this class is very different with
* base class and other derivatives, destroy the ref
* in the destructor and the destructor is public.
**/
virtual ~aosl_ares_class ()
{
aosl_ref_t refid = ref ();
if (!aosl_ref_invalid (refid))
aosl_ref_destroy (refid, true);
}
/* complete the async result */
int complete (intptr_t result = 0)
{
return aosl_ares_complete (ref (), result);
}
/* wait the async result to be completed */
int wait (intptr_t timeo, intptr_t *result = NULL)
{
return aosl_ares_wait (ref (), timeo, result);
}
/* reset the signaled state */
int reset (void)
{
return aosl_ares_reset (ref ());
}
operator aosl_ref_t () const
{
return ref ();
}
private:
/* we do not allow invoke the destroy function of base class */
int destroy (bool do_delete = true)
{
abort ();
return 0;
}
#if (__cplusplus >= 201103) || (defined (_MSC_VER) && _MSC_VER >= 1800)
private:
aosl_ares_class (const aosl_ares_class &) = delete;
aosl_ares_class (aosl_ares_class &&) = delete;
aosl_ares_class &operator = (const aosl_ares_class &) = delete;
aosl_ares_class &operator = (aosl_ares_class &&) = delete;
#else
private:
aosl_ares_class (const aosl_ares_class &);
aosl_ares_class &operator = (const aosl_ares_class &);
#endif /* C++11 */
};
#endif /* __AOSL_ARES_CLASS_H__ */

View File

@@ -0,0 +1,134 @@
/*************************************************************
* Author: Lionfore Hao (haolianfu@agora.io)
* Date : Jun 23rd, 2023
* Module: AOSL poll functionality for C++ definition file
*
*
* This is a part of the Advanced Operating System Layer.
* Copyright (C) 2018 ~ 2023 Agora IO
* All rights reserved.
*
*************************************************************/
#ifndef __AOSL_POLL_CLASS_H__
#define __AOSL_POLL_CLASS_H__
#include <aosl/api/aosl_types.h>
#include <aosl/api/aosl_defs.h>
#include <aosl/api/aosl_ref.h>
#include <aosl/api/aosl_poll.h>
#include <aosl/api/cpp/aosl_ares_class.h>
#if (__cplusplus >= 201103) || (defined (_MSC_VER) && _MSC_VER >= 1800)
#include <memory>
#endif
#include <map>
#include <vector>
class aosl_poll_class {
private:
std::map<aosl_ref_t, const aosl_ares_class *> poll_refs;
std::vector<const aosl_ares_class *> signaled_refs;
public:
void add (const aosl_ares_class &tail)
{
poll_refs [tail.ref ()] = &tail;
}
#if (__cplusplus >= 201103) || (defined (_MSC_VER) && _MSC_VER >= 1800)
template <class T, class ...Targs>
void add (const T &head, const Targs&... rest)
{
poll_refs [head.ref ()] = &head;
add (rest...);
}
/* constructor with variable args */
template <class ...Targs>
aosl_poll_class (Targs&... args)
{
add (args...);
}
#endif /* C++11 */
aosl_poll_class (const aosl_ares_class * const areses [], size_t count)
{
size_t i;
for (i = 0; i < count; i++)
add (*areses [i]);
}
/* poll the constructed async results */
int poll (size_t min, intptr_t timeo)
{
aosl_ref_t local_refs [32];
aosl_ref_t *refs = local_refs;
size_t count = poll_refs.size ();
std::map<aosl_ref_t, const aosl_ares_class *>::iterator it;
int i;
int err;
if (count > sizeof local_refs / sizeof local_refs [0]) {
refs = new aosl_ref_t [count];
if (refs == NULL)
return -1;
}
i = 0;
for (it = poll_refs.begin (); it != poll_refs.end (); it++)
refs [i++] = it->first;
err = aosl_poll (refs, count, min, timeo);
signaled_refs.clear ();
for (i = 0; i < err; i++) {
it = poll_refs.find (refs [i]);
if (it != poll_refs.end ())
signaled_refs.push_back (it->second);
}
if (refs != local_refs)
delete [] refs;
return err;
}
/* total async results count */
size_t total ()
{
return poll_refs.size ();
}
/* signaled async results count */
size_t signaled ()
{
return signaled_refs.size ();
}
/* operator for accessing the signaled async results */
const aosl_ares_class *operator [] (size_t idx)
{
if (idx < signaled_refs.size ())
return signaled_refs [idx];
return NULL;
}
#if (__cplusplus >= 201103) || (defined (_MSC_VER) && _MSC_VER >= 1800)
private:
aosl_poll_class (const aosl_poll_class &) = delete;
aosl_poll_class (aosl_poll_class &&) = delete;
aosl_poll_class &operator = (const aosl_poll_class &) = delete;
aosl_poll_class &operator = (aosl_poll_class &&) = delete;
#else
private:
aosl_poll_class (const aosl_poll_class &);
aosl_poll_class &operator = (const aosl_poll_class &);
#endif
};
#endif /* __AOSL_POLL_CLASS_H__ */

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>aosl</string>
<key>CFBundleIdentifier</key>
<string>io.agora.aosl</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>aosl</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.2.13</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2022 Agora IO. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>