Merge pull request #1256 from emoose/enumerate-fix

[Kernel] Remove item limit from enumerators, fixes #1255
This commit is contained in:
Rick Gibbed 2018-11-07 19:32:07 -06:00 committed by GitHub
commit dc3ae5c2cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 22 deletions

View File

@ -158,7 +158,7 @@ SHIM_CALL XamContentResolve_shim(PPCContext* ppc_context,
dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id,
dword_t content_type,
dword_t content_flags,
dword_t max_count,
dword_t items_per_enumerate,
lpdword_t buffer_size_ptr,
lpdword_t handle_out) {
assert_not_null(handle_out);
@ -173,11 +173,11 @@ dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id,
}
if (buffer_size_ptr) {
*buffer_size_ptr = (uint32_t)XCONTENT_DATA::kSize * max_count;
*buffer_size_ptr = (uint32_t)XCONTENT_DATA::kSize * items_per_enumerate;
}
auto e =
new XStaticEnumerator(kernel_state(), max_count, XCONTENT_DATA::kSize);
auto e = new XStaticEnumerator(kernel_state(), items_per_enumerate,
XCONTENT_DATA::kSize);
e->Initialize();
// Get all content data.
@ -187,14 +187,13 @@ dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id,
content_type);
for (auto& content_data : content_datas) {
auto ptr = e->AppendItem();
if (!ptr) {
// Too many items.
break;
}
assert_not_null(ptr);
content_data.Write(ptr);
}
XELOGD("XamContentCreateEnumerator: added %d items to enumerator",
e->item_count());
*handle_out = e->handle();
return X_ERROR_SUCCESS;
}

View File

@ -12,10 +12,10 @@
namespace xe {
namespace kernel {
XEnumerator::XEnumerator(KernelState* kernel_state, size_t item_capacity,
XEnumerator::XEnumerator(KernelState* kernel_state, size_t items_per_enumerate,
size_t item_size)
: XObject(kernel_state, kTypeEnumerator),
item_capacity_(item_capacity),
items_per_enumerate_(items_per_enumerate),
item_size_(item_size) {}
XEnumerator::~XEnumerator() = default;

View File

@ -23,7 +23,7 @@ class XEnumerator : public XObject {
public:
static const Type kType = kTypeEnumerator;
XEnumerator(KernelState* kernel_state, size_t item_capacity,
XEnumerator(KernelState* kernel_state, size_t items_per_enumerate,
size_t item_size);
virtual ~XEnumerator();
@ -34,30 +34,28 @@ class XEnumerator : public XObject {
virtual bool WriteItem(uint8_t* buffer) = 0;
size_t item_size() const { return item_size_; }
size_t items_per_enumerate() const { return items_per_enumerate_; }
size_t current_item() const { return current_item_; }
protected:
size_t item_capacity_ = 0;
size_t items_per_enumerate_ = 0;
size_t item_size_ = 0;
size_t current_item_ = 0;
};
class XStaticEnumerator : public XEnumerator {
public:
XStaticEnumerator(KernelState* kernel_state, size_t item_capacity,
XStaticEnumerator(KernelState* kernel_state, size_t items_per_enumerate,
size_t item_size)
: XEnumerator(kernel_state, item_capacity, item_size), item_count_(0) {
buffer_.resize(item_capacity_ * item_size_);
}
: XEnumerator(kernel_state, items_per_enumerate, item_size),
item_count_(0) {}
uint32_t item_count() const override { return item_count_; }
uint8_t* AppendItem() {
if (item_count_ + 1 > item_capacity_) {
return nullptr;
}
auto ptr = const_cast<uint8_t*>(buffer_.data() + item_count_ * item_size_);
++item_count_;
buffer_.resize(++item_count_ * item_size_);
auto ptr =
const_cast<uint8_t*>(buffer_.data() + (item_count_ - 1) * item_size_);
return ptr;
}