Skip to content
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

kernel: add CONST_BAG_HEADER #3884

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 2 deletions src/gasman.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static void CANARY_ALLOW_ACCESS_BAG(Bag bag)
Int bagLength = SIZE_BAG(bag);
VALGRIND_MAKE_MEM_DEFINED(ptr, bagLength);

BagHeader * header = BAG_HEADER(bag);
const BagHeader * header = CONST_BAG_HEADER(bag);
VALGRIND_MAKE_MEM_DEFINED(
header, sizeof(*header) - sizeof(header->memory_canary_padding));
}
Expand All @@ -554,7 +554,7 @@ static void CANARY_FORBID_ACCESS_BAG(Bag bag)
Int bagLength = SIZE_BAG(bag);
VALGRIND_MAKE_MEM_NOACCESS(ptr, bagLength);

BagHeader * header = BAG_HEADER(bag);
const BagHeader * header = CONST_BAG_HEADER(bag);
VALGRIND_MAKE_MEM_NOACCESS(
header, sizeof(*header) - sizeof(header->memory_canary_padding));
}
Expand Down
26 changes: 19 additions & 7 deletions src/gasman.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ enum {
/****************************************************************************
**
*F BAG_HEADER(<bag>) . . . . . . . . . . . . . . . . . . . . header of a bag
*F CONST_BAG_HEADER(<bag>) . . . . . . . . . . . . read-only header of a bag
**
** 'BAG_HEADER' returns the header of the bag with the identifier <bag>.
*/
EXPORT_INLINE BagHeader * BAG_HEADER(Bag bag)
{
GAP_ASSERT(bag);
return (((BagHeader *)*bag) - 1);
return ((*(BagHeader **)bag) - 1);
}

EXPORT_INLINE const BagHeader * CONST_BAG_HEADER(Bag bag)
{
GAP_ASSERT(bag);
return ((*(const BagHeader **)bag) - 1);
}


Expand All @@ -136,7 +143,7 @@ EXPORT_INLINE BagHeader * BAG_HEADER(Bag bag)
*/
EXPORT_INLINE UInt TNUM_BAG(Bag bag)
{
return BAG_HEADER(bag)->type;
return CONST_BAG_HEADER(bag)->type;
}


Expand Down Expand Up @@ -168,7 +175,7 @@ EXPORT_INLINE UInt TNUM_BAG(Bag bag)
*/
EXPORT_INLINE uint8_t TEST_BAG_FLAG(Bag bag, uint8_t flag)
{
return BAG_HEADER(bag)->flags & flag;
return CONST_BAG_HEADER(bag)->flags & flag;
}

EXPORT_INLINE void SET_BAG_FLAG(Bag bag, uint8_t flag)
Expand All @@ -181,6 +188,7 @@ EXPORT_INLINE void CLEAR_BAG_FLAG(Bag bag, uint8_t flag)
BAG_HEADER(bag)->flags &= ~flag;
}


/****************************************************************************
**
*F IS_BAG_REF(<bag>) . . . . . . verify that <bag> is a valid bag identifier
Expand Down Expand Up @@ -209,8 +217,9 @@ EXPORT_INLINE BOOL IS_BAG_REF(Obj bag)
** the size of a bag when it allocates it with 'NewBag' and may later change
** it with 'ResizeBag' (see "NewBag" and "ResizeBag").
*/
EXPORT_INLINE UInt SIZE_BAG(Bag bag) {
return BAG_HEADER(bag)->size;
EXPORT_INLINE UInt SIZE_BAG(Bag bag)
{
return CONST_BAG_HEADER(bag)->size;
}


Expand All @@ -223,7 +232,8 @@ EXPORT_INLINE UInt SIZE_BAG(Bag bag) {
** atomic operations that require a memory barrier in between dereferencing
** the bag pointer and accessing the contents of the bag.
*/
EXPORT_INLINE UInt SIZE_BAG_CONTENTS(const void *ptr) {
EXPORT_INLINE UInt SIZE_BAG_CONTENTS(const void *ptr)
{
return ((const BagHeader *)ptr)[-1].size;
}

Expand All @@ -244,7 +254,9 @@ EXPORT_INLINE UInt SIZE_BAG_CONTENTS(const void *ptr) {

/****************************************************************************
**
*F PTR_BAG(<bag>) . . . . . . . . . . . . . . . . . . . . pointer to a bag
*F PTR_BAG(<bag>) . . . . . . . . . . . . . . . . . . . . . pointer to a bag
*F CONST_PTR_BAG(<bag>) . . . . . . . . . . . . . read-only pointer to a bag
*F SET_PTR_BAG(<bag>) . . . . . . . . . . . . . . . set the pointer to a bag
**
** 'PTR_BAG' returns the address of the data area of the bag with identifier
** <bag>. Using this pointer the application can then read data from the
Expand Down
4 changes: 2 additions & 2 deletions src/weakptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ static inline void SET_ELM_WPOBJ(Obj list, UInt pos, Obj val)
}
if (!IS_BAG_REF(ptr[pos])) {
ptr[pos] = (Bag)jl_gc_new_weakref((jl_value_t *)val);
jl_gc_wb_back(BAG_HEADER(list));
jl_gc_wb_back(CONST_BAG_HEADER(list));
}
else {
jl_weakref_t * wref = (jl_weakref_t *)(ptr[pos]);
wref->value = (jl_value_t *)val;
jl_gc_wb(wref, BAG_HEADER(val));
jl_gc_wb(wref, CONST_BAG_HEADER(val));
}
#endif
}
Expand Down