kernel: Use KernelReferenceable for the supplementary_groups array.
Instead of the malloc_referenced system. Makes for some cleaner code, and the malloc_referenced system was only used here, so it can now be dropped altogether.
This commit is contained in:
@@ -201,6 +201,12 @@ typedef int32 (*thread_entry_func)(thread_func, void *);
|
|||||||
namespace BKernel {
|
namespace BKernel {
|
||||||
|
|
||||||
|
|
||||||
|
struct GroupsArray : KernelReferenceable {
|
||||||
|
int count;
|
||||||
|
gid_t groups[];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename IDType>
|
template<typename IDType>
|
||||||
struct TeamThreadIteratorEntry
|
struct TeamThreadIteratorEntry
|
||||||
: DoublyLinkedListLinkImpl<TeamThreadIteratorEntry<IDType> > {
|
: DoublyLinkedListLinkImpl<TeamThreadIteratorEntry<IDType> > {
|
||||||
@@ -287,8 +293,7 @@ struct Team : TeamThreadIteratorEntry<team_id>, KernelReferenceable,
|
|||||||
gid_t saved_set_gid;
|
gid_t saved_set_gid;
|
||||||
gid_t real_gid;
|
gid_t real_gid;
|
||||||
gid_t effective_gid;
|
gid_t effective_gid;
|
||||||
gid_t* supplementary_groups;
|
BReference<GroupsArray> supplementary_groups;
|
||||||
int supplementary_group_count;
|
|
||||||
|
|
||||||
// Exit status information. Set when the first terminal event occurs,
|
// Exit status information. Set when the first terminal event occurs,
|
||||||
// immutable afterwards. Protected by fLock.
|
// immutable afterwards. Protected by fLock.
|
||||||
|
|||||||
@@ -462,9 +462,6 @@ Team::Team(team_id id, bool kernel)
|
|||||||
|
|
||||||
commpage_address = NULL;
|
commpage_address = NULL;
|
||||||
|
|
||||||
supplementary_groups = NULL;
|
|
||||||
supplementary_group_count = 0;
|
|
||||||
|
|
||||||
dead_threads_kernel_time = 0;
|
dead_threads_kernel_time = 0;
|
||||||
dead_threads_user_time = 0;
|
dead_threads_user_time = 0;
|
||||||
cpu_clock_offset = 0;
|
cpu_clock_offset = 0;
|
||||||
@@ -541,8 +538,6 @@ Team::~Team()
|
|||||||
free(entry);
|
free(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
malloc_referenced_release(supplementary_groups);
|
|
||||||
|
|
||||||
delete job_control_entry;
|
delete job_control_entry;
|
||||||
// usually already NULL and transferred to the parent
|
// usually already NULL and transferred to the parent
|
||||||
|
|
||||||
@@ -2872,7 +2867,6 @@ team_init(kernel_args* args)
|
|||||||
sKernelTeam->real_gid = 0;
|
sKernelTeam->real_gid = 0;
|
||||||
sKernelTeam->effective_gid = 0;
|
sKernelTeam->effective_gid = 0;
|
||||||
sKernelTeam->supplementary_groups = NULL;
|
sKernelTeam->supplementary_groups = NULL;
|
||||||
sKernelTeam->supplementary_group_count = 0;
|
|
||||||
|
|
||||||
insert_team_into_group(group, sKernelTeam);
|
insert_team_into_group(group, sKernelTeam);
|
||||||
|
|
||||||
|
|||||||
@@ -169,8 +169,13 @@ common_getgroups(int groupCount, gid_t* groupList, bool kernel)
|
|||||||
|
|
||||||
TeamLocker teamLocker(team);
|
TeamLocker teamLocker(team);
|
||||||
|
|
||||||
const gid_t* groups = team->supplementary_groups;
|
const gid_t* groups = NULL;
|
||||||
int actualCount = team->supplementary_group_count;
|
int actualCount = 0;
|
||||||
|
|
||||||
|
if (team->supplementary_groups != NULL) {
|
||||||
|
groups = team->supplementary_groups->groups;
|
||||||
|
actualCount = team->supplementary_groups->count;
|
||||||
|
}
|
||||||
|
|
||||||
// follow the specification and return always at least one group
|
// follow the specification and return always at least one group
|
||||||
if (actualCount == 0) {
|
if (actualCount == 0) {
|
||||||
@@ -207,36 +212,36 @@ common_setgroups(int groupCount, const gid_t* groupList, bool kernel)
|
|||||||
if (groupCount < 0 || groupCount > NGROUPS_MAX)
|
if (groupCount < 0 || groupCount > NGROUPS_MAX)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
gid_t* newGroups = NULL;
|
BKernel::GroupsArray* newGroups = NULL;
|
||||||
if (groupCount > 0) {
|
if (groupCount > 0) {
|
||||||
newGroups = (gid_t*)malloc_referenced(sizeof(gid_t) * groupCount);
|
newGroups = (BKernel::GroupsArray*)malloc(sizeof(BKernel::GroupsArray)
|
||||||
|
+ (sizeof(gid_t) * groupCount));
|
||||||
if (newGroups == NULL)
|
if (newGroups == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
new(newGroups) BKernel::GroupsArray;
|
||||||
|
|
||||||
if (kernel) {
|
if (kernel) {
|
||||||
memcpy(newGroups, groupList, sizeof(gid_t) * groupCount);
|
memcpy(newGroups->groups, groupList, sizeof(gid_t) * groupCount);
|
||||||
} else {
|
} else {
|
||||||
if (!IS_USER_ADDRESS(groupList)
|
if (!IS_USER_ADDRESS(groupList)
|
||||||
|| user_memcpy(newGroups, groupList,
|
|| user_memcpy(newGroups->groups, groupList,
|
||||||
sizeof(gid_t) * groupCount) != B_OK) {
|
sizeof(gid_t) * groupCount) != B_OK) {
|
||||||
malloc_referenced_release(newGroups);
|
delete newGroups;
|
||||||
return B_BAD_ADDRESS;
|
return B_BAD_ADDRESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
newGroups->count = groupCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
Team* team = thread_get_current_thread()->team;
|
Team* team = thread_get_current_thread()->team;
|
||||||
|
|
||||||
TeamLocker teamLocker(team);
|
TeamLocker teamLocker(team);
|
||||||
|
|
||||||
gid_t* toFree = team->supplementary_groups;
|
BReference<BKernel::GroupsArray> previous = team->supplementary_groups;
|
||||||
team->supplementary_groups = newGroups;
|
// so it will not be (potentially) destroyed until after we unlock
|
||||||
team->supplementary_group_count = groupCount;
|
team->supplementary_groups.SetTo(newGroups, true);
|
||||||
|
|
||||||
teamLocker.Unlock();
|
teamLocker.Unlock();
|
||||||
|
|
||||||
malloc_referenced_release(toFree);
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,10 +261,7 @@ inherit_parent_user_and_group(Team* team, Team* parent)
|
|||||||
team->saved_set_gid = parent->saved_set_gid;
|
team->saved_set_gid = parent->saved_set_gid;
|
||||||
team->real_gid = parent->real_gid;
|
team->real_gid = parent->real_gid;
|
||||||
team->effective_gid = parent->effective_gid;
|
team->effective_gid = parent->effective_gid;
|
||||||
|
|
||||||
malloc_referenced_acquire(parent->supplementary_groups);
|
|
||||||
team->supplementary_groups = parent->supplementary_groups;
|
team->supplementary_groups = parent->supplementary_groups;
|
||||||
team->supplementary_group_count = parent->supplementary_group_count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user